aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorYan Jing <yanjng@21cn.com>2011-09-08 20:09:40 +0200
committerMichael Niedermayer <michaelni@gmx.at>2011-09-08 20:09:40 +0200
commit59810f8388ab4e746229b2e0048aa9eb4f36bdd7 (patch)
treeca887a8ed870235372eeb01d33dec380be6a201d /libavformat
parent6337de9252fc5a635ae785ec616b5a77990e1741 (diff)
downloadffmpeg-59810f8388ab4e746229b2e0048aa9eb4f36bdd7.tar.gz
ffmdec: handle wrapped file in ffm_seek
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/ffmdec.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/libavformat/ffmdec.c b/libavformat/ffmdec.c
index 2fd154fa25..0747f8dbe0 100644
--- a/libavformat/ffmdec.c
+++ b/libavformat/ffmdec.c
@@ -461,11 +461,25 @@ static int ffm_seek(AVFormatContext *s, int stream_index, int64_t wanted_pts, in
av_dlog(s, "wanted_pts=%0.6f\n", wanted_pts / 1000000.0);
/* find the position using linear interpolation (better than
dichotomy in typical cases) */
- pos_min = FFM_PACKET_SIZE;
- pos_max = ffm->file_size - FFM_PACKET_SIZE;
+ if (ffm->write_index < ffm->file_size) {
+ if (get_dts(s, FFM_PACKET_SIZE) < wanted_pts) {
+ pos_min = FFM_PACKET_SIZE;
+ pos_max = ffm->write_index - FFM_PACKET_SIZE;
+ } else {
+ pos_min = ffm->write_index;
+ pos_max = ffm->file_size - FFM_PACKET_SIZE;
+ }
+ } else {
+ pos_min = FFM_PACKET_SIZE;
+ pos_max = ffm->file_size - FFM_PACKET_SIZE;
+ }
while (pos_min <= pos_max) {
pts_min = get_dts(s, pos_min);
pts_max = get_dts(s, pos_max);
+ if (pts_min > wanted_pts || pts_max < wanted_pts) {
+ pos = pts_min > wanted_pts ? pos_min : pos_max;
+ goto found;
+ }
/* linear interpolation */
pos1 = (double)(pos_max - pos_min) * (double)(wanted_pts - pts_min) /
(double)(pts_max - pts_min);