Search in sources :

Example 46 with ExtractorInput

use of com.google.android.exoplayer2.extractor.ExtractorInput in project ExoPlayer by google.

the class DefaultHlsExtractorFactoryTest method createExtractor_withInvalidFileTypeInUri_returnsSniffedType.

@Test
public void createExtractor_withInvalidFileTypeInUri_returnsSniffedType() throws Exception {
    ExtractorInput tsExtractorInput = new FakeExtractorInput.Builder().setData(TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), "media/ts/sample_ac3.ts")).build();
    BundledHlsMediaChunkExtractor result = new DefaultHlsExtractorFactory().createExtractor(URI_WITH_JPEG_EXTENSION, webVttFormat, /* muxedCaptionFormats= */
    null, timestampAdjuster, ImmutableMap.of("Content-Type", ImmutableList.of(MimeTypes.IMAGE_JPEG)), tsExtractorInput, PlayerId.UNSET);
    assertThat(result.extractor.getClass()).isEqualTo(TsExtractor.class);
}
Also used : ExtractorInput(com.google.android.exoplayer2.extractor.ExtractorInput) FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) Test(org.junit.Test)

Example 47 with ExtractorInput

use of com.google.android.exoplayer2.extractor.ExtractorInput in project ExoPlayer by google.

the class DefaultHlsExtractorFactoryTest method createExtractor_onFailedSniff_fallsBackOnFormatInferred.

@Test
public void createExtractor_onFailedSniff_fallsBackOnFormatInferred() throws Exception {
    ExtractorInput emptyExtractorInput = new FakeExtractorInput.Builder().build();
    BundledHlsMediaChunkExtractor result = new DefaultHlsExtractorFactory().createExtractor(URI_WITH_MP4_EXTENSION, webVttFormat, /* muxedCaptionFormats= */
    null, timestampAdjuster, ac3ResponseHeaders, emptyExtractorInput, PlayerId.UNSET);
    // The format indicates WebVTT so we expect a WebVTT extractor.
    assertThat(result.extractor.getClass()).isEqualTo(WebvttExtractor.class);
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) ExtractorInput(com.google.android.exoplayer2.extractor.ExtractorInput) FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) Test(org.junit.Test)

Example 48 with ExtractorInput

use of com.google.android.exoplayer2.extractor.ExtractorInput in project ExoPlayer by google.

the class DefaultHlsExtractorFactoryTest method createExtractor_onFailedSniff_fallsBackOnHttpContentType.

@Test
public void createExtractor_onFailedSniff_fallsBackOnHttpContentType() throws Exception {
    ExtractorInput emptyExtractorInput = new FakeExtractorInput.Builder().build();
    BundledHlsMediaChunkExtractor result = new DefaultHlsExtractorFactory().createExtractor(URI_WITH_MP4_EXTENSION, new Format.Builder().build(), /* muxedCaptionFormats= */
    null, timestampAdjuster, ac3ResponseHeaders, emptyExtractorInput, PlayerId.UNSET);
    // No format info, so we expect an AC-3 Extractor, as per HTTP Content-Type header.
    assertThat(result.extractor.getClass()).isEqualTo(Ac3Extractor.class);
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) ExtractorInput(com.google.android.exoplayer2.extractor.ExtractorInput) FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) Test(org.junit.Test)

Example 49 with ExtractorInput

use of com.google.android.exoplayer2.extractor.ExtractorInput in project ExoPlayer by google.

the class DefaultHlsExtractorFactoryTest method createExtractor_onFailedSniff_fallsBackOnFileExtension.

@Test
public void createExtractor_onFailedSniff_fallsBackOnFileExtension() throws Exception {
    ExtractorInput emptyExtractorInput = new FakeExtractorInput.Builder().build();
    BundledHlsMediaChunkExtractor result = new DefaultHlsExtractorFactory().createExtractor(URI_WITH_MP4_EXTENSION, new Format.Builder().build(), /* muxedCaptionFormats= */
    null, timestampAdjuster, /* responseHeaders= */
    ImmutableMap.of(), emptyExtractorInput, PlayerId.UNSET);
    // No format info, and no HTTP headers, so we expect an fMP4 extractor, as per file extension.
    assertThat(result.extractor.getClass()).isEqualTo(FragmentedMp4Extractor.class);
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) ExtractorInput(com.google.android.exoplayer2.extractor.ExtractorInput) FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) Test(org.junit.Test)

Example 50 with ExtractorInput

use of com.google.android.exoplayer2.extractor.ExtractorInput in project ExoPlayer by google.

the class FragmentedMp4Extractor method readAtomHeader.

