Search in sources :

Example 11 with HlsMediaPlaylist

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

the class HlsMediaPlaylistParserTest method parseMediaPlaylist_withByteRanges.

@Test
public void parseMediaPlaylist_withByteRanges() throws Exception {
    Uri playlistUri = Uri.parse("https://example.com/test.m3u8");
    String playlistString = "#EXTM3U\n" + "#EXT-X-VERSION:3\n" + "#EXT-X-TARGETDURATION:5\n" + "\n" + "#EXT-X-BYTERANGE:200@100\n" + "#EXT-X-MAP:URI=\"stream.mp4\"\n" + "#EXTINF:5,\n" + "#EXT-X-BYTERANGE:400\n" + "stream.mp4\n" + "#EXTINF:5,\n" + "#EXT-X-BYTERANGE:500\n" + "stream.mp4\n" + "#EXT-X-DISCONTINUITY\n" + "#EXT-X-MAP:URI=\"init.mp4\"\n" + "#EXTINF:5,\n" + "segment.mp4\n";
    InputStream inputStream = new ByteArrayInputStream(Util.getUtf8Bytes(playlistString));
    HlsPlaylist playlist = new HlsPlaylistParser().parse(playlistUri, inputStream);
    HlsMediaPlaylist mediaPlaylist = (HlsMediaPlaylist) playlist;
    List<Segment> segments = mediaPlaylist.segments;
    assertThat(segments).isNotNull();
    assertThat(segments).hasSize(3);
    Segment segment = segments.get(0);
    assertThat(segment.initializationSegment.byteRangeOffset).isEqualTo(100);
    assertThat(segment.initializationSegment.byteRangeLength).isEqualTo(200);
    assertThat(segment.byteRangeOffset).isEqualTo(300);
    assertThat(segment.byteRangeLength).isEqualTo(400);
    segment = segments.get(1);
    assertThat(segment.byteRangeOffset).isEqualTo(700);
    assertThat(segment.byteRangeLength).isEqualTo(500);
    segment = segments.get(2);
    assertThat(segment.initializationSegment.byteRangeOffset).isEqualTo(0);
    assertThat(segment.initializationSegment.byteRangeLength).isEqualTo(C.LENGTH_UNSET);
    assertThat(segment.byteRangeOffset).isEqualTo(0);
    assertThat(segment.byteRangeLength).isEqualTo(C.LENGTH_UNSET);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Uri(android.net.Uri) Segment(com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment) Test(org.junit.Test)

Example 12 with HlsMediaPlaylist

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

the class HlsMediaPlaylistParserTest method iframeOnly_withExplicitInitSegment_hasCorrectByteRange.

@Test
public void iframeOnly_withExplicitInitSegment_hasCorrectByteRange() throws IOException {
    Uri playlistUri = Uri.parse("https://example.com/test3.m3u8");
    String playlistString = "#EXTM3U\n" + "#EXT-X-VERSION:6\n" + "#EXT-X-MEDIA-SEQUENCE:1616630672\n" + "#EXT-X-TARGETDURATION:7\n" + "#EXT-X-DISCONTINUITY-SEQUENCE:491 \n" + "#EXT-X-MAP:URI=\"iframe0.tsv\",BYTERANGE=\"564@0\"\n" + "\n" + "#EXT-X-I-FRAMES-ONLY\n" + "#EXT-X-PROGRAM-DATE-TIME:2021-04-12T17:08:22.000Z\n" + "#EXTINF:1.001000,\n" + "#EXT-X-BYTERANGE:121260@1128\n" + "iframe0.tsv";
    InputStream inputStream = new ByteArrayInputStream(Util.getUtf8Bytes(playlistString));
    HlsMediaPlaylist standalonePlaylist = (HlsMediaPlaylist) new HlsPlaylistParser().parse(playlistUri, inputStream);
    @Nullable Segment initSegment = standalonePlaylist.segments.get(0).initializationSegment;
    assertThat(standalonePlaylist.segments).hasSize(1);
    assertThat(initSegment.byteRangeLength).isEqualTo(564);
    assertThat(initSegment.byteRangeOffset).isEqualTo(0);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Uri(android.net.Uri) Nullable(androidx.annotation.Nullable) Segment(com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment) Test(org.junit.Test)

Example 13 with HlsMediaPlaylist

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

the class HlsChunkSourceTest method getAdjustedSeekPositionUs_noIndependentSegments.

@Test
public void getAdjustedSeekPositionUs_noIndependentSegments() throws IOException {
    InputStream inputStream = TestUtil.getInputStream(ApplicationProvider.getApplicationContext(), PLAYLIST);
    HlsMediaPlaylist playlist = (HlsMediaPlaylist) new HlsPlaylistParser().parse(PLAYLIST_URI, inputStream);
    when(mockPlaylistTracker.getPlaylistSnapshot(eq(PLAYLIST_URI), anyBoolean())).thenReturn(playlist);
    long adjustedPositionUs = testChunkSource.getAdjustedSeekPositionUs(playlistTimeToPeriodTimeUs(100_000_000), SeekParameters.EXACT);
    assertThat(periodTimeToPlaylistTimeUs(adjustedPositionUs)).isEqualTo(100_000_000);
}
Also used : InputStream(java.io.InputStream) HlsPlaylistParser(com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistParser) HlsMediaPlaylist(com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist) Test(org.junit.Test)

Example 14 with HlsMediaPlaylist

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

the class HlsChunkSourceTest method setup.

@Before
public void setup() throws IOException {
    mockPlaylistTracker = Mockito.mock(HlsPlaylistTracker.class);
    InputStream inputStream = TestUtil.getInputStream(ApplicationProvider.getApplicationContext(), PLAYLIST_INDEPENDENT_SEGMENTS);
    HlsMediaPlaylist playlist = (HlsMediaPlaylist) new HlsPlaylistParser().parse(PLAYLIST_URI, inputStream);
    when(mockPlaylistTracker.getPlaylistSnapshot(eq(PLAYLIST_URI), anyBoolean())).thenReturn(playlist);
    testChunkSource = new HlsChunkSource(HlsExtractorFactory.DEFAULT, mockPlaylistTracker, new Uri[] { IFRAME_URI, PLAYLIST_URI }, new Format[] { IFRAME_FORMAT, ExoPlayerTestRunner.VIDEO_FORMAT }, new DefaultHlsDataSourceFactory(new FakeDataSource.Factory()), /* mediaTransferListener= */
    null, new TimestampAdjusterProvider(), /* muxedCaptionFormats= */
    null, PlayerId.UNSET);
    when(mockPlaylistTracker.isSnapshotValid(eq(PLAYLIST_URI))).thenReturn(true);
    // Mock that segments totalling PLAYLIST_START_PERIOD_OFFSET_US in duration have been removed
    // from the start of the playlist.
    when(mockPlaylistTracker.getInitialStartTimeUs()).thenReturn(playlist.startTimeUs - PLAYLIST_START_PERIOD_OFFSET_US);
}
Also used : Format(com.google.android.exoplayer2.Format) FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) HlsPlaylistTracker(com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistTracker) InputStream(java.io.InputStream) HlsPlaylistParser(com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistParser) HlsMediaPlaylist(com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist) Uri(android.net.Uri) Before(org.junit.Before)

Example 15 with HlsMediaPlaylist

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

the class HlsMediaPlaylistSegmentIteratorTest method create_withMediaSequenceBehindLiveWindow_isEmpty.

@Test
public void create_withMediaSequenceBehindLiveWindow_isEmpty() {
    HlsMediaPlaylist mediaPlaylist = getHlsMediaPlaylist(LOW_LATENCY_SEGMENTS_AND_PARTS);
    HlsChunkSource.HlsMediaPlaylistSegmentIterator hlsMediaPlaylistSegmentIterator = new HlsChunkSource.HlsMediaPlaylistSegmentIterator(mediaPlaylist.baseUri, /* startOfPlaylistInPeriodUs= */
    0, HlsChunkSource.getSegmentBaseList(mediaPlaylist, mediaPlaylist.mediaSequence - 1, /* partIndex= */
    C.INDEX_UNSET));
    assertThat(hlsMediaPlaylistSegmentIterator.next()).isFalse();
}
Also used : HlsMediaPlaylist(com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist) Test(org.junit.Test)

Aggregations

HlsMediaPlaylist (com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist)20 Uri (android.net.Uri)18 Segment (com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment)18 Test (org.junit.Test)18 InputStream (java.io.InputStream)11 ArrayList (java.util.ArrayList)11 Nullable (androidx.annotation.Nullable)9 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)9 ByteArrayInputStream (java.io.ByteArrayInputStream)9 HlsPlaylistParser (com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistParser)4 IOException (java.io.IOException)3 ParserException (com.google.android.exoplayer2.ParserException)2 BehindLiveWindowException (com.google.android.exoplayer2.source.BehindLiveWindowException)2 BaseMediaChunkIterator (com.google.android.exoplayer2.source.chunk.BaseMediaChunkIterator)2 MediaChunkIterator (com.google.android.exoplayer2.source.chunk.MediaChunkIterator)2 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)2 SystemClock (android.os.SystemClock)1 Pair (android.util.Pair)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)1