diff mbox series

[FFmpeg-devel,v3,5/5] avcodec/utils: simplify, remove duplicate code

Message ID 1588254981-7627-1-git-send-email-lance.lmwang@gmail.com
State Accepted
Headers show
Series None | expand

Commit Message

Lance Wang April 30, 2020, 1:56 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavcodec/utils.c | 38 ++++++--------------------------------
 1 file changed, 6 insertions(+), 32 deletions(-)

Comments

Andreas Rheinhardt April 30, 2020, 2:03 p.m. UTC | #1
lance.lmwang@gmail.com:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavcodec/utils.c | 38 ++++++--------------------------------
>  1 file changed, 6 insertions(+), 32 deletions(-)
> 
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index e77090d..1a8ca16 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -583,38 +583,12 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
>      }
>      avctx->internal = avci;
>  
> -    avci->to_free = av_frame_alloc();
> -    if (!avci->to_free) {
> -        ret = AVERROR(ENOMEM);
> -        goto free_and_end;
> -    }
> -
> -    avci->compat_decode_frame = av_frame_alloc();
> -    if (!avci->compat_decode_frame) {
> -        ret = AVERROR(ENOMEM);
> -        goto free_and_end;
> -    }
> -
> -    avci->buffer_frame = av_frame_alloc();
> -    if (!avci->buffer_frame) {
> -        ret = AVERROR(ENOMEM);
> -        goto free_and_end;
> -    }
> -
> -    avci->buffer_pkt = av_packet_alloc();
> -    if (!avci->buffer_pkt) {
> -        ret = AVERROR(ENOMEM);
> -        goto free_and_end;
> -    }
> -
> -    avci->ds.in_pkt = av_packet_alloc();
> -    if (!avci->ds.in_pkt) {
> -        ret = AVERROR(ENOMEM);
> -        goto free_and_end;
> -    }
> -
> -    avci->last_pkt_props = av_packet_alloc();
> -    if (!avci->last_pkt_props) {
> +    if (!(avci->to_free             = av_frame_alloc())  ||
> +        !(avci->compat_decode_frame = av_frame_alloc())  ||
> +        !(avci->buffer_frame        = av_frame_alloc())  ||
> +        !(avci->buffer_pkt          = av_packet_alloc()) ||
> +        !(avci->ds.in_pkt           = av_packet_alloc()) ||
> +        !(avci->last_pkt_props      = av_packet_alloc())) {
>          ret = AVERROR(ENOMEM);
>          goto free_and_end;
>      }
> 
LGTM. But I don't maintain that code.

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index e77090d..1a8ca16 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -583,38 +583,12 @@  int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
     }
     avctx->internal = avci;
 
-    avci->to_free = av_frame_alloc();
-    if (!avci->to_free) {
-        ret = AVERROR(ENOMEM);
-        goto free_and_end;
-    }
-
-    avci->compat_decode_frame = av_frame_alloc();
-    if (!avci->compat_decode_frame) {
-        ret = AVERROR(ENOMEM);
-        goto free_and_end;
-    }
-
-    avci->buffer_frame = av_frame_alloc();
-    if (!avci->buffer_frame) {
-        ret = AVERROR(ENOMEM);
-        goto free_and_end;
-    }
-
-    avci->buffer_pkt = av_packet_alloc();
-    if (!avci->buffer_pkt) {
-        ret = AVERROR(ENOMEM);
-        goto free_and_end;
-    }
-
-    avci->ds.in_pkt = av_packet_alloc();
-    if (!avci->ds.in_pkt) {
-        ret = AVERROR(ENOMEM);
-        goto free_and_end;
-    }
-
-    avci->last_pkt_props = av_packet_alloc();
-    if (!avci->last_pkt_props) {
+    if (!(avci->to_free             = av_frame_alloc())  ||
+        !(avci->compat_decode_frame = av_frame_alloc())  ||
+        !(avci->buffer_frame        = av_frame_alloc())  ||
+        !(avci->buffer_pkt          = av_packet_alloc()) ||
+        !(avci->ds.in_pkt           = av_packet_alloc()) ||
+        !(avci->last_pkt_props      = av_packet_alloc())) {
         ret = AVERROR(ENOMEM);
         goto free_and_end;
     }