ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinha...@outlook.com> | 
Thu Dec  9 12:37:18 2021 +0100| [9644ee224f56118e5b1ac4edc1b088a6a6ac2ac7] | 
committer: Andreas Rheinhardt

avcodec/mmaldec: Avoid creating unnecessary reference, simplify code

ffmal_add_packet() basically duplicated the logic in
av_packet_make_refcounted() with the added twist that it always
created a reference even if one is already available.
This commit stops doing this.

Tested-by: Cameron Gutman <aicomman...@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinha...@outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9644ee224f56118e5b1ac4edc1b088a6a6ac2ac7
---

 libavcodec/mmaldec.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/libavcodec/mmaldec.c b/libavcodec/mmaldec.c
index b0140170f2..0a1905b3a0 100644
--- a/libavcodec/mmaldec.c
+++ b/libavcodec/mmaldec.c
@@ -485,29 +485,19 @@ static int ffmmal_add_packet(AVCodecContext *avctx, 
AVPacket *avpkt,
                              int is_extradata)
 {
     MMALDecodeContext *ctx = avctx->priv_data;
-    AVBufferRef *buf = NULL;
+    const AVBufferRef *buf = NULL;
     int size = 0;
     uint8_t *data = (uint8_t *)"";
     uint8_t *start;
     int ret = 0;
 
     if (avpkt->size) {
-        if (avpkt->buf) {
-            buf = av_buffer_ref(avpkt->buf);
-            size = avpkt->size;
-            data = avpkt->data;
-        } else {
-            buf = av_buffer_alloc(avpkt->size);
-            if (buf) {
-                memcpy(buf->data, avpkt->data, avpkt->size);
-                size = buf->size;
-                data = buf->data;
-            }
-        }
-        if (!buf) {
-            ret = AVERROR(ENOMEM);
+        ret = av_packet_make_refcounted(avpkt);
+        if (ret < 0)
             goto done;
-        }
+        buf  = avpkt->buf;
+        data = avpkt->data;
+        size = avpkt->size;
         if (!is_extradata)
             ctx->packets_sent++;
     } else {
@@ -573,7 +563,6 @@ static int ffmmal_add_packet(AVCodecContext *avctx, 
AVPacket *avpkt,
     } while (size);
 
 done:
-    av_buffer_unref(&buf);
     av_packet_unref(avpkt);
     return ret;
 }

_______________________________________________
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to