Search in sources :

Example 21 with ParserException

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

the class HlsPlaylistParser method parse.

@Override
public HlsPlaylist parse(Uri uri, InputStream inputStream) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
    Queue<String> extraLines = new LinkedList<>();
    String line;
    try {
        if (!checkPlaylistHeader(reader)) {
            throw new UnrecognizedInputFormatException("Input does not start with the #EXTM3U header.", uri);
        }
        while ((line = reader.readLine()) != null) {
            line = line.trim();
            if (line.isEmpty()) {
            // Do nothing.
            } else if (line.startsWith(TAG_STREAM_INF)) {
                extraLines.add(line);
                return parseMasterPlaylist(new LineIterator(extraLines, reader), uri.toString());
            } else if (line.startsWith(TAG_TARGET_DURATION) || line.startsWith(TAG_MEDIA_SEQUENCE) || line.startsWith(TAG_MEDIA_DURATION) || line.startsWith(TAG_KEY) || line.startsWith(TAG_BYTERANGE) || line.equals(TAG_DISCONTINUITY) || line.equals(TAG_DISCONTINUITY_SEQUENCE) || line.equals(TAG_ENDLIST)) {
                extraLines.add(line);
                return parseMediaPlaylist(new LineIterator(extraLines, reader), uri.toString());
            } else {
                extraLines.add(line);
            }
        }
    } finally {
        Util.closeQuietly(reader);
    }
    throw new ParserException("Failed to parse the playlist, could not identify any tags.");
}
Also used : UnrecognizedInputFormatException(com.google.android.exoplayer2.source.UnrecognizedInputFormatException) ParserException(com.google.android.exoplayer2.ParserException) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) LinkedList(java.util.LinkedList)

Example 22 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 23 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)

Example 24 with ParserException

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

the class VorbisUtilTest method testVerifyVorbisHeaderCapturePatternInvalidHeaderQuite.

public void testVerifyVorbisHeaderCapturePatternInvalidHeaderQuite() throws ParserException {
    ParsableByteArray header = new ParsableByteArray(new byte[] { 0x01, 'v', 'o', 'r', 'b', 'i', 's' });
    assertFalse(VorbisUtil.verifyVorbisHeaderCapturePattern(0x99, header, true));
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray)

Example 25 with ParserException

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

the class WavExtractor method read.

@Override
public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException, InterruptedException {
    if (wavHeader == null) {
        wavHeader = WavHeaderReader.peek(input);
        if (wavHeader == null) {
            // Should only happen if the media wasn't sniffed.
            throw new ParserException("Unsupported or unrecognized wav header.");
        }
        Format format = Format.createAudioSampleFormat(null, MimeTypes.AUDIO_RAW, null, wavHeader.getBitrate(), MAX_INPUT_SIZE, wavHeader.getNumChannels(), wavHeader.getSampleRateHz(), wavHeader.getEncoding(), null, null, 0, null);
        trackOutput.format(format);
        bytesPerFrame = wavHeader.getBytesPerFrame();
    }
    if (!wavHeader.hasDataBounds()) {
        WavHeaderReader.skipToData(input, wavHeader);
        extractorOutput.seekMap(this);
    }
    int bytesAppended = trackOutput.sampleData(input, MAX_INPUT_SIZE - pendingBytes, true);
    if (bytesAppended != RESULT_END_OF_INPUT) {
        pendingBytes += bytesAppended;
    }
    // Samples must consist of a whole number of frames.
    int pendingFrames = pendingBytes / bytesPerFrame;
    if (pendingFrames > 0) {
        long timeUs = wavHeader.getTimeUs(input.getPosition() - pendingBytes);
        int size = pendingFrames * bytesPerFrame;
        pendingBytes -= size;
        trackOutput.sampleMetadata(timeUs, C.BUFFER_FLAG_KEY_FRAME, size, pendingBytes, null);
    }
    return bytesAppended == RESULT_END_OF_INPUT ? RESULT_END_OF_INPUT : RESULT_CONTINUE;
}
Also used : ParserException(com.google.android.exoplayer2.ParserException) Format(com.google.android.exoplayer2.Format)

Aggregations

ParserException (com.google.android.exoplayer2.ParserException)23 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)14 ContainerAtom (com.google.android.exoplayer2.extractor.mp4.Atom.ContainerAtom)4 ArrayList (java.util.ArrayList)4 Format (com.google.android.exoplayer2.Format)3 DrmInitData (com.google.android.exoplayer2.drm.DrmInitData)3 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)3 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)3 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)2 LeafAtom (com.google.android.exoplayer2.extractor.mp4.Atom.LeafAtom)2 AvcConfig (com.google.android.exoplayer2.video.AvcConfig)2 Matcher (java.util.regex.Matcher)2 XmlPullParser (org.xmlpull.v1.XmlPullParser)2 Point (android.graphics.Point)1 Uri (android.net.Uri)1 Pair (android.util.Pair)1 SparseArray (android.util.SparseArray)1 SchemeData (com.google.android.exoplayer2.drm.DrmInitData.SchemeData)1 ChunkIndex (com.google.android.exoplayer2.extractor.ChunkIndex)1 GaplessInfoHolder (com.google.android.exoplayer2.extractor.GaplessInfoHolder)1