Search in sources :

Example 16 with AmrExtractor

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

the class AmrExtractorSeekTest method seeking_handlesRandomSeeks_extractsCorrectFrames_forWideBandAmr.

@Test
public void seeking_handlesRandomSeeks_extractsCorrectFrames_forWideBandAmr() throws IOException, InterruptedException {
    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 numSeek = 100;
    for (long i = 0; i < numSeek; i++) {
        long targetSeekTimeUs = random.nextInt(NARROW_BAND_FILE_DURATION_US + 1);
        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 17 with AmrExtractor

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

the class AmrExtractorSeekTest method seeking_handlesSeekingForward_extractsCorrectFrames_forWideBandAmr.

@Test
public void seeking_handlesSeekingForward_extractsCorrectFrames_forWideBandAmr() throws IOException, InterruptedException {
    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 = 1_200_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 18 with AmrExtractor

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

the class AmrExtractorSeekTest method seeking_handlesSeekingForward_extractsCorrectFrames_forNarrowBandAmr.

@Test
public void seeking_handlesSeekingForward_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 = 1_200_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 19 with AmrExtractor

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

the class AmrExtractorNonParameterizedTest method read_amrNb_returnParserException_forInvalidFrameHeader.

@Test
public void read_amrNb_returnParserException_forInvalidFrameHeader() throws IOException {
    AmrExtractor amrExtractor = setupAmrExtractorWithOutput();
    byte[] invalidHeaderFrame = newNarrowBandAmrFrameWithType(4);
    // The padding bits are at bit-1 positions in the following pattern: 1000 0011
    // Padding bits must be 0.
    invalidHeaderFrame[0] = (byte) (invalidHeaderFrame[0] | 0b01111101);
    byte[] data = joinData(amrSignatureNb(), invalidHeaderFrame);
    FakeExtractorInput input = fakeExtractorInputWithData(data);
    try {
        amrExtractor.read(input, new PositionHolder());
        fail();
    } catch (ParserException e) {
    // expected
    }
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) ParserException(com.google.android.exoplayer2.ParserException) PositionHolder(com.google.android.exoplayer2.extractor.PositionHolder) Test(org.junit.Test)

Example 20 with AmrExtractor

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

the class AmrExtractorNonParameterizedTest method sniff_nonAmrSignature_returnFalse.

@Test
public void sniff_nonAmrSignature_returnFalse() throws IOException {
    AmrExtractor amrExtractor = setupAmrExtractorWithOutput();
    FakeExtractorInput input = fakeExtractorInputWithData(Util.getUtf8Bytes("0#!AMR\n123"));
    boolean result = amrExtractor.sniff(input);
    assertThat(result).isFalse();
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) 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