Skip to content

fix(android): put out a GOP that goes back in time after the one before it - #6

Merged
andreialecu merged 2 commits into
mainfrom
fix/android-gop-back-in-time
Nov 25, 2026
Merged

andreialecu merged 2 commits into
mainfrom
fix/android-gop-back-in-time

Conversation

@andreialecu

Copy link
Copy Markdown
Owner

These two commits were reviewed in #5, but #5 was merged into fix/ios-top-items after that branch had already been merged into main (#4), so they never reached main. This PR brings them over unchanged.

On Android, a key frame earlier than the chunks before it, decoded without a flush, came out in the wrong order. The emulator's c2.goldfish.h264.decoder held the later GOP's last frames until the end of the stream, and put out the earlier GOP in decoding order. The pictures matched their timestamps; only the order was wrong.

Fix (android/src/main/cpp/VideoDecoder.hpp)

  • Draining at a backward key frame. A key chunk earlier than a chunk before it now drains the codec first: end of stream, every picture delivered, then a codec flush. iOS does the same.
  • Durations. A chunk's duration is now recorded on the input thread, after any such drain. Delivering a frame can then still drop the durations of every earlier timestamp, since the earlier GOP has already come out by the time the later one's durations are written.

Test

"outputs a GOP that goes back in time after the one before it" is now strict on Android too, as it already is on iOS. It checks each frame's picture against the GOPs decoded on their own, using a 16x16 luma grid read through WebGPU. It also checks that every frame has a duration.

  • Android emulator (API 35): the full e2e suite passes 65/65, and the strict test passed 3 more times on its own.
  • iOS: the changed test passes on the Simulator and on a physical iPhone (iOS 27.2.1).

Refs #5

…re it

A key frame earlier than a chunk before it, without a flush, now drains
the codec (end of stream, every picture delivered, codec flush) before it
is queued, as iOS does. The emulator's c2.goldfish.h264.decoder otherwise
held the previous GOP's last frames until the end of the stream and put
out the earlier GOP in decoding order; the pictures matched their
timestamps, only the order was wrong.

A frame's duration is no longer dropped along with every earlier
timestamp's when it is delivered: those may be a GOP queued to go back in
time.

The test is strict on Android too, and checks each frame's picture (a
16x16 luma grid through WebGPU) against the GOPs decoded on their own,
and that every frame has a duration.
- VideoDecoder: write a chunk's duration on the input thread, after any
  drain for a GOP that goes back in time, instead of on the JS thread.
  takeDuration() can then drop every entry up to the picture put out
  again, so durations of frames never put out no longer pile up until
  the next flush.
- VideoDecoder: drop the `_queuedSinceFlush > 0` term of the back-in-time
  check; `_latestQueued` is INT64_MIN whenever nothing was queued.
- test: in decodeRuns' output callback, return early without grids
  before checking the duration, instead of testing `ctx.grids` twice.
@andreialecu
andreialecu merged commit 2c808a3 into main Nov 25, 2026
2 of 3 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.1.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant