[FFmpeg-devel] [PATCH] avutil/frame: allow only one element per type in frame side data

James Almer jamrial at gmail.com
Sat Jul 29 07:12:56 EEST 2017


On 7/25/2017 9:10 PM, James Almer wrote:
> Same rationale as with packet side data, it was never meant to do otherwise
> as av_frame_get_side_data returns the first entry it finds of a given type.
> 
> Based on code from libavformat's av_stream_add_side_data().
> 
> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
>  libavutil/frame.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index 24d5d5f184..c41d4be8cc 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -638,10 +638,24 @@ static AVFrameSideData *frame_new_side_data(AVFrame *frame,
>                                              AVBufferRef *buf)
>  {
>      AVFrameSideData *ret, **tmp;
> +    int i;
>  
>      if (!buf)
>          return NULL;
>  
> +    for (i = 0; i < frame->nb_side_data; i++) {
> +        AVFrameSideData *sd = frame->side_data[i];
> +
> +        if (sd->type == type) {
> +            av_buffer_unref(&sd->buf);
> +            av_dict_free(&sd->metadata);
> +            sd->buf  = buf;
> +            sd->data = sd->buf->data;
> +            sd->size = buf->size;
> +            return sd;
> +        }
> +    }
> +
>      if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
>          goto fail;

Ping.


More information about the ffmpeg-devel mailing list