diff mbox series

[FFmpeg-devel,29/36] avcodec/movsub_bsf: Remove intermediate packet

Message ID 20200530160541.29517-29-andreas.rheinhardt@gmail.com
State New
Headers show
Series [FFmpeg-devel,01/36] avcodec/vp9_superframe_bsf: Check for existence of data before reading it
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt May 30, 2020, 4:05 p.m. UTC
This commit ends using separate packets for in- and output. Instead,
the input is read directly into the packet destined for output via
ff_bsf_get_packet_ref() and only the buffer-related fields are modified;
the others are not touched.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/movsub_bsf.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/movsub_bsf.c b/libavcodec/movsub_bsf.c
index 6e29fa8e50..b5b714ce7e 100644
--- a/libavcodec/movsub_bsf.c
+++ b/libavcodec/movsub_bsf.c
@@ -23,37 +23,33 @@ 
 #include "bsf.h"
 #include "bsf_internal.h"
 
-static int text2movsub(AVBSFContext *ctx, AVPacket *out)
+static int text2movsub(AVBSFContext *ctx, AVPacket *pkt)
 {
-    AVPacket *in;
+    AVBufferRef *out = NULL;
     int ret = 0;
 
-    ret = ff_bsf_get_packet(ctx, &in);
+    ret = ff_bsf_get_packet_ref(ctx, pkt);
     if (ret < 0)
         return ret;
 
-    if (in->size > 0xffff) {
+    if (pkt->size > 0xffff) {
         ret = AVERROR_INVALIDDATA;
         goto fail;
     }
 
-    ret = av_new_packet(out, in->size + 2);
+    ret = ff_buffer_padded_realloc(&out, pkt->size + 2);
     if (ret < 0) {
-        ret = AVERROR(ENOMEM);
         goto fail;
     }
 
-    ret = av_packet_copy_props(out, in);
-    if (ret < 0)
-        goto fail;
+    AV_WB16(out->data, pkt->size);
+    memcpy(out->data + 2, pkt->data, pkt->size);
 
-    AV_WB16(out->data, in->size);
-    memcpy(out->data + 2, in->data, in->size);
+    ff_packet_replace_buffer(pkt, out);
 
 fail:
     if (ret < 0)
-        av_packet_unref(out);
-    av_packet_free(&in);
+        av_packet_unref(pkt);
     return ret;
 }