Commit c54b195a by andrewlewis Committed by Oliver Woodman

Allow applications to access codec capabilities

Issue: #3820

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=192115208
parent d4a03d3b
......@@ -22,6 +22,7 @@ import android.media.MediaCodecInfo.AudioCapabilities;
import android.media.MediaCodecInfo.CodecCapabilities;
import android.media.MediaCodecInfo.CodecProfileLevel;
import android.media.MediaCodecInfo.VideoCapabilities;
import android.support.annotation.Nullable;
import android.util.Log;
import android.util.Pair;
import com.google.android.exoplayer2.Format;
......@@ -38,6 +39,12 @@ public final class MediaCodecInfo {
public static final String TAG = "MediaCodecInfo";
/**
* The value returned by {@link #getMaxSupportedInstances()} if the upper bound on the maximum
* number of supported instances is unknown.
*/
public static final int MAX_SUPPORTED_INSTANCES_UNKNOWN = -1;
/**
* The name of the decoder.
* <p>
* May be passed to {@link MediaCodec#createByCodecName(String)} to create an instance of the
......@@ -69,8 +76,13 @@ public final class MediaCodecInfo {
*/
public final boolean secure;
/**
* The capabilities of the decoder, like the profiles/levels it supports, or {@code null} if this
* is a passthrough codec.
*/
public final @Nullable CodecCapabilities capabilities;
private final String mimeType;
private final CodecCapabilities capabilities;
/**
* Creates an instance representing an audio passthrough decoder.
......@@ -79,7 +91,12 @@ public final class MediaCodecInfo {
* @return The created instance.
*/
public static MediaCodecInfo newPassthroughInstance(String name) {
return new MediaCodecInfo(name, null, null, false, false);
return new MediaCodecInfo(
name,
/* mimeType= */ null,
/* capabilities= */ null,
/* forceDisableAdaptive= */ false,
/* forceSecure= */ false);
}
/**
......@@ -92,7 +109,8 @@ public final class MediaCodecInfo {
*/
public static MediaCodecInfo newInstance(String name, String mimeType,
CodecCapabilities capabilities) {
return new MediaCodecInfo(name, mimeType, capabilities, false, false);
return new MediaCodecInfo(
name, mimeType, capabilities, /* forceDisableAdaptive= */ false, /* forceSecure= */ false);
}
/**
......@@ -105,16 +123,24 @@ public final class MediaCodecInfo {
* @param forceSecure Whether {@link #secure} should be forced to {@code true}.
* @return The created instance.
*/
public static MediaCodecInfo newInstance(String name, String mimeType,
CodecCapabilities capabilities, boolean forceDisableAdaptive, boolean forceSecure) {
public static MediaCodecInfo newInstance(
String name,
String mimeType,
CodecCapabilities capabilities,
boolean forceDisableAdaptive,
boolean forceSecure) {
return new MediaCodecInfo(name, mimeType, capabilities, forceDisableAdaptive, forceSecure);
}
private MediaCodecInfo(String name, String mimeType, CodecCapabilities capabilities,
boolean forceDisableAdaptive, boolean forceSecure) {
private MediaCodecInfo(
String name,
String mimeType,
@Nullable CodecCapabilities capabilities,
boolean forceDisableAdaptive,
boolean forceSecure) {
this.name = Assertions.checkNotNull(name);
this.mimeType = mimeType;
this.capabilities = capabilities;
this.mimeType = mimeType;
adaptive = !forceDisableAdaptive && capabilities != null && isAdaptive(capabilities);
tunneling = capabilities != null && isTunneling(capabilities);
secure = forceSecure || (capabilities != null && isSecure(capabilities));
......@@ -131,6 +157,19 @@ public final class MediaCodecInfo {
}
/**
* Returns an upper bound on the maximum number of supported instances, or {@link
* #MAX_SUPPORTED_INSTANCES_UNKNOWN} if unknown. Applications should not expect to operate more
* instances than the returned maximum.
*
* @see CodecCapabilities#getMaxSupportedInstances()
*/
public int getMaxSupportedInstances() {
return (Util.SDK_INT < 23 || capabilities == null)
? MAX_SUPPORTED_INSTANCES_UNKNOWN
: getMaxSupportedInstancesV23(capabilities);
}
/**
* Whether the decoder supports the given {@code codec}. If there is insufficient information to
* decide, returns true.
*
......@@ -362,4 +401,8 @@ public final class MediaCodecInfo {
: capabilities.areSizeAndRateSupported(width, height, frameRate);
}
@TargetApi(23)
private static int getMaxSupportedInstancesV23(CodecCapabilities capabilities) {
return capabilities.getMaxSupportedInstances();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment