Search in sources :

Example 11 with AmrExtractor

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

the class AmrExtractorSeekTest method seeking_handlesSeekingToPositionInFile_extractsCorrectFrame_forNarrowBandAmr.

@Test
public void seeking_handlesSeekingToPositionInFile_extractsCorrectFrame_forNarrowBandAmr() throws IOException {
    String fileName = NARROW_BAND_AMR_FILE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAmrExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
    AmrExtractor extractor = createAmrExtractor();
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long targetSeekTimeUs = 980_000;
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(-1);
    assertFirstFrameAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Example 12 with AmrExtractor

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

the class AmrExtractorSeekTest method seeking_handlesSeekingBackward_extractsCorrectFrames_forNarrowBandAmr.

@Test
public void seeking_handlesSeekingBackward_extractsCorrectFrames_forNarrowBandAmr() throws IOException {
    String fileName = NARROW_BAND_AMR_FILE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAmrExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
    AmrExtractor extractor = createAmrExtractor();
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long firstSeekTimeUs = 980_000;
    TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
    long targetSeekTimeUs = 0;
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(-1);
    assertFirstFrameAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Example 13 with AmrExtractor

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

the class DefaultExtractorsFactory method addExtractorsForFileType.

private void addExtractorsForFileType(@FileTypes.Type int fileType, List<Extractor> extractors) {
    switch(fileType) {
        case FileTypes.AC3:
            extractors.add(new Ac3Extractor());
            break;
        case FileTypes.AC4:
            extractors.add(new Ac4Extractor());
            break;
        case FileTypes.ADTS:
            extractors.add(new AdtsExtractor(adtsFlags | (constantBitrateSeekingEnabled ? AdtsExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING : 0) | (constantBitrateSeekingAlwaysEnabled ? AdtsExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING_ALWAYS : 0)));
            break;
        case FileTypes.AMR:
            extractors.add(new AmrExtractor(amrFlags | (constantBitrateSeekingEnabled ? AmrExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING : 0) | (constantBitrateSeekingAlwaysEnabled ? AmrExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING_ALWAYS : 0)));
            break;
        case FileTypes.FLAC:
            @Nullable Extractor flacExtractor = FLAC_EXTENSION_LOADER.getExtractor(flacFlags);
            if (flacExtractor != null) {
                extractors.add(flacExtractor);
            } else {
                extractors.add(new FlacExtractor(flacFlags));
            }
            break;
        case FileTypes.FLV:
            extractors.add(new FlvExtractor());
            break;
        case FileTypes.MATROSKA:
            extractors.add(new MatroskaExtractor(matroskaFlags));
            break;
        case FileTypes.MP3:
            extractors.add(new Mp3Extractor(mp3Flags | (constantBitrateSeekingEnabled ? Mp3Extractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING : 0) | (constantBitrateSeekingAlwaysEnabled ? Mp3Extractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING_ALWAYS : 0)));
            break;
        case FileTypes.MP4:
            extractors.add(new FragmentedMp4Extractor(fragmentedMp4Flags));
            extractors.add(new Mp4Extractor(mp4Flags));
            break;
        case FileTypes.OGG:
            extractors.add(new OggExtractor());
            break;
        case FileTypes.PS:
            extractors.add(new PsExtractor());
            break;
        case FileTypes.TS:
            extractors.add(new TsExtractor(tsMode, tsFlags, tsTimestampSearchBytes));
            break;
        case FileTypes.WAV:
            extractors.add(new WavExtractor());
            break;
        case FileTypes.JPEG:
            extractors.add(new JpegExtractor());
            break;
        case FileTypes.WEBVTT:
        case FileTypes.UNKNOWN:
        default:
            break;
    }
}
Also used : FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) JpegExtractor(com.google.android.exoplayer2.extractor.jpeg.JpegExtractor) Ac4Extractor(com.google.android.exoplayer2.extractor.ts.Ac4Extractor) AdtsExtractor(com.google.android.exoplayer2.extractor.ts.AdtsExtractor) Mp3Extractor(com.google.android.exoplayer2.extractor.mp3.Mp3Extractor) MatroskaExtractor(com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor) TsExtractor(com.google.android.exoplayer2.extractor.ts.TsExtractor) FlacExtractor(com.google.android.exoplayer2.extractor.flac.FlacExtractor) AmrExtractor(com.google.android.exoplayer2.extractor.amr.AmrExtractor) FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) Mp4Extractor(com.google.android.exoplayer2.extractor.mp4.Mp4Extractor) PsExtractor(com.google.android.exoplayer2.extractor.ts.PsExtractor) OggExtractor(com.google.android.exoplayer2.extractor.ogg.OggExtractor) WavExtractor(com.google.android.exoplayer2.extractor.wav.WavExtractor) FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) PsExtractor(com.google.android.exoplayer2.extractor.ts.PsExtractor) FlvExtractor(com.google.android.exoplayer2.extractor.flv.FlvExtractor) OggExtractor(com.google.android.exoplayer2.extractor.ogg.OggExtractor) TsExtractor(com.google.android.exoplayer2.extractor.ts.TsExtractor) JpegExtractor(com.google.android.exoplayer2.extractor.jpeg.JpegExtractor) Mp4Extractor(com.google.android.exoplayer2.extractor.mp4.Mp4Extractor) Mp3Extractor(com.google.android.exoplayer2.extractor.mp3.Mp3Extractor) Ac4Extractor(com.google.android.exoplayer2.extractor.ts.Ac4Extractor) WavExtractor(com.google.android.exoplayer2.extractor.wav.WavExtractor) AdtsExtractor(com.google.android.exoplayer2.extractor.ts.AdtsExtractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor) AmrExtractor(com.google.android.exoplayer2.extractor.amr.AmrExtractor) MatroskaExtractor(com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor) FlacExtractor(com.google.android.exoplayer2.extractor.flac.FlacExtractor) FlvExtractor(com.google.android.exoplayer2.extractor.flv.FlvExtractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor) Nullable(androidx.annotation.Nullable)

