Skip to content

Commit 53191e5

Browse files
committed
theoraplay: Changed seeking strategy.
This is back to the less-correct but much faster approach, but I added in the seek_only_backwards trick, which was solving the accuracy problem; eventually the bisecting would choose the same seek position it just tried and would have to give up; at this point, now we start moving backwards exclusively until we have a reasonable position and call it a day. Still fast, but with all the bug fixes!
1 parent 9f9ffcd commit 53191e5

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

data/games/maddog/game.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ scenes = {
16001600

16011601
-- first time through, after the ambush, you stare at the door for three seconds before going in. There's a skull you can shoot during this time.
16021602
enter_saloon_delay = {
1603-
start_time = laserdisc_frame_to_ms(5440),
1603+
start_time = laserdisc_frame_to_ms(5447),
16041604
is_single_frame = true,
16051605
timeout = { when=time_to_ms(3, 0), nextsequence="enter_saloon" },
16061606
actions = {

thirdparty/theoraplay/theoraplay.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ static int PumpDecoder(TheoraDecoder *ctx, int desired_frames)
552552

553553
if (ctx->current_seek_generation != ctx->seek_generation) // seek requested
554554
{
555+
int seek_only_backwards = 0;
555556
unsigned long targetms;
556557
long seekpos;
557558
long lo, hi;
@@ -628,6 +629,14 @@ static int PumpDecoder(TheoraDecoder *ctx, int desired_frames)
628629

629630
if ((ms < targetms) && ((targetms - ms) >= 500) && ((targetms - ms) <= 1000)) // !!! FIXME: tweak this number?
630631
found = 1; // found something close enough to the target!
632+
else if (seek_only_backwards)
633+
{
634+
if ((ms < targetms) && ((targetms - ms) > 1500))
635+
{
636+
printf("Uhoh, seeking backwards totally missed it!\n");
637+
found = 1; // ugh, we're way past it, give up and just go from here.
638+
}
639+
}
631640
else // adjust binary search position and try again.
632641
{
633642
const long newpos = (lo / 2) + (hi / 2);
@@ -643,10 +652,28 @@ static int PumpDecoder(TheoraDecoder *ctx, int desired_frames)
643652
if (found)
644653
break;
645654

646-
const long newseekpos = (lo / 2) + (hi / 2);
647-
if (seekpos == newseekpos)
648-
break; // we did the best we could, just go from here.
649-
seekpos = newseekpos;
655+
if (!seek_only_backwards)
656+
{
657+
const long newseekpos = (lo / 2) + (hi / 2);
658+
if (seekpos != newseekpos)
659+
seekpos = newseekpos;
660+
else
661+
seek_only_backwards = 1; // bisecting isn't cutting it, we're probably within a frame or two, so walk backwards now.
662+
}
663+
664+
if (seek_only_backwards)
665+
{
666+
const long backwards_increments = 8 * 1024;
667+
if (seekpos >= backwards_increments)
668+
seekpos -= backwards_increments;
669+
else
670+
{
671+
if (seekpos == 0)
672+
break; // we're at the start of file, we have to give up now.
673+
else
674+
seekpos = 0;
675+
}
676+
}
650677
} // while
651678

652679
// at this point, we have seek'd to something reasonably close to our target. Now decode until we're as close as possible to it.

0 commit comments

Comments
 (0)