[FFmpeg-devel] avutil/opt: Implement av_opt_set_defaults* in O(N) instead of O(N²) time

Don Moir donmoir at comcast.net
Mon May 12 13:32:06 CEST 2014


Appears there is a bug in this implementation:

http://git.videolan.org/?p=ffmpeg.git;a=commit;h=e8ac905daea47572abf90c873cd184dbfbbf34a7

Wrong pointers, overwrites, or similiar. I believe this has not been addressed in more recent versions, but it's not really the point of this email. I will check the bug out later.

When I was looking for the problem and trying to understand how this is supposed to work, avcodec_alloc_context3 gets called and from there, avcodec_get_context_defaults3 gets called.

int avcodec_get_context_defaults3(AVCodecContext *s, const AVCodec *codec)
{
    int flags=0;
    memset(s, 0, sizeof(AVCodecContext));

    s->av_class = &av_codec_context_class;

    s->codec_type = codec ? codec->type : AVMEDIA_TYPE_UNKNOWN;
    if (codec)
        s->codec_id = codec->id;

    if(s->codec_type == AVMEDIA_TYPE_AUDIO)
        flags= AV_OPT_FLAG_AUDIO_PARAM;
    else if(s->codec_type == AVMEDIA_TYPE_VIDEO)
        flags= AV_OPT_FLAG_VIDEO_PARAM;
    else if(s->codec_type == AVMEDIA_TYPE_SUBTITLE)
        flags= AV_OPT_FLAG_SUBTITLE_PARAM;
    av_opt_set_defaults2(s, flags, flags);
   ...
}

Appears to me that every new AVCodecContext gets a pointer to the static av_codec_context_class.  Then this is stomped on by av_opt_set_defaults2(s, flags, flags);

1) Am I seeing that right?

2) If the defaults are constant then why is it recalculated and why does it go thru av_opt_set_defaults2?

3) Seems that an allocation for av_class and assignment would be appropriate.

4) much work is done in av_opt_set_defaults2 and seems should be avoided.



More information about the ffmpeg-devel mailing list