Search in sources :

Example 36 with ParserException

use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.

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(com.google.android.exoplayer2.drm.DrmInitData.SchemeData) Nullable(androidx.annotation.Nullable)

Example 37 with ParserException

use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.

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(com.google.android.exoplayer2.ParserException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Uri(android.net.Uri) Test(org.junit.Test)

Example 38 with ParserException

use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.

the class OggExtractor method sniff.

@Override
public boolean sniff(ExtractorInput input) throws IOException, InterruptedException {
    try {
        OggPageHeader header = new OggPageHeader();
        if (!header.populate(input, true) || (header.type & 0x02) != 0x02) {
            return false;
        }
        int length = Math.min(header.bodySize, MAX_VERIFICATION_BYTES);
        ParsableByteArray scratch = new ParsableByteArray(length);
        input.peekFully(scratch.data, 0, length);
        if (FlacReader.verifyBitstreamType(resetPosition(scratch))) {
            streamReader = new FlacReader();
        } else if (VorbisReader.verifyBitstreamType(resetPosition(scratch))) {
            streamReader = new VorbisReader();
        } else if (OpusReader.verifyBitstreamType(resetPosition(scratch))) {
            streamReader = new OpusReader();
        } else {
            return false;
        }
        return true;
    } catch (ParserException e) {
        return false;
    }
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray) ParserException(com.google.android.exoplayer2.ParserException)

Example 39 with ParserException

use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.

the class VorbisUtilTest method testReadCommentHeader.

public void testReadCommentHeader() throws ParserException {
    byte[] data = TestData.getCommentHeaderDataUTF8();
    ParsableByteArray headerData = new ParsableByteArray(data, data.length);
    VorbisUtil.CommentHeader commentHeader = VorbisUtil.readVorbisCommentHeader(headerData);
    assertEquals("Xiph.Org libVorbis I 20120203 (Omnipresent)", commentHeader.vendor);
    assertEquals(3, commentHeader.comments.length);
    assertEquals("ALBUM=รครถ", commentHeader.comments[0]);
    assertEquals("TITLE=A sample song", commentHeader.comments[1]);
    assertEquals("ARTIST=Google", commentHeader.comments[2]);
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray)

Example 40 with ParserException

use of com.google.android.exoplayer2.ParserException in project ExoPlayer by google.

the class VorbisUtilTest method testVerifyVorbisHeaderCapturePatternInvalidPattern.

public void testVerifyVorbisHeaderCapturePatternInvalidPattern() {
    ParsableByteArray header = new ParsableByteArray(new byte[] { 0x01, 'x', 'v', 'o', 'r', 'b', 'i', 's' });
    try {
        VorbisUtil.verifyVorbisHeaderCapturePattern(0x01, header, false);
        fail();
    } catch (ParserException e) {
        assertEquals("expected characters 'vorbis'", e.getMessage());
    }
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray) ParserException(com.google.android.exoplayer2.ParserException)

Aggregations

ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)25 Test (org.junit.Test)25 ParserException (com.google.android.exoplayer2.ParserException)21 MediaItem (com.google.android.exoplayer2.MediaItem)13 Timeline (com.google.android.exoplayer2.Timeline)13 Nullable (androidx.annotation.Nullable)12 Format (com.google.android.exoplayer2.Format)7 PositionHolder (com.google.android.exoplayer2.extractor.PositionHolder)5 LeafAtom (com.google.android.exoplayer2.extractor.mp4.Atom.LeafAtom)5 FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)5 ArrayList (java.util.ArrayList)5 Uri (android.net.Uri)3 DrmInitData (com.google.android.exoplayer2.drm.DrmInitData)3 ContainerAtom (com.google.android.exoplayer2.extractor.mp4.Atom.ContainerAtom)3 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)3 CallSuper (androidx.annotation.CallSuper)2 AacUtil (com.google.android.exoplayer2.audio.AacUtil)2 SchemeData (com.google.android.exoplayer2.drm.DrmInitData.SchemeData)2 GaplessInfoHolder (com.google.android.exoplayer2.extractor.GaplessInfoHolder)2 AvcConfig (com.google.android.exoplayer2.video.AvcConfig)2