Search in sources :

Example 11 with CodecCapabilities

use of android.media.MediaCodecInfo.CodecCapabilities in project ExoPlayer by google.

the class MediaCodecVideoRendererTest method supportsFormat_withDolbyVisionMedia_returnsTrueWhenFallbackToH265orH264Allowed.

@Test
public void supportsFormat_withDolbyVisionMedia_returnsTrueWhenFallbackToH265orH264Allowed() throws Exception {
    // Create Dolby media formats that could fall back to H265 or H264.
    Format formatDvheDtrFallbackToH265 = new Format.Builder().setSampleMimeType(MimeTypes.VIDEO_DOLBY_VISION).setCodecs("dvhe.04.01").build();
    Format formatDvheStFallbackToH265 = new Format.Builder().setSampleMimeType(MimeTypes.VIDEO_DOLBY_VISION).setCodecs("dvhe.08.01").build();
    Format formatDvavSeFallbackToH264 = new Format.Builder().setSampleMimeType(MimeTypes.VIDEO_DOLBY_VISION).setCodecs("dvav.09.01").build();
    Format formatNoFallbackPossible = new Format.Builder().setSampleMimeType(MimeTypes.VIDEO_DOLBY_VISION).setCodecs("dvav.01.01").build();
    // Only provide H264 and H265 decoders with codec profiles needed for fallback.
    MediaCodecSelector mediaCodecSelector = (mimeType, requiresSecureDecoder, requiresTunnelingDecoder) -> {
        switch(mimeType) {
            case MimeTypes.VIDEO_H264:
                CodecCapabilities capabilitiesH264 = new CodecCapabilities();
                capabilitiesH264.profileLevels = new CodecProfileLevel[] { new CodecProfileLevel(), new CodecProfileLevel() };
                capabilitiesH264.profileLevels[0].profile = CodecProfileLevel.AVCProfileBaseline;
                capabilitiesH264.profileLevels[0].level = CodecProfileLevel.AVCLevel42;
                capabilitiesH264.profileLevels[1].profile = CodecProfileLevel.AVCProfileHigh;
                capabilitiesH264.profileLevels[1].level = CodecProfileLevel.AVCLevel42;
                return ImmutableList.of(MediaCodecInfo.newInstance(/* name= */
                "h264-codec", /* mimeType= */
                mimeType, /* codecMimeType= */
                mimeType, /* capabilities= */
                capabilitiesH264, /* hardwareAccelerated= */
                false, /* softwareOnly= */
                true, /* vendor= */
                false, /* forceDisableAdaptive= */
                false, /* forceSecure= */
                false));
            case MimeTypes.VIDEO_H265:
                CodecCapabilities capabilitiesH265 = new CodecCapabilities();
                capabilitiesH265.profileLevels = new CodecProfileLevel[] { new CodecProfileLevel(), new CodecProfileLevel() };
                capabilitiesH265.profileLevels[0].profile = CodecProfileLevel.HEVCProfileMain;
                capabilitiesH265.profileLevels[0].level = CodecProfileLevel.HEVCMainTierLevel41;
                capabilitiesH265.profileLevels[1].profile = CodecProfileLevel.HEVCProfileMain10;
                capabilitiesH265.profileLevels[1].level = CodecProfileLevel.HEVCHighTierLevel51;
                return ImmutableList.of(MediaCodecInfo.newInstance(/* name= */
                "h265-codec", /* mimeType= */
                mimeType, /* codecMimeType= */
                mimeType, /* capabilities= */
                capabilitiesH265, /* hardwareAccelerated= */
                false, /* softwareOnly= */
                true, /* vendor= */
                false, /* forceDisableAdaptive= */
                false, /* forceSecure= */
                false));
            default:
                return ImmutableList.of();
        }
    };
    MediaCodecVideoRenderer renderer = new MediaCodecVideoRenderer(ApplicationProvider.getApplicationContext(), mediaCodecSelector, /* allowedJoiningTimeMs= */
    0, /* eventHandler= */
    new Handler(testMainLooper), /* eventListener= */
    eventListener, /* maxDroppedFramesToNotify= */
    1);
    renderer.init(/* index= */
    0, PlayerId.UNSET);
    @Capabilities int capabilitiesDvheDtrFallbackToH265 = renderer.supportsFormat(formatDvheDtrFallbackToH265);
    @Capabilities int capabilitiesDvheStFallbackToH265 = renderer.supportsFormat(formatDvheStFallbackToH265);
    @Capabilities int capabilitiesDvavSeFallbackToH264 = renderer.supportsFormat(formatDvavSeFallbackToH264);
    @Capabilities int capabilitiesNoFallbackPossible = renderer.supportsFormat(formatNoFallbackPossible);
    assertThat(RendererCapabilities.getFormatSupport(capabilitiesDvheDtrFallbackToH265)).isEqualTo(C.FORMAT_HANDLED);
    assertThat(RendererCapabilities.getFormatSupport(capabilitiesDvheStFallbackToH265)).isEqualTo(C.FORMAT_HANDLED);
    assertThat(RendererCapabilities.getFormatSupport(capabilitiesDvavSeFallbackToH264)).isEqualTo(C.FORMAT_HANDLED);
    assertThat(RendererCapabilities.getFormatSupport(capabilitiesNoFallbackPossible)).isEqualTo(C.FORMAT_UNSUPPORTED_SUBTYPE);
}
Also used : ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) CodecProfileLevel(android.media.MediaCodecInfo.CodecProfileLevel) MediaFormat(android.media.MediaFormat) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) SystemClock(android.os.SystemClock) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) Shadows.shadowOf(org.robolectric.Shadows.shadowOf) ApplicationProvider(androidx.test.core.app.ApplicationProvider) Format(com.google.android.exoplayer2.Format) PlayerId(com.google.android.exoplayer2.analytics.PlayerId) MediaCodecInfo(com.google.android.exoplayer2.mediacodec.MediaCodecInfo) ArgumentCaptor(org.mockito.ArgumentCaptor) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) MimeTypes(com.google.android.exoplayer2.util.MimeTypes) ImmutableList(com.google.common.collect.ImmutableList) Handler(android.os.Handler) Looper(android.os.Looper) After(org.junit.After) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities) MockitoJUnit(org.mockito.junit.MockitoJUnit) FakeSampleStream(com.google.android.exoplayer2.testutil.FakeSampleStream) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) C(com.google.android.exoplayer2.C) Before(org.junit.Before) FakeSampleStreamItem.format(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.format) SurfaceTexture(android.graphics.SurfaceTexture) Capabilities(com.google.android.exoplayer2.RendererCapabilities.Capabilities) ShadowLooper(org.robolectric.shadows.ShadowLooper) END_OF_STREAM_ITEM(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM) Surface(android.view.Surface) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) FakeSampleStreamItem.oneByteSample(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.oneByteSample) Mockito.never(org.mockito.Mockito.never) Nullable(androidx.annotation.Nullable) Rule(org.junit.Rule) RendererConfiguration(com.google.android.exoplayer2.RendererConfiguration) MediaCodecSelector(com.google.android.exoplayer2.mediacodec.MediaCodecSelector) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) MockitoRule(org.mockito.junit.MockitoRule) Renderer(com.google.android.exoplayer2.Renderer) Collections(java.util.Collections) CodecProfileLevel(android.media.MediaCodecInfo.CodecProfileLevel) MediaCodecSelector(com.google.android.exoplayer2.mediacodec.MediaCodecSelector) MediaFormat(android.media.MediaFormat) Format(com.google.android.exoplayer2.Format) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities) Capabilities(com.google.android.exoplayer2.RendererCapabilities.Capabilities) Handler(android.os.Handler) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities) Test(org.junit.Test)

