use of com.google.android.exoplayer2.source.MediaSource.MediaSourceCaller in project ExoPlayer by google.
the class HlsMediaSourceTest method refreshPlaylist_targetLiveOffsetRemainsInWindow.
@Test
public void refreshPlaylist_targetLiveOffsetRemainsInWindow() throws TimeoutException, IOException {
String playlistUri1 = "fake://foo.bar/media0/playlist1.m3u8";
// The playlist has a duration of 16 seconds and a hold back of 12 seconds.
String playlist1 = "#EXTM3U\n" + "#EXT-X-TARGETDURATION:4\n" + "#EXT-X-VERSION:3\n" + "#EXT-X-MEDIA-SEQUENCE:0\n" + "#EXTINF:4.00000,\n" + "fileSequence0.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence1.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence2.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence3.ts\n" + "#EXT-X-SERVER-CONTROL:HOLD-BACK:12";
// The second playlist defines a different hold back.
String playlistUri2 = "fake://foo.bar/media0/playlist2.m3u8";
String playlist2 = "#EXTM3U\n" + "#EXT-X-TARGETDURATION:4\n" + "#EXT-X-VERSION:3\n" + "#EXT-X-MEDIA-SEQUENCE:4\n" + "#EXTINF:4.00000,\n" + "fileSequence4.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence5.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence6.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence7.ts\n" + "#EXT-X-SERVER-CONTROL:HOLD-BACK:14";
// The third playlist has a duration of 8 seconds.
String playlistUri3 = "fake://foo.bar/media0/playlist3.m3u8";
String playlist3 = "#EXTM3U\n" + "#EXT-X-TARGETDURATION:4\n" + "#EXT-X-VERSION:3\n" + "#EXT-X-MEDIA-SEQUENCE:4\n" + "#EXTINF:4.00000,\n" + "fileSequence8.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence9.ts\n" + "#EXTINF:4.00000,\n" + "#EXT-X-SERVER-CONTROL:HOLD-BACK:12";
// The third playlist has a duration of 16 seconds but the target live offset should remain at
// 8 seconds.
String playlistUri4 = "fake://foo.bar/media0/playlist4.m3u8";
String playlist4 = "#EXTM3U\n" + "#EXT-X-TARGETDURATION:4\n" + "#EXT-X-VERSION:3\n" + "#EXT-X-MEDIA-SEQUENCE:4\n" + "#EXTINF:4.00000,\n" + "fileSequence10.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence11.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence12.ts\n" + "#EXTINF:4.00000,\n" + "fileSequence13.ts\n" + "#EXTINF:4.00000,\n" + "#EXT-X-SERVER-CONTROL:HOLD-BACK:12";
HlsMediaSource.Factory factory = createHlsMediaSourceFactory(playlistUri1, playlist1);
MediaItem mediaItem = new MediaItem.Builder().setUri(playlistUri1).build();
HlsMediaSource mediaSource = factory.createMediaSource(mediaItem);
HlsMediaPlaylist secondPlaylist = parseHlsMediaPlaylist(playlistUri2, playlist2);
HlsMediaPlaylist thirdPlaylist = parseHlsMediaPlaylist(playlistUri3, playlist3);
HlsMediaPlaylist fourthPlaylist = parseHlsMediaPlaylist(playlistUri4, playlist4);
List<Timeline> timelines = new ArrayList<>();
MediaSource.MediaSourceCaller mediaSourceCaller = (source, timeline) -> timelines.add(timeline);
mediaSource.prepareSource(mediaSourceCaller, /* mediaTransferListener= */
null, PlayerId.UNSET);
runMainLooperUntil(() -> timelines.size() == 1);
mediaSource.onPrimaryPlaylistRefreshed(secondPlaylist);
runMainLooperUntil(() -> timelines.size() == 2);
mediaSource.onPrimaryPlaylistRefreshed(thirdPlaylist);
runMainLooperUntil(() -> timelines.size() == 3);
mediaSource.onPrimaryPlaylistRefreshed(fourthPlaylist);
runMainLooperUntil(() -> timelines.size() == 4);
Timeline.Window window = new Timeline.Window();
assertThat(timelines.get(0).getWindow(0, window).liveConfiguration.targetOffsetMs).isEqualTo(12000);
assertThat(timelines.get(1).getWindow(0, window).liveConfiguration.targetOffsetMs).isEqualTo(12000);
assertThat(timelines.get(2).getWindow(0, window).liveConfiguration.targetOffsetMs).isEqualTo(8000);
assertThat(timelines.get(3).getWindow(0, window).liveConfiguration.targetOffsetMs).isEqualTo(8000);
}
use of com.google.android.exoplayer2.source.MediaSource.MediaSourceCaller in project ExoPlayer by google.
the class BaseMediaSource method prepareSource.
@Override
public final void prepareSource(MediaSourceCaller caller, @Nullable TransferListener mediaTransferListener, PlayerId playerId) {
Looper looper = Looper.myLooper();
Assertions.checkArgument(this.looper == null || this.looper == looper);
this.playerId = playerId;
@Nullable Timeline timeline = this.timeline;
mediaSourceCallers.add(caller);
if (this.looper == null) {
this.looper = looper;
enabledMediaSourceCallers.add(caller);
prepareSourceInternal(mediaTransferListener);
} else if (timeline != null) {
enable(caller);
caller.onSourceInfoRefreshed(/* source= */
this, timeline);
}
}
use of com.google.android.exoplayer2.source.MediaSource.MediaSourceCaller in project ExoPlayer by google.
the class DashMediaSourceTest method prepareAndWaitForTimelineRefresh.
private static Window prepareAndWaitForTimelineRefresh(MediaSource mediaSource) throws InterruptedException {
AtomicReference<Window> windowReference = new AtomicReference<>();
CountDownLatch countDownLatch = new CountDownLatch(/* count= */
1);
MediaSourceCaller caller = (MediaSource source, Timeline timeline) -> {
if (windowReference.get() == null) {
windowReference.set(timeline.getWindow(0, new Timeline.Window()));
countDownLatch.countDown();
}
};
mediaSource.prepareSource(caller, /* mediaTransferListener= */
null, PlayerId.UNSET);
while (!countDownLatch.await(/* timeout= */
10, MILLISECONDS)) {
ShadowLooper.idleMainLooper();
}
return windowReference.get();
}
use of com.google.android.exoplayer2.source.MediaSource.MediaSourceCaller in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method customCallbackIsCalledAfterRelease.
@Test
public void customCallbackIsCalledAfterRelease() throws Exception {
DummyMainThread testThread = new DummyMainThread();
CountDownLatch callbackCalledCondition = new CountDownLatch(1);
try {
testThread.runOnMainThread(() -> {
MediaSourceCaller caller = mock(MediaSourceCaller.class);
mediaSource.addMediaSources(Arrays.asList(createMediaSources(2)));
mediaSource.prepareSource(caller, /* mediaTransferListener= */
null, PlayerId.UNSET);
mediaSource.moveMediaSource(/* currentIndex= */
0, /* newIndex= */
1, Util.createHandlerForCurrentLooper(), callbackCalledCondition::countDown);
mediaSource.releaseSource(caller);
});
assertThat(callbackCalledCondition.await(MediaSourceTestRunner.TIMEOUT_MS, MILLISECONDS)).isTrue();
} finally {
testThread.release();
}
}
Aggregations