Search in sources :

Example 16 with TrackGroupArray

use of androidx.media3.common.TrackGroupArray in project media by androidx.

the class MetadataRetrieverTest method retrieveMetadata_sefSlowMotion_outputsExpectedMetadata.

@Test
public void retrieveMetadata_sefSlowMotion_outputsExpectedMetadata() throws Exception {
    MediaItem mediaItem = MediaItem.fromUri(Uri.parse("asset://android_asset/media/mp4/sample_sef_slow_motion.mp4"));
    SmtaMetadataEntry expectedSmtaEntry = new SmtaMetadataEntry(/* captureFrameRate= */
    240, /* svcTemporalLayerCount= */
    4);
    List<SlowMotionData.Segment> segments = new ArrayList<>();
    segments.add(new SlowMotionData.Segment(/* startTimeMs= */
    88, /* endTimeMs= */
    879, /* speedDivisor= */
    2));
    segments.add(new SlowMotionData.Segment(/* startTimeMs= */
    1255, /* endTimeMs= */
    1970, /* speedDivisor= */
    8));
    SlowMotionData expectedSlowMotionData = new SlowMotionData(segments);
    MdtaMetadataEntry expectedMdtaEntry = new MdtaMetadataEntry(KEY_ANDROID_CAPTURE_FPS, /* value= */
    new byte[] { 67, 112, 0, 0 }, /* localeIndicator= */
    0, /* typeIndicator= */
    23);
    ListenableFuture<TrackGroupArray> trackGroupsFuture = retrieveMetadata(context, mediaItem, clock);
    ShadowLooper.idleMainLooper();
    TrackGroupArray trackGroups = trackGroupsFuture.get(TEST_TIMEOUT_SEC, TimeUnit.SECONDS);
    // Video and audio
    assertThat(trackGroups.length).isEqualTo(2);
    // Audio
    assertThat(trackGroups.get(0).getFormat(0).metadata.length()).isEqualTo(2);
    assertThat(trackGroups.get(0).getFormat(0).metadata.get(0)).isEqualTo(expectedSmtaEntry);
    assertThat(trackGroups.get(0).getFormat(0).metadata.get(1)).isEqualTo(expectedSlowMotionData);
    // Video
    assertThat(trackGroups.get(1).getFormat(0).metadata.length()).isEqualTo(3);
    assertThat(trackGroups.get(1).getFormat(0).metadata.get(0)).isEqualTo(expectedMdtaEntry);
    assertThat(trackGroups.get(1).getFormat(0).metadata.get(1)).isEqualTo(expectedSmtaEntry);
    assertThat(trackGroups.get(1).getFormat(0).metadata.get(2)).isEqualTo(expectedSlowMotionData);
}
Also used : SmtaMetadataEntry(androidx.media3.extractor.metadata.mp4.SmtaMetadataEntry) MediaItem(androidx.media3.common.MediaItem) SlowMotionData(androidx.media3.extractor.metadata.mp4.SlowMotionData) ArrayList(java.util.ArrayList) TrackGroupArray(androidx.media3.common.TrackGroupArray) MdtaMetadataEntry(androidx.media3.extractor.metadata.mp4.MdtaMetadataEntry) Test(org.junit.Test)

Example 17 with TrackGroupArray

use of androidx.media3.common.TrackGroupArray in project media by androidx.

the class MetadataRetrieverTest method retrieveMetadata_heicStillPhoto_outputsEmptyMetadata.

@Test
public void retrieveMetadata_heicStillPhoto_outputsEmptyMetadata() throws Exception {
    MediaItem mediaItem = MediaItem.fromUri(Uri.parse("asset://android_asset/media/mp4/sample_still_photo.heic"));
    ListenableFuture<TrackGroupArray> trackGroupsFuture = retrieveMetadata(context, mediaItem, clock);
    ShadowLooper.idleMainLooper();
    TrackGroupArray trackGroups = trackGroupsFuture.get(TEST_TIMEOUT_SEC, TimeUnit.SECONDS);
    assertThat(trackGroups.length).isEqualTo(1);
    assertThat(trackGroups.get(0).length).isEqualTo(1);
    assertThat(trackGroups.get(0).getFormat(0).metadata).isNull();
}
Also used : MediaItem(androidx.media3.common.MediaItem) TrackGroupArray(androidx.media3.common.TrackGroupArray) Test(org.junit.Test)

Example 18 with TrackGroupArray

use of androidx.media3.common.TrackGroupArray in project media by androidx.

