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

Commit cb54fb25 authored by Steve Kondik's avatar Steve Kondik Committed by Gerrit Code Review
Browse files

Merge "stagefright: Fix playback for mkv files with lacing" into ics

parents d060d3b5 6870e24f
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -369,8 +369,9 @@ status_t MatroskaSource::readBlock() {
    const mkvparser::Block *block = mBlockIter.block();

    int64_t timeUs = mBlockIter.blockTimeUs();
    int frameCount = block->GetFrameCount();

    for (int i = 0; i < block->GetFrameCount(); ++i) {
    for (int i = 0; i < frameCount; ++i) {
        const mkvparser::Block::Frame &frame = block->GetFrame(i);

        MediaBuffer *mbuf = new MediaBuffer(frame.len);
@@ -390,6 +391,27 @@ status_t MatroskaSource::readBlock() {

    mBlockIter.advance();

    if (!mBlockIter.eos() && frameCount > 1) {
        // For files with lacing enabled, we need to amend they kKeyTime of
        // each frame so that their kKeyTime are advanced accordingly (instead
        // of being set to the same value). To do this, we need to find out
        // the duration of the block using the start time of the next block.
        int64_t duration = mBlockIter.blockTimeUs() - timeUs;
        int64_t durationPerFrame = duration / frameCount;
        int64_t durationRemainder = duration % frameCount;

        // We split duration to each of the frame, distributing the remainder (if any)
        // to the later frames. The later frames are processed first due to the
        // use of the iterator for the doubly linked list
        List<MediaBuffer *>::iterator it = mPendingFrames.end();
        for (int i = frameCount - 1; i >= 0; --i) {
            --it;
            int64_t frameRemainder = durationRemainder >= frameCount - i ? 1 : 0;
            int64_t frameTimeUs = timeUs + durationPerFrame * i + frameRemainder;
            (*it)->meta_data()->setInt64(kKeyTime, frameTimeUs);
        }
    }

    return OK;
}