private boolean readAtomHeader(ExtractorInput input) throws IOException {
    if (atomHeaderBytesRead == 0) {
        // Read the standard length atom header.
        if (!input.readFully(atomHeader.getData(), 0, Atom.HEADER_SIZE, true)) {
            return false;
        }
        atomHeaderBytesRead = Atom.HEADER_SIZE;
        atomHeader.setPosition(0);
        atomSize = atomHeader.readUnsignedInt();
        atomType = atomHeader.readInt();
    }
    if (atomSize == Atom.DEFINES_LARGE_SIZE) {
        // Read the large size.
        int headerBytesRemaining = Atom.LONG_HEADER_SIZE - Atom.HEADER_SIZE;
        input.readFully(atomHeader.getData(), Atom.HEADER_SIZE, headerBytesRemaining);
        atomHeaderBytesRead += headerBytesRemaining;
        atomSize = atomHeader.readUnsignedLongToLong();
    } else if (atomSize == Atom.EXTENDS_TO_END_SIZE) {
        // The atom extends to the end of the file. Note that if the atom is within a container we can
        // work out its size even if the input length is unknown.
        long endPosition = input.getLength();
        if (endPosition == C.LENGTH_UNSET && !containerAtoms.isEmpty()) {
            endPosition = containerAtoms.peek().endPosition;
        }
        if (endPosition != C.LENGTH_UNSET) {
            atomSize = endPosition - input.getPosition() + atomHeaderBytesRead;
        }
    }
    if (atomSize < atomHeaderBytesRead) {
        throw ParserException.createForUnsupportedContainerFeature("Atom size less than header length (unsupported).");
    }
    long atomPosition = input.getPosition() - atomHeaderBytesRead;
    if (atomType == Atom.TYPE_moof || atomType == Atom.TYPE_mdat) {
        if (!haveOutputSeekMap) {
            // This must be the first moof or mdat in the stream.
            extractorOutput.seekMap(new SeekMap.Unseekable(durationUs, atomPosition));
            haveOutputSeekMap = true;
        }
    }
    if (atomType == Atom.TYPE_moof) {
        // The data positions may be updated when parsing the tfhd/trun.
        int trackCount = trackBundles.size();
        for (int i = 0; i < trackCount; i++) {
            TrackFragment fragment = trackBundles.valueAt(i).fragment;
            fragment.atomPosition = atomPosition;
            fragment.auxiliaryDataPosition = atomPosition;
            fragment.dataPosition = atomPosition;
        }
    }
    if (atomType == Atom.TYPE_mdat) {
        currentTrackBundle = null;
        endOfMdatPosition = atomPosition + atomSize;
        parserState = STATE_READING_ENCRYPTION_DATA;
        return true;
    }
    if (shouldParseContainerAtom(atomType)) {
        long endPosition = input.getPosition() + atomSize - Atom.HEADER_SIZE;
        containerAtoms.push(new ContainerAtom(atomType, endPosition));
        if (atomSize == atomHeaderBytesRead) {
            processAtomEnded(endPosition);
        } else {
            // Start reading the first child atom.
            enterReadingAtomHeaderState();
        }
    } else if (shouldParseLeafAtom(atomType)) {
        if (atomHeaderBytesRead != Atom.HEADER_SIZE) {
            throw ParserException.createForUnsupportedContainerFeature("Leaf atom defines extended atom size (unsupported).");
        }
        if (atomSize > Integer.MAX_VALUE) {
            throw ParserException.createForUnsupportedContainerFeature("Leaf atom with length > 2147483647 (unsupported).");
        }
        ParsableByteArray atomData = new ParsableByteArray((int) atomSize);
        System.arraycopy(atomHeader.getData(), 0, atomData.getData(), 0, Atom.HEADER_SIZE);
        this.atomData = atomData;
        parserState = STATE_READING_ATOM_PAYLOAD;
    } else {
        if (atomSize > Integer.MAX_VALUE) {
            throw ParserException.createForUnsupportedContainerFeature("Skipping atom with length > 2147483647 (unsupported).");
        }
        atomData = null;
        parserState = STATE_READING_ATOM_PAYLOAD;
    }
    return true;
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray) ContainerAtom(com.google.android.exoplayer2.extractor.mp4.Atom.ContainerAtom) SeekMap(com.google.android.exoplayer2.extractor.SeekMap)

Aggregations

FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)85 Test (org.junit.Test)71 ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)53 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)39 FlacStreamMetadataHolder (com.google.android.exoplayer2.extractor.FlacMetadataReader.FlacStreamMetadataHolder)20 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)17 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)16 Nullable (androidx.annotation.Nullable)15 Metadata (com.google.android.exoplayer2.metadata.Metadata)13 SampleNumberHolder (com.google.android.exoplayer2.extractor.FlacFrameReader.SampleNumberHolder)9 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)9 EOFException (java.io.EOFException)8 SeekPoint (com.google.android.exoplayer2.extractor.SeekPoint)7 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)7 ParserException (com.google.android.exoplayer2.ParserException)5 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)5 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)5 IOException (java.io.IOException)5 PositionHolder (com.google.android.exoplayer2.extractor.PositionHolder)3 Id3Decoder (com.google.android.exoplayer2.metadata.id3.Id3Decoder)3