the class ExoPlayerTest method resettingMediaSourcesGivesFreshSourceInfo.

@Test
public void resettingMediaSourcesGivesFreshSourceInfo() throws Exception {
    FakeRenderer renderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
    Timeline firstTimeline = new FakeTimeline(new TimelineWindowDefinition(/* isSeekable= */
    true, /* isDynamic= */
    false, /* durationUs= */
    1_000_000_000));
    MediaSource firstSource = new FakeMediaSource(firstTimeline, ExoPlayerTestRunner.VIDEO_FORMAT);
    AtomicBoolean secondSourcePrepared = new AtomicBoolean();
    MediaSource secondSource = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT) {

        @Override
        public synchronized void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
            super.prepareSourceInternal(mediaTransferListener);
            secondSourcePrepared.set(true);
        }
    };
    Timeline thirdTimeline = new FakeTimeline();
    MediaSource thirdSource = new FakeMediaSource(thirdTimeline, ExoPlayerTestRunner.VIDEO_FORMAT);
    ExoPlayer player = new TestExoPlayerBuilder(context).setRenderers(renderer).build();
    Player.Listener mockPlayerListener = mock(Player.Listener.class);
    player.addListener(mockPlayerListener);
    player.setMediaSource(firstSource);
    player.prepare();
    player.play();
    runUntilTimelineChanged(player);
    player.setMediaSource(secondSource);
    runMainLooperUntil(secondSourcePrepared::get);
    player.setMediaSource(thirdSource);
    runUntilPlaybackState(player, Player.STATE_ENDED);
    // The first source's preparation completed with a real timeline. When the second source was
    // prepared, it immediately exposed a placeholder timeline, but the source info refresh from the
    // second source was suppressed as we replace it with the third source before the update
    // arrives.
    InOrder inOrder = inOrder(mockPlayerListener);
    inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(placeholderTimeline)), eq(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED));
    inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(firstTimeline)), eq(Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE));
    inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(placeholderTimeline)), eq(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED));
    inOrder.verify(mockPlayerListener).onPositionDiscontinuity(any(), any(), eq(Player.DISCONTINUITY_REASON_REMOVE));
    inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(placeholderTimeline)), eq(Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED));
    inOrder.verify(mockPlayerListener).onPositionDiscontinuity(any(), any(), eq(Player.DISCONTINUITY_REASON_REMOVE));
    inOrder.verify(mockPlayerListener).onTimelineChanged(argThat(noUid(thirdTimeline)), eq(Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE));
    inOrder.verify(mockPlayerListener).onTracksChanged(eq(new TrackGroupArray(new TrackGroup(ExoPlayerTestRunner.VIDEO_FORMAT))), any());
    assertThat(renderer.isEnded).isTrue();
}
Also used : TransferListener(androidx.media3.datasource.TransferListener) Player(androidx.media3.common.Player) InOrder(org.mockito.InOrder) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) TrackGroupArray(androidx.media3.common.TrackGroupArray) FakeRenderer(androidx.media3.test.utils.FakeRenderer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Listener(androidx.media3.common.Player.Listener) Timeline(androidx.media3.common.Timeline) NoUidTimeline(androidx.media3.test.utils.NoUidTimeline) FakeTimeline(androidx.media3.test.utils.FakeTimeline) SinglePeriodTimeline(androidx.media3.exoplayer.source.SinglePeriodTimeline) CompositeMediaSource(androidx.media3.exoplayer.source.CompositeMediaSource) ClippingMediaSource(androidx.media3.exoplayer.source.ClippingMediaSource) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) MaskingMediaSource(androidx.media3.exoplayer.source.MaskingMediaSource) ServerSideAdInsertionMediaSource(androidx.media3.exoplayer.source.ads.ServerSideAdInsertionMediaSource) FakeAdaptiveMediaSource(androidx.media3.test.utils.FakeAdaptiveMediaSource) ConcatenatingMediaSource(androidx.media3.exoplayer.source.ConcatenatingMediaSource) MediaSource(androidx.media3.exoplayer.source.MediaSource) FakeTimeline(androidx.media3.test.utils.FakeTimeline) TrackGroup(androidx.media3.common.TrackGroup) TimelineWindowDefinition(androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition) TestExoPlayerBuilder(androidx.media3.test.utils.TestExoPlayerBuilder) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 19 with TrackGroupArray

use of androidx.media3.common.TrackGroupArray in project media by androidx.

the class DashMediaPeriodTest method trickPlayProperty_mergesTrackGroups.

