Search in sources :

Example 26 with MediaPeriod

use of androidx.media3.exoplayer.source.MediaPeriod in project media by androidx.

the class MediaPeriodAsserts method prepareAndGetTrackGroups.

private static TrackGroupArray prepareAndGetTrackGroups(MediaPeriod mediaPeriod) {
    AtomicReference<TrackGroupArray> trackGroupArray = new AtomicReference<>();
    DummyMainThread testThread = new DummyMainThread();
    ConditionVariable preparedCondition = new ConditionVariable();
    testThread.runOnMainThread(() -> mediaPeriod.prepare(new Callback() {

        @Override
        public void onPrepared(MediaPeriod mediaPeriod) {
            trackGroupArray.set(mediaPeriod.getTrackGroups());
            preparedCondition.open();
        }

        @Override
        public void onContinueLoadingRequested(MediaPeriod source) {
        // Ignore.
        }
    }, /* positionUs= */
    0));
    try {
        preparedCondition.block();
    } catch (InterruptedException e) {
    // Ignore.
    }
    testThread.release();
    return trackGroupArray.get();
}
Also used : ConditionVariable(androidx.media3.common.util.ConditionVariable) Callback(androidx.media3.exoplayer.source.MediaPeriod.Callback) TrackGroupArray(androidx.media3.common.TrackGroupArray) AtomicReference(java.util.concurrent.atomic.AtomicReference) MediaPeriod(androidx.media3.exoplayer.source.MediaPeriod)

Example 27 with MediaPeriod

use of androidx.media3.exoplayer.source.MediaPeriod in project media by androidx.

the class MediaPeriodAsserts method assertGetStreamKeysAndManifestFilterIntegration.

/**
 * Asserts that the values returns by {@link MediaPeriod#getStreamKeys(List)} are compatible with
 * a {@link FilterableManifest} using these stream keys.
 *
 * @param mediaPeriodFactory A factory to create a {@link MediaPeriod} based on a manifest.
 * @param manifest The manifest which is to be tested.
 * @param periodIndex The index of period in the manifest.
 * @param ignoredMimeType Optional mime type whose existence in the filtered track groups is not
 *     asserted.
 */
public static <T extends FilterableManifest<T>> void assertGetStreamKeysAndManifestFilterIntegration(FilterableManifestMediaPeriodFactory<T> mediaPeriodFactory, T manifest, int periodIndex, @Nullable String ignoredMimeType) {
    MediaPeriod mediaPeriod = mediaPeriodFactory.createMediaPeriod(manifest, periodIndex);
    TrackGroupArray trackGroupArray = prepareAndGetTrackGroups(mediaPeriod);
    // Create test vector of query test selections:
    // - One selection with one track per group, two tracks or all tracks.
    // - Two selections with tracks from multiple groups, or tracks from a single group.
    // - Multiple selections with tracks from all groups.
    List<List<ExoTrackSelection>> testSelections = new ArrayList<>();
    for (int i = 0; i < trackGroupArray.length; i++) {
        TrackGroup trackGroup = trackGroupArray.get(i);
        for (int j = 0; j < trackGroup.length; j++) {
            testSelections.add(Collections.singletonList(new TestTrackSelection(trackGroup, j)));
        }
        if (trackGroup.length > 1) {
            testSelections.add(Collections.singletonList(new TestTrackSelection(trackGroup, 0, 1)));
            testSelections.add(Arrays.asList(new ExoTrackSelection[] { new TestTrackSelection(trackGroup, 0), new TestTrackSelection(trackGroup, 1) }));
        }
        if (trackGroup.length > 2) {
            int[] allTracks = new int[trackGroup.length];
            for (int j = 0; j < trackGroup.length; j++) {
                allTracks[j] = j;
            }
            testSelections.add(Collections.singletonList(new TestTrackSelection(trackGroup, allTracks)));
        }
    }
    if (trackGroupArray.length > 1) {
        for (int i = 0; i < trackGroupArray.length - 1; i++) {
            for (int j = i + 1; j < trackGroupArray.length; j++) {
                testSelections.add(Arrays.asList(new ExoTrackSelection[] { new TestTrackSelection(trackGroupArray.get(i), 0), new TestTrackSelection(trackGroupArray.get(j), 0) }));
            }
        }
    }
    if (trackGroupArray.length > 2) {
        List<ExoTrackSelection> selectionsFromAllGroups = new ArrayList<>();
        for (int i = 0; i < trackGroupArray.length; i++) {
            selectionsFromAllGroups.add(new TestTrackSelection(trackGroupArray.get(i), 0));
        }
        testSelections.add(selectionsFromAllGroups);
    }
    // contain at least all requested formats.
    for (List<ExoTrackSelection> testSelection : testSelections) {
        List<StreamKey> streamKeys = mediaPeriod.getStreamKeys(testSelection);
        if (streamKeys.isEmpty()) {
            // Manifests won't be filtered if stream key is empty.
            continue;
        }
        T filteredManifest = manifest.copy(streamKeys);
        // The filtered manifest should only have one period left.
        MediaPeriod filteredMediaPeriod = mediaPeriodFactory.createMediaPeriod(filteredManifest, /* periodIndex= */
        0);
        TrackGroupArray filteredTrackGroupArray = prepareAndGetTrackGroups(filteredMediaPeriod);
        for (ExoTrackSelection trackSelection : testSelection) {
            if (ignoredMimeType != null && ignoredMimeType.equals(trackSelection.getFormat(0).sampleMimeType)) {
                continue;
            }
            Format[] expectedFormats = new Format[trackSelection.length()];
            for (int k = 0; k < trackSelection.length(); k++) {
                expectedFormats[k] = trackSelection.getFormat(k);
            }
            assertOneTrackGroupContainsFormats(filteredTrackGroupArray, expectedFormats);
        }
    }
}
Also used : TrackGroupArray(androidx.media3.common.TrackGroupArray) ArrayList(java.util.ArrayList) Format(androidx.media3.common.Format) ExoTrackSelection(androidx.media3.exoplayer.trackselection.ExoTrackSelection) TrackGroup(androidx.media3.common.TrackGroup) ArrayList(java.util.ArrayList) List(java.util.List) MediaPeriod(androidx.media3.exoplayer.source.MediaPeriod) StreamKey(androidx.media3.common.StreamKey)

