Add MediaCodecSelector.getPassthroughDecoderInfo.

Issue: #1518
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=122157463
This commit is contained in:
olly 2016-05-12 08:01:36 -07:00 committed by Oliver Woodman
parent 180d10334a
commit 7301b53829
3 changed files with 24 additions and 20 deletions

View file

@ -170,7 +170,7 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem
if (!MimeTypes.isAudio(mimeType)) {
return FORMAT_UNSUPPORTED_TYPE;
}
if (allowPassthrough(mimeType) && mediaCodecSelector.getPassthroughDecoderName() != null) {
if (allowPassthrough(mimeType) && mediaCodecSelector.getPassthroughDecoderInfo() != null) {
return ADAPTIVE_NOT_SEAMLESS | FORMAT_HANDLED;
}
// TODO[REFACTOR]: If requiresSecureDecryption then we should probably also check that the
@ -194,10 +194,10 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem
protected DecoderInfo getDecoderInfo(MediaCodecSelector mediaCodecSelector, Format format,
boolean requiresSecureDecoder) throws DecoderQueryException {
if (allowPassthrough(format.sampleMimeType)) {
String passthroughDecoderName = mediaCodecSelector.getPassthroughDecoderName();
if (passthroughDecoderName != null) {
DecoderInfo passthroughDecoderInfo = mediaCodecSelector.getPassthroughDecoderInfo();
if (passthroughDecoderInfo != null) {
passthroughEnabled = true;
return new DecoderInfo(passthroughDecoderName);
return passthroughDecoderInfo;
}
}
passthroughEnabled = false;

View file

@ -29,11 +29,6 @@ public interface MediaCodecSelector {
*/
MediaCodecSelector DEFAULT = new MediaCodecSelector() {
/**
* The name for the raw (passthrough) decoder OMX component.
*/
private static final String RAW_DECODER_NAME = "OMX.google.raw.decoder";
@Override
public DecoderInfo getDecoderInfo(String mimeType, boolean requiresSecureDecoder)
throws DecoderQueryException {
@ -41,9 +36,8 @@ public interface MediaCodecSelector {
}
@Override
public String getPassthroughDecoderName() throws DecoderQueryException {
// TODO: Return null if the raw decoder doesn't exist.
return RAW_DECODER_NAME;
public DecoderInfo getPassthroughDecoderInfo() throws DecoderQueryException {
return MediaCodecUtil.getPassthroughDecoderInfo();
}
};
@ -53,20 +47,18 @@ public interface MediaCodecSelector {
*
* @param mimeType The mime type for which a decoder is required.
* @param requiresSecureDecoder Whether a secure decoder is required.
* @return A {@link DecoderInfo} describing the decoder to instantiate, or null if no suitable
* decoder exists.
* @return A {@link DecoderInfo} describing the decoder, or null if no suitable decoder exists.
* @throws DecoderQueryException Thrown if there was an error querying decoders.
*/
DecoderInfo getDecoderInfo(String mimeType, boolean requiresSecureDecoder)
throws DecoderQueryException;
/**
* Gets the name of a decoder suitable for audio passthrough.
* Selects a decoder to instantiate for audio passthrough.
*
* @return The name of a decoder suitable for audio passthrough, or null if no suitable decoder
* exists.
* @return A {@link DecoderInfo} describing the decoder, or null if no suitable decoder exists.
* @throws DecoderQueryException Thrown if there was an error querying decoders.
*/
String getPassthroughDecoderName() throws DecoderQueryException;
DecoderInfo getPassthroughDecoderInfo() throws DecoderQueryException;
}

View file

@ -52,6 +52,8 @@ public final class MediaCodecUtil {
}
private static final String TAG = "MediaCodecUtil";
private static final DecoderInfo PASSTHROUGH_DECODER_INFO =
new DecoderInfo("OMX.google.raw.decoder", null);
private static final HashMap<CodecKey, List<DecoderInfo>> decoderInfosCache = new HashMap<>();
@ -79,12 +81,22 @@ public final class MediaCodecUtil {
}
/**
* Returns information about the decoder that will be used for a given mime type.
* Returns information about a decoder suitable for audio passthrough.
**
* @return A {@link DecoderInfo} describing the decoder, or null if no suitable decoder exists.
*/
public static DecoderInfo getPassthroughDecoderInfo() {
// TODO: Return null if the raw decoder doesn't exist.
return PASSTHROUGH_DECODER_INFO;
}
/**
* Returns information about the preferred decoder for a given mime type.
*
* @param mimeType The mime type.
* @param secure Whether the decoder is required to support secure decryption. Always pass false
* unless secure decryption really is required.
* @return Information about the decoder that will be used, or null if no decoder exists.
* @return A {@link DecoderInfo} describing the decoder, or null if no suitable decoder exists.
*/
public static DecoderInfo getDecoderInfo(String mimeType, boolean secure)
throws DecoderQueryException {