Search in sources :

Example 6 with AmrExtractor

use of androidx.media3.extractor.amr.AmrExtractor in project media by androidx.

the class AmrExtractorSeekTest method seeking_handlesSeekToEoF_extractsLastFrame_forNarrowBandAmr.

@Test
public void seeking_handlesSeekToEoF_extractsLastFrame_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 = seekMap.getDurationUs();
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(-1);
    assertFirstFrameAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(androidx.media3.test.utils.FakeTrackOutput) SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(androidx.media3.test.utils.FakeExtractorOutput) Test(org.junit.Test)

Example 7 with AmrExtractor

use of androidx.media3.extractor.amr.AmrExtractor in project media by androidx.

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(androidx.media3.test.utils.FakeTrackOutput) SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(androidx.media3.test.utils.FakeExtractorOutput) Test(org.junit.Test)

Example 8 with AmrExtractor

use of androidx.media3.extractor.amr.AmrExtractor in project bolan by qiusunshine.

the class MyDefaultExtractorsFactory method addExtractorsForFileType.

private void addExtractorsForFileType(int fileType, List<Extractor> extractors) {
    switch(fileType) {
        case -1:
        case 13:
        default:
            break;
        case 0:
            extractors.add(new Ac3Extractor());
            break;
        case 1:
            extractors.add(new Ac4Extractor());
            break;
        case 2:
            extractors.add(new AdtsExtractor(this.adtsFlags | (this.constantBitrateSeekingEnabled ? 1 : 0)));
            break;
        case 3:
            extractors.add(new AmrExtractor(this.amrFlags | (this.constantBitrateSeekingEnabled ? 1 : 0)));
            break;
        case 4:
            if (FLAC_EXTENSION_EXTRACTOR_CONSTRUCTOR != null) {
                try {
                    extractors.add((Extractor) FLAC_EXTENSION_EXTRACTOR_CONSTRUCTOR.newInstance(this.flacFlags));
                } catch (Exception var4) {
                    throw new IllegalStateException("Unexpected error creating FLAC extractor", var4);
                }
            } else {
                extractors.add(new FlacExtractor(this.flacFlags));
            }
            break;
        case 5:
            extractors.add(new FlvExtractor());
            break;
        case 6:
            extractors.add(new MatroskaExtractor(this.matroskaFlags));
            break;
        case 7:
            extractors.add(new Mp3Extractor(this.mp3Flags | (this.constantBitrateSeekingEnabled ? 1 : 0)));
            break;
        case 8:
            extractors.add(new FragmentedMp4Extractor(this.fragmentedMp4Flags));
            extractors.add(new Mp4Extractor(this.mp4Flags));
            break;
        case 9:
            extractors.add(new OggExtractor());
            break;
        case 10:
            extractors.add(new PsExtractor());
            break;
        case 11:
            extractors.add(new TsExtractor(this.tsMode, this.tsFlags, this.tsTimestampSearchBytes));
            break;
        case 12:
            extractors.add(new WavExtractor());
            break;
        case 14:
            extractors.add(new JpegExtractor());
    }
}
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) FlvExtractor(com.google.android.exoplayer2.extractor.flv.FlvExtractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor)

Example 9 with AmrExtractor

use of androidx.media3.extractor.amr.AmrExtractor in project Telegram-FOSS by Telegram-FOSS-Team.

the class DefaultExtractorsFactory method createExtractors.