Example 14 with AmrExtractor

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

the class AmrExtractorSeekTest method amrExtractorReads_returnSeekableSeekMap_forWideBandAmr.

@Test
public void amrExtractorReads_returnSeekableSeekMap_forWideBandAmr() throws IOException {
    String fileName = WIDE_BAND_AMR_FILE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAmrExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
    AmrExtractor extractor = createAmrExtractor();
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, new FakeExtractorOutput(), dataSource, fileUri);
    assertThat(seekMap).isNotNull();
    assertThat(seekMap.getDurationUs()).isEqualTo(WIDE_BAND_FILE_DURATION_US);
    assertThat(seekMap.isSeekable()).isTrue();
}
Also used : SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Example 15 with AmrExtractor

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

the class AmrExtractorSeekTest method seeking_handlesSeekingBackward_extractsCorrectFrames_forWideBandAmr.

@Test
public void seeking_handlesSeekingBackward_extractsCorrectFrames_forWideBandAmr() throws IOException {
    String fileName = WIDE_BAND_AMR_FILE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAmrExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
    AmrExtractor extractor = createAmrExtractor();
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long firstSeekTimeUs = 980_000;
    TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
    long targetSeekTimeUs = 0;
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(-1);
    assertFirstFrameAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 FakeExtractorOutput (com.google.android.exoplayer2.testutil.FakeExtractorOutput)13 Uri (android.net.Uri)12 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)12 FakeTrackOutput (com.google.android.exoplayer2.testutil.FakeTrackOutput)10 FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)8 PositionHolder (com.google.android.exoplayer2.extractor.PositionHolder)7 ParserException (com.google.android.exoplayer2.ParserException)5 Nullable (androidx.annotation.Nullable)1 AmrExtractor (com.google.android.exoplayer2.extractor.amr.AmrExtractor)1 FlacExtractor (com.google.android.exoplayer2.extractor.flac.FlacExtractor)1 FlvExtractor (com.google.android.exoplayer2.extractor.flv.FlvExtractor)1 JpegExtractor (com.google.android.exoplayer2.extractor.jpeg.JpegExtractor)1 MatroskaExtractor (com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor)1 Mp3Extractor (com.google.android.exoplayer2.extractor.mp3.Mp3Extractor)1 FragmentedMp4Extractor (com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor)1 Mp4Extractor (com.google.android.exoplayer2.extractor.mp4.Mp4Extractor)1 OggExtractor (com.google.android.exoplayer2.extractor.ogg.OggExtractor)1 Ac3Extractor (com.google.android.exoplayer2.extractor.ts.Ac3Extractor)1 Ac4Extractor (com.google.android.exoplayer2.extractor.ts.Ac4Extractor)1