diff options
author | Paul Kelly <paul@stjohnspoint.co.uk> | 2008-01-13 13:33:37 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2008-01-13 13:33:37 +0000 |
commit | 3dea63bd7e611b625d135fe9bc8b3cef891bc757 (patch) | |
tree | ac9bb100ccb98d185503c44954626f481486ead8 /libavformat/utils.c | |
parent | 3ed546fe525eace861e708ab970cf91f69bfdd09 (diff) | |
download | ffmpeg-3dea63bd7e611b625d135fe9bc8b3cef891bc757.tar.gz |
user specifyable maximum amount of memory to use for the index.
patch by Paul Kelly paul stjohnspoint co uk
with some changes by me
Originally committed as revision 11521 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/utils.c')
-rw-r--r-- | libavformat/utils.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c index ea47bcf014..d116e845dd 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -324,6 +324,7 @@ static const AVOption options[]={ {"year", "set the year", OFFSET(year), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, E}, {"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), FF_OPT_TYPE_INT, 3*AV_TIME_BASE, 0, INT_MAX, D}, {"cryptokey", "decryption key", OFFSET(key), FF_OPT_TYPE_BINARY, 0, 0, 0, D}, +{"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), FF_OPT_TYPE_INT, INT_MAX, 0, INT_MAX, D}, {NULL}, }; @@ -791,6 +792,7 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) compute_pkt_fields(s, st, st->parser, pkt); if((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & PKT_FLAG_KEY){ + ff_reduce_index(s, st->index); av_add_index_entry(st, st->parser->frame_offset, pkt->dts, 0, 0, AVINDEX_KEYFRAME); } @@ -1008,6 +1010,19 @@ void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp){ } } +void ff_reduce_index(AVFormatContext *s, int stream_index) +{ + AVStream *st= s->streams[stream_index]; + unsigned int max_entries= s->max_index_size / sizeof(AVIndexEntry); + + if((unsigned)st->nb_index_entries >= max_entries){ + int i; + for(i=0; 2*i<st->nb_index_entries; i++) + st->index_entries[i]= st->index_entries[2*i]; + st->nb_index_entries= i; + } +} + int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags) { |