[FFmpeg-devel] MPEG-PS demuxer index memory usage

Baptiste Coudurier baptiste.coudurier
Mon Jan 7 01:36:39 CET 2008


Hi guys,

Paul Kelly wrote:
> On Sat, 5 Jan 2008, Michael Niedermayer wrote:
> 
>> On Sat, Jan 05, 2008 at 05:14:21PM +0000, Paul Kelly wrote:
>>> On Sat, 5 Jan 2008, Michael Niedermayer wrote:
>>>
>>>> also iam slightly thinking that this would belong more to
>>>> AVFormatContext
>>>> or what is the use case of having max_index_size differ between streams
>>>> and the user should be able to set it from the command line
>>>> if it were in AVFormatContext you only would have to add a single
>>>> line to
>>>> the AVOption array in libavformat/utils.c
>>>
>>> Ok I understand now about the AVOption array - it's a very neat idea
>>> and I
>>> agree adding it there and putting max_index_size in AVFormatContext is a
>>> more logical and elegant solution than putting it in AVStream.
> [...]
>>> If that's the case then the only way I can see that having it in
>>> AVFormatContext would work would be to rewrite av_add_index_entry()
>>> to take
>>> a pointer to an AVFormatContext, and change everywhere it is called
>>> in all
>>> the demuxers -
>>
>> yes, if its in AVFormatContext av_add_index_entry() and all calls to it
>> need a tiny change.
> 
> OK, the attached patch changes av_add_index_stream() to take a pointer
> to an AVFormatContext and a stream index instead of a pointer to an
> AVStream (in a similar manner to av_seek_frame_binary()), and changes
> all calls to av_add_index_entry() accordingly.
> 
> The new struct member max_index_size is added to the end of
> AVFormatContext, and the AVOption array has a new entry to allow it to
> be set from the command line.
> 
> Things I'm still not sure about:
> * Should there be also an FF_OPT_TYPE_UINT, or is setting max_index_size
> to INT_MAX as the default (as I have done) OK?
> * Should the option be marked as relevant to encoding as well as
> decoding (not sure how to do that) - while changing all the calls to
> av_add_index_entry() some of the calls to it appeared to be in muxers as
> well as demuxers (example: nutenc.c)
> 
> [...]
>  
> +    max_entries= s->max_index_size / sizeof(AVIndexEntry);
> +    if(max_entries == 0)
> +        return -1;
> +    if((unsigned)st->nb_index_entries >= max_entries){
> +        int in, out= 0;
> +        /* Halve the size of the index by removing every second entry */
> +        for(in=0; in<st->nb_index_entries; in+= 2)
> +            st->index_entries[out++]= st->index_entries[in];
> +        st->nb_index_entries= out;
> +    }
> +
>      entries = av_fast_realloc(st->index_entries,

Just a note to remember that mov demuxer is building index containing
all samples, and absolutely need all index entries to seek and demux, so
you cannot remove any index entry with the current implementation.

-- 
Baptiste COUDURIER                              GnuPG Key Id: 0x5C1ABAAA
SMARTJOG S.A.                                    http://www.smartjog.com
Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
Phone: +33 1 49966312




More information about the ffmpeg-devel mailing list