diff mbox series

[FFmpeg-devel] avfilter/buffersrc: simplify av_buffersrc_add_frame_flags()

Message ID 20210207142958.51043-1-jamrial@gmail.com
State Accepted
Commit 04dfdde09b8533076993d2a90b5f9af6d5a68604
Headers show
Series [FFmpeg-devel] avfilter/buffersrc: simplify av_buffersrc_add_frame_flags() | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

James Almer Feb. 7, 2021, 2:29 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavfilter/buffersrc.c | 38 ++++++++------------------------------
 1 file changed, 8 insertions(+), 30 deletions(-)

Comments

James Almer Feb. 16, 2021, 2:02 p.m. UTC | #1
On 2/7/2021 11:29 AM, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>   libavfilter/buffersrc.c | 38 ++++++++------------------------------
>   1 file changed, 8 insertions(+), 30 deletions(-)
> 
> diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
> index bf30f54177..da1cf9941e 100644
> --- a/libavfilter/buffersrc.c
> +++ b/libavfilter/buffersrc.c
> @@ -149,33 +149,6 @@ int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *fr
>       return av_buffersrc_add_frame_flags(ctx, frame, 0);
>   }
>   
> -static int av_buffersrc_add_frame_internal(AVFilterContext *ctx,
> -                                           AVFrame *frame, int flags);
> -
> -int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
> -{
> -    AVFrame *copy = NULL;
> -    int ret = 0;
> -
> -    if (frame && frame->channel_layout &&
> -        av_get_channel_layout_nb_channels(frame->channel_layout) != frame->channels) {
> -        av_log(ctx, AV_LOG_ERROR, "Layout indicates a different number of channels than actually present\n");
> -        return AVERROR(EINVAL);
> -    }
> -
> -    if (!(flags & AV_BUFFERSRC_FLAG_KEEP_REF) || !frame)
> -        return av_buffersrc_add_frame_internal(ctx, frame, flags);
> -
> -    if (!(copy = av_frame_alloc()))
> -        return AVERROR(ENOMEM);
> -    ret = av_frame_ref(copy, frame);
> -    if (ret >= 0)
> -        ret = av_buffersrc_add_frame_internal(ctx, copy, flags);
> -
> -    av_frame_free(&copy);
> -    return ret;
> -}
> -
>   static int push_frame(AVFilterGraph *graph)
>   {
>       int ret;
> @@ -190,13 +163,18 @@ static int push_frame(AVFilterGraph *graph)
>       return 0;
>   }
>   
> -static int av_buffersrc_add_frame_internal(AVFilterContext *ctx,
> -                                           AVFrame *frame, int flags)
> +int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
>   {
>       BufferSourceContext *s = ctx->priv;
>       AVFrame *copy;
>       int refcounted, ret;
>   
> +    if (frame && frame->channel_layout &&
> +        av_get_channel_layout_nb_channels(frame->channel_layout) != frame->channels) {
> +        av_log(ctx, AV_LOG_ERROR, "Layout indicates a different number of channels than actually present\n");
> +        return AVERROR(EINVAL);
> +    }
> +
>       s->nb_failed_requests = 0;
>   
>       if (!frame)
> @@ -229,7 +207,7 @@ static int av_buffersrc_add_frame_internal(AVFilterContext *ctx,
>       if (!(copy = av_frame_alloc()))
>           return AVERROR(ENOMEM);
>   
> -    if (refcounted) {
> +    if (refcounted && !(flags & AV_BUFFERSRC_FLAG_KEEP_REF)) {
>           av_frame_move_ref(copy, frame);
>       } else {
>           ret = av_frame_ref(copy, frame);

Will apply soon if there are no objections.
Nicolas George Feb. 16, 2021, 3:25 p.m. UTC | #2
James Almer (12021-02-07):
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavfilter/buffersrc.c | 38 ++++++++------------------------------
>  1 file changed, 8 insertions(+), 30 deletions(-)

Sorry, forgot to look at it.

Looks ok, thanks.

Regards,
James Almer Feb. 16, 2021, 3:38 p.m. UTC | #3
On 2/16/2021 12:25 PM, Nicolas George wrote:
> James Almer (12021-02-07):
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   libavfilter/buffersrc.c | 38 ++++++++------------------------------
>>   1 file changed, 8 insertions(+), 30 deletions(-)
> 
> Sorry, forgot to look at it.
> 
> Looks ok, thanks.
> 
> Regards,

Applied, thanks.
diff mbox series

Patch

diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
index bf30f54177..da1cf9941e 100644
--- a/libavfilter/buffersrc.c
+++ b/libavfilter/buffersrc.c
@@ -149,33 +149,6 @@  int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *fr
     return av_buffersrc_add_frame_flags(ctx, frame, 0);
 }
 
-static int av_buffersrc_add_frame_internal(AVFilterContext *ctx,
-                                           AVFrame *frame, int flags);
-
-int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
-{
-    AVFrame *copy = NULL;
-    int ret = 0;
-
-    if (frame && frame->channel_layout &&
-        av_get_channel_layout_nb_channels(frame->channel_layout) != frame->channels) {
-        av_log(ctx, AV_LOG_ERROR, "Layout indicates a different number of channels than actually present\n");
-        return AVERROR(EINVAL);
-    }
-
-    if (!(flags & AV_BUFFERSRC_FLAG_KEEP_REF) || !frame)
-        return av_buffersrc_add_frame_internal(ctx, frame, flags);
-
-    if (!(copy = av_frame_alloc()))
-        return AVERROR(ENOMEM);
-    ret = av_frame_ref(copy, frame);
-    if (ret >= 0)
-        ret = av_buffersrc_add_frame_internal(ctx, copy, flags);
-
-    av_frame_free(&copy);
-    return ret;
-}
-
 static int push_frame(AVFilterGraph *graph)
 {
     int ret;
@@ -190,13 +163,18 @@  static int push_frame(AVFilterGraph *graph)
     return 0;
 }
 
-static int av_buffersrc_add_frame_internal(AVFilterContext *ctx,
-                                           AVFrame *frame, int flags)
+int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
 {
     BufferSourceContext *s = ctx->priv;
     AVFrame *copy;
     int refcounted, ret;
 
+    if (frame && frame->channel_layout &&
+        av_get_channel_layout_nb_channels(frame->channel_layout) != frame->channels) {
+        av_log(ctx, AV_LOG_ERROR, "Layout indicates a different number of channels than actually present\n");
+        return AVERROR(EINVAL);
+    }
+
     s->nb_failed_requests = 0;
 
     if (!frame)
@@ -229,7 +207,7 @@  static int av_buffersrc_add_frame_internal(AVFilterContext *ctx,
     if (!(copy = av_frame_alloc()))
         return AVERROR(ENOMEM);
 
-    if (refcounted) {
+    if (refcounted && !(flags & AV_BUFFERSRC_FLAG_KEEP_REF)) {
         av_frame_move_ref(copy, frame);
     } else {
         ret = av_frame_ref(copy, frame);