Search in sources :

Example 26 with Part

use of com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Part in project ExoPlayer by google.

the class HlsMediaSourceTest method loadLivePlaylist_partHoldBackWithoutPartInformationInPlaylist_targetLiveOffsetFromHoldBack.

@Test
public void loadLivePlaylist_partHoldBackWithoutPartInformationInPlaylist_targetLiveOffsetFromHoldBack() throws TimeoutException, ParserException {
    String playlistUri = "fake://foo.bar/media0/playlist.m3u8";
    // The playlist has a part hold back but not EXT-X-PART-INF. We should pick up the hold back.
    // The duration of the playlist is 16 seconds so that the defined hold back is within the live
    // window.
    String playlist = "#EXTM3U\n" + "#EXT-X-PROGRAM-DATE-TIME:2020-01-01T00:00:00.0+00:00\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,PART-HOLD-BACK=3";
    // The playlist finishes 1 second before the current time.
    SystemClock.setCurrentTimeMillis(Util.parseXsDateTime("2020-01-01T00:00:17.0+00:00"));
    HlsMediaSource.Factory factory = createHlsMediaSourceFactory(playlistUri, playlist);
    MediaItem mediaItem = MediaItem.fromUri(playlistUri);
    HlsMediaSource mediaSource = factory.createMediaSource(mediaItem);
    Timeline timeline = prepareAndWaitForTimeline(mediaSource);
    Timeline.Window window = timeline.getWindow(0, new Timeline.Window());
    // The target live offset is picked from hold back and then expressed in relation to the live
    // edge (+1 seconds).
    assertThat(window.liveConfiguration.targetOffsetMs).isEqualTo(13000);
    assertThat(window.liveConfiguration.minPlaybackSpeed).isEqualTo(C.RATE_UNSET);
    assertThat(window.liveConfiguration.maxPlaybackSpeed).isEqualTo(C.RATE_UNSET);
    assertThat(window.defaultPositionUs).isEqualTo(4000000);
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 27 with Part

use of com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Part in project ExoPlayer by google.

the class HlsMediaSourceTest method loadLivePlaylist_withNonPreciseStartTimeAndUserDefinedLiveOffset_startsFromPrecedingSegment.

@Test
public void loadLivePlaylist_withNonPreciseStartTimeAndUserDefinedLiveOffset_startsFromPrecedingSegment() throws TimeoutException, ParserException {
    String playlistUri = "fake://foo.bar/media0/playlist.m3u8";
    // The playlist has a duration of 16 seconds, and part hold back, hold back and start time
    // defined.
    String playlist = "#EXTM3U\n" + "#EXT-X-PROGRAM-DATE-TIME:2020-01-01T00:00:00.0+00:00\n" + "#EXT-X-TARGETDURATION:4\n" + "#EXT-X-VERSION:3\n" + "#EXT-X-START:TIME-OFFSET=-10\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,PART-HOLD-BACK=3\n";
    // The playlist finishes 1 second before the current time.
    SystemClock.setCurrentTimeMillis(Util.parseXsDateTime("2020-01-01T00:00:17.0+00:00"));
    HlsMediaSource.Factory factory = createHlsMediaSourceFactory(playlistUri, playlist);
    MediaItem mediaItem = new MediaItem.Builder().setUri(playlistUri).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(3000).build()).build();
    HlsMediaSource mediaSource = factory.createMediaSource(mediaItem);
    Timeline timeline = prepareAndWaitForTimeline(mediaSource);
    Timeline.Window window = timeline.getWindow(0, new Timeline.Window());
    assertThat(window.liveConfiguration.targetOffsetMs).isEqualTo(3000);
    // The default position points to the segment containing the start time.
    assertThat(window.defaultPositionUs).isEqualTo(4000000);
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 28 with Part

use of com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Part in project ExoPlayer by google.

the class HlsMediaPlaylistSegmentIteratorTest method next_startIteratorAtTrailingPart_correctElements.

@Test
public void next_startIteratorAtTrailingPart_correctElements() {
    HlsMediaPlaylist mediaPlaylist = getHlsMediaPlaylist(LOW_LATENCY_SEGMENTS_AND_PARTS);
    HlsChunkSource.HlsMediaPlaylistSegmentIterator hlsMediaPlaylistSegmentIterator = new HlsChunkSource.HlsMediaPlaylistSegmentIterator(mediaPlaylist.baseUri, /* startOfPlaylistInPeriodUs= */
    0, HlsChunkSource.getSegmentBaseList(mediaPlaylist, /* mediaSequence= */
    16, /* partIndex= */
    1));
    List<DataSpec> datasSpecs = new ArrayList<>();
    while (hlsMediaPlaylistSegmentIterator.next()) {
        datasSpecs.add(hlsMediaPlaylistSegmentIterator.getDataSpec());
    }
    assertThat(datasSpecs).hasSize(2);
    // The iterator starts with 2 parts.
    assertThat(datasSpecs.get(0).uri.toString()).isEqualTo("fileSequence16.1.ts");
    // The preload part is the last.
    assertThat(Iterables.getLast(datasSpecs).uri.toString()).isEqualTo("fileSequence16.2.ts");
}
Also used : ArrayList(java.util.ArrayList) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) HlsMediaPlaylist(com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 MediaItem (com.google.android.exoplayer2.MediaItem)11 Timeline (com.google.android.exoplayer2.Timeline)11 Nullable (androidx.annotation.Nullable)6 HlsMediaPlaylist (com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist)6 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)6 ArrayList (java.util.ArrayList)6 Segment (com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment)4 Uri (android.net.Uri)3 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)3 SurfaceTexture (android.graphics.SurfaceTexture)2 Pair (android.util.Pair)2 Surface (android.view.Surface)2 ApplicationProvider (androidx.test.core.app.ApplicationProvider)2 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)2 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)2 Player (com.google.android.exoplayer2.Player)2 DrmInitData (com.google.android.exoplayer2.drm.DrmInitData)2 MediaChunkIterator (com.google.android.exoplayer2.source.chunk.MediaChunkIterator)2 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)2