Thanks to visit codestin.com
Credit goes to github.com

Skip to content

VIDEO: Check validity of granulepos in TheoraVideoTrack::decodePacket - #7427

Merged
bluegr merged 1 commit into
scummvm:masterfrom
prograhamer:fix-theora-syberia
Apr 13, 2026
Merged

VIDEO: Check validity of granulepos in TheoraVideoTrack::decodePacket#7427
bluegr merged 1 commit into
scummvm:masterfrom
prograhamer:fix-theora-syberia

Conversation

@prograhamer

Copy link
Copy Markdown
Contributor

A fix was introduced in 43c5d3e, which adds handling for dropped frames in theora decoding. However, this didn't handle the case where the granule position for the current packet is invalid.

These changes introduce a check on the granule position of the current packet. If the granule position is valid, proceed to properly calculate the frame number and the next frame start time from the granule position. If the granule position is not valid, use best estimation of for these values.

These changes also refactor to combine the checks for the two cases where the granule position is passed to theora functions. The documentation for both of these functions states that they will return -1 in the case that the provided granule position is negative.

Background

I was trying to play Syberia on ScummVM v2026.2.0, and found it unplayable due to the choppy video playback in the main menu and intro video, which also seemingly affects the UI in the game with high latency.

I found v2026.1.0 worked OK, so did a git bisect to locate the commit which introduced the problem for me as 43c5d3e.

Through some debugging I could see that oggPacket.granulepos was often -1, which led to _curFrame being reset to -1 frequently throughout video playback. It seems that the code below for calculating _nextFrameStartTime was handling this case, so I applied a similar fix to calling th_granule_frame, but switching the condition to be on oggPacket.granulepos rather than calling the function and checking if the result is invalid. I think this is a reasonable change, having read the documentation for th_granule_frame and th_granule_time, but I can change the approach to check the result of the function call rather than its input if that is preferable.

A fix was introduced in 43c5d3e, which
adds handling for dropped frames in theora decoding. However, this
didn't handle the case where the granule position for the current packet
is invalid.

These changes introduce a check on the granule position of the current
packet. If the granule position is valid, proceed to properly calculate
the frame number and the next frame start time from the granule
position. If the granule position is not valid, use best estimation of
for these values.

These changes also refactor to combine the checks for the two cases
where the granule position is passed to theora functions. The
documentation for both of these functions states that they will return
-1 in the case that the provided granule position is negative.
@bluegr

bluegr commented Apr 13, 2026

Copy link
Copy Markdown
Member

Nice catch, thanks!

@bluegr
bluegr merged commit 6469df1 into scummvm:master Apr 13, 2026
1 check passed
@prograhamer
prograhamer deleted the fix-theora-syberia branch April 13, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants