[FFmpeg-devel] [PATCH v2] avcodec/h264_parser: Try to avoid (un)referencing

Anton Khirnov anton at khirnov.net
Mon Jun 1 12:49:06 EEST 2020


Quoting Andreas Rheinhardt (2020-05-29 18:31:57)
> When a slice is encountered, the H.264 parser up until now always
> unreferenced and reset the currently active PPS; immediately
> afterwards, the currently active PPS is set again which includes
> referencing it. Given that it is typical for the active parameter
> sets to change only seldomly, most of the time the new active PPS will
> be the old one. Therefore this commit checks for this and only
> unreferences the PPS if it changed.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> ---
> New and much simplified version of [1]. This has been made possible by
> 5e316096fa9ba4493d9dbb48847ad8e0b0e188c3.
> 
> [1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2019-August/248374.html
> 
>  libavcodec/h264_parser.c | 2 ++
>  1 file changed, 2 insertions(+)

I've been considering a utility function along the lines of:

int av_buffer_update(AVBufferRef **dst, AVBufferRef *src)
{
    if ((*dst)->buffer == src->buffer)
        return 0;
    av_buffer_unref(dst);
    *dst = av_buffer_ref(src);
    return 1;
}

which would help avoid unnecessary unrefs+refs in such cases. Thoughts?

-- 
Anton Khirnov


More information about the ffmpeg-devel mailing list