[FFmpeg-devel] [PATCH 1/3] avutil/frame: add av_frame_replace
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Fri Aug 13 18:50:40 EEST 2021
James Almer:
> On 8/13/2021 12:27 PM, Andreas Rheinhardt wrote:
>> James Almer:
>>> Signed-off-by: James Almer <jamrial at gmail.com>
>>> ---
>>> Not going to bother with implementing replace for side data, since
>>> it's IMO not
>>> worth it, but patches are welcome of course.
>>>
>>> Missing version bump and APIchanges entry.
>>>
>>> libavutil/frame.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++
>>> libavutil/frame.h | 18 +++++++++
>>> 2 files changed, 116 insertions(+)
>>>
>>> diff --git a/libavutil/frame.h b/libavutil/frame.h
>>> index ff2540a20f..36ed128886 100644
>>> --- a/libavutil/frame.h
>>> +++ b/libavutil/frame.h
>>> @@ -695,6 +695,24 @@ void av_frame_free(AVFrame **frame);
>>> */
>>> int av_frame_ref(AVFrame *dst, const AVFrame *src);
>>> +/**
>>> + * Ensure the destination frame refers to the same data described by
>>> the source
>>> + * frame.
>>> + *
>>> + * Copy frame properties from src to dst and create a new reference
>>> for each
>>> + * AVBufferRef from src if they differ from those in dst.
>>> + *
>>> + * src must be reference counted.
>>> + *
>>> + * @param src The source frame. If there's data described in it, it
>>> must be
>>> + * reference counted.
>>> + * @param dst The destination frame.
>>> + *
>>> + * @return 0 on success, a negative AVERROR on error. On error, dst is
>>> + * unreferenced.
>>> + */
>>> +int av_frame_replace(AVFrame *dst, const AVFrame *src);
>>> +
>>> /**
>>> * Create a new frame that references the same data as src.
>>> *
>>>
>> av_buffer_replace() is a no-op if src == dst (and documented to be so);
>> this is not true for this function where you instantly wipe side data.
>
> Like i said above, I'm not going to try and implement replace for side
> data. It's just not worth the extra complexity.
>
I don't think you got my comment: It was not about saving allocations
for side data; it is about what happens when src and dst coincide.
According to the documentation, you should do nothing, because src and
dst already refer to the same data. Instead you wipe the side data and
modify the frame.
- Andreas
More information about the ffmpeg-devel
mailing list