Search in sources :

Example 1 with TsExtractor

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

the class TsExtractorTest method testCustomInitialSectionReader.

public void testCustomInitialSectionReader() throws Exception {
    CustomTsPayloadReaderFactory factory = new CustomTsPayloadReaderFactory(false, true);
    TsExtractor tsExtractor = new TsExtractor(TsExtractor.MODE_NORMAL, new TimestampAdjuster(0), factory);
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(TestUtil.getByteArray(getInstrumentation(), "ts/sample_with_sdt.ts")).setSimulateIOErrors(false).setSimulateUnknownLength(false).setSimulatePartialReads(false).build();
    tsExtractor.init(new FakeExtractorOutput());
    PositionHolder seekPositionHolder = new PositionHolder();
    int readResult = Extractor.RESULT_CONTINUE;
    while (readResult != Extractor.RESULT_END_OF_INPUT) {
        readResult = tsExtractor.read(input, seekPositionHolder);
    }
    assertEquals(1, factory.sdtReader.consumedSdts);
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) PositionHolder(com.google.android.exoplayer2.extractor.PositionHolder) TimestampAdjuster(com.google.android.exoplayer2.util.TimestampAdjuster) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput)

Example 2 with TsExtractor

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

the class TsExtractorTest method testCustomPesReader.

public void testCustomPesReader() throws Exception {
    CustomTsPayloadReaderFactory factory = new CustomTsPayloadReaderFactory(true, false);
    TsExtractor tsExtractor = new TsExtractor(TsExtractor.MODE_NORMAL, new TimestampAdjuster(0), factory);
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(TestUtil.getByteArray(getInstrumentation(), "ts/sample.ts")).setSimulateIOErrors(false).setSimulateUnknownLength(false).setSimulatePartialReads(false).build();
    FakeExtractorOutput output = new FakeExtractorOutput();
    tsExtractor.init(output);
    PositionHolder seekPositionHolder = new PositionHolder();
    int readResult = Extractor.RESULT_CONTINUE;
    while (readResult != Extractor.RESULT_END_OF_INPUT) {
        readResult = tsExtractor.read(input, seekPositionHolder);
    }
    CustomEsReader reader = factory.esReader;
    assertEquals(2, reader.packetsRead);
    TrackOutput trackOutput = reader.getTrackOutput();
    assertTrue(trackOutput == output.trackOutputs.get(257));
    assertEquals(Format.createTextSampleFormat("1/257", "mime", null, 0, 0, "und", null, 0), ((FakeTrackOutput) trackOutput).format);
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) PositionHolder(com.google.android.exoplayer2.extractor.PositionHolder) TimestampAdjuster(com.google.android.exoplayer2.util.TimestampAdjuster) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) TrackOutput(com.google.android.exoplayer2.extractor.TrackOutput) FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput)

Example 3 with TsExtractor

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

the class TsExtractorTest method testIncompleteSample.

public void testIncompleteSample() throws Exception {
    Random random = new Random(0);
    byte[] fileData = TestUtil.getByteArray(getInstrumentation(), "ts/sample.ts");
    ByteArrayOutputStream out = new ByteArrayOutputStream(fileData.length * 2);
    writeJunkData(out, random.nextInt(TS_PACKET_SIZE - 1) + 1);
    out.write(fileData, 0, TS_PACKET_SIZE * 5);
    for (int i = TS_PACKET_SIZE * 5; i < fileData.length; i += TS_PACKET_SIZE) {
        writeJunkData(out, random.nextInt(TS_PACKET_SIZE));
        out.write(fileData, i, TS_PACKET_SIZE);
    }
    out.write(TS_SYNC_BYTE);
    writeJunkData(out, random.nextInt(TS_PACKET_SIZE - 1) + 1);
    fileData = out.toByteArray();
    TestUtil.assertOutput(new TestUtil.ExtractorFactory() {

        @Override
        public Extractor create() {
            return new TsExtractor();
        }
    }, "ts/sample.ts", fileData, getInstrumentation());
}
Also used : Random(java.util.Random) TestUtil(com.google.android.exoplayer2.testutil.TestUtil) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Extractor(com.google.android.exoplayer2.extractor.Extractor)

Example 4 with TsExtractor

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