Example 12 with CodecCapabilities

use of android.media.MediaCodecInfo.CodecCapabilities in project ExoPlayer by google.

the class EnumerateDecodersTest method logDecoderInfos.

private void logDecoderInfos(String mimeType, boolean secure, boolean tunneling) throws DecoderQueryException {
    List<MediaCodecInfo> mediaCodecInfos = MediaCodecUtil.getDecoderInfos(mimeType, secure, tunneling);
    for (MediaCodecInfo mediaCodecInfo : mediaCodecInfos) {
        CodecCapabilities capabilities = mediaCodecInfo.capabilities;
        metricsLogger.logMetric("capabilities_" + mediaCodecInfo.name, codecCapabilitiesToString(mimeType, capabilities));
    }
}
Also used : MediaCodecInfo(com.google.android.exoplayer2.mediacodec.MediaCodecInfo) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities)

Example 13 with CodecCapabilities

use of android.media.MediaCodecInfo.CodecCapabilities in project robolectric by robolectric.

the class ShadowMediaCodecListTest method codecCapabilities_createFromProfileLevel.

@Test
public void codecCapabilities_createFromProfileLevel() {
    CodecCapabilities codecCapabilities = CodecCapabilities.createFromProfileLevel(MediaFormat.MIMETYPE_VIDEO_AVC, CodecProfileLevel.AVCProfileBaseline, CodecProfileLevel.AVCLevel2);
    CodecProfileLevel expected = new CodecProfileLevel();
    expected.profile = CodecProfileLevel.AVCProfileBaseline;
    expected.level = CodecProfileLevel.AVCLevel2;
    assertThat(codecCapabilities.getMimeType()).isEqualTo(MediaFormat.MIMETYPE_VIDEO_AVC);
    assertThat(codecCapabilities.profileLevels).hasLength(1);
    assertThat(codecCapabilities.profileLevels[0]).isEqualTo(expected);
}
Also used : CodecProfileLevel(android.media.MediaCodecInfo.CodecProfileLevel) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities) Test(org.junit.Test)

Example 14 with CodecCapabilities

use of android.media.MediaCodecInfo.CodecCapabilities in project robolectric by robolectric.