@Override
public synchronized Extractor[] createExtractors() {
    Extractor[] extractors = new Extractor[14];
    extractors[0] = new MatroskaExtractor(matroskaFlags);
    extractors[1] = new FragmentedMp4Extractor(fragmentedMp4Flags);
    extractors[2] = new Mp4Extractor(mp4Flags);
    extractors[3] = new OggExtractor();
    extractors[4] = new Mp3Extractor(mp3Flags | (constantBitrateSeekingEnabled ? Mp3Extractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING : 0));
    extractors[5] = new AdtsExtractor(adtsFlags | (constantBitrateSeekingEnabled ? AdtsExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING : 0));
    extractors[6] = new Ac3Extractor();
    extractors[7] = new TsExtractor(tsMode, tsFlags);
    extractors[8] = new FlvExtractor();
    extractors[9] = new PsExtractor();
    extractors[10] = new WavExtractor();
    extractors[11] = new AmrExtractor(amrFlags | (constantBitrateSeekingEnabled ? AmrExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING : 0));
    extractors[12] = new Ac4Extractor();
    if (FLAC_EXTENSION_EXTRACTOR_CONSTRUCTOR != null) {
        try {
            extractors[13] = FLAC_EXTENSION_EXTRACTOR_CONSTRUCTOR.newInstance();
        } catch (Exception e) {
            // Should never happen.
            throw new IllegalStateException("Unexpected error creating FLAC extractor", e);
        }
    } else {
        extractors[13] = new FlacExtractor();
    }
    return extractors;
}
Also used : FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) AdtsExtractor(com.google.android.exoplayer2.extractor.ts.AdtsExtractor) Ac4Extractor(com.google.android.exoplayer2.extractor.ts.Ac4Extractor) 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) Mp4Extractor(com.google.android.exoplayer2.extractor.mp4.Mp4Extractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor) Mp3Extractor(com.google.android.exoplayer2.extractor.mp3.Mp3Extractor) Ac4Extractor(com.google.android.exoplayer2.extractor.ts.Ac4Extractor) WavExtractor(com.google.android.exoplayer2.extractor.wav.WavExtractor) AmrExtractor(com.google.android.exoplayer2.extractor.amr.AmrExtractor) MatroskaExtractor(com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor) AdtsExtractor(com.google.android.exoplayer2.extractor.ts.AdtsExtractor) FlacExtractor(com.google.android.exoplayer2.extractor.flac.FlacExtractor) FlvExtractor(com.google.android.exoplayer2.extractor.flv.FlvExtractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor)

Example 10 with AmrExtractor

use of androidx.media3.extractor.amr.AmrExtractor in project media by androidx.

the class AmrExtractorNonParameterizedTest method read_amrNb_returnParserException_forInvalidFrameType.

@Test
public void read_amrNb_returnParserException_forInvalidFrameType() throws IOException {
    AmrExtractor amrExtractor = setupAmrExtractorWithOutput();
    // Frame type 12-14 for narrow band is reserved for future usage.
    byte[] amrFrame = newNarrowBandAmrFrameWithType(12);
    byte[] data = joinData(amrSignatureNb(), amrFrame);
    FakeExtractorInput input = fakeExtractorInputWithData(data);
    try {
        amrExtractor.read(input, new PositionHolder());
        fail();
    } catch (ParserException e) {
    // expected
    }
}
Also used : FakeExtractorInput(androidx.media3.test.utils.FakeExtractorInput) ParserException(androidx.media3.common.ParserException) PositionHolder(androidx.media3.extractor.PositionHolder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 FakeExtractorOutput (androidx.media3.test.utils.FakeExtractorOutput)13 Uri (android.net.Uri)12 SeekMap (androidx.media3.extractor.SeekMap)12 FakeTrackOutput (androidx.media3.test.utils.FakeTrackOutput)10 FakeExtractorInput (androidx.media3.test.utils.FakeExtractorInput)8 PositionHolder (androidx.media3.extractor.PositionHolder)7 ParserException (androidx.media3.common.ParserException)5 AmrExtractor (com.google.android.exoplayer2.extractor.amr.AmrExtractor)3 FlacExtractor (com.google.android.exoplayer2.extractor.flac.FlacExtractor)3 FlvExtractor (com.google.android.exoplayer2.extractor.flv.FlvExtractor)3 MatroskaExtractor (com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor)3 Mp3Extractor (com.google.android.exoplayer2.extractor.mp3.Mp3Extractor)3 FragmentedMp4Extractor (com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor)3 Mp4Extractor (com.google.android.exoplayer2.extractor.mp4.Mp4Extractor)3 OggExtractor (com.google.android.exoplayer2.extractor.ogg.OggExtractor)3 Ac3Extractor (com.google.android.exoplayer2.extractor.ts.Ac3Extractor)3 Ac4Extractor (com.google.android.exoplayer2.extractor.ts.Ac4Extractor)3 AdtsExtractor (com.google.android.exoplayer2.extractor.ts.AdtsExtractor)3 PsExtractor (com.google.android.exoplayer2.extractor.ts.PsExtractor)3