[FFmpeg-cvslog] h264_redundant_pps: Avoid allocations and copies of packet structures

Andreas Rheinhardt git at videolan.org
Mon Jul 8 01:11:39 EEST 2019


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Thu Jun 20 01:45:03 2019 +0200| [d78553cc4c791d0e276b37e1f2687301b02ea4a7] | committer: Mark Thompson

h264_redundant_pps: Avoid allocations and copies of packet structures

This commit changes h264_redundant_pps to (a) use ff_bsf_get_packet_ref
instead of ff_bsf_get_packet (thereby avoiding one malloc and free per
filtered packet) and (b) to use only one packet structure at all,
thereby avoiding a call to av_packet_copy_props.

(b) has been made possible by the recent changes to ff_cbs_write_packet.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>

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

 libavcodec/h264_redundant_pps_bsf.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/libavcodec/h264_redundant_pps_bsf.c b/libavcodec/h264_redundant_pps_bsf.c
index db8717d69a..80b8634c7b 100644
--- a/libavcodec/h264_redundant_pps_bsf.c
+++ b/libavcodec/h264_redundant_pps_bsf.c
@@ -66,19 +66,18 @@ static int h264_redundant_pps_fixup_slice(H264RedundantPPSContext *ctx,
     return 0;
 }
 
-static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out)
+static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *pkt)
 {
     H264RedundantPPSContext *ctx = bsf->priv_data;
-    AVPacket *in;
     CodedBitstreamFragment *au = &ctx->access_unit;
     int au_has_sps;
     int err, i;
 
-    err = ff_bsf_get_packet(bsf, &in);
+    err = ff_bsf_get_packet_ref(bsf, pkt);
     if (err < 0)
         return err;
 
-    err = ff_cbs_read_packet(ctx->input, au, in);
+    err = ff_cbs_read_packet(ctx->input, au, pkt);
     if (err < 0)
         goto fail;
 
@@ -94,7 +93,7 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out)
                 goto fail;
             if (!au_has_sps) {
                 av_log(bsf, AV_LOG_VERBOSE, "Deleting redundant PPS "
-                       "at %"PRId64".\n", in->pts);
+                       "at %"PRId64".\n", pkt->pts);
                 err = ff_cbs_delete_unit(ctx->input, au, i);
                 if (err < 0)
                     goto fail;
@@ -107,21 +106,15 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out)
         }
     }
 
-    err = ff_cbs_write_packet(ctx->output, out, au);
-    if (err < 0)
-        goto fail;
-
-
-    err = av_packet_copy_props(out, in);
+    err = ff_cbs_write_packet(ctx->output, pkt, au);
     if (err < 0)
         goto fail;
 
     err = 0;
 fail:
     ff_cbs_fragment_reset(ctx->output, au);
-    av_packet_free(&in);
     if (err < 0)
-        av_packet_unref(out);
+        av_packet_unref(pkt);
 
     return err;
 }



More information about the ffmpeg-cvslog mailing list