Search in sources :

Example 1 with ParserException

use of androidx.media3.common.ParserException in project media by androidx.

the class HlsMediaPlaylistParserTest method encryptedMapTagWithNoIvFails.

@Test
public void encryptedMapTagWithNoIvFails() throws IOException {
    Uri playlistUri = Uri.parse("https://example.com/test3.m3u8");
    String playlistString = "#EXTM3U\n" + "#EXT-X-VERSION:3\n" + "#EXT-X-TARGETDURATION:5\n" + "#EXT-X-MEDIA-SEQUENCE:10\n" + "#EXT-X-KEY:METHOD=AES-128," + "URI=\"https://priv.example.com/key.php?r=2680\"\n" + "#EXT-X-MAP:URI=\"init1.ts\"" + "#EXTINF:5.005,\n" + "02/00/32.ts\n";
    InputStream inputStream = new ByteArrayInputStream(Util.getUtf8Bytes(playlistString));
    try {
        new HlsPlaylistParser().parse(playlistUri, inputStream);
        fail();
    } catch (ParserException e) {
    // Expected because the initialization segment does not have a defined initialization vector,
    // although it is affected by an EXT-X-KEY tag.
    }
}
Also used : ParserException(androidx.media3.common.ParserException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Uri(android.net.Uri) Test(org.junit.Test)

Example 2 with ParserException

use of androidx.media3.common.ParserException in project media by androidx.

the class HlsPlaylistParser method parseDrmSchemeData.

@Nullable
private static SchemeData parseDrmSchemeData(String line, String keyFormat, Map<String, String> variableDefinitions) throws ParserException {
    String keyFormatVersions = parseOptionalStringAttr(line, REGEX_KEYFORMATVERSIONS, "1", variableDefinitions);
    if (KEYFORMAT_WIDEVINE_PSSH_BINARY.equals(keyFormat)) {
        String uriString = parseStringAttr(line, REGEX_URI, variableDefinitions);
        return new SchemeData(C.WIDEVINE_UUID, MimeTypes.VIDEO_MP4, Base64.decode(uriString.substring(uriString.indexOf(',')), Base64.DEFAULT));
    } else if (KEYFORMAT_WIDEVINE_PSSH_JSON.equals(keyFormat)) {
        return new SchemeData(C.WIDEVINE_UUID, "hls", Util.getUtf8Bytes(line));
    } else if (KEYFORMAT_PLAYREADY.equals(keyFormat) && "1".equals(keyFormatVersions)) {
        String uriString = parseStringAttr(line, REGEX_URI, variableDefinitions);
        byte[] data = Base64.decode(uriString.substring(uriString.indexOf(',')), Base64.DEFAULT);
        byte[] psshData = PsshAtomUtil.buildPsshAtom(C.PLAYREADY_UUID, data);
        return new SchemeData(C.PLAYREADY_UUID, MimeTypes.VIDEO_MP4, psshData);
    }
    return null;
}
Also used : SchemeData(androidx.media3.common.DrmInitData.SchemeData) Nullable(androidx.annotation.Nullable)

Example 3 with ParserException

use of androidx.media3.common.ParserException in project media by androidx.

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(androidx.media3.common.Timeline) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 4 with ParserException

use of androidx.media3.common.ParserException in project media by androidx.

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(androidx.media3.common.Timeline) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Example 5 with ParserException

use of androidx.media3.common.ParserException in project media by androidx.

the class HlsMediaSourceTest method loadLivePlaylist_withParts_defaultPositionPointsAtClosestIndependentPart.

@Test
public void loadLivePlaylist_withParts_defaultPositionPointsAtClosestIndependentPart() throws TimeoutException, ParserException {
    String playlistUri = "fake://foo.bar/media0/playlist.m3u8";
    // The playlist has a duration of 7 seconds, part hold back and EXT-X-PART-INF 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-MEDIA-SEQUENCE:0\n" + "#EXTINF:4.00000,\n" + "fileSequence0.ts\n" + "#EXT-X-SERVER-CONTROL:HOLD-BACK=12,PART-HOLD-BACK=2\n" + "#EXT-X-PART-INF:PART-TARGET=0.5\n" + "#EXT-X-PART:DURATION=0.5000,URI=\"fileSequence1.0.ts\",INDEPENDENT=YES\n" + "#EXT-X-PART:DURATION=0.5000,URI=\"fileSequence1.1.ts\"\n" + "#EXT-X-PART:DURATION=0.5000,URI=\"fileSequence1.2.ts\",INDEPENDENT=YES\n" + "#EXT-X-PART:DURATION=0.5000,URI=\"fileSequence1.3.ts\"\n" + "#EXT-X-PART:DURATION=0.5000,URI=\"fileSequence1.4.ts\",INDEPENDENT=YES\n" + "#EXT-X-PART:DURATION=0.5000,URI=\"fileSequence1.5.ts\"";
    // The playlist finishes 1 second before the current time.
    SystemClock.setCurrentTimeMillis(Util.parseXsDateTime("2020-01-01T00:00:08.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 part hold back and then expressed in relation to the
    // live edge (+1 seconds).
    assertThat(window.liveConfiguration.targetOffsetMs).isEqualTo(3000);
    // The default position points the closest preceding independent part.
    assertThat(window.defaultPositionUs).isEqualTo(5000000);
}
Also used : Timeline(androidx.media3.common.Timeline) MediaItem(androidx.media3.common.MediaItem) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)25 ParsableByteArray (androidx.media3.common.util.ParsableByteArray)15 MediaItem (androidx.media3.common.MediaItem)13 Timeline (androidx.media3.common.Timeline)13 Nullable (androidx.annotation.Nullable)12 ParserException (androidx.media3.common.ParserException)11 Format (androidx.media3.common.Format)6 PositionHolder (androidx.media3.extractor.PositionHolder)5 FakeExtractorInput (androidx.media3.test.utils.FakeExtractorInput)5 LeafAtom (androidx.media3.extractor.mp4.Atom.LeafAtom)4 DrmInitData (androidx.media3.common.DrmInitData)3 ContainerAtom (androidx.media3.extractor.mp4.Atom.ContainerAtom)3 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)3 Uri (android.net.Uri)2 CallSuper (androidx.annotation.CallSuper)2 SchemeData (androidx.media3.common.DrmInitData.SchemeData)2 AacUtil (androidx.media3.extractor.AacUtil)2 AvcConfig (androidx.media3.extractor.AvcConfig)2 GaplessInfoHolder (androidx.media3.extractor.GaplessInfoHolder)2 ArrayList (java.util.ArrayList)2