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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations