avformat/utils: factor ff_find_last_ts() out of ff_gen_search()

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer
2013-07-06 21:52:07 +02:00
parent d64f3b72e0
commit 8ca5d277d8
2 changed files with 42 additions and 24 deletions

View File

@@ -242,6 +242,9 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index,
*/
void ff_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
int ff_find_last_ts(AVFormatContext *s, int stream_index, int64_t *ts, int64_t *pos,
int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
/**
* Perform a binary search using read_timestamp().
*

View File

@@ -1745,37 +1745,16 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts
return 0;
}
int64_t ff_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts,
int64_t pos_min, int64_t pos_max, int64_t pos_limit,
int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret,
int ff_find_last_ts(AVFormatContext *s, int stream_index, int64_t *ts, int64_t *pos,
int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ))
{
int64_t pos, ts;
int64_t start_pos, filesize;
int no_change;
av_dlog(s, "gen_seek: %d %s\n", stream_index, av_ts2str(target_ts));
if(ts_min == AV_NOPTS_VALUE){
pos_min = s->data_offset;
ts_min = ff_read_timestamp(s, stream_index, &pos_min, INT64_MAX, read_timestamp);
if (ts_min == AV_NOPTS_VALUE)
return -1;
}
if(ts_min >= target_ts){
*ts_ret= ts_min;
return pos_min;
}
if(ts_max == AV_NOPTS_VALUE){
int64_t step= 1024;
int64_t limit;
filesize = avio_size(s->pb);
pos_max = filesize - 1;
int64_t limit, ts_max;
int64_t filesize = avio_size(s->pb);
int64_t pos_max = filesize - 1;
do{
limit = pos_max;
pos_max = FFMAX(0, pos_max - step);
pos_max = FFMAX(0, (pos_max) - step);
ts_max = ff_read_timestamp(s, stream_index, &pos_max, limit, read_timestamp);
step += step;
}while(ts_max == AV_NOPTS_VALUE && 2*limit > step);
@@ -1792,6 +1771,42 @@ int64_t ff_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts,
if(tmp_pos >= filesize)
break;
}
if (ts)
*ts = ts_max;
if (pos)
*pos = pos_max;
return 0;
}
int64_t ff_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts,
int64_t pos_min, int64_t pos_max, int64_t pos_limit,
int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret,
int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ))
{
int64_t pos, ts;
int64_t start_pos;
int no_change;
int ret;
av_dlog(s, "gen_seek: %d %s\n", stream_index, av_ts2str(target_ts));
if(ts_min == AV_NOPTS_VALUE){
pos_min = s->data_offset;
ts_min = ff_read_timestamp(s, stream_index, &pos_min, INT64_MAX, read_timestamp);
if (ts_min == AV_NOPTS_VALUE)
return -1;
}
if(ts_min >= target_ts){
*ts_ret= ts_min;
return pos_min;
}
if(ts_max == AV_NOPTS_VALUE){
if ((ret = ff_find_last_ts(s, stream_index, &ts_max, &pos_max, read_timestamp)) < 0)
return ret;
pos_limit= pos_max;
}