[FFmpeg-devel] [PATCH 07/10] sws: add a new scaling API

James Almer jamrial at gmail.com
Mon Aug 9 06:45:09 EEST 2021


On 8/8/2021 2:29 PM, Anton Khirnov wrote:
> +int sws_frame_start(struct SwsContext *c, AVFrame *dst, const AVFrame *src)
> +{
> +    int ret, allocated = 0;
> +
> +    ret = av_frame_ref(c->frame_src, src);
> +    if (ret < 0)
> +        return ret;
> +
> +    if (!dst->buf[0]) {

The frame could have non refcounted buffers, and av_frame_get_buffer() 
below would overwrite the data pointers.
IMO, just state in the doxy that if already allocated, the data buffers 
must be reference counted.

> +        dst->width  = c->dstW;
> +        dst->height = c->dstH;
> +        dst->format = c->dstFormat;
> +
> +        ret = av_frame_get_buffer(dst, 0);
> +        if (ret < 0)
> +            return ret;
> +        allocated = 1;
> +    }
> +
> +    ret = av_frame_ref(c->frame_dst, dst);
> +    if (ret < 0) {
> +        if (allocated)
> +            av_frame_unref(dst);
> +
> +        return ret;
> +    }
> +
> +    return 0;
> +}



More information about the ffmpeg-devel mailing list