Newer
Older
static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
{
AVIContext *avi = s->priv_data;
AVStream *st;
Michael Niedermayer
committed
int i, index;
int64_t pos;
if (!avi->index_loaded) {
/* we only load the index on demand */
avi_load_index(s);
avi->index_loaded = 1;
}
Michael Niedermayer
committed
assert(stream_index>= 0);
Michael Niedermayer
committed
index= av_index_search_timestamp(st, timestamp, flags);
if(index<0)
Michael Niedermayer
committed
pos = st->index_entries[index].pos;
timestamp = st->index_entries[index].timestamp;
// av_log(s, AV_LOG_DEBUG, "XX %"PRId64" %d %"PRId64"\n", timestamp, index, st->index_entries[index].timestamp);
Aurelien Jacobs
committed
if (CONFIG_DV_DEMUXER && avi->dv_demux) {
/* One and only one real stream for DV in AVI, and it has video */
/* offsets. Calling with other stream indexes should have failed */
/* the av_index_search_timestamp call above. */
assert(stream_index == 0);
/* Feed the DV video stream version of the timestamp to the */
/* DV demux so it can synthesize correct timestamps. */
dv_offset_reset(avi->dv_demux, timestamp);
url_fseek(s->pb, pos, SEEK_SET);
avi->stream_index= -1;
return 0;
}
Michael Niedermayer
committed
AVStream *st2 = s->streams[i];
AVIStream *ast2 = st2->priv_data;
ast2->packet_size=
ast2->remaining= 0;
Michael Niedermayer
committed
if (st2->nb_index_entries <= 0)
continue;
// assert(st2->codec->block_align);
Baptiste Coudurier
committed
assert((int64_t)st2->time_base.num*ast2->rate == (int64_t)st2->time_base.den*ast2->scale);
Michael Niedermayer
committed
index = av_index_search_timestamp(
Michael Niedermayer
committed
av_rescale(timestamp, st2->time_base.den*(int64_t)st->time_base.num, st->time_base.den * (int64_t)st2->time_base.num),
flags | AVSEEK_FLAG_BACKWARD);
if(index<0)
index=0;
if(!avi->non_interleaved){
while(index>0 && st2->index_entries[index].pos > pos)
index--;
while(index+1 < st2->nb_index_entries && st2->index_entries[index].pos < pos)
index++;
}
// av_log(s, AV_LOG_DEBUG, "%"PRId64" %d %"PRId64"\n", timestamp, index, st2->index_entries[index].timestamp);
Michael Niedermayer
committed
/* extract the current frame number */
ast2->frame_offset = st2->index_entries[index].timestamp;
if(ast2->sample_size)
ast2->frame_offset *=ast2->sample_size;
Michael Niedermayer
committed
url_fseek(s->pb, pos, SEEK_SET);
static int avi_read_close(AVFormatContext *s)
int i;
AVIContext *avi = s->priv_data;
for(i=0;i<s->nb_streams;i++) {
AVStream *st = s->streams[i];
Michael Niedermayer
committed
av_free(st->codec->palctrl);
if (avi->dv_demux)
av_free(avi->dv_demux);
return 0;
}
static int avi_probe(AVProbeData *p)
{
for(i=0; avi_headers[i][0]; i++)
if(!memcmp(p->buf , avi_headers[i] , 4) &&
!memcmp(p->buf+8, avi_headers[i]+4, 4))
return AVPROBE_SCORE_MAX;
return 0;
AVInputFormat avi_demuxer = {
NULL_IF_CONFIG_SMALL("AVI format"),
sizeof(AVIContext),
avi_probe,
avi_read_header,
avi_read_packet,
avi_read_close,