|
|
@ -1421,8 +1421,6 @@ int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, |
|
|
|
wanted_timestamp, flags); |
|
|
|
wanted_timestamp, flags); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#define DEBUG_SEEK |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){ |
|
|
|
int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){ |
|
|
|
AVInputFormat *avif= s->iformat; |
|
|
|
AVInputFormat *avif= s->iformat; |
|
|
|
int64_t av_uninit(pos_min), av_uninit(pos_max), pos, pos_limit; |
|
|
|
int64_t av_uninit(pos_min), av_uninit(pos_max), pos, pos_limit; |
|
|
@ -1434,9 +1432,7 @@ int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts |
|
|
|
if (stream_index < 0) |
|
|
|
if (stream_index < 0) |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_SEEK |
|
|
|
av_dlog(s, "read_seek: %d %"PRId64"\n", stream_index, target_ts); |
|
|
|
av_log(s, AV_LOG_DEBUG, "read_seek: %d %"PRId64"\n", stream_index, target_ts); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ts_max= |
|
|
|
ts_max= |
|
|
|
ts_min= AV_NOPTS_VALUE; |
|
|
|
ts_min= AV_NOPTS_VALUE; |
|
|
@ -1453,10 +1449,8 @@ int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts |
|
|
|
if(e->timestamp <= target_ts || e->pos == e->min_distance){ |
|
|
|
if(e->timestamp <= target_ts || e->pos == e->min_distance){ |
|
|
|
pos_min= e->pos; |
|
|
|
pos_min= e->pos; |
|
|
|
ts_min= e->timestamp; |
|
|
|
ts_min= e->timestamp; |
|
|
|
#ifdef DEBUG_SEEK |
|
|
|
av_dlog(s, "using cached pos_min=0x%"PRIx64" dts_min=%"PRId64"\n", |
|
|
|
av_log(s, AV_LOG_DEBUG, "using cached pos_min=0x%"PRIx64" dts_min=%"PRId64"\n", |
|
|
|
pos_min,ts_min); |
|
|
|
pos_min,ts_min); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
assert(index==0); |
|
|
|
assert(index==0); |
|
|
|
} |
|
|
|
} |
|
|
@ -1469,10 +1463,8 @@ int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts |
|
|
|
pos_max= e->pos; |
|
|
|
pos_max= e->pos; |
|
|
|
ts_max= e->timestamp; |
|
|
|
ts_max= e->timestamp; |
|
|
|
pos_limit= pos_max - e->min_distance; |
|
|
|
pos_limit= pos_max - e->min_distance; |
|
|
|
#ifdef DEBUG_SEEK |
|
|
|
av_dlog(s, "using cached pos_max=0x%"PRIx64" pos_limit=0x%"PRIx64" dts_max=%"PRId64"\n", |
|
|
|
av_log(s, AV_LOG_DEBUG, "using cached pos_max=0x%"PRIx64" pos_limit=0x%"PRIx64" dts_max=%"PRId64"\n", |
|
|
|
pos_max,pos_limit, ts_max); |
|
|
|
pos_max,pos_limit, ts_max); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1494,9 +1486,7 @@ int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, i |
|
|
|
int64_t start_pos, filesize; |
|
|
|
int64_t start_pos, filesize; |
|
|
|
int no_change; |
|
|
|
int no_change; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_SEEK |
|
|
|
av_dlog(s, "gen_seek: %d %"PRId64"\n", stream_index, target_ts); |
|
|
|
av_log(s, AV_LOG_DEBUG, "gen_seek: %d %"PRId64"\n", stream_index, target_ts); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ts_min == AV_NOPTS_VALUE){ |
|
|
|
if(ts_min == AV_NOPTS_VALUE){ |
|
|
|
pos_min = s->data_offset; |
|
|
|
pos_min = s->data_offset; |
|
|
@ -1538,11 +1528,8 @@ int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, i |
|
|
|
|
|
|
|
|
|
|
|
no_change=0; |
|
|
|
no_change=0; |
|
|
|
while (pos_min < pos_limit) { |
|
|
|
while (pos_min < pos_limit) { |
|
|
|
#ifdef DEBUG_SEEK |
|
|
|
av_dlog(s, "pos_min=0x%"PRIx64" pos_max=0x%"PRIx64" dts_min=%"PRId64" dts_max=%"PRId64"\n", |
|
|
|
av_log(s, AV_LOG_DEBUG, "pos_min=0x%"PRIx64" pos_max=0x%"PRIx64" dts_min=%"PRId64" dts_max=%"PRId64"\n", |
|
|
|
pos_min, pos_max, ts_min, ts_max); |
|
|
|
pos_min, pos_max, |
|
|
|
|
|
|
|
ts_min, ts_max); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
assert(pos_limit <= pos_max); |
|
|
|
assert(pos_limit <= pos_max); |
|
|
|
|
|
|
|
|
|
|
|
if(no_change==0){ |
|
|
|
if(no_change==0){ |
|
|
@ -1569,11 +1556,9 @@ int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, i |
|
|
|
no_change++; |
|
|
|
no_change++; |
|
|
|
else |
|
|
|
else |
|
|
|
no_change=0; |
|
|
|
no_change=0; |
|
|
|
#ifdef DEBUG_SEEK |
|
|
|
av_dlog(s, "%"PRId64" %"PRId64" %"PRId64" / %"PRId64" %"PRId64" %"PRId64" target:%"PRId64" limit:%"PRId64" start:%"PRId64" noc:%d\n", |
|
|
|
av_log(s, AV_LOG_DEBUG, "%"PRId64" %"PRId64" %"PRId64" / %"PRId64" %"PRId64" %"PRId64" target:%"PRId64" limit:%"PRId64" start:%"PRId64" noc:%d\n", |
|
|
|
pos_min, pos, pos_max, ts_min, ts, ts_max, target_ts, |
|
|
|
pos_min, pos, pos_max, ts_min, ts, ts_max, target_ts, pos_limit, |
|
|
|
pos_limit, start_pos, no_change); |
|
|
|
start_pos, no_change); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
if(ts == AV_NOPTS_VALUE){ |
|
|
|
if(ts == AV_NOPTS_VALUE){ |
|
|
|
av_log(s, AV_LOG_ERROR, "read_timestamp() failed in the middle\n"); |
|
|
|
av_log(s, AV_LOG_ERROR, "read_timestamp() failed in the middle\n"); |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
@ -1592,13 +1577,13 @@ int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, i |
|
|
|
|
|
|
|
|
|
|
|
pos = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max; |
|
|
|
pos = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max; |
|
|
|
ts = (flags & AVSEEK_FLAG_BACKWARD) ? ts_min : ts_max; |
|
|
|
ts = (flags & AVSEEK_FLAG_BACKWARD) ? ts_min : ts_max; |
|
|
|
#ifdef DEBUG_SEEK |
|
|
|
#if 1 |
|
|
|
pos_min = pos; |
|
|
|
pos_min = pos; |
|
|
|
ts_min = read_timestamp(s, stream_index, &pos_min, INT64_MAX); |
|
|
|
ts_min = read_timestamp(s, stream_index, &pos_min, INT64_MAX); |
|
|
|
pos_min++; |
|
|
|
pos_min++; |
|
|
|
ts_max = read_timestamp(s, stream_index, &pos_min, INT64_MAX); |
|
|
|
ts_max = read_timestamp(s, stream_index, &pos_min, INT64_MAX); |
|
|
|
av_log(s, AV_LOG_DEBUG, "pos=0x%"PRIx64" %"PRId64"<=%"PRId64"<=%"PRId64"\n", |
|
|
|
av_dlog(s, "pos=0x%"PRIx64" %"PRId64"<=%"PRId64"<=%"PRId64"\n", |
|
|
|
pos, ts_min, target_ts, ts_max); |
|
|
|
pos, ts_min, target_ts, ts_max); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
*ts_ret= ts; |
|
|
|
*ts_ret= ts; |
|
|
|
return pos; |
|
|
|
return pos; |
|
|
@ -2651,9 +2636,7 @@ AVProgram *av_new_program(AVFormatContext *ac, int id) |
|
|
|
AVProgram *program=NULL; |
|
|
|
AVProgram *program=NULL; |
|
|
|
int i; |
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_SI |
|
|
|
av_dlog(ac, "new_program: id=0x%04x\n", id); |
|
|
|
av_log(ac, AV_LOG_DEBUG, "new_program: id=0x%04x\n", id); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(i=0; i<ac->nb_programs; i++) |
|
|
|
for(i=0; i<ac->nb_programs; i++) |
|
|
|
if(ac->programs[i]->id == id) |
|
|
|
if(ac->programs[i]->id == id) |
|
|
|