the class MediaCodecInfoBuilderTest method canCreateVideoEncoderCapabilities.

@Test
@Config(minSdk = Q)
public void canCreateVideoEncoderCapabilities() {
    CodecCapabilities codecCapabilities = MediaCodecInfoBuilder.CodecCapabilitiesBuilder.newBuilder().setMediaFormat(AVC_MEDIA_FORMAT).setIsEncoder(true).setProfileLevels(AVC_PROFILE_LEVELS).setColorFormats(AVC_COLOR_FORMATS).build();
    assertThat(codecCapabilities.getMimeType()).isEqualTo(MIMETYPE_VIDEO_AVC);
    assertThat(codecCapabilities.getAudioCapabilities()).isNull();
    assertThat(codecCapabilities.getVideoCapabilities()).isNotNull();
    assertThat(codecCapabilities.getEncoderCapabilities()).isNotNull();
    assertThat(codecCapabilities.isFeatureSupported(CodecCapabilities.FEATURE_IntraRefresh)).isTrue();
    assertThat(codecCapabilities.isFeatureSupported(CodecCapabilities.FEATURE_MultipleFrames)).isFalse();
    assertThat(codecCapabilities.profileLevels).hasLength(AVC_PROFILE_LEVELS.length);
    assertThat(codecCapabilities.profileLevels).isEqualTo(AVC_PROFILE_LEVELS);
    assertThat(codecCapabilities.colorFormats).hasLength(AVC_COLOR_FORMATS.length);
    assertThat(codecCapabilities.colorFormats).isEqualTo(AVC_COLOR_FORMATS);
}
Also used : CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 15 with CodecCapabilities

use of android.media.MediaCodecInfo.CodecCapabilities in project robolectric by robolectric.

the class MediaCodecInfoBuilderTest method canCreateMediaCodecInfoWithMultipleFormats.

@Test
@Config(minSdk = Q)
public void canCreateMediaCodecInfoWithMultipleFormats() {
    CodecCapabilities avcEncoderCapabilities = MediaCodecInfoBuilder.CodecCapabilitiesBuilder.newBuilder().setMediaFormat(AVC_MEDIA_FORMAT).setIsEncoder(true).setProfileLevels(AVC_PROFILE_LEVELS).setColorFormats(AVC_COLOR_FORMATS).build();
    CodecCapabilities vp9EncoderCapabilities = MediaCodecInfoBuilder.CodecCapabilitiesBuilder.newBuilder().setMediaFormat(VP9_MEDIA_FORMAT).setIsEncoder(true).setProfileLevels(VP9_PROFILE_LEVELS).setColorFormats(VP9_COLOR_FORMATS).build();
    MediaCodecInfo mediaCodecInfo = MediaCodecInfoBuilder.newBuilder().setName(MULTIFORMAT_ENCODER_NAME).setIsEncoder(true).setCapabilities(avcEncoderCapabilities, vp9EncoderCapabilities).build();
    assertThat(mediaCodecInfo.getName()).isEqualTo(MULTIFORMAT_ENCODER_NAME);
    assertThat(mediaCodecInfo.isEncoder()).isTrue();
    assertThat(mediaCodecInfo.isVendor()).isFalse();
    assertThat(mediaCodecInfo.isSoftwareOnly()).isFalse();
    assertThat(mediaCodecInfo.isHardwareAccelerated()).isFalse();
    assertThat(mediaCodecInfo.getSupportedTypes()).asList().contains(MIMETYPE_VIDEO_AVC);
    assertThat(mediaCodecInfo.getSupportedTypes()).asList().contains(MIMETYPE_VIDEO_VP9);
    assertThat(mediaCodecInfo.getCapabilitiesForType(MIMETYPE_VIDEO_AVC)).isNotNull();
    assertThat(mediaCodecInfo.getCapabilitiesForType(MIMETYPE_VIDEO_VP9)).isNotNull();
}
Also used : MediaCodecInfo(android.media.MediaCodecInfo) CodecCapabilities(android.media.MediaCodecInfo.CodecCapabilities) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

CodecCapabilities (android.media.MediaCodecInfo.CodecCapabilities)28 MediaCodecInfo (android.media.MediaCodecInfo)15 Test (org.junit.Test)11 Config (org.robolectric.annotation.Config)8 CodecProfileLevel (android.media.MediaCodecInfo.CodecProfileLevel)7 Nullable (androidx.annotation.Nullable)6 ArrayList (java.util.ArrayList)5 SparseIntArray (android.util.SparseIntArray)4 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 SuppressLint (android.annotation.SuppressLint)3 Point (android.graphics.Point)3 VideoCapabilities (android.media.MediaCodecInfo.VideoCapabilities)3 MediaCodecList (android.media.MediaCodecList)3 TreeMap (java.util.TreeMap)3 SurfaceTexture (android.graphics.SurfaceTexture)2 MediaFormat (android.media.MediaFormat)2 Handler (android.os.Handler)2 Looper (android.os.Looper)2 SystemClock (android.os.SystemClock)2