@Test
public void trickPlayProperty_mergesTrackGroups() throws IOException {
    DashManifest manifest = parseManifest("media/mpd/sample_mpd_trick_play_property");
    DashMediaPeriod dashMediaPeriod = createDashMediaPeriod(manifest, 0);
    List<AdaptationSet> adaptationSets = manifest.getPeriod(0).adaptationSets;
    // We expect the trick play adaptation sets to be merged with the ones to which they refer,
    // retaining representations in their original order.
    TrackGroupArray expectedTrackGroups = new TrackGroupArray(new TrackGroup(/* id= */
    "0", adaptationSets.get(0).representations.get(0).format, adaptationSets.get(0).representations.get(1).format, adaptationSets.get(1).representations.get(0).format), new TrackGroup(/* id= */
    "2", adaptationSets.get(2).representations.get(0).format, adaptationSets.get(2).representations.get(1).format, adaptationSets.get(3).representations.get(0).format));
    MediaPeriodAsserts.assertTrackGroups(dashMediaPeriod, expectedTrackGroups);
}
Also used : TrackGroup(androidx.media3.common.TrackGroup) DashManifest(androidx.media3.exoplayer.dash.manifest.DashManifest) TrackGroupArray(androidx.media3.common.TrackGroupArray) AdaptationSet(androidx.media3.exoplayer.dash.manifest.AdaptationSet) Test(org.junit.Test)

Example 20 with TrackGroupArray

use of androidx.media3.common.TrackGroupArray in project media by androidx.

the class DashMediaPeriodTest method cea708AccessibilityDescriptor_createsCea708TrackGroup.

@Test
public void cea708AccessibilityDescriptor_createsCea708TrackGroup() throws IOException {
    DashManifest manifest = parseManifest("media/mpd/sample_mpd_cea_708_accessibility");
    DashMediaPeriod dashMediaPeriod = createDashMediaPeriod(manifest, 0);
    List<AdaptationSet> adaptationSets = manifest.getPeriod(0).adaptationSets;
    // We expect two adaptation sets. The first containing the video representations, and the second
    // containing the embedded CEA-708 tracks.
    Format.Builder cea608FormatBuilder = new Format.Builder().setSampleMimeType(MimeTypes.APPLICATION_CEA708);
    TrackGroupArray expectedTrackGroups = new TrackGroupArray(new TrackGroup(/* id= */
    "123", adaptationSets.get(0).representations.get(0).format, adaptationSets.get(0).representations.get(1).format), new TrackGroup(/* id= */
    "123:cc", cea608FormatBuilder.setId("123:cea708:1").setLanguage("eng").setAccessibilityChannel(1).build(), cea608FormatBuilder.setId("123:cea708:2").setLanguage("deu").setAccessibilityChannel(2).build()));
    MediaPeriodAsserts.assertTrackGroups(dashMediaPeriod, expectedTrackGroups);
}
Also used : Format(androidx.media3.common.Format) TrackGroup(androidx.media3.common.TrackGroup) DashManifest(androidx.media3.exoplayer.dash.manifest.DashManifest) TrackGroupArray(androidx.media3.common.TrackGroupArray) AdaptationSet(androidx.media3.exoplayer.dash.manifest.AdaptationSet) Test(org.junit.Test)

Aggregations

TrackGroupArray (androidx.media3.common.TrackGroupArray)117 Test (org.junit.Test)92 Format (androidx.media3.common.Format)60 TrackGroup (androidx.media3.common.TrackGroup)40 RendererCapabilities (androidx.media3.exoplayer.RendererCapabilities)36 Nullable (androidx.annotation.Nullable)18 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)17 FakeTimeline (androidx.media3.test.utils.FakeTimeline)17 TransferListener (androidx.media3.datasource.TransferListener)14 DrmSessionManager (androidx.media3.exoplayer.drm.DrmSessionManager)13 MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)13 FakeMediaPeriod (androidx.media3.test.utils.FakeMediaPeriod)13 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)13 Allocator (androidx.media3.exoplayer.upstream.Allocator)12 MediaSource (androidx.media3.exoplayer.source.MediaSource)10 MediaItem (androidx.media3.common.MediaItem)9 ClippingMediaSource (androidx.media3.exoplayer.source.ClippingMediaSource)9 CompositeMediaSource (androidx.media3.exoplayer.source.CompositeMediaSource)9 ConcatenatingMediaSource (androidx.media3.exoplayer.source.ConcatenatingMediaSource)9 MaskingMediaSource (androidx.media3.exoplayer.source.MaskingMediaSource)9