Example 28 with MediaPeriod

use of androidx.media3.exoplayer.source.MediaPeriod in project media by androidx.

the class FakeMediaSource method createPeriod.

@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
    assertThat(preparedSource).isTrue();
    assertThat(releasedSource).isFalse();
    int periodIndex = castNonNull(timeline).getIndexOfPeriod(id.periodUid);
    Assertions.checkArgument(periodIndex != C.INDEX_UNSET);
    Period period = timeline.getPeriod(periodIndex, new Period());
    MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher = createEventDispatcher(period.windowIndex, id, period.getPositionInWindowMs());
    DrmSessionEventListener.EventDispatcher drmEventDispatcher = createDrmEventDispatcher(period.windowIndex, id);
    MediaPeriod mediaPeriod = createMediaPeriod(id, trackGroupArray, allocator, mediaSourceEventDispatcher, drmSessionManager, drmEventDispatcher, transferListener);
    activeMediaPeriods.add(mediaPeriod);
    createdMediaPeriods.add(id);
    return mediaPeriod;
}
Also used : MediaSourceEventListener(androidx.media3.exoplayer.source.MediaSourceEventListener) MediaPeriod(androidx.media3.exoplayer.source.MediaPeriod) Period(androidx.media3.common.Timeline.Period) MediaPeriod(androidx.media3.exoplayer.source.MediaPeriod) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener)

Example 29 with MediaPeriod

use of androidx.media3.exoplayer.source.MediaPeriod in project media by androidx.

the class ConcatenatingMediaSourceTest method removeChildSourceWithActiveMediaPeriod.

@Test
public void removeChildSourceWithActiveMediaPeriod() throws IOException {
    FakeMediaSource childSource = createFakeMediaSource();
    mediaSource.addMediaSource(childSource);
    Timeline timeline = testRunner.prepareSource();
    MediaPeriod mediaPeriod = testRunner.createPeriod(new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    0), /* windowSequenceNumber= */
    0));
    mediaSource.removeMediaSource(/* index= */
    0);
    testRunner.assertTimelineChangeBlocking();
    testRunner.releasePeriod(mediaPeriod);
    childSource.assertReleased();
    testRunner.releaseSource();
}
Also used : FakeTimeline(androidx.media3.test.utils.FakeTimeline) Timeline(androidx.media3.common.Timeline) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 30 with MediaPeriod

use of androidx.media3.exoplayer.source.MediaPeriod in project media by androidx.

the class ClippingMediaSourceTest method getClippedTimelines.

private static Timeline[] getClippedTimelines(FakeMediaSource fakeMediaSource, ClippingMediaSource clippingMediaSource, Timeline... additionalTimelines) throws IOException {
    MediaSourceTestRunner testRunner = new MediaSourceTestRunner(clippingMediaSource, /* allocator= */
    null);
    Timeline[] clippedTimelines = new Timeline[additionalTimelines.length + 1];
    try {
        clippedTimelines[0] = testRunner.prepareSource();
        MediaPeriod mediaPeriod = testRunner.createPeriod(new MediaPeriodId(clippedTimelines[0].getUidOfPeriod(/* periodIndex= */
        0), /* windowSequenceNumber= */
        0));
        for (int i = 0; i < additionalTimelines.length; i++) {
            fakeMediaSource.setNewSourceInfo(additionalTimelines[i]);
            clippedTimelines[i + 1] = testRunner.assertTimelineChangeBlocking();
        }
        testRunner.releasePeriod(mediaPeriod);
        testRunner.releaseSource();
        fakeMediaSource.assertReleased();
        return clippedTimelines;
    } finally {
        testRunner.release();
    }
}
Also used : FakeTimeline(androidx.media3.test.utils.FakeTimeline) PlaceholderTimeline(androidx.media3.exoplayer.source.MaskingMediaSource.PlaceholderTimeline) Timeline(androidx.media3.common.Timeline) MediaSourceTestRunner(androidx.media3.test.utils.MediaSourceTestRunner) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)

Aggregations

MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)23 Test (org.junit.Test)21 FakeTimeline (androidx.media3.test.utils.FakeTimeline)18 Nullable (androidx.annotation.Nullable)17 TrackGroupArray (androidx.media3.common.TrackGroupArray)17 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)17 Allocator (androidx.media3.exoplayer.upstream.Allocator)15 DrmSessionManager (androidx.media3.exoplayer.drm.DrmSessionManager)14 MediaPeriod (androidx.media3.exoplayer.source.MediaPeriod)14 FakeMediaPeriod (androidx.media3.test.utils.FakeMediaPeriod)14 TransferListener (androidx.media3.datasource.TransferListener)13 Timeline (androidx.media3.common.Timeline)11 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)11 DrmSessionEventListener (androidx.media3.exoplayer.drm.DrmSessionEventListener)9 AdPlaybackState (androidx.media3.common.AdPlaybackState)8 ExoPlayerTestRunner (androidx.media3.test.utils.ExoPlayerTestRunner)8 C (androidx.media3.common.C)7 TrackGroup (androidx.media3.common.TrackGroup)7 MediaSourceEventListener (androidx.media3.exoplayer.source.MediaSourceEventListener)7 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)7