diff mbox series

[FFmpeg-devel,25/36] avcodec/hevc_mp4toannexb_bsf: Remove intermediate packet

Message ID 20200530160541.29517-25-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 | expand

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/hevc_mp4toannexb_bsf.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/hevc_mp4toannexb_bsf.c b/libavcodec/hevc_mp4toannexb_bsf.c
index 731ff2e7d3..9450efe2c8 100644
--- a/libavcodec/hevc_mp4toannexb_bsf.c
+++ b/libavcodec/hevc_mp4toannexb_bsf.c
@@ -116,20 +116,18 @@  static int hevc_mp4toannexb_init(AVBSFContext *ctx)
     return 0;
 }
 
-static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out)
+static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *pkt)
 {
     HEVCBSFContext *s = ctx->priv_data;
     PutByteContext pb;
-    AVPacket *in;
+    AVBufferRef *out = NULL;
     int ret;
 
-    ret = ff_bsf_get_packet(ctx, &in);
+    ret = ff_bsf_get_packet_ref(ctx, pkt);
     if (ret < 0)
         return ret;
 
     if (!s->extradata_parsed) {
-        av_packet_move_ref(out, in);
-        av_packet_free(&in);
         return 0;
     }
 
@@ -138,7 +136,7 @@  static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out)
         uint64_t out_size = 0;
         int got_irap = 0;
 
-        bytestream2_init(&gb, in->data, in->size);
+        bytestream2_init(&gb, pkt->data, pkt->size);
 
         while (bytestream2_get_bytes_left(&gb)) {
             uint32_t nalu_size = 0;
@@ -181,7 +179,7 @@  static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out)
                 ret = AVERROR(ERANGE);
                 goto fail;
             }
-            ret = av_new_packet(out, out_size);
+            ret = ff_buffer_padded_realloc(&out, out_size);
             if (ret < 0)
                 goto fail;
 
@@ -189,14 +187,11 @@  static int hevc_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out)
         }
     }
 
-    ret = av_packet_copy_props(out, in);
-    if (ret < 0)
-        goto fail;
+    ff_packet_replace_buffer(pkt, out);
 
 fail:
     if (ret < 0)
-        av_packet_unref(out);
-    av_packet_free(&in);
+        av_packet_unref(pkt);
 
     return ret;
 }