Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7398f05d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Transcoder: MediaSampleReader sometimes drops last sample." into sc-dev

parents 31a60210 6da1c549
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -98,6 +98,9 @@ bool MediaSampleReaderNDK::advanceExtractor_l() {
        mTrackCursors[mExtractorTrackIndex].next.reset();
    }

    // Update the extractor's sample index even if this track reaches EOS, so that the other tracks
    // are not given an incorrect extractor position.
    mExtractorSampleIndex++;
    if (!AMediaExtractor_advance(mExtractor)) {
        LOG(DEBUG) << "  EOS in advanceExtractor_l";
        mEosReached = true;
@@ -108,7 +111,6 @@ bool MediaSampleReaderNDK::advanceExtractor_l() {
    }

    mExtractorTrackIndex = AMediaExtractor_getSampleTrackIndex(mExtractor);
    mExtractorSampleIndex++;

    SampleCursor& cursor = mTrackCursors[mExtractorTrackIndex];
    if (mExtractorSampleIndex > cursor.previous.index) {
+32 −0
Original line number Diff line number Diff line
@@ -272,6 +272,38 @@ TEST_F(MediaSampleReaderNDKTests, TestParallelSampleAccess) {
    compareSamples(tester.getSamples());
}

/** Reads all samples except the last in each track, before finishing. */
TEST_F(MediaSampleReaderNDKTests, TestLastSampleBeforeEOS) {
    LOG(DEBUG) << "TestLastSampleBeforeEOS Starts";
    initExtractorSamples();

    {  // Natural track order
        SampleAccessTester tester{mSourceFd, mFileSize};
        for (int trackIndex = 0; trackIndex < mTrackCount; ++trackIndex) {
            tester.readSamplesAsync(trackIndex, mExtractorSamples[trackIndex].size() - 1);
        }
        tester.waitForTracks();
        for (int trackIndex = 0; trackIndex < mTrackCount; ++trackIndex) {
            tester.readSamplesAsync(trackIndex, SAMPLE_COUNT_ALL);
            tester.waitForTrack(trackIndex);
        }
        compareSamples(tester.getSamples());
    }

    {  // Reverse track order
        SampleAccessTester tester{mSourceFd, mFileSize};
        for (int trackIndex = mTrackCount - 1; trackIndex >= 0; --trackIndex) {
            tester.readSamplesAsync(trackIndex, mExtractorSamples[trackIndex].size() - 1);
        }
        tester.waitForTracks();
        for (int trackIndex = mTrackCount - 1; trackIndex >= 0; --trackIndex) {
            tester.readSamplesAsync(trackIndex, SAMPLE_COUNT_ALL);
            tester.waitForTrack(trackIndex);
        }
        compareSamples(tester.getSamples());
    }
}

/** Reads all samples from all tracks sequentially. */
TEST_F(MediaSampleReaderNDKTests, TestSequentialSampleAccess) {
    LOG(DEBUG) << "TestSequentialSampleAccess Starts";