[Scummvm-git-logs] scummvm master -> 6469df1baaf82cecc1c2ac6faeac134ad080852c

bluegr noreply at scummvm.org
Mon Apr 13 20:02:43 UTC 2026


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .

Summary:
6469df1baa VIDEO: Check validity of granulepos in TheoraVideoTrack::decodePacket


Commit: 6469df1baaf82cecc1c2ac6faeac134ad080852c
    https://github.com/scummvm/scummvm/commit/6469df1baaf82cecc1c2ac6faeac134ad080852c
Author: Graham Brereton (prograhamer at users.noreply.github.com)
Date: 2026-04-13T23:02:39+03:00

Commit Message:
VIDEO: Check validity of granulepos in TheoraVideoTrack::decodePacket

A fix was introduced in 43c5d3e7c9933fdb8da19491f0b7a69d6b688390, 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.

Changed paths:
    video/theora_decoder.cpp


diff --git a/video/theora_decoder.cpp b/video/theora_decoder.cpp
index 4218a6a4b44..2b09df5b178 100644
--- a/video/theora_decoder.cpp
+++ b/video/theora_decoder.cpp
@@ -316,19 +316,16 @@ bool TheoraDecoder::TheoraVideoTrack::decodePacket(ogg_packet &oggPacket) {
 			translateYUVtoRGBA(yuv);
 		}
 
-		// We set the current frame counter, delegating the calculation to libtheora 
-		_curFrame = (int) th_granule_frame(_theoraDecode, oggPacket.granulepos);
-
-		double time = th_granule_time(_theoraDecode, oggPacket.granulepos);
-
-		// We need to calculate when the next frame should be shown
-		// This is all in floating point because that's what the Ogg code gives us
-		// Ogg is a lossy container format, so it doesn't always list the time to the
-		// next frame. In such cases, we need to calculate it ourselves.
-		if (time == -1.0)
+		// If we have a valid granule position for this packet, use it to calculate the next
+		// frame information. If we don't have a valid granule position, we need to do our
+		// calculation for the frame number and timing.
+		if (oggPacket.granulepos >= 0) {
+			_curFrame = (int)th_granule_frame(_theoraDecode, oggPacket.granulepos);
+			_nextFrameStartTime = th_granule_time(_theoraDecode, oggPacket.granulepos);
+		} else {
+			_curFrame++;
 			_nextFrameStartTime += _frameRate.getInverse().toDouble();
-		else
-			_nextFrameStartTime = time;
+		}
 
 		return true;
 	}




More information about the Scummvm-git-logs mailing list