the class HlsMediaChunk method createExtractor.

private Extractor createExtractor() {
    // Select the extractor that will read the chunk.
    Extractor extractor;
    boolean usingNewExtractor = true;
    if (MimeTypes.TEXT_VTT.equals(hlsUrl.format.sampleMimeType) || lastPathSegment.endsWith(WEBVTT_FILE_EXTENSION) || lastPathSegment.endsWith(VTT_FILE_EXTENSION)) {
        extractor = new WebvttExtractor(trackFormat.language, timestampAdjuster);
    } else if (!needNewExtractor) {
        // Only reuse TS and fMP4 extractors.
        usingNewExtractor = false;
        extractor = previousExtractor;
    } else if (lastPathSegment.endsWith(MP4_FILE_EXTENSION) || lastPathSegment.startsWith(M4_FILE_EXTENSION_PREFIX, lastPathSegment.length() - 4)) {
        extractor = new FragmentedMp4Extractor(0, timestampAdjuster);
    } else {
        // MPEG-2 TS segments, but we need a new extractor.
        // This flag ensures the change of pid between streams does not affect the sample queues.
        @DefaultTsPayloadReaderFactory.Flags int esReaderFactoryFlags = DefaultTsPayloadReaderFactory.FLAG_IGNORE_SPLICE_INFO_STREAM;
        if (!muxedCaptionFormats.isEmpty()) {
            // The playlist declares closed caption renditions, we should ignore descriptors.
            esReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_OVERRIDE_CAPTION_DESCRIPTORS;
        }
        String codecs = trackFormat.codecs;
        if (!TextUtils.isEmpty(codecs)) {
            // explicitly ignore them even if they're declared.
            if (!MimeTypes.AUDIO_AAC.equals(MimeTypes.getAudioMediaMimeType(codecs))) {
                esReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_AAC_STREAM;
            }
            if (!MimeTypes.VIDEO_H264.equals(MimeTypes.getVideoMediaMimeType(codecs))) {
                esReaderFactoryFlags |= DefaultTsPayloadReaderFactory.FLAG_IGNORE_H264_STREAM;
            }
        }
        extractor = new TsExtractor(TsExtractor.MODE_HLS, timestampAdjuster, new DefaultTsPayloadReaderFactory(esReaderFactoryFlags, muxedCaptionFormats));
    }
    if (usingNewExtractor) {
        extractor.init(extractorOutput);
    }
    return extractor;
}
Also used : FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) Extractor(com.google.android.exoplayer2.extractor.Extractor) TsExtractor(com.google.android.exoplayer2.extractor.ts.TsExtractor) Mp3Extractor(com.google.android.exoplayer2.extractor.mp3.Mp3Extractor) AdtsExtractor(com.google.android.exoplayer2.extractor.ts.AdtsExtractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor) TsExtractor(com.google.android.exoplayer2.extractor.ts.TsExtractor) DefaultTsPayloadReaderFactory(com.google.android.exoplayer2.extractor.ts.DefaultTsPayloadReaderFactory)

Aggregations

Extractor (com.google.android.exoplayer2.extractor.Extractor)2 PositionHolder (com.google.android.exoplayer2.extractor.PositionHolder)2 FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)2 FakeExtractorOutput (com.google.android.exoplayer2.testutil.FakeExtractorOutput)2 TimestampAdjuster (com.google.android.exoplayer2.util.TimestampAdjuster)2 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)1 Mp3Extractor (com.google.android.exoplayer2.extractor.mp3.Mp3Extractor)1 FragmentedMp4Extractor (com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor)1 Ac3Extractor (com.google.android.exoplayer2.extractor.ts.Ac3Extractor)1 AdtsExtractor (com.google.android.exoplayer2.extractor.ts.AdtsExtractor)1 DefaultTsPayloadReaderFactory (com.google.android.exoplayer2.extractor.ts.DefaultTsPayloadReaderFactory)1 TsExtractor (com.google.android.exoplayer2.extractor.ts.TsExtractor)1 FakeTrackOutput (com.google.android.exoplayer2.testutil.FakeTrackOutput)1 TestUtil (com.google.android.exoplayer2.testutil.TestUtil)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Random (java.util.Random)1