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();
}
}
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);
}
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);
}
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());
}
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);
}
Aggregations