Search in sources :

Example 31 with MediaPeriodId

use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.

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 : PlaceholderTimeline(com.google.android.exoplayer2.source.MaskingMediaSource.PlaceholderTimeline) Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) MediaSourceTestRunner(com.google.android.exoplayer2.testutil.MediaSourceTestRunner) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)

Example 32 with MediaPeriodId

use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId 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 33 with MediaPeriodId

use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.

the class DefaultDrmSessionManagerTest method preacquireSession_loadsKeysBeforeFullAcquisition.

@Test(timeout = 10_000)
public void preacquireSession_loadsKeysBeforeFullAcquisition() throws Exception {
    AtomicInteger keyLoadCount = new AtomicInteger(0);
    DrmSessionEventListener.EventDispatcher eventDispatcher = new DrmSessionEventListener.EventDispatcher();
    eventDispatcher.addEventListener(Util.createHandlerForCurrentLooper(), new DrmSessionEventListener() {

        @Override
        public void onDrmKeysLoaded(int windowIndex, @Nullable MediaSource.MediaPeriodId mediaPeriodId) {
            keyLoadCount.incrementAndGet();
        }
    });
    FakeExoMediaDrm.LicenseServer licenseServer = FakeExoMediaDrm.LicenseServer.allowingSchemeDatas(DRM_SCHEME_DATAS);
    DrmSessionManager drmSessionManager = new DefaultDrmSessionManager.Builder().setUuidAndExoMediaDrmProvider(DRM_SCHEME_UUID, uuid -> new FakeExoMediaDrm()).setSessionKeepaliveMs(C.TIME_UNSET).build(/* mediaDrmCallback= */
    licenseServer);
    drmSessionManager.prepare();
    drmSessionManager.setPlayer(/* playbackLooper= */
    Looper.myLooper(), PlayerId.UNSET);
    DrmSessionReference sessionReference = drmSessionManager.preacquireSession(eventDispatcher, FORMAT_WITH_DRM_INIT_DATA);
    // STATE_OPENED_WITH_KEYS.
    while (keyLoadCount.get() == 0) {
        // Allow the key response to be handled.
        ShadowLooper.idleMainLooper();
    }
    DrmSession drmSession = checkNotNull(drmSessionManager.acquireSession(/* eventDispatcher= */
    null, FORMAT_WITH_DRM_INIT_DATA));
    // Without idling the main/playback looper, we assert the session is already in OPENED_WITH_KEYS
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS);
    assertThat(keyLoadCount.get()).isEqualTo(1);
    // After releasing our concrete session reference, the session is held open by the pre-acquired
    // reference.
    drmSession.release(/* eventDispatcher= */
    null);
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_OPENED_WITH_KEYS);
    // Releasing the pre-acquired reference allows the session to be fully released.
    sessionReference.release();
    assertThat(drmSession.getState()).isEqualTo(DrmSession.STATE_RELEASED);
}
Also used : FakeExoMediaDrm(com.google.android.exoplayer2.testutil.FakeExoMediaDrm) DrmSessionReference(com.google.android.exoplayer2.drm.DrmSessionManager.DrmSessionReference) MediaSource(com.google.android.exoplayer2.source.MediaSource) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 34 with MediaPeriodId

use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.

the class DefaultPlaybackSessionManagerTest method updateSessions_ofSameWindow_withAd_afterWithoutMediaPeriodId_createsNewSession.

@Test
public void updateSessions_ofSameWindow_withAd_afterWithoutMediaPeriodId_createsNewSession() {
    Timeline timeline = new FakeTimeline();
    MediaPeriodId mediaPeriodId = new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    0), /* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0, /* windowSequenceNumber= */
    0);
    EventTime eventTime1 = createEventTime(timeline, /* windowIndex= */
    0, /* mediaPeriodId= */
    null);
    EventTime eventTime2 = createEventTime(timeline, /* windowIndex= */
    0, mediaPeriodId);
    sessionManager.updateSessions(eventTime1);
    sessionManager.updateSessions(eventTime2);
    ArgumentCaptor<String> contentSessionId = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> adSessionId = ArgumentCaptor.forClass(String.class);
    verify(mockListener).onSessionCreated(eq(eventTime1), contentSessionId.capture());
    verify(mockListener).onSessionCreated(eq(eventTime2), adSessionId.capture());
    verify(mockListener).onSessionActive(eventTime1, contentSessionId.getValue());
    verifyNoMoreInteractions(mockListener);
    assertThat(contentSessionId).isNotEqualTo(adSessionId);
    assertThat(sessionManager.getSessionForMediaPeriodId(timeline, mediaPeriodId)).isEqualTo(adSessionId.getValue());
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 35 with MediaPeriodId

use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.

the class DefaultPlaybackSessionManagerTest method updateSessions_ofOtherWindow_createsNewSession.

@Test
public void updateSessions_ofOtherWindow_createsNewSession() {
    Timeline timeline = new FakeTimeline(/* windowCount= */
    2);
    EventTime eventTime1 = createEventTime(timeline, /* windowIndex= */
    0, /* mediaPeriodId= */
    null);
    EventTime eventTime2 = createEventTime(timeline, /* windowIndex= */
    1, /* mediaPeriodId= */
    null);
    sessionManager.updateSessions(eventTime1);
    sessionManager.updateSessions(eventTime2);
    ArgumentCaptor<String> sessionId1 = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> sessionId2 = ArgumentCaptor.forClass(String.class);
    verify(mockListener).onSessionCreated(eq(eventTime1), sessionId1.capture());
    verify(mockListener).onSessionCreated(eq(eventTime2), sessionId2.capture());
    verify(mockListener).onSessionActive(eventTime1, sessionId1.getValue());
    verifyNoMoreInteractions(mockListener);
    assertThat(sessionId1).isNotEqualTo(sessionId2);
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)106 Test (org.junit.Test)85 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)75 Timeline (com.google.android.exoplayer2.Timeline)50 EventTime (com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)48 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)28 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)28 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)27 Nullable (androidx.annotation.Nullable)26 Allocator (com.google.android.exoplayer2.upstream.Allocator)22 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)19 DrmSessionManager (com.google.android.exoplayer2.drm.DrmSessionManager)17 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)16 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)15 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)15 FakeMediaPeriod (com.google.android.exoplayer2.testutil.FakeMediaPeriod)15 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)15 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)13 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)12 MediaPeriod (com.google.android.exoplayer2.source.MediaPeriod)11