Search in sources :

Example 56 with FakeTrackOutput

use of com.google.android.exoplayer2.testutil.FakeTrackOutput in project ExoPlayer by google.

the class AdtsExtractorSeekTest method seeking_handlesSeekingBackward_extractsCorrectSamples.

@Test
public void seeking_handlesSeekingBackward_extractsCorrectSamples() throws IOException {
    String fileName = TEST_FILE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAdtsExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
    AdtsExtractor extractor = createAdtsExtractor();
    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 extractedSampleIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedSampleIndex).isNotEqualTo(-1);
    assertFirstSampleAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedSampleIndex);
}
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 57 with FakeTrackOutput

use of com.google.android.exoplayer2.testutil.FakeTrackOutput in project ExoPlayer by google.

the class ConstantBitrateSeekerTest method assertFirstFrameAfterSeekIsWithin1FrameOfExactFrame.

private static void assertFirstFrameAfterSeekIsWithin1FrameOfExactFrame(String fileName, FakeTrackOutput trackOutput, long targetSeekTimeUs, int firstFrameIndexAfterSeek) throws IOException {
    FakeTrackOutput expectedTrackOutput = getExpectedTrackOutput(fileName);
    int exactFrameIndex = getFrameIndex(expectedTrackOutput, targetSeekTimeUs);
    boolean foundPreviousFrame = exactFrameIndex != 0 && Arrays.equals(trackOutput.getSampleData(firstFrameIndexAfterSeek), expectedTrackOutput.getSampleData(exactFrameIndex - 1));
    boolean foundExactFrame = Arrays.equals(trackOutput.getSampleData(firstFrameIndexAfterSeek), expectedTrackOutput.getSampleData(exactFrameIndex));
    boolean foundNextFrame = exactFrameIndex != expectedTrackOutput.getSampleCount() - 1 && Arrays.equals(trackOutput.getSampleData(firstFrameIndexAfterSeek), expectedTrackOutput.getSampleData(exactFrameIndex + 1));
    assertThat(foundPreviousFrame || foundExactFrame || foundNextFrame).isTrue();
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput)

Example 58 with FakeTrackOutput

use of com.google.android.exoplayer2.testutil.FakeTrackOutput in project ExoPlayer by google.

the class ConstantBitrateSeekerTest method seeking_variableFrameSize_seeksNearlyExactlyToCorrectFrame.

@Test
public void seeking_variableFrameSize_seeksNearlyExactlyToCorrectFrame() throws IOException {
    String fileName = VARIABLE_FRAME_SIZE_TEST_FILE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long targetSeekTimeUs = 1_234_000;
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
    assertFirstFrameAfterSeekIsWithin1FrameOfExactFrame(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 59 with FakeTrackOutput

use of com.google.android.exoplayer2.testutil.FakeTrackOutput in project ExoPlayer by google.

the class TestUtil method extractSeekMap.

/**
 * Reads from the given input using the given {@link Extractor}, until it can produce the {@link
 * SeekMap} and all of the track formats have been identified, or until the extractor encounters
 * EOF.
 *
 * @param extractor The {@link Extractor} to extractor from input.
 * @param output The {@link FakeTrackOutput} to store the extracted {@link SeekMap} and track.
 * @param dataSource The {@link DataSource} that will be used to read from the input.
 * @param uri The Uri of the input.
 * @return The extracted {@link SeekMap}.
 * @throws IOException If an error occurred reading from the input, or if the extractor finishes
 *     reading from input without extracting any {@link SeekMap}.
 */
public static SeekMap extractSeekMap(Extractor extractor, FakeExtractorOutput output, DataSource dataSource, Uri uri) throws IOException {
    ExtractorInput input = getExtractorInputFromPosition(dataSource, /* position= */
    0, uri);
    extractor.init(output);
    PositionHolder positionHolder = new PositionHolder();
    int readResult = Extractor.RESULT_CONTINUE;
    while (true) {
        try {
            // Keep reading until we get the seek map and the track information.
            while (readResult == Extractor.RESULT_CONTINUE && (output.seekMap == null || !output.tracksEnded)) {
                readResult = extractor.read(input, positionHolder);
            }
            for (int i = 0; i < output.trackOutputs.size(); i++) {
                int trackId = output.trackOutputs.keyAt(i);
                while (readResult == Extractor.RESULT_CONTINUE && output.trackOutputs.get(trackId).lastFormat == null) {
                    readResult = extractor.read(input, positionHolder);
                }
            }
        } finally {
            DataSourceUtil.closeQuietly(dataSource);
        }
        if (readResult == Extractor.RESULT_SEEK) {
            input = getExtractorInputFromPosition(dataSource, positionHolder.position, uri);
            readResult = Extractor.RESULT_CONTINUE;
        } else if (readResult == Extractor.RESULT_END_OF_INPUT) {
            throw new IOException("EOF encountered without seekmap");
        }
        if (output.seekMap != null) {
            return output.seekMap;
        }
    }
}
Also used : ExtractorInput(com.google.android.exoplayer2.extractor.ExtractorInput) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput) PositionHolder(com.google.android.exoplayer2.extractor.PositionHolder) IOException(java.io.IOException)

Example 60 with FakeTrackOutput

use of com.google.android.exoplayer2.testutil.FakeTrackOutput in project ExoPlayer by google.

the class PsExtractorSeekTest method handlePendingSeek_handlesSeekingBackward_extractsCorrectFrame.

@Test
public void handlePendingSeek_handlesSeekingBackward_extractsCorrectFrame() throws IOException {
    PsExtractor extractor = new PsExtractor();
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    SeekMap seekMap = extractSeekMapAndTracks(extractor, extractorOutput);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(VIDEO_TRACK_ID);
    long firstSeekTimeUs = 987_000;
    seekToTimeUs(extractor, seekMap, firstSeekTimeUs, trackOutput);
    long targetSeekTimeUs = 0;
    int extractedFrameIndex = seekToTimeUs(extractor, seekMap, targetSeekTimeUs, trackOutput);
    assertThat(extractedFrameIndex).isNotEqualTo(-1);
    assertFirstFrameAfterSeekContainsTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Aggregations

FakeTrackOutput (com.google.android.exoplayer2.testutil.FakeTrackOutput)71 Test (org.junit.Test)60 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)58 Uri (android.net.Uri)50 FakeExtractorOutput (com.google.android.exoplayer2.testutil.FakeExtractorOutput)32 FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)6 PositionHolder (com.google.android.exoplayer2.extractor.PositionHolder)5 Format (com.google.android.exoplayer2.Format)4 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)3 ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)3 WebvttDecoder (com.google.android.exoplayer2.text.webvtt.WebvttDecoder)3 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)2 TimestampAdjuster (com.google.android.exoplayer2.util.TimestampAdjuster)2 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)1 IOException (java.io.IOException)1 Before (org.junit.Before)1