diff --git a/media/java/android/media/MediaCodecInfo.java b/media/java/android/media/MediaCodecInfo.java index 72fb1e9cad709..70029a3dad109 100644 --- a/media/java/android/media/MediaCodecInfo.java +++ b/media/java/android/media/MediaCodecInfo.java @@ -750,6 +750,9 @@ public final class MediaCodecInfo { * Retrieve the codec capabilities for a certain {@code mime type}, {@code * profile} and {@code level}. If the type, or profile-level combination * is not understood by the framework, it returns null. + *

In {@link android.os.Build.VERSION_CODES#M}, calling this + * method without calling any method of the {@link MediaCodecList} class beforehand + * results in a {@link NullPointerException}.

*/ public static CodecCapabilities createFromProfileLevel( String mime, int profile, int level) { diff --git a/media/java/android/media/MediaCodecList.java b/media/java/android/media/MediaCodecList.java index cd7b3d35a5907..42ce5110f134b 100644 --- a/media/java/android/media/MediaCodecList.java +++ b/media/java/android/media/MediaCodecList.java @@ -63,6 +63,11 @@ final public class MediaCodecList { } /* package private */ static final Map getGlobalSettings() { + synchronized (sInitLock) { + if (sGlobalSettings == null) { + sGlobalSettings = native_getGlobalSettings(); + } + } return sGlobalSettings; } @@ -74,7 +79,6 @@ final public class MediaCodecList { private static final void initCodecList() { synchronized (sInitLock) { if (sRegularCodecInfos == null) { - sGlobalSettings = native_getGlobalSettings(); int count = native_getCodecCount(); ArrayList regulars = new ArrayList(); ArrayList all = new ArrayList();