Ensure MediaCodecHelper is initialized before evaluating codecs

This commit is contained in:
Cameron Gutman 2017-11-21 19:27:08 -08:00
parent a56689aea3
commit bfa5a6349e
2 changed files with 19 additions and 0 deletions

View File

@ -38,6 +38,7 @@ public class MediaCodecHelper {
private static final List<String> refFrameInvalidationHevcPrefixes;
private static boolean isLowEndSnapdragon = false;
private static boolean initialized = false;
static {
directSubmitPrefixes = new LinkedList<>();
@ -171,6 +172,10 @@ public class MediaCodecHelper {
}
public static void initialize(Context context, String glRenderer) {
if (initialized) {
return;
}
ActivityManager activityManager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo configInfo = activityManager.getDeviceConfigurationInfo();
@ -214,9 +219,15 @@ public class MediaCodecHelper {
blacklistedDecoderPrefixes.add("OMX.qcom.video.decoder.hevc");
}
}
initialized = true;
}
private static boolean isDecoderInList(List<String> decoderList, String decoderName) {
if (!initialized) {
throw new IllegalStateException("MediaCodecHelper must be initialized before use");
}
for (String badPrefix : decoderList) {
if (decoderName.length() >= badPrefix.length()) {
String prefix = decoderName.substring(0, badPrefix.length());
@ -374,6 +385,10 @@ public class MediaCodecHelper {
// because we want to evaluate the decoders in our list's order
// rather than MediaCodecList's order
if (!initialized) {
throw new IllegalStateException("MediaCodecHelper must be initialized before use");
}
for (String preferredDecoder : preferredDecoders) {
for (MediaCodecInfo codecInfo : getMediaCodecList()) {
// Skip encoders

View File

@ -134,6 +134,10 @@ public class StreamSettings extends Activity {
}
}
// This must be called to do runtime initialization before calling functions that evaluate
// decoder lists.
MediaCodecHelper.initialize(getContext(), GlPreferences.readPreferences(getContext()).glRenderer);
MediaCodecInfo avcDecoder = MediaCodecHelper.findProbableSafeDecoder("video/avc", -1);
MediaCodecInfo hevcDecoder = MediaCodecHelper.findProbableSafeDecoder("video/hevc", -1);