[FFmpeg-devel] [PATCH 06/13] src_buffer: move buffer copy in a separate function.

Stefano Sabatini stefasab at gmail.com
Sun Apr 29 17:30:58 CEST 2012


On date Saturday 2012-04-28 16:31:48 +0200, Nicolas George encoded:
> This will make merging with the audio part easier.
> 
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> ---
>  libavfilter/src_buffer.c |   37 ++++++++++++++++++++++++++-----------
>  1 files changed, 26 insertions(+), 11 deletions(-)
> 
> diff --git a/libavfilter/src_buffer.c b/libavfilter/src_buffer.c
> index 8e5e1fe..52c4c4a 100644
> --- a/libavfilter/src_buffer.c
> +++ b/libavfilter/src_buffer.c
> @@ -133,11 +133,33 @@ static int check_format_change(AVFilterContext *buffer_filter,
>      }
>  }
>  
> +static AVFilterBufferRef *copy_buffer_ref(AVFilterContext *ctx,
> +                                          AVFilterBufferRef *ref)
> +{
> +    AVFilterLink *outlink = ctx->outputs[0];
> +    AVFilterBufferRef *buf;
> +
> +    switch (outlink->type) {
> +
> +    case AVMEDIA_TYPE_VIDEO:
> +        buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
> +                                        ref->video->w, ref->video->h);
> +        av_image_copy(buf->data, buf->linesize,
> +                      (void*)ref->data, ref->linesize,
> +                      ref->format, ref->video->w, ref->video->h);
> +        break;
> +
> +    default:
> +        return NULL;
> +    }
> +    avfilter_copy_buffer_ref_props(buf, ref);
> +    return buf;
> +}
> +
>  int av_buffersrc_add_ref(AVFilterContext *buffer_filter,
>                           AVFilterBufferRef *picref, int flags)
>  {
>      BufferSourceContext *c = buffer_filter->priv;
> -    AVFilterLink *outlink = buffer_filter->outputs[0];
>      AVFilterBufferRef *buf;
>      int ret;
>  
> @@ -157,17 +179,10 @@ int av_buffersrc_add_ref(AVFilterContext *buffer_filter,
>          if (ret < 0)
>              return ret;
>      }
> -    if (flags & AV_BUFFERSRC_FLAG_NO_COPY) {
> +    if (flags & AV_BUFFERSRC_FLAG_NO_COPY)
>          buf = picref;
> -    } else {
> -    buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
> -                                    picref->video->w, picref->video->h);
> -    av_image_copy(buf->data, buf->linesize,
> -                  (void*)picref->data, picref->linesize,
> -                  picref->format, picref->video->w, picref->video->h);
> -    avfilter_copy_buffer_ref_props(buf, picref);
> -
> -    }
> +    else
> +        buf = copy_buffer_ref(buffer_filter, picref);

Should be fine. My only concern is that the additional function call
may affect performance. I suppose it is the job of the compiler to
optimize it, I wonder if inlining the function may help with it.
-- 
FFmpeg = Fabulous & Fostering Miracolous Peaceful Erroneous Glue


More information about the ffmpeg-devel mailing list