Search in sources :

Example 1 with FilterableManifestMediaPeriodFactory

use of androidx.media3.test.utils.MediaPeriodAsserts.FilterableManifestMediaPeriodFactory in project media by androidx.

the class SsMediaPeriodTest method getSteamKeys_isCompatibleWithSsManifestFilter.

@Test
public void getSteamKeys_isCompatibleWithSsManifestFilter() {
    SsManifest testManifest = createSsManifest(createStreamElement(/* name= */
    "video", C.TRACK_TYPE_VIDEO, createVideoFormat(/* bitrate= */
    200000), createVideoFormat(/* bitrate= */
    400000), createVideoFormat(/* bitrate= */
    800000)), createStreamElement(/* name= */
    "audio", C.TRACK_TYPE_AUDIO, createAudioFormat(/* bitrate= */
    48000), createAudioFormat(/* bitrate= */
    96000)), createStreamElement(/* name= */
    "text", C.TRACK_TYPE_TEXT, createTextFormat(/* language= */
    "eng")));
    FilterableManifestMediaPeriodFactory<SsManifest> mediaPeriodFactory = (manifest, periodIndex) -> {
        MediaPeriodId mediaPeriodId = new MediaPeriodId(/* periodUid= */
        new Object());
        return new SsMediaPeriod(manifest, mock(SsChunkSource.Factory.class), mock(TransferListener.class), mock(CompositeSequenceableLoaderFactory.class), mock(DrmSessionManager.class), new DrmSessionEventListener.EventDispatcher().withParameters(/* windowIndex= */
        0, mediaPeriodId), mock(LoadErrorHandlingPolicy.class), new MediaSourceEventListener.EventDispatcher().withParameters(/* windowIndex= */
        0, mediaPeriodId, /* mediaTimeOffsetMs= */
        0), mock(LoaderErrorThrower.class), mock(Allocator.class));
    };
    MediaPeriodAsserts.assertGetStreamKeysAndManifestFilterIntegration(mediaPeriodFactory, testManifest);
}
Also used : LoaderErrorThrower(androidx.media3.exoplayer.upstream.LoaderErrorThrower) FilterableManifestMediaPeriodFactory(androidx.media3.test.utils.MediaPeriodAsserts.FilterableManifestMediaPeriodFactory) SsManifest(androidx.media3.exoplayer.smoothstreaming.manifest.SsManifest) TransferListener(androidx.media3.datasource.TransferListener) MediaSourceEventListener(androidx.media3.exoplayer.source.MediaSourceEventListener) MimeTypes(androidx.media3.common.MimeTypes) LoadErrorHandlingPolicy(androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy) RunWith(org.junit.runner.RunWith) SsTestUtils.createSsManifest(androidx.media3.exoplayer.smoothstreaming.SsTestUtils.createSsManifest) Allocator(androidx.media3.exoplayer.upstream.Allocator) Test(org.junit.Test) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) Format(androidx.media3.common.Format) DrmSessionManager(androidx.media3.exoplayer.drm.DrmSessionManager) C(androidx.media3.common.C) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) CompositeSequenceableLoaderFactory(androidx.media3.exoplayer.source.CompositeSequenceableLoaderFactory) SsTestUtils.createStreamElement(androidx.media3.exoplayer.smoothstreaming.SsTestUtils.createStreamElement) MediaPeriodAsserts(androidx.media3.test.utils.MediaPeriodAsserts) Mockito.mock(org.mockito.Mockito.mock) MediaSourceEventListener(androidx.media3.exoplayer.source.MediaSourceEventListener) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener) SsManifest(androidx.media3.exoplayer.smoothstreaming.manifest.SsManifest) SsTestUtils.createSsManifest(androidx.media3.exoplayer.smoothstreaming.SsTestUtils.createSsManifest) Test(org.junit.Test)

Example 2 with FilterableManifestMediaPeriodFactory

use of androidx.media3.test.utils.MediaPeriodAsserts.FilterableManifestMediaPeriodFactory 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 3 with FilterableManifestMediaPeriodFactory

use of androidx.media3.test.utils.MediaPeriodAsserts.FilterableManifestMediaPeriodFactory in project media by androidx.

the class HlsMediaPeriodTest method getSteamKeys_isCompatibleWithHlsMultivariantPlaylistFilter.

