MediaCodecInfo: add codec attributes and performance points.
Bug: 112374531
Bug: 119631295
Bug: 112370870
Change-Id: Icf8db614a616bd5c815bc272093ce77d05eb4406
diff --git a/api/current.txt b/api/current.txt
index 4026404..ccc6293 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -24138,6 +24138,7 @@
method public int dequeueOutputBuffer(android.media.MediaCodec.BufferInfo, long);
method protected void finalize();
method public void flush();
+ method public java.lang.String getCanonicalName();
method public android.media.MediaCodecInfo getCodecInfo();
method public java.nio.ByteBuffer getInputBuffer(int);
method public deprecated java.nio.ByteBuffer[] getInputBuffers();
@@ -24264,10 +24265,15 @@
}
public final class MediaCodecInfo {
+ method public java.lang.String getCanonicalName();
method public android.media.MediaCodecInfo.CodecCapabilities getCapabilitiesForType(java.lang.String);
method public java.lang.String getName();
method public java.lang.String[] getSupportedTypes();
+ method public boolean isAlias();
method public boolean isEncoder();
+ method public boolean isHardwareAccelerated();
+ method public boolean isSoftwareOnly();
+ method public boolean isVendor();
}
public static final class MediaCodecInfo.AudioCapabilities {
@@ -24343,7 +24349,10 @@
field public static final deprecated int COLOR_QCOM_FormatYUV420SemiPlanar = 2141391872; // 0x7fa30c00
field public static final deprecated int COLOR_TI_FormatYUV420PackedSemiPlanar = 2130706688; // 0x7f000100
field public static final java.lang.String FEATURE_AdaptivePlayback = "adaptive-playback";
+ field public static final java.lang.String FEATURE_DynamicTimestamp = "dynamic-timestamp";
+ field public static final java.lang.String FEATURE_FrameParsing = "frame-parsing";
field public static final java.lang.String FEATURE_IntraRefresh = "intra-refresh";
+ field public static final java.lang.String FEATURE_MultipleFrames = "multiple-frames";
field public static final java.lang.String FEATURE_PartialFrame = "partial-frame";
field public static final java.lang.String FEATURE_SecurePlayback = "secure-playback";
field public static final java.lang.String FEATURE_TunneledPlayback = "tunneled-playback";
@@ -24544,12 +24553,53 @@
method public android.util.Range<java.lang.Double> getSupportedFrameRatesFor(int, int);
method public android.util.Range<java.lang.Integer> getSupportedHeights();
method public android.util.Range<java.lang.Integer> getSupportedHeightsFor(int);
+ method public java.util.List<android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint> getSupportedPerformancePoints();
method public android.util.Range<java.lang.Integer> getSupportedWidths();
method public android.util.Range<java.lang.Integer> getSupportedWidthsFor(int);
method public int getWidthAlignment();
method public boolean isSizeSupported(int, int);
}
+ public static final class MediaCodecInfo.VideoCapabilities.PerformancePoint {
+ method public boolean covers(android.media.MediaFormat);
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint FHD_100;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint FHD_120;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint FHD_200;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint FHD_24;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint FHD_240;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint FHD_25;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint FHD_30;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint FHD_50;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint FHD_60;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint HD_100;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint HD_120;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint HD_200;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint HD_24;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint HD_240;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint HD_25;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint HD_30;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint HD_50;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint HD_60;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint SD_24;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint SD_25;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint SD_30;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint SD_48;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint SD_50;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint SD_60;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint UHD_100;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint UHD_120;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint UHD_200;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint UHD_24;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint UHD_240;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint UHD_25;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint UHD_30;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint UHD_50;
+ field public static final android.media.MediaCodecInfo.VideoCapabilities.PerformancePoint UHD_60;
+ field public final int frameRate;
+ field public final int height;
+ field public final int width;
+ }
+
public final class MediaCodecList {
ctor public MediaCodecList(int);
method public java.lang.String findDecoderForFormat(android.media.MediaFormat);
diff --git a/media/java/android/media/MediaCodec.java b/media/java/android/media/MediaCodec.java
index bc9500d..f756658 100644
--- a/media/java/android/media/MediaCodec.java
+++ b/media/java/android/media/MediaCodec.java
@@ -1829,9 +1829,14 @@
mBufferLock = new Object();
+ // save name used at creation
+ mNameAtCreation = nameIsType ? null : name;
+
native_setup(name, nameIsType, encoder);
}
+ private String mNameAtCreation;
+
@Override
protected void finalize() {
native_finalize();
@@ -3317,12 +3322,36 @@
private native void native_setAudioPresentation(int presentationId, int programId);
/**
- * Get the component name. If the codec was created by createDecoderByType
- * or createEncoderByType, what component is chosen is not known beforehand.
+ * Retrieve the codec name.
+ *
+ * If the codec was created by createDecoderByType or createEncoderByType, what component is
+ * chosen is not known beforehand. This method returns the name of the codec that was
+ * selected by the platform.
+ *
+ * <strong>Note:</strong> Implementations may provide multiple aliases (codec
+ * names) for the same underlying codec, any of which can be used to instantiate the same
+ * underlying codec in {@link MediaCodec#createByCodecName}. This method returns the
+ * name used to create the codec in this case.
+ *
* @throws IllegalStateException if in the Released state.
*/
@NonNull
- public native final String getName();
+ public final String getName() {
+ // get canonical name to handle exception
+ String canonicalName = getCanonicalName();
+ return mNameAtCreation != null ? mNameAtCreation : canonicalName;
+ }
+
+ /**
+ * Retrieve the underlying codec name.
+ *
+ * This method is similar to {@link #getName}, except that it returns the underlying component
+ * name even if an alias was used to create this MediaCodec object by name,
+ *
+ * @throws IllegalStateException if in the Released state.
+ */
+ @NonNull
+ public native final String getCanonicalName();
/**
* Return Metrics data about the current codec instance.
diff --git a/media/java/android/media/MediaCodecInfo.java b/media/java/android/media/MediaCodecInfo.java
index 10a1e3a..368ab5e 100644
--- a/media/java/android/media/MediaCodecInfo.java
+++ b/media/java/android/media/MediaCodecInfo.java
@@ -32,8 +32,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.Vector;
/**
* Provides information about a given media codec available on the device. You can
@@ -61,15 +63,25 @@
*
*/
public final class MediaCodecInfo {
- private boolean mIsEncoder;
+ private static final String TAG = "MediaCodecInfo";
+
+ private static final int FLAG_IS_ENCODER = (1 << 0);
+ private static final int FLAG_IS_VENDOR = (1 << 1);
+ private static final int FLAG_IS_SOFTWARE_ONLY = (1 << 2);
+ private static final int FLAG_IS_HARDWARE_ACCELERATED = (1 << 3);
+
+ private int mFlags;
private String mName;
+ private String mCanonicalName;
private Map<String, CodecCapabilities> mCaps;
/* package private */ MediaCodecInfo(
- String name, boolean isEncoder, CodecCapabilities[] caps) {
+ String name, String canonicalName, int flags, CodecCapabilities[] caps) {
mName = name;
- mIsEncoder = isEncoder;
+ mCanonicalName = canonicalName;
+ mFlags = flags;
mCaps = new HashMap<String, CodecCapabilities>();
+
for (CodecCapabilities c: caps) {
mCaps.put(c.getMimeType(), c);
}
@@ -77,16 +89,69 @@
/**
* Retrieve the codec name.
+ *
+ * <strong>Note:</strong> Implementations may provide multiple aliases (codec
+ * names) for the same underlying codec, any of which can be used to instantiate the same
+ * underlying codec in {@link MediaCodec#createByCodecName}.
+ *
+ * Applications targeting SDK < {@link android.os.Build.VERSION_CODES#Q}, cannot determine if
+ * the multiple codec names listed in MediaCodecList are in-fact for the same codec.
*/
+ @NonNull
public final String getName() {
return mName;
}
/**
+ * Retrieve the underlying codec name.
+ *
+ * Device implementations may provide multiple aliases (codec names) for the same underlying
+ * codec to maintain backward app compatibility. This method returns the name of the underlying
+ * codec name, which must not be another alias. For non-aliases this is always the name of the
+ * codec.
+ */
+ @NonNull
+ public final String getCanonicalName() {
+ return mCanonicalName;
+ }
+
+ /**
+ * Query if the codec is an alias for another underlying codec.
+ */
+ public final boolean isAlias() {
+ return !mName.equals(mCanonicalName);
+ }
+
+ /**
* Query if the codec is an encoder.
*/
public final boolean isEncoder() {
- return mIsEncoder;
+ return (mFlags & FLAG_IS_ENCODER) != 0;
+ }
+
+ /**
+ * Query if the codec is provided by the Android platform (false) or the device manufacturer
+ * (true).
+ */
+ public final boolean isVendor() {
+ return (mFlags & FLAG_IS_VENDOR) != 0;
+ }
+
+ /**
+ * Query if the codec is software only. Software-only codecs are more secure as they run in
+ * a tighter security sandbox. On the other hand, software-only codecs do not provide any
+ * performance guarantees.
+ */
+ public final boolean isSoftwareOnly() {
+ return (mFlags & FLAG_IS_SOFTWARE_ONLY) != 0;
+ }
+
+ /**
+ * Query if the codec is hardware accelerated. This attribute is provided by the device
+ * manufacturer. Note that it cannot be tested for correctness.
+ */
+ public final boolean isHardwareAccelerated() {
+ return (mFlags & FLAG_IS_HARDWARE_ACCELERATED) != 0;
}
/**
@@ -462,6 +527,26 @@
public static final String FEATURE_TunneledPlayback = "tunneled-playback";
/**
+ * If true, the timestamp of each output buffer is derived from the timestamp of the input
+ * buffer that produced the output. If false, the timestamp of each output buffer is
+ * derived from the timestamp of the first input buffer.
+ */
+ public static final String FEATURE_DynamicTimestamp = "dynamic-timestamp";
+
+ /**
+ * <b>decoder only</b>If true, the codec supports partial (including multiple) access units
+ * per input buffer.
+ */
+ public static final String FEATURE_FrameParsing = "frame-parsing";
+
+ /**
+ * If true, the codec supports multiple access units (for decoding, or to output for
+ * encoders). If false, the codec only supports single access units. Producing multiple
+ * access units for output is an optional feature.
+ */
+ public static final String FEATURE_MultipleFrames = "multiple-frames";
+
+ /**
* <b>video decoder only</b>: codec supports queuing partial frames.
*/
public static final String FEATURE_PartialFrame = "partial-frame";
@@ -497,10 +582,15 @@
new Feature(FEATURE_SecurePlayback, (1 << 1), false),
new Feature(FEATURE_TunneledPlayback, (1 << 2), false),
new Feature(FEATURE_PartialFrame, (1 << 3), false),
+ new Feature(FEATURE_FrameParsing, (1 << 4), false),
+ new Feature(FEATURE_MultipleFrames, (1 << 5), false),
+ new Feature(FEATURE_DynamicTimestamp, (1 << 6), false),
};
private static final Feature[] encoderFeatures = {
new Feature(FEATURE_IntraRefresh, (1 << 0), false),
+ new Feature(FEATURE_MultipleFrames, (1 << 1), false),
+ new Feature(FEATURE_DynamicTimestamp, (1 << 2), false),
};
/** @hide */
@@ -869,7 +959,7 @@
CodecCapabilities ret = new CodecCapabilities(
new CodecProfileLevel[] { pl }, new int[0], true /* encoder */,
- 0 /* flags */, defaultFormat, new MediaFormat() /* info */);
+ defaultFormat, new MediaFormat() /* info */);
if (ret.mError != 0) {
return null;
}
@@ -878,10 +968,10 @@
/* package private */ CodecCapabilities(
CodecProfileLevel[] profLevs, int[] colFmts,
- boolean encoder, int flags,
+ boolean encoder,
Map<String, Object>defaultFormatMap,
Map<String, Object>capabilitiesMap) {
- this(profLevs, colFmts, encoder, flags,
+ this(profLevs, colFmts, encoder,
new MediaFormat(defaultFormatMap),
new MediaFormat(capabilitiesMap));
}
@@ -889,11 +979,11 @@
private MediaFormat mCapabilitiesInfo;
/* package private */ CodecCapabilities(
- CodecProfileLevel[] profLevs, int[] colFmts, boolean encoder, int flags,
+ CodecProfileLevel[] profLevs, int[] colFmts, boolean encoder,
MediaFormat defaultFormat, MediaFormat info) {
final Map<String, Object> map = info.getMap();
colorFormats = colFmts;
- mFlagsVerified = flags;
+ mFlagsVerified = 0; // TODO: remove as it is unused
mDefaultFormat = defaultFormat;
mCapabilitiesInfo = info;
mMime = mDefaultFormat.getString(MediaFormat.KEY_MIME);
@@ -1243,6 +1333,7 @@
private Range<Rational> mBlockAspectRatioRange;
private Range<Long> mBlocksPerSecondRange;
private Map<Size, Range<Long>> mMeasuredFrameRates;
+ private Vector<PerformancePoint> mPerformancePoints;
private Range<Integer> mFrameRateRange;
private int mBlockWidth;
@@ -1524,6 +1615,158 @@
}
/**
+ * Video performance points are a set of standard performance points defined by pixel rate.
+ */
+ public static final class PerformancePoint {
+ /**
+ * Frame width in pixels.
+ */
+ public final int width;
+
+ /**
+ * Frame height in pixels.
+ */
+ public final int height;
+
+ /**
+ * Frame rate in frames per second.
+ */
+ public final int frameRate;
+
+ /* package private */
+ PerformancePoint(int width_, int height_, int frameRate_) {
+ width = width_;
+ height = height_;
+ frameRate = frameRate_;
+ }
+
+ /**
+ * Checks whether the performance point covers a media format.
+ *
+ * @param format Stream format considered
+ *
+ * @return {@code true} if the performance point covers the format.
+ */
+ public boolean covers(@NonNull MediaFormat format) {
+ // for simplicity, this code assumes a 16x16 block size.
+ long macroBlocks = ((width + 15) / 16) * (long)((height + 15) / 16);
+ long mbps = macroBlocks * frameRate;
+
+ long formatMacroBlocks =
+ (long)((format.getInteger(MediaFormat.KEY_WIDTH, 0) + 15) / 16)
+ * ((format.getInteger(MediaFormat.KEY_HEIGHT, 0) + 15) / 16);
+ double formatMbps =
+ Math.ceil(formatMacroBlocks
+ * format.getNumber(MediaFormat.KEY_FRAME_RATE, 0).doubleValue());
+ return formatMacroBlocks > 0 && formatMacroBlocks <= macroBlocks
+ && formatMbps <= mbps;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof PerformancePoint) {
+ PerformancePoint other = (PerformancePoint)o;
+ return ((long)width * height) == ((long)other.width * other.height)
+ && frameRate == other.frameRate;
+ }
+ return false;
+ }
+
+ /** 480p 24fps */
+ public static final PerformancePoint SD_24 = new PerformancePoint(720, 480, 24);
+ /** 576p 25fps */
+ public static final PerformancePoint SD_25 = new PerformancePoint(720, 576, 25);
+ /** 480p 30fps */
+ public static final PerformancePoint SD_30 = new PerformancePoint(720, 480, 30);
+ /** 480p 48fps */
+ public static final PerformancePoint SD_48 = new PerformancePoint(720, 480, 48);
+ /** 576p 50fps */
+ public static final PerformancePoint SD_50 = new PerformancePoint(720, 576, 50);
+ /** 480p 60fps */
+ public static final PerformancePoint SD_60 = new PerformancePoint(720, 480, 60);
+
+ /** 720p 24fps */
+ public static final PerformancePoint HD_24 = new PerformancePoint(1280, 720, 24);
+ /** 720p 25fps */
+ public static final PerformancePoint HD_25 = new PerformancePoint(1280, 720, 25);
+ /** 720p 30fps */
+ public static final PerformancePoint HD_30 = new PerformancePoint(1280, 720, 30);
+ /** 720p 50fps */
+ public static final PerformancePoint HD_50 = new PerformancePoint(1280, 720, 50);
+ /** 720p 60fps */
+ public static final PerformancePoint HD_60 = new PerformancePoint(1280, 720, 60);
+ /** 720p 100fps */
+ public static final PerformancePoint HD_100 = new PerformancePoint(1280, 720, 100);
+ /** 720p 120fps */
+ public static final PerformancePoint HD_120 = new PerformancePoint(1280, 720, 120);
+ /** 720p 200fps */
+ public static final PerformancePoint HD_200 = new PerformancePoint(1280, 720, 200);
+ /** 720p 240fps */
+ public static final PerformancePoint HD_240 = new PerformancePoint(1280, 720, 240);
+
+ /** 1080p 24fps */
+ public static final PerformancePoint FHD_24 = new PerformancePoint(1920, 1080, 24);
+ /** 1080p 25fps */
+ public static final PerformancePoint FHD_25 = new PerformancePoint(1920, 1080, 25);
+ /** 1080p 30fps */
+ public static final PerformancePoint FHD_30 = new PerformancePoint(1920, 1080, 30);
+ /** 1080p 50fps */
+ public static final PerformancePoint FHD_50 = new PerformancePoint(1920, 1080, 50);
+ /** 1080p 60fps */
+ public static final PerformancePoint FHD_60 = new PerformancePoint(1920, 1080, 60);
+ /** 1080p 100fps */
+ public static final PerformancePoint FHD_100 = new PerformancePoint(1920, 1080, 100);
+ /** 1080p 120fps */
+ public static final PerformancePoint FHD_120 = new PerformancePoint(1920, 1080, 120);
+ /** 1080p 200fps */
+ public static final PerformancePoint FHD_200 = new PerformancePoint(1920, 1080, 200);
+ /** 1080p 240fps */
+ public static final PerformancePoint FHD_240 = new PerformancePoint(1920, 1080, 240);
+
+ /** 2160p 24fps */
+ public static final PerformancePoint UHD_24 = new PerformancePoint(3840, 2160, 24);
+ /** 2160p 25fps */
+ public static final PerformancePoint UHD_25 = new PerformancePoint(3840, 2160, 25);
+ /** 2160p 30fps */
+ public static final PerformancePoint UHD_30 = new PerformancePoint(3840, 2160, 30);
+ /** 2160p 50fps */
+ public static final PerformancePoint UHD_50 = new PerformancePoint(3840, 2160, 50);
+ /** 2160p 60fps */
+ public static final PerformancePoint UHD_60 = new PerformancePoint(3840, 2160, 60);
+ /** 2160p 100fps */
+ public static final PerformancePoint UHD_100 = new PerformancePoint(3840, 2160, 100);
+ /** 2160p 120fps */
+ public static final PerformancePoint UHD_120 = new PerformancePoint(3840, 2160, 120);
+ /** 2160p 200fps */
+ public static final PerformancePoint UHD_200 = new PerformancePoint(3840, 2160, 200);
+ /** 2160p 240fps */
+ public static final PerformancePoint UHD_240 = new PerformancePoint(3840, 2160, 240);
+ }
+
+ /**
+ * Returns the supported performance points. May return {@code null} if the codec did not
+ * publish any performance point information (e.g. the vendor codecs have not been updated
+ * to the latest android release). May return an empty list if the codec published that
+ * if does not guarantee any performance points.
+ * <p>
+ * This is a performance guarantee provided by the device manufacturer for hardware codecs
+ * based on hardware capabilities of the device.
+ * <p>
+ * The returned list is sorted first by decreasing number of pixels, then by decreasing
+ * width, and finally by decreasing frame rate.
+ * Performance points assume a single active codec. For use cases where multiple
+ * codecs are active, should use that highest pixel count, and add the frame rates of
+ * each individual codec.
+ */
+ @Nullable
+ public List<PerformancePoint> getSupportedPerformancePoints() {
+ if (mPerformancePoints == null) {
+ return null;
+ }
+ return new ArrayList<PerformancePoint>(mPerformancePoints);
+ }
+
+ /**
* Returns whether a given video size ({@code width} and
* {@code height}) and {@code frameRate} combination is supported.
*/
@@ -1659,6 +1902,50 @@
mSmallerDimensionUpperLimit = SIZE_RANGE.getUpper();
}
+ private @Nullable Vector<PerformancePoint> getPerformancePoints(Map<String, Object> map) {
+ Vector<PerformancePoint> ret = new Vector<>();
+ final String prefix = "performance-point-";
+ Set<String> keys = map.keySet();
+ for (String key : keys) {
+ // looking for: performance-point-WIDTHxHEIGHT-range
+ if (!key.startsWith(prefix)) {
+ continue;
+ }
+ String subKey = key.substring(prefix.length());
+ if (subKey.equals("none") && ret.size() == 0) {
+ // This means that component knowingly did not publish performance points.
+ // This is different from when the component forgot to publish performance
+ // points.
+ return ret;
+ }
+ String[] temp = key.split("-");
+ if (temp.length != 4) {
+ continue;
+ }
+ String sizeStr = temp[2];
+ Size size = Utils.parseSize(sizeStr, null);
+ if (size == null || size.getWidth() * size.getHeight() <= 0) {
+ continue;
+ }
+ Range<Long> range = Utils.parseLongRange(map.get(key), null);
+ if (range == null || range.getLower() < 0 || range.getUpper() < 0) {
+ continue;
+ }
+ ret.add(new PerformancePoint(
+ size.getWidth(), size.getHeight(), range.getLower().intValue()));
+ }
+ // check if the component specified no performance point indication
+ if (ret.size() == 0) {
+ return null;
+ }
+
+ // sort reversed by area first, then by frame rate
+ ret.sort((a, b) -> (a.width * a.height != b.width * b.height ?
+ (b.width * b.height - a.width * a.height) :
+ (b.frameRate - a.frameRate)));
+ return ret;
+ }
+
private Map<Size, Range<Long>> getMeasuredFrameRates(Map<String, Object> map) {
Map<Size, Range<Long>> ret = new HashMap<Size, Range<Long>>();
final String prefix = "measured-frame-rate-";
@@ -1770,6 +2057,7 @@
blockRates =
Utils.parseLongRange(map.get("blocks-per-second-range"), null);
mMeasuredFrameRates = getMeasuredFrameRates(map);
+ mPerformancePoints = getPerformancePoints(map);
Pair<Range<Integer>, Range<Integer>> sizeRanges =
parseWidthHeightRanges(map.get("size-range"));
if (sizeRanges != null) {
@@ -3157,7 +3445,7 @@
}
return new MediaCodecInfo(
- mName, mIsEncoder,
+ mName, mCanonicalName, mFlags,
caps.toArray(new CodecCapabilities[caps.size()]));
}
}
diff --git a/media/java/android/media/MediaCodecList.java b/media/java/android/media/MediaCodecList.java
index 2e47865..a460954 100644
--- a/media/java/android/media/MediaCodecList.java
+++ b/media/java/android/media/MediaCodecList.java
@@ -111,12 +111,14 @@
caps[typeIx++] = getCodecCapabilities(index, type);
}
return new MediaCodecInfo(
- getCodecName(index), isEncoder(index), caps);
+ getCodecName(index), getCanonicalName(index), getAttributes(index), caps);
}
/* package private */ static native final String getCodecName(int index);
- /* package private */ static native final boolean isEncoder(int index);
+ /* package private */ static native final String getCanonicalName(int index);
+
+ /* package private */ static native final int getAttributes(int index);
/* package private */ static native final String[] getSupportedTypes(int index);
diff --git a/media/jni/android_media_MediaCodec.cpp b/media/jni/android_media_MediaCodec.cpp
index 7b07bea3..9c51996 100644
--- a/media/jni/android_media_MediaCodec.cpp
+++ b/media/jni/android_media_MediaCodec.cpp
@@ -648,7 +648,6 @@
capabilities->getSupportedColorFormats(&colorFormats);
capabilities->getSupportedProfileLevels(&profileLevels);
- uint32_t flags = capabilities->getFlags();
sp<AMessage> details = capabilities->getDetails();
jobject defaultFormatObj = NULL;
@@ -687,7 +686,7 @@
return env->NewObject(
gCodecInfo.capsClazz, gCodecInfo.capsCtorId,
- profileLevelArray.get(), colorFormatsArray.get(), isEncoder, flags,
+ profileLevelArray.get(), colorFormatsArray.get(), isEncoder,
defaultFormatRef.get(), detailsRef.get());
}
@@ -700,23 +699,28 @@
return err;
}
+ // TODO: get alias
ScopedLocalRef<jstring> nameObject(env,
env->NewStringUTF(codecInfo->getCodecName()));
+ ScopedLocalRef<jstring> canonicalNameObject(env,
+ env->NewStringUTF(codecInfo->getCodecName()));
+
+ MediaCodecInfo::Attributes attributes = codecInfo->getAttributes();
bool isEncoder = codecInfo->isEncoder();
- Vector<AString> mimes;
- codecInfo->getSupportedMimes(&mimes);
+ Vector<AString> mediaTypes;
+ codecInfo->getSupportedMediaTypes(&mediaTypes);
ScopedLocalRef<jobjectArray> capsArrayObj(env,
- env->NewObjectArray(mimes.size(), gCodecInfo.capsClazz, NULL));
+ env->NewObjectArray(mediaTypes.size(), gCodecInfo.capsClazz, NULL));
- for (size_t i = 0; i < mimes.size(); i++) {
+ for (size_t i = 0; i < mediaTypes.size(); i++) {
const sp<MediaCodecInfo::Capabilities> caps =
- codecInfo->getCapabilitiesFor(mimes[i].c_str());
+ codecInfo->getCapabilitiesFor(mediaTypes[i].c_str());
ScopedLocalRef<jobject> capsObj(env, getCodecCapabilitiesObject(
- env, mimes[i].c_str(), isEncoder, caps));
+ env, mediaTypes[i].c_str(), isEncoder, caps));
env->SetObjectArrayElement(capsArrayObj.get(), i, capsObj.get());
}
@@ -729,7 +733,7 @@
"(Ljava/lang/String;Z[Landroid/media/MediaCodecInfo$CodecCapabilities;)V");
*codecInfoObject = env->NewObject(codecInfoClazz.get(), codecInfoCtorID,
- nameObject.get(), isEncoder, capsArrayObj.get());
+ nameObject.get(), canonicalNameObject.get(), attributes, capsArrayObj.get());
return OK;
}
@@ -2079,7 +2083,7 @@
gCodecInfo.capsClazz = (jclass)env->NewGlobalRef(clazz.get());
method = env->GetMethodID(clazz.get(), "<init>",
- "([Landroid/media/MediaCodecInfo$CodecProfileLevel;[IZI"
+ "([Landroid/media/MediaCodecInfo$CodecProfileLevel;[IZ"
"Ljava/util/Map;Ljava/util/Map;)V");
CHECK(method != NULL);
gCodecInfo.capsCtorId = method;
@@ -2217,7 +2221,7 @@
{ "getImage", "(ZI)Landroid/media/Image;",
(void *)android_media_MediaCodec_getImage },
- { "getName", "()Ljava/lang/String;",
+ { "getCanonicalName", "()Ljava/lang/String;",
(void *)android_media_MediaCodec_getName },
{ "getOwnCodecInfo", "()Landroid/media/MediaCodecInfo;",
diff --git a/media/jni/android_media_MediaCodecList.cpp b/media/jni/android_media_MediaCodecList.cpp
index 8de11ca..cf14942 100644
--- a/media/jni/android_media_MediaCodecList.cpp
+++ b/media/jni/android_media_MediaCodecList.cpp
@@ -41,6 +41,21 @@
return mcl;
}
+static sp<MediaCodecInfo> getCodecInfo(JNIEnv *env, jint index) {
+ sp<IMediaCodecList> mcl = getCodecList(env);
+ if (mcl == NULL) {
+ // Runtime exception already pending.
+ return NULL;
+ }
+
+ sp<MediaCodecInfo> info = mcl->getCodecInfo(index);
+ if (info == NULL) {
+ jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
+ }
+
+ return info;
+}
+
static jint android_media_MediaCodecList_getCodecCount(
JNIEnv *env, jobject /* thiz */) {
sp<IMediaCodecList> mcl = getCodecList(env);
@@ -53,15 +68,22 @@
static jstring android_media_MediaCodecList_getCodecName(
JNIEnv *env, jobject /* thiz */, jint index) {
- sp<IMediaCodecList> mcl = getCodecList(env);
- if (mcl == NULL) {
+ sp<MediaCodecInfo> info = getCodecInfo(env, index);
+ if (info == NULL) {
// Runtime exception already pending.
return NULL;
}
- const sp<MediaCodecInfo> &info = mcl->getCodecInfo(index);
+ // TODO: support aliases
+ const char *name = info->getCodecName();
+ return env->NewStringUTF(name);
+}
+
+static jstring android_media_MediaCodecList_getCanonicalName(
+ JNIEnv *env, jobject /* thiz */, jint index) {
+ sp<MediaCodecInfo> info = getCodecInfo(env, index);
if (info == NULL) {
- jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
+ // Runtime exception already pending.
return NULL;
}
@@ -94,39 +116,27 @@
return ret;
}
-static jboolean android_media_MediaCodecList_isEncoder(
+static jboolean android_media_MediaCodecList_getAttributes(
JNIEnv *env, jobject /* thiz */, jint index) {
- sp<IMediaCodecList> mcl = getCodecList(env);
- if (mcl == NULL) {
- // Runtime exception already pending.
- return false;
- }
-
- const sp<MediaCodecInfo> &info = mcl->getCodecInfo(index);
+ sp<MediaCodecInfo> info = getCodecInfo(env, index);
if (info == NULL) {
- jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
- return false;
+ // Runtime exception already pending.
+ return 0;
}
- return info->isEncoder();
+ return info->getAttributes();
}
static jarray android_media_MediaCodecList_getSupportedTypes(
JNIEnv *env, jobject /* thiz */, jint index) {
- sp<IMediaCodecList> mcl = getCodecList(env);
- if (mcl == NULL) {
+ sp<MediaCodecInfo> info = getCodecInfo(env, index);
+ if (info == NULL) {
// Runtime exception already pending.
return NULL;
}
- const sp<MediaCodecInfo> &info = mcl->getCodecInfo(index);
- if (info == NULL) {
- jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
- return NULL;
- }
-
Vector<AString> types;
- info->getSupportedMimes(&types);
+ info->getSupportedMediaTypes(&types);
jclass clazz = env->FindClass("java/lang/String");
CHECK(clazz != NULL);
@@ -150,17 +160,12 @@
return NULL;
}
- sp<IMediaCodecList> mcl = getCodecList(env);
- if (mcl == NULL) {
+ sp<MediaCodecInfo> info = getCodecInfo(env, index);
+ if (info == NULL) {
// Runtime exception already pending.
return NULL;
}
- const sp<MediaCodecInfo> &info = mcl->getCodecInfo(index);
- if (info == NULL) {
- jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
- return NULL;
- }
const char *typeStr = env->GetStringUTFChars(type, NULL);
if (typeStr == NULL) {
@@ -186,7 +191,6 @@
capabilities->getSupportedColorFormats(&colorFormats);
capabilities->getSupportedProfileLevels(&profileLevels);
- uint32_t flags = capabilities->getFlags();
sp<AMessage> details = capabilities->getDetails();
bool isEncoder = info->isEncoder();
@@ -240,11 +244,11 @@
}
jmethodID capsConstructID = env->GetMethodID(capsClazz, "<init>",
- "([Landroid/media/MediaCodecInfo$CodecProfileLevel;[IZI"
+ "([Landroid/media/MediaCodecInfo$CodecProfileLevel;[IZ"
"Ljava/util/Map;Ljava/util/Map;)V");
jobject caps = env->NewObject(capsClazz, capsConstructID,
- profileLevelArray, colorFormatsArray, isEncoder, flags,
+ profileLevelArray, colorFormatsArray, isEncoder,
defaultFormatObj, infoObj);
env->DeleteLocalRef(profileLevelArray);
@@ -288,9 +292,15 @@
static const JNINativeMethod gMethods[] = {
{ "native_getCodecCount", "()I", (void *)android_media_MediaCodecList_getCodecCount },
+
+ { "getCanonicalName", "(I)Ljava/lang/String;",
+ (void *)android_media_MediaCodecList_getCanonicalName },
+
{ "getCodecName", "(I)Ljava/lang/String;",
(void *)android_media_MediaCodecList_getCodecName },
- { "isEncoder", "(I)Z", (void *)android_media_MediaCodecList_isEncoder },
+
+ { "getAttributes", "(I)I", (void *)android_media_MediaCodecList_getAttributes },
+
{ "getSupportedTypes", "(I)[Ljava/lang/String;",
(void *)android_media_MediaCodecList_getSupportedTypes },