Author: uau Date: Fri Mar 16 15:55:41 2007 New Revision: 22634 Modified: trunk/libmpdemux/demux_mkv.c Log: Matroska seeking fixes If a relative seek forward went past the last index position the Matroska demuxer did not seek to any index position. It did however set the mkv_d->skip_to_timecode variable which meant that the next fill_buffer() call would read from the current position until the target position (probably the end of the file). Fix this by changing the code to seek to the last index position if that is between the current and target positions. Also change backwards relative seek to accept an exactly matching index position (<= vs <) and reorganize the seeking conditionals to allow making the above change without turning the code into a complete mess. Modified: trunk/libmpdemux/demux_mkv.c ============================================================================== --- trunk/libmpdemux/demux_mkv.c (original) +++ trunk/libmpdemux/demux_mkv.c Fri Mar 16 15:55:41 2007 @@ -28,6 +28,8 @@ #include "libass/ass.h" #include "libass/ass_mp.h" +#include "libavutil/common.h" + #ifdef USE_QTX_CODECS #include "loader/qtx/qtxsdk/components.h" #endif @@ -3554,18 +3556,26 @@ demux_mkv_seek (demuxer_t *demuxer, floa diff = target_timecode + mkv_d->first_tc - (int64_t) mkv_d->indexes[i].timecode * mkv_d->tc_scale / 1000000.0; - if ((flags & 1 || target_timecode <= mkv_d->last_pts*1000) - && diff >= 0 && diff < min_diff) - { - min_diff = diff; - index = mkv_d->indexes + i; - } - else if (target_timecode > mkv_d->last_pts*1000 - && diff < 0 && -diff < min_diff) - { - min_diff = -diff; - index = mkv_d->indexes + i; - } + if ((flags & 1 || target_timecode <= mkv_d->last_pts*1000)) { + // Absolute seek or seek backward: find the last index + // position before target time + if (diff < 0 || diff >= min_diff) + continue; + } + else { + // Relative seek forward: find the first index position + // after target time. If no such index exists, find last + // position between current position and target time. + if (diff <= 0) { + if (min_diff <= 0 && diff <= min_diff) + continue; + } + else if (diff >= FFMIN(target_timecode - mkv_d->last_pts, + min_diff)) + continue; + } + min_diff = diff; + index = mkv_d->indexes + i; } if (index) /* We've found an entry. */
uau wrote:
Author: uau Date: Fri Mar 16 15:55:41 2007 New Revision: 22634
Modified: trunk/libmpdemux/demux_mkv.c
Log: Matroska seeking fixes
If a relative seek forward went past the last index position the Matroska demuxer did not seek to any index position. It did however set the mkv_d->skip_to_timecode variable which meant that the next fill_buffer() call would read from the current position until the target position (probably the end of the file). Fix this by changing the code to seek to the last index position if that is between the current and target positions.
Also change backwards relative seek to accept an exactly matching index position (<= vs <) and reorganize the seeking conditionals to allow making the above change without turning the code into a complete mess.
grep "demux_mkv.c" DOCS/tech/MAINTAINERS * demux_mkv.c - Moritz Bunkus DOCS/tech/svn-howto.txt reads: 9. Do NOT commit to code actively maintained by others without permission. Send a patch to mplayer-dev-eng instead. Though Moritz isn't active in writing code, he does review patches pointed out to him. Has Moritz approved this patch? Guillaume
Hey, On Friday 16 March 2007 16:06, Guillaume Poirier wrote:
Has Moritz approved this patch?
No, I haven't, but I've looked at it now, and it looks OK to me. I don't have time to test it tonight, but I will tomorrow, but I'm pretty sure that it's OK as it is. Mosu -- If Darl McBride was in charge, he'd probably make marriage unconstitutional too, since clearly it de-emphasizes the commercial nature of normal human interaction, and probably is a major impediment to the commercial growth of prostitution. - Linus Torvalds
participants (3)
-
Guillaume Poirier -
Moritz Bunkus -
uau