Search in sources :

Example 46 with Segment

use of androidx.media3.test.utils.FakeDataSet.FakeData.Segment in project media by androidx.

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(androidx.media3.exoplayer.hls.playlist.HlsMediaPlaylist.Segment) Test(org.junit.Test)

Example 47 with Segment

use of androidx.media3.test.utils.FakeDataSet.FakeData.Segment in project media by androidx.

the class HlsMediaSourceTest method loadLivePlaylist_withNonPreciseStartTime_targetLiveOffsetFromStartTime.

@Test
public void loadLivePlaylist_withNonPreciseStartTime_targetLiveOffsetFromStartTime() 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 = 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 start time (16 - 10 = 6) and then expressed in relation
    // to the live edge (17 - 6 = 11 seconds).
    assertThat(window.liveConfiguration.targetOffsetMs).isEqualTo(11000);
    // The default position points to the segment containing the start time.
    assertThat(window.defaultPositionUs).isEqualTo(4000000);
}
Also used : Timeline(androidx.media3.common.Timeline) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 48 with Segment

use of androidx.media3.test.utils.FakeDataSet.FakeData.Segment in project media by androidx.

the class HlsSampleStreamWrapper method maybeFinishPrepare.

private void maybeFinishPrepare() {
    if (released || trackGroupToSampleQueueIndex != null || !sampleQueuesBuilt) {
        return;
    }
    for (SampleQueue sampleQueue : sampleQueues) {
        if (sampleQueue.getUpstreamFormat() == null) {
            return;
        }
    }
    if (trackGroups != null) {
        // The track groups were created with multivariant playlist information. They only need to be
        // mapped to a sample queue.
        mapSampleQueuesToMatchTrackGroups();
    } else {
        // Tracks are created using media segment information.
        buildTracksFromSampleStreams();
        setIsPrepared();
        callback.onPrepared();
    }
}
Also used : SampleQueue(androidx.media3.exoplayer.source.SampleQueue)

Example 49 with Segment

use of androidx.media3.test.utils.FakeDataSet.FakeData.Segment in project media by androidx.

the class HlsDownloader method getSegments.

@Override
protected List<Segment> getSegments(DataSource dataSource, HlsPlaylist playlist, boolean removing) throws IOException, InterruptedException {
    ArrayList<DataSpec> mediaPlaylistDataSpecs = new ArrayList<>();
    if (playlist instanceof HlsMultivariantPlaylist) {
        HlsMultivariantPlaylist multivariantPlaylist = (HlsMultivariantPlaylist) playlist;
        addMediaPlaylistDataSpecs(multivariantPlaylist.mediaPlaylistUrls, mediaPlaylistDataSpecs);
    } else {
        mediaPlaylistDataSpecs.add(SegmentDownloader.getCompressibleDataSpec(Uri.parse(playlist.baseUri)));
    }
    ArrayList<Segment> segments = new ArrayList<>();
    HashSet<Uri> seenEncryptionKeyUris = new HashSet<>();
    for (DataSpec mediaPlaylistDataSpec : mediaPlaylistDataSpecs) {
        segments.add(new Segment(/* startTimeUs= */
        0, mediaPlaylistDataSpec));
        HlsMediaPlaylist mediaPlaylist;
        try {
            mediaPlaylist = (HlsMediaPlaylist) getManifest(dataSource, mediaPlaylistDataSpec, removing);
        } catch (IOException e) {
            if (!removing) {
                throw e;
            }
            // Generating an incomplete segment list is allowed. Advance to the next media playlist.
            continue;
        }
        @Nullable HlsMediaPlaylist.Segment lastInitSegment = null;
        List<HlsMediaPlaylist.Segment> hlsSegments = mediaPlaylist.segments;
        for (int i = 0; i < hlsSegments.size(); i++) {
            HlsMediaPlaylist.Segment segment = hlsSegments.get(i);
            HlsMediaPlaylist.Segment initSegment = segment.initializationSegment;
            if (initSegment != null && initSegment != lastInitSegment) {
                lastInitSegment = initSegment;
                addSegment(mediaPlaylist, initSegment, seenEncryptionKeyUris, segments);
            }
            addSegment(mediaPlaylist, segment, seenEncryptionKeyUris, segments);
        }
    }
    return segments;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) Uri(android.net.Uri) DataSpec(androidx.media3.datasource.DataSpec) HlsMediaPlaylist(androidx.media3.exoplayer.hls.playlist.HlsMediaPlaylist) HlsMultivariantPlaylist(androidx.media3.exoplayer.hls.playlist.HlsMultivariantPlaylist) Nullable(androidx.annotation.Nullable) HashSet(java.util.HashSet)

Example 50 with Segment

use of androidx.media3.test.utils.FakeDataSet.FakeData.Segment in project media by androidx.

the class DefaultHlsPlaylistTracker method getLoadedPlaylistDiscontinuitySequence.

private int getLoadedPlaylistDiscontinuitySequence(@Nullable HlsMediaPlaylist oldPlaylist, HlsMediaPlaylist loadedPlaylist) {
    if (loadedPlaylist.hasDiscontinuitySequence) {
        return loadedPlaylist.discontinuitySequence;
    }
    // TODO: Improve cross-playlist discontinuity adjustment.
    int primaryUrlDiscontinuitySequence = primaryMediaPlaylistSnapshot != null ? primaryMediaPlaylistSnapshot.discontinuitySequence : 0;
    if (oldPlaylist == null) {
        return primaryUrlDiscontinuitySequence;
    }
    Segment firstOldOverlappingSegment = getFirstOldOverlappingSegment(oldPlaylist, loadedPlaylist);
    if (firstOldOverlappingSegment != null) {
        return oldPlaylist.discontinuitySequence + firstOldOverlappingSegment.relativeDiscontinuitySequence - loadedPlaylist.segments.get(0).relativeDiscontinuitySequence;
    }
    return primaryUrlDiscontinuitySequence;
}
Also used : Segment(androidx.media3.exoplayer.hls.playlist.HlsMediaPlaylist.Segment)

Aggregations

Test (org.junit.Test)20 Uri (android.net.Uri)16 Nullable (androidx.annotation.Nullable)16 Segment (androidx.media3.exoplayer.hls.playlist.HlsMediaPlaylist.Segment)13 DataSpec (androidx.media3.datasource.DataSpec)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 IOException (java.io.IOException)8 InputStream (java.io.InputStream)8 ArrayList (java.util.ArrayList)8 HlsMediaPlaylist (androidx.media3.exoplayer.hls.playlist.HlsMediaPlaylist)7 Format (androidx.media3.common.Format)6 SlowMotionData (androidx.media3.extractor.metadata.mp4.SlowMotionData)5 Segment (androidx.media3.test.utils.FakeDataSet.FakeData.Segment)5 SingleSampleMediaChunk (androidx.media3.exoplayer.source.chunk.SingleSampleMediaChunk)4 Window (androidx.media3.common.Timeline.Window)3 RangedUri (androidx.media3.exoplayer.dash.manifest.RangedUri)3 Representation (androidx.media3.exoplayer.dash.manifest.Representation)3 ContainerMediaChunk (androidx.media3.exoplayer.source.chunk.ContainerMediaChunk)3 MediaChunkIterator (androidx.media3.exoplayer.source.chunk.MediaChunkIterator)3 Segment (androidx.media3.extractor.metadata.mp4.SlowMotionData.Segment)3