use of androidx.media3.exoplayer.mediacodec.MediaCodecInfo in project media by androidx.
the class MediaCodecAudioRenderer method supportsFormat.
@Override
@Capabilities
protected int supportsFormat(MediaCodecSelector mediaCodecSelector, Format format) throws DecoderQueryException {
if (!MimeTypes.isAudio(format.sampleMimeType)) {
return RendererCapabilities.create(C.FORMAT_UNSUPPORTED_TYPE);
}
@TunnelingSupport int tunnelingSupport = Util.SDK_INT >= 21 ? TUNNELING_SUPPORTED : TUNNELING_NOT_SUPPORTED;
boolean formatHasDrm = format.cryptoType != C.CRYPTO_TYPE_NONE;
boolean supportsFormatDrm = supportsFormatDrm(format);
// Else we don't don't need a decoder at all.
if (supportsFormatDrm && audioSink.supportsFormat(format) && (!formatHasDrm || MediaCodecUtil.getDecryptOnlyDecoderInfo() != null)) {
return RendererCapabilities.create(C.FORMAT_HANDLED, ADAPTIVE_NOT_SEAMLESS, tunnelingSupport);
}
// the input format directly.
if (MimeTypes.AUDIO_RAW.equals(format.sampleMimeType) && !audioSink.supportsFormat(format)) {
return RendererCapabilities.create(C.FORMAT_UNSUPPORTED_SUBTYPE);
}
// For all other input formats, we expect the decoder to output 16-bit PCM.
if (!audioSink.supportsFormat(Util.getPcmFormat(C.ENCODING_PCM_16BIT, format.channelCount, format.sampleRate))) {
return RendererCapabilities.create(C.FORMAT_UNSUPPORTED_SUBTYPE);
}
List<MediaCodecInfo> decoderInfos = getDecoderInfos(mediaCodecSelector, format, /* requiresSecureDecoder= */
false, audioSink);
if (decoderInfos.isEmpty()) {
return RendererCapabilities.create(C.FORMAT_UNSUPPORTED_SUBTYPE);
}
if (!supportsFormatDrm) {
return RendererCapabilities.create(C.FORMAT_UNSUPPORTED_DRM);
}
// Check whether the first decoder supports the format. This is the preferred decoder for the
// format's MIME type, according to the MediaCodecSelector.
MediaCodecInfo decoderInfo = decoderInfos.get(0);
boolean isFormatSupported = decoderInfo.isFormatSupported(format);
boolean isPreferredDecoder = true;
if (!isFormatSupported) {
// Check whether any of the other decoders support the format.
for (int i = 1; i < decoderInfos.size(); i++) {
MediaCodecInfo otherDecoderInfo = decoderInfos.get(i);
if (otherDecoderInfo.isFormatSupported(format)) {
decoderInfo = otherDecoderInfo;
isFormatSupported = true;
isPreferredDecoder = false;
break;
}
}
}
@C.FormatSupport int formatSupport = isFormatSupported ? C.FORMAT_HANDLED : C.FORMAT_EXCEEDS_CAPABILITIES;
@AdaptiveSupport int adaptiveSupport = isFormatSupported && decoderInfo.isSeamlessAdaptationSupported(format) ? ADAPTIVE_SEAMLESS : ADAPTIVE_NOT_SEAMLESS;
@HardwareAccelerationSupport int hardwareAccelerationSupport = decoderInfo.hardwareAccelerated ? HARDWARE_ACCELERATION_SUPPORTED : HARDWARE_ACCELERATION_NOT_SUPPORTED;
@DecoderSupport int decoderSupport = isPreferredDecoder ? DECODER_SUPPORT_PRIMARY : DECODER_SUPPORT_FALLBACK;
return RendererCapabilities.create(formatSupport, adaptiveSupport, tunnelingSupport, hardwareAccelerationSupport, decoderSupport);
}
use of androidx.media3.exoplayer.mediacodec.MediaCodecInfo in project media by androidx.
the class MediaCodecInfoTest method isSeamlessAdaptationSupported_noResolutionChange_nonAdaptiveCodec_returnsTrue.
@Test
@SuppressWarnings("deprecation")
public void isSeamlessAdaptationSupported_noResolutionChange_nonAdaptiveCodec_returnsTrue() {
MediaCodecInfo codecInfo = buildH264CodecInfo(/* adaptive= */
false);
Format hdVariantFormat = FORMAT_H264_HD.buildUpon().setInitializationData(ImmutableList.of(new byte[] { 0 })).build();
assertThat(codecInfo.isSeamlessAdaptationSupported(FORMAT_H264_HD, hdVariantFormat, /* isNewFormatComplete= */
true)).isTrue();
}
use of androidx.media3.exoplayer.mediacodec.MediaCodecInfo in project media by androidx.
the class MediaCodecInfoTest method isSeamlessAdaptationSupported_audioWithDifferentInitializationData_returnsFalse.
@Test
@SuppressWarnings("deprecation")
public void isSeamlessAdaptationSupported_audioWithDifferentInitializationData_returnsFalse() {
MediaCodecInfo codecInfo = buildAacCodecInfo();
Format stereoVariantFormat = FORMAT_AAC_STEREO.buildUpon().setInitializationData(ImmutableList.of(new byte[] { 0 })).build();
assertThat(codecInfo.isSeamlessAdaptationSupported(FORMAT_AAC_STEREO, stereoVariantFormat, /* isNewFormatComplete= */
true)).isFalse();
}
use of androidx.media3.exoplayer.mediacodec.MediaCodecInfo in project media by androidx.
the class MediaCodecInfoTest method canKeepCodec_colorInfoChange_returnsNo.
@Test
public void canKeepCodec_colorInfoChange_returnsNo() {
MediaCodecInfo codecInfo = buildH264CodecInfo(/* adaptive= */
false);
Format hdrVariantFormat1 = FORMAT_H264_4K.buildUpon().setColorInfo(buildColorInfo(C.COLOR_SPACE_BT601)).build();
Format hdrVariantFormat2 = FORMAT_H264_4K.buildUpon().setColorInfo(buildColorInfo(C.COLOR_SPACE_BT709)).build();
assertThat(codecInfo.canReuseCodec(hdrVariantFormat1, hdrVariantFormat2)).isEqualTo(new DecoderReuseEvaluation(codecInfo.name, hdrVariantFormat1, hdrVariantFormat2, REUSE_RESULT_NO, DISCARD_REASON_VIDEO_COLOR_INFO_CHANGED));
}
use of androidx.media3.exoplayer.mediacodec.MediaCodecInfo in project media by androidx.
the class MediaCodecInfoTest method canKeepCodec_withResolutionChange_adaptiveCodec_returnsYesWithReconfiguration.
@Test
public void canKeepCodec_withResolutionChange_adaptiveCodec_returnsYesWithReconfiguration() {
MediaCodecInfo codecInfo = buildH264CodecInfo(/* adaptive= */
true);
assertThat(codecInfo.canReuseCodec(FORMAT_H264_HD, FORMAT_H264_4K)).isEqualTo(new DecoderReuseEvaluation(codecInfo.name, FORMAT_H264_HD, FORMAT_H264_4K, REUSE_RESULT_YES_WITH_RECONFIGURATION, /* discardReasons= */
0));
}
Aggregations