@Test
public void getSteamKeys_isCompatibleWithHlsMultivariantPlaylistFilter() {
    HlsMultivariantPlaylist testMultivariantPlaylist = createMultivariantPlaylist(/* variants= */
    Arrays.asList(createAudioOnlyVariant(/* peakBitrate= */
    10000), createMuxedVideoAudioVariant(/* peakBitrate= */
    200000), createAudioOnlyVariant(/* peakBitrate= */
    300000), createMuxedVideoAudioVariant(/* peakBitrate= */
    400000), createMuxedVideoAudioVariant(/* peakBitrate= */
    600000)), /* audios= */
    Arrays.asList(createAudioRendition(/* language= */
    "spa"), createAudioRendition(/* language= */
    "ger"), createAudioRendition(/* language= */
    "tur")), /* subtitles= */
    Arrays.asList(createSubtitleRendition(/* language= */
    "spa"), createSubtitleRendition(/* language= */
    "ger"), createSubtitleRendition(/* language= */
    "tur")), /* muxedAudioFormat= */
    createAudioFormat("eng"), /* muxedCaptionFormats= */
    Arrays.asList(createSubtitleFormat("eng"), createSubtitleFormat("gsw")));
    FilterableManifestMediaPeriodFactory<HlsPlaylist> mediaPeriodFactory = (playlist, periodIndex) -> {
        HlsDataSourceFactory mockDataSourceFactory = mock(HlsDataSourceFactory.class);
        when(mockDataSourceFactory.createDataSource(anyInt())).thenReturn(mock(DataSource.class));
        HlsPlaylistTracker mockPlaylistTracker = mock(HlsPlaylistTracker.class);
        when(mockPlaylistTracker.getMultivariantPlaylist()).thenReturn((HlsMultivariantPlaylist) playlist);
        MediaPeriodId mediaPeriodId = new MediaPeriodId(/* periodUid= */
        new Object());
        return new HlsMediaPeriod(mock(HlsExtractorFactory.class), mockPlaylistTracker, mockDataSourceFactory, mock(TransferListener.class), mock(DrmSessionManager.class), new DrmSessionEventListener.EventDispatcher().withParameters(/* windowIndex= */
        0, mediaPeriodId), mock(LoadErrorHandlingPolicy.class), new MediaSourceEventListener.EventDispatcher().withParameters(/* windowIndex= */
        0, mediaPeriodId, /* mediaTimeOffsetMs= */
        0), mock(Allocator.class), mock(CompositeSequenceableLoaderFactory.class), /* allowChunklessPreparation= */
        true, HlsMediaSource.METADATA_TYPE_ID3, /* useSessionKeys= */
        false, PlayerId.UNSET);
    };
    MediaPeriodAsserts.assertGetStreamKeysAndManifestFilterIntegration(mediaPeriodFactory, testMultivariantPlaylist);
}
Also used : Arrays(java.util.Arrays) Variant(androidx.media3.exoplayer.hls.playlist.HlsMultivariantPlaylist.Variant) Uri(android.net.Uri) LoadErrorHandlingPolicy(androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy) RunWith(org.junit.runner.RunWith) Allocator(androidx.media3.exoplayer.upstream.Allocator) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) DrmSessionManager(androidx.media3.exoplayer.drm.DrmSessionManager) HlsMultivariantPlaylist(androidx.media3.exoplayer.hls.playlist.HlsMultivariantPlaylist) HlsPlaylist(androidx.media3.exoplayer.hls.playlist.HlsPlaylist) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) FilterableManifestMediaPeriodFactory(androidx.media3.test.utils.MediaPeriodAsserts.FilterableManifestMediaPeriodFactory) TransferListener(androidx.media3.datasource.TransferListener) MediaSourceEventListener(androidx.media3.exoplayer.source.MediaSourceEventListener) MimeTypes(androidx.media3.common.MimeTypes) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) DataSource(androidx.media3.datasource.DataSource) Format(androidx.media3.common.Format) HlsPlaylistTracker(androidx.media3.exoplayer.hls.playlist.HlsPlaylistTracker) List(java.util.List) Rendition(androidx.media3.exoplayer.hls.playlist.HlsMultivariantPlaylist.Rendition) PlayerId(androidx.media3.exoplayer.analytics.PlayerId) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) CompositeSequenceableLoaderFactory(androidx.media3.exoplayer.source.CompositeSequenceableLoaderFactory) MediaPeriodAsserts(androidx.media3.test.utils.MediaPeriodAsserts) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) HlsPlaylistTracker(androidx.media3.exoplayer.hls.playlist.HlsPlaylistTracker) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener) HlsPlaylist(androidx.media3.exoplayer.hls.playlist.HlsPlaylist) MediaSourceEventListener(androidx.media3.exoplayer.source.MediaSourceEventListener) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) HlsMultivariantPlaylist(androidx.media3.exoplayer.hls.playlist.HlsMultivariantPlaylist) Test(org.junit.Test)

Aggregations

Format (androidx.media3.common.Format)3 MimeTypes (androidx.media3.common.MimeTypes)2 TransferListener (androidx.media3.datasource.TransferListener)2 DrmSessionEventListener (androidx.media3.exoplayer.drm.DrmSessionEventListener)2 DrmSessionManager (androidx.media3.exoplayer.drm.DrmSessionManager)2 CompositeSequenceableLoaderFactory (androidx.media3.exoplayer.source.CompositeSequenceableLoaderFactory)2 MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)2 MediaSourceEventListener (androidx.media3.exoplayer.source.MediaSourceEventListener)2 Allocator (androidx.media3.exoplayer.upstream.Allocator)2 LoadErrorHandlingPolicy (androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy)2 MediaPeriodAsserts (androidx.media3.test.utils.MediaPeriodAsserts)2 FilterableManifestMediaPeriodFactory (androidx.media3.test.utils.MediaPeriodAsserts.FilterableManifestMediaPeriodFactory)2 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)2 List (java.util.List)2 Test (org.junit.Test)2 RunWith (org.junit.runner.RunWith)2 Mockito.mock (org.mockito.Mockito.mock)2 Uri (android.net.Uri)1 C (androidx.media3.common.C)1 StreamKey (androidx.media3.common.StreamKey)1