Check full format support in decoder for Transformer

For the case where a hardware decoder does not fully
support the requested format, a software decoder will
be preferred.

PiperOrigin-RevId: 717584768
This commit is contained in:
sheenachhabra 2025-01-20 11:25:08 -08:00 committed by Copybara-Service
parent 6fe011beb4
commit 7c10ef03e4
3 changed files with 22 additions and 2 deletions

View File

@ -256,6 +256,26 @@ public final class MediaCodecUtil {
return decoderInfos;
}
/**
* Returns a copy of the provided decoder list sorted such that decoders with complete format
* support are listed first. The returned list is modifiable for convenience.
*/
@CheckResult
public static List<MediaCodecInfo> getDecoderInfosSortedByFullFormatSupport(
List<MediaCodecInfo> decoderInfos, Format format) {
decoderInfos = new ArrayList<>(decoderInfos);
sortByScore(
decoderInfos,
decoderInfo -> {
try {
return decoderInfo.isFormatSupported(format) ? 1 : 0;
} catch (DecoderQueryException e) {
return -1;
}
});
return decoderInfos;
}
/**
* Returns a copy of the provided decoder list sorted such that software decoders are listed
* first. Break ties by listing non-{@link MediaCodecInfo#vendor} decoders first, due to issues

View File

@ -1400,7 +1400,7 @@ public final class AndroidTestUtil {
private static String findDecoderForFormat(Format format)
throws MediaCodecUtil.DecoderQueryException {
List<androidx.media3.exoplayer.mediacodec.MediaCodecInfo> decoderInfoList =
MediaCodecUtil.getDecoderInfosSortedByFormatSupport(
MediaCodecUtil.getDecoderInfosSortedByFullFormatSupport(
MediaCodecUtil.getDecoderInfosSoftMatch(
MediaCodecSelector.DEFAULT,
format,

View File

@ -312,7 +312,7 @@ public final class DefaultDecoderFactory implements Codec.DecoderFactory {
checkNotNull(format.sampleMimeType);
try {
decoderInfos =
MediaCodecUtil.getDecoderInfosSortedByFormatSupport(
MediaCodecUtil.getDecoderInfosSortedByFullFormatSupport(
MediaCodecUtil.getDecoderInfosSoftMatch(
mediaCodecSelector,
format,