Search in sources :

Example 6 with MediaCodecInfo

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);
}
Also used : MediaCodecInfo(androidx.media3.exoplayer.mediacodec.MediaCodecInfo) SuppressLint(android.annotation.SuppressLint) RendererCapabilities(androidx.media3.exoplayer.RendererCapabilities)

Example 7 with MediaCodecInfo

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();
}
Also used : Format(androidx.media3.common.Format) Test(org.junit.Test)

Example 8 with MediaCodecInfo

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();
}
Also used : Format(androidx.media3.common.Format) Test(org.junit.Test)

Example 9 with MediaCodecInfo

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));
}
Also used : Format(androidx.media3.common.Format) DecoderReuseEvaluation(androidx.media3.exoplayer.DecoderReuseEvaluation) Test(org.junit.Test)

Example 10 with MediaCodecInfo

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));
}
Also used : DecoderReuseEvaluation(androidx.media3.exoplayer.DecoderReuseEvaluation) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)21 Format (androidx.media3.common.Format)20 DecoderReuseEvaluation (androidx.media3.exoplayer.DecoderReuseEvaluation)14 SuppressLint (android.annotation.SuppressLint)8 Nullable (androidx.annotation.Nullable)6 MediaCodecInfo (androidx.media3.exoplayer.mediacodec.MediaCodecInfo)6 Point (android.graphics.Point)5 MediaFormat (android.media.MediaFormat)3 DecoderDiscardReasons (androidx.media3.exoplayer.DecoderReuseEvaluation.DecoderDiscardReasons)3 CodecCapabilities (android.media.MediaCodecInfo.CodecCapabilities)2 RendererCapabilities (androidx.media3.exoplayer.RendererCapabilities)2 MediaCodecInfo (android.media.MediaCodecInfo)1 Surface (android.view.Surface)1 CallSuper (androidx.annotation.CallSuper)1 DrmInitData (androidx.media3.common.DrmInitData)1 FrameworkCryptoConfig (androidx.media3.exoplayer.drm.FrameworkCryptoConfig)1 MediaCodecAdapter (androidx.media3.exoplayer.mediacodec.MediaCodecAdapter)1 DecoderQueryException (androidx.media3.exoplayer.mediacodec.MediaCodecUtil.DecoderQueryException)1 GtsTestUtil.shouldSkipWidevineTest (androidx.media3.test.exoplayer.playback.gts.GtsTestUtil.shouldSkipWidevineTest)1 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)1