diff mbox series

[FFmpeg-devel,32/36] avcodec/mp3_header_decompress_bsf: Remove intermediate packet

Message ID 20200530160541.29517-32-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/mp3_header_decompress_bsf.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/mp3_header_decompress_bsf.c b/libavcodec/mp3_header_decompress_bsf.c
index 3d357dd27e..29ab5721ef 100644
--- a/libavcodec/mp3_header_decompress_bsf.c
+++ b/libavcodec/mp3_header_decompress_bsf.c
@@ -26,28 +26,25 @@ 
 #include "mpegaudiodata.h"
 
 
-static int mp3_header_decompress(AVBSFContext *ctx, AVPacket *out)
+static int mp3_header_decompress(AVBSFContext *ctx, AVPacket *pkt)
 {
-    AVPacket *in;
     uint32_t header;
     int sample_rate= ctx->par_in->sample_rate;
     int sample_rate_index=0;
     int lsf, mpeg25, bitrate_index, frame_size, offset, ret;
+    AVBufferRef *out = NULL;
     const uint8_t *buf;
     int buf_size;
 
-    ret = ff_bsf_get_packet(ctx, &in);
+    ret = ff_bsf_get_packet_ref(ctx, pkt);
     if (ret < 0)
         return ret;
 
-    buf      = in->data;
-    buf_size = in->size;
+    buf      = pkt->data;
+    buf_size = pkt->size;
 
     header = AV_RB32(buf);
     if(ff_mpa_check_header(header) >= 0){
-        av_packet_move_ref(out, in);
-        av_packet_free(&in);
-
         return 0;
     }
 
@@ -89,14 +86,9 @@  static int mp3_header_decompress(AVBSFContext *ctx, AVPacket *out)
         offset++;
     }
 
-    ret = av_new_packet(out, frame_size);
+    ret = ff_buffer_padded_realloc(&out, frame_size);
     if (ret < 0)
         goto fail;
-    ret = av_packet_copy_props(out, in);
-    if (ret < 0) {
-        av_packet_unref(out);
-        goto fail;
-    }
     memcpy(out->data + offset, buf, buf_size);
 
     if(ctx->par_in->channels==2){
@@ -118,10 +110,13 @@  static int mp3_header_decompress(AVBSFContext *ctx, AVPacket *out)
         header |= 1 << 16; // protection_bit
     AV_WB32(out->data, header);
 
+    ff_packet_replace_buffer(pkt, out);
+
     ret = 0;
 
 fail:
-    av_packet_free(&in);
+    if (ret < 0)
+        av_packet_unref(pkt);
     return ret;
 }