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