From d64c82776f12435589aa3c3d146e69a31f108949 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Tue, 1 Apr 2008 06:09:12 +0000 Subject: [PATCH] Place a limit on the estimate fudging when searching timestamps in mpegplayer. It doesn't have to be very much. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16907 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/mpegplayer/mpeg_parser.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/plugins/mpegplayer/mpeg_parser.c b/apps/plugins/mpegplayer/mpeg_parser.c index 345aa73111..cd54e84452 100644 --- a/apps/plugins/mpegplayer/mpeg_parser.c +++ b/apps/plugins/mpegplayer/mpeg_parser.c @@ -378,6 +378,8 @@ static off_t mpeg_parser_seek_PTS(uint32_t time, unsigned id) if (currpts != INVALID_TIMESTAMP) { + ssize_t pos_adj; /* Adjustment to over or under-estimate */ + /* Found a valid timestamp - see were it lies in relation to * target */ if (currpts < time) @@ -401,10 +403,14 @@ static off_t mpeg_parser_seek_PTS(uint32_t time, unsigned id) pos_new = muldiv_uint32(time - time_left, pos_right - pos_left, - time_right - time_left) + pos_left; + time_right - time_left); /* Point is ahead of us - fudge estimate a bit high */ - pos_new = muldiv_uint32(11, pos_new - pos_left, 10) - + pos_left; + pos_adj = pos_new / 10; + + if (pos_adj > 512*1024) + pos_adj = 512*1024; + + pos_new += pos_left + pos_adj; if (pos_new >= pos_right) { @@ -431,9 +437,14 @@ static off_t mpeg_parser_seek_PTS(uint32_t time, unsigned id) pos_new = muldiv_uint32(time - time_left, pos_right - pos_left, - time_right - time_left) + pos_left; + time_right - time_left); /* Overshot the seek point - fudge estimate a bit low */ - pos_new = muldiv_uint32(9, pos_new - pos_left, 10) + pos_left; + pos_adj = pos_new / 10; + + if (pos_adj > 512*1024) + pos_adj = 512*1024; + + pos_new += pos_left - pos_adj; state = state3; /* Last scan was late */ sk.dir = SSCAN_REVERSE;