Search in sources :

Example 1 with FilterableManifestMediaPeriodFactory

use of com.google.android.exoplayer2.testutil.MediaPeriodAsserts.FilterableManifestMediaPeriodFactory in project ExoPlayer by google.

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 : HlsPlaylistTracker(com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistTracker) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Arrays(java.util.Arrays) Uri(android.net.Uri) RunWith(org.junit.runner.RunWith) CompositeSequenceableLoaderFactory(com.google.android.exoplayer2.source.CompositeSequenceableLoaderFactory) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) Rendition(com.google.android.exoplayer2.source.hls.playlist.HlsMultivariantPlaylist.Rendition) Format(com.google.android.exoplayer2.Format) PlayerId(com.google.android.exoplayer2.analytics.PlayerId) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) MimeTypes(com.google.android.exoplayer2.util.MimeTypes) HlsPlaylist(com.google.android.exoplayer2.source.hls.playlist.HlsPlaylist) Variant(com.google.android.exoplayer2.source.hls.playlist.HlsMultivariantPlaylist.Variant) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) Allocator(com.google.android.exoplayer2.upstream.Allocator) TransferListener(com.google.android.exoplayer2.upstream.TransferListener) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) DataSource(com.google.android.exoplayer2.upstream.DataSource) MediaPeriodAsserts(com.google.android.exoplayer2.testutil.MediaPeriodAsserts) List(java.util.List) HlsMultivariantPlaylist(com.google.android.exoplayer2.source.hls.playlist.HlsMultivariantPlaylist) LoadErrorHandlingPolicy(com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy) FilterableManifestMediaPeriodFactory(com.google.android.exoplayer2.testutil.MediaPeriodAsserts.FilterableManifestMediaPeriodFactory) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) HlsPlaylistTracker(com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistTracker) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) HlsPlaylist(com.google.android.exoplayer2.source.hls.playlist.HlsPlaylist) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) HlsMultivariantPlaylist(com.google.android.exoplayer2.source.hls.playlist.HlsMultivariantPlaylist) Test(org.junit.Test)

Example 2 with FilterableManifestMediaPeriodFactory

use of com.google.android.exoplayer2.testutil.MediaPeriodAsserts.FilterableManifestMediaPeriodFactory in project ExoPlayer by google.

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(com.google.android.exoplayer2.source.TrackGroupArray) ArrayList(java.util.ArrayList) Format(com.google.android.exoplayer2.Format) ExoTrackSelection(com.google.android.exoplayer2.trackselection.ExoTrackSelection) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) ArrayList(java.util.ArrayList) List(java.util.List) MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) StreamKey(com.google.android.exoplayer2.offline.StreamKey)

Example 3 with FilterableManifestMediaPeriodFactory

use of com.google.android.exoplayer2.testutil.MediaPeriodAsserts.FilterableManifestMediaPeriodFactory in project ExoPlayer by google.

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 : MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) TransferListener(com.google.android.exoplayer2.upstream.TransferListener) SsTestUtils.createSsManifest(com.google.android.exoplayer2.source.smoothstreaming.SsTestUtils.createSsManifest) RunWith(org.junit.runner.RunWith) CompositeSequenceableLoaderFactory(com.google.android.exoplayer2.source.CompositeSequenceableLoaderFactory) Test(org.junit.Test) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) Format(com.google.android.exoplayer2.Format) MediaPeriodAsserts(com.google.android.exoplayer2.testutil.MediaPeriodAsserts) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) MimeTypes(com.google.android.exoplayer2.util.MimeTypes) LoadErrorHandlingPolicy(com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy) SsManifest(com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest) FilterableManifestMediaPeriodFactory(com.google.android.exoplayer2.testutil.MediaPeriodAsserts.FilterableManifestMediaPeriodFactory) SsTestUtils.createStreamElement(com.google.android.exoplayer2.source.smoothstreaming.SsTestUtils.createStreamElement) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) Mockito.mock(org.mockito.Mockito.mock) C(com.google.android.exoplayer2.C) Allocator(com.google.android.exoplayer2.upstream.Allocator) LoaderErrorThrower(com.google.android.exoplayer2.upstream.LoaderErrorThrower) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) SsTestUtils.createSsManifest(com.google.android.exoplayer2.source.smoothstreaming.SsTestUtils.createSsManifest) SsManifest(com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest) Test(org.junit.Test)

Aggregations

Format (com.google.android.exoplayer2.Format)3 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)2 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)2 DrmSessionManager (com.google.android.exoplayer2.drm.DrmSessionManager)2 CompositeSequenceableLoaderFactory (com.google.android.exoplayer2.source.CompositeSequenceableLoaderFactory)2 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)2 MediaSourceEventListener (com.google.android.exoplayer2.source.MediaSourceEventListener)2 MediaPeriodAsserts (com.google.android.exoplayer2.testutil.MediaPeriodAsserts)2 FilterableManifestMediaPeriodFactory (com.google.android.exoplayer2.testutil.MediaPeriodAsserts.FilterableManifestMediaPeriodFactory)2 Allocator (com.google.android.exoplayer2.upstream.Allocator)2 LoadErrorHandlingPolicy (com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy)2 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)2 MimeTypes (com.google.android.exoplayer2.util.MimeTypes)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 (com.google.android.exoplayer2.C)1 PlayerId (com.google.android.exoplayer2.analytics.PlayerId)1