Search in sources :

Example 1 with ParserException

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

the class FragmentedMp4Extractor method parseTraf.

/**
   * Parses a traf atom (defined in 14496-12).
   */
private static void parseTraf(ContainerAtom traf, SparseArray<TrackBundle> trackBundleArray, @Flags int flags, byte[] extendedTypeScratch) throws ParserException {
    LeafAtom tfhd = traf.getLeafAtomOfType(Atom.TYPE_tfhd);
    TrackBundle trackBundle = parseTfhd(tfhd.data, trackBundleArray, flags);
    if (trackBundle == null) {
        return;
    }
    TrackFragment fragment = trackBundle.fragment;
    long decodeTime = fragment.nextFragmentDecodeTime;
    trackBundle.reset();
    LeafAtom tfdtAtom = traf.getLeafAtomOfType(Atom.TYPE_tfdt);
    if (tfdtAtom != null && (flags & FLAG_WORKAROUND_IGNORE_TFDT_BOX) == 0) {
        decodeTime = parseTfdt(traf.getLeafAtomOfType(Atom.TYPE_tfdt).data);
    }
    parseTruns(traf, trackBundle, decodeTime, flags);
    LeafAtom saiz = traf.getLeafAtomOfType(Atom.TYPE_saiz);
    if (saiz != null) {
        TrackEncryptionBox trackEncryptionBox = trackBundle.track.sampleDescriptionEncryptionBoxes[fragment.header.sampleDescriptionIndex];
        parseSaiz(trackEncryptionBox, saiz.data, fragment);
    }
    LeafAtom saio = traf.getLeafAtomOfType(Atom.TYPE_saio);
    if (saio != null) {
        parseSaio(saio.data, fragment);
    }
    LeafAtom senc = traf.getLeafAtomOfType(Atom.TYPE_senc);
    if (senc != null) {
        parseSenc(senc.data, fragment);
    }
    LeafAtom sbgp = traf.getLeafAtomOfType(Atom.TYPE_sbgp);
    LeafAtom sgpd = traf.getLeafAtomOfType(Atom.TYPE_sgpd);
    if (sbgp != null && sgpd != null) {
        parseSgpd(sbgp.data, sgpd.data, fragment);
    }
    int leafChildrenSize = traf.leafChildren.size();
    for (int i = 0; i < leafChildrenSize; i++) {
        LeafAtom atom = traf.leafChildren.get(i);
        if (atom.type == Atom.TYPE_uuid) {
            parseUuid(atom.data, fragment, extendedTypeScratch);
        }
    }
}
Also used : LeafAtom(com.google.android.exoplayer2.extractor.mp4.Atom.LeafAtom)

Example 2 with ParserException

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

the class WavHeaderReader method peek.

/**
   * Peeks and returns a {@code WavHeader}.
   *
   * @param input Input stream to peek the WAV header from.
   * @throws ParserException If the input file is an incorrect RIFF WAV.
   * @throws IOException If peeking from the input fails.
   * @throws InterruptedException If interrupted while peeking from input.
   * @return A new {@code WavHeader} peeked from {@code input}, or null if the input is not a
   *     supported WAV format.
   */
public static WavHeader peek(ExtractorInput input) throws IOException, InterruptedException {
    Assertions.checkNotNull(input);
    // Allocate a scratch buffer large enough to store the format chunk.
    ParsableByteArray scratch = new ParsableByteArray(16);
    // Attempt to read the RIFF chunk.
    ChunkHeader chunkHeader = ChunkHeader.peek(input, scratch);
    if (chunkHeader.id != Util.getIntegerCodeForString("RIFF")) {
        return null;
    }
    input.peekFully(scratch.data, 0, 4);
    scratch.setPosition(0);
    int riffFormat = scratch.readInt();
    if (riffFormat != Util.getIntegerCodeForString("WAVE")) {
        Log.e(TAG, "Unsupported RIFF format: " + riffFormat);
        return null;
    }
    // Skip chunks until we find the format chunk.
    chunkHeader = ChunkHeader.peek(input, scratch);
    while (chunkHeader.id != Util.getIntegerCodeForString("fmt ")) {
        input.advancePeekPosition((int) chunkHeader.size);
        chunkHeader = ChunkHeader.peek(input, scratch);
    }
    Assertions.checkState(chunkHeader.size >= 16);
    input.peekFully(scratch.data, 0, 16);
    scratch.setPosition(0);
    int type = scratch.readLittleEndianUnsignedShort();
    int numChannels = scratch.readLittleEndianUnsignedShort();
    int sampleRateHz = scratch.readLittleEndianUnsignedIntToInt();
    int averageBytesPerSecond = scratch.readLittleEndianUnsignedIntToInt();
    int blockAlignment = scratch.readLittleEndianUnsignedShort();
    int bitsPerSample = scratch.readLittleEndianUnsignedShort();
    int expectedBlockAlignment = numChannels * bitsPerSample / 8;
    if (blockAlignment != expectedBlockAlignment) {
        throw new ParserException("Expected block alignment: " + expectedBlockAlignment + "; got: " + blockAlignment);
    }
    @C.PcmEncoding int encoding = Util.getPcmEncoding(bitsPerSample);
    if (encoding == C.ENCODING_INVALID) {
        Log.e(TAG, "Unsupported WAV bit depth: " + bitsPerSample);
        return null;
    }
    if (type != TYPE_PCM && type != TYPE_WAVE_FORMAT_EXTENSIBLE) {
        Log.e(TAG, "Unsupported WAV format type: " + type);
        return null;
    }
    // If present, skip extensionSize, validBitsPerSample, channelMask, subFormatGuid, ...
    input.advancePeekPosition((int) chunkHeader.size - 16);
    return new WavHeader(numChannels, sampleRateHz, averageBytesPerSecond, blockAlignment, bitsPerSample, encoding);
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray) ParserException(com.google.android.exoplayer2.ParserException)

Example 3 with ParserException

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

the class VorbisUtilTest method testVerifyVorbisHeaderCapturePatternQuiteInvalidPatternQuite.

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

Example 4 with ParserException

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

the class VorbisUtilTest method testVerifyVorbisHeaderCapturePatternInvalidHeader.

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

Example 5 with ParserException

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

the class VorbisUtilTest method testVerifyVorbisHeaderCapturePattern.

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

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