diff mbox

[FFmpeg-devel,1/2] filter_units, trace_headers: Always use fragment from context

Message ID 20190211224743.3752-1-andreas.rheinhardt@googlemail.com
State Accepted
Commit c5b452ed2f16a0d7bf01d7d84097337f8756987b
Headers show

Commit Message

Andreas Rheinhardt Feb. 11, 2019, 10:47 p.m. UTC
This is in preparation for another patch that will stop needless
reallocations of the unit array.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com>
---
 libavcodec/filter_units_bsf.c  |  8 ++++----
 libavcodec/trace_headers_bsf.c | 13 +++++++------
 2 files changed, 11 insertions(+), 10 deletions(-)

Comments

Mark Thompson Feb. 25, 2019, 11:03 p.m. UTC | #1
On 11/02/2019 22:47, Andreas Rheinhardt wrote:
> This is in preparation for another patch that will stop needless
> reallocations of the unit array.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com>
> ---
>  libavcodec/filter_units_bsf.c  |  8 ++++----
>  libavcodec/trace_headers_bsf.c | 13 +++++++------
>  2 files changed, 11 insertions(+), 10 deletions(-)

On 11/02/2019 22:47, Andreas Rheinhardt wrote:> Currently, a fragment's unit array is constantly reallocated during
> splitting of a packet. This commit changes this: One can keep the units
> array by distinguishing between the number of allocated and the number
> of valid units in the units array.
> 
> The more units a packet is split into, the bigger the benefit.
> So MPEG-2 benefits the most; for a video coming from an NTSC-DVD
> (usually 32 units per frame) the average cost of cbs_insert_unit (for a
> single unit) went down from 6717 decicycles to 450 decicycles (based
> upon 10 runs with 4194304 runs each); if each packet consists of only
> one unit, it went down from 2425 to 448; for a H.264 video where most
> packets contain nine units, it went from 4431 to 450.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com>
> ---
>  This time I have also changed VAAPI to stop reallocating the units
> array. Keep in mind that I couldn't test this at all.
>  libavcodec/av1_metadata_bsf.c       |  6 ++-
>  libavcodec/av1_parser.c             |  5 ++-
>  libavcodec/cbs.c                    | 62 +++++++++++++++++------------
>  libavcodec/cbs.h                    | 33 +++++++++++++--
>  libavcodec/filter_units_bsf.c       |  7 ++--
>  libavcodec/h264_metadata_bsf.c      |  6 ++-
>  libavcodec/h264_redundant_pps_bsf.c |  6 ++-
>  libavcodec/h265_metadata_bsf.c      |  6 ++-
>  libavcodec/mpeg2_metadata_bsf.c     |  6 ++-
>  libavcodec/trace_headers_bsf.c      |  5 ++-
>  libavcodec/vaapi_encode_h264.c      |  9 +++--
>  libavcodec/vaapi_encode_h265.c      |  9 +++--
>  libavcodec/vaapi_encode_mjpeg.c     |  3 +-
>  libavcodec/vaapi_encode_mpeg2.c     |  5 ++-
>  libavcodec/vp9_metadata_bsf.c       |  4 +-
>  15 files changed, 113 insertions(+), 59 deletions(-)

LGTM, applied.

Thank you!

- Mark
diff mbox

Patch

diff --git a/libavcodec/filter_units_bsf.c b/libavcodec/filter_units_bsf.c
index 1ee0afdf2b..0500dea6b2 100644
--- a/libavcodec/filter_units_bsf.c
+++ b/libavcodec/filter_units_bsf.c
@@ -199,18 +199,18 @@  static int filter_units_init(AVBSFContext *bsf)
     ctx->cbc->nb_decompose_unit_types = 0;
 
     if (bsf->par_in->extradata) {
-        CodedBitstreamFragment ps;
+        CodedBitstreamFragment *frag = &ctx->fragment;
 
-        err = ff_cbs_read_extradata(ctx->cbc, &ps, bsf->par_in);
+        err = ff_cbs_read_extradata(ctx->cbc, frag, bsf->par_in);
         if (err < 0) {
             av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n");
         } else {
-            err = ff_cbs_write_extradata(ctx->cbc, bsf->par_out, &ps);
+            err = ff_cbs_write_extradata(ctx->cbc, bsf->par_out, frag);
             if (err < 0)
                 av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n");
         }
 
-        ff_cbs_fragment_uninit(ctx->cbc, &ps);
+        ff_cbs_fragment_uninit(ctx->cbc, frag);
     }
 
     return err;
diff --git a/libavcodec/trace_headers_bsf.c b/libavcodec/trace_headers_bsf.c
index 8322229d4c..61284e615e 100644
--- a/libavcodec/trace_headers_bsf.c
+++ b/libavcodec/trace_headers_bsf.c
@@ -28,6 +28,7 @@ 
 
 typedef struct TraceHeadersContext {
     CodedBitstreamContext *cbc;
+    CodedBitstreamFragment fragment;
 } TraceHeadersContext;
 
 
@@ -44,13 +45,13 @@  static int trace_headers_init(AVBSFContext *bsf)
     ctx->cbc->trace_level  = AV_LOG_INFO;
 
     if (bsf->par_in->extradata) {
-        CodedBitstreamFragment ps;
+        CodedBitstreamFragment *frag = &ctx->fragment;
 
         av_log(bsf, AV_LOG_INFO, "Extradata\n");
 
-        err = ff_cbs_read_extradata(ctx->cbc, &ps, bsf->par_in);
+        err = ff_cbs_read_extradata(ctx->cbc, frag, bsf->par_in);
 
-        ff_cbs_fragment_uninit(ctx->cbc, &ps);
+        ff_cbs_fragment_uninit(ctx->cbc, frag);
     }
 
     return err;
@@ -66,7 +67,7 @@  static void trace_headers_close(AVBSFContext *bsf)
 static int trace_headers(AVBSFContext *bsf, AVPacket *pkt)
 {
     TraceHeadersContext *ctx = bsf->priv_data;
-    CodedBitstreamFragment au;
+    CodedBitstreamFragment *frag = &ctx->fragment;
     char tmp[256] = { 0 };
     int err;
 
@@ -92,9 +93,9 @@  static int trace_headers(AVBSFContext *bsf, AVPacket *pkt)
 
     av_log(bsf, AV_LOG_INFO, "Packet: %d bytes%s.\n", pkt->size, tmp);
 
-    err = ff_cbs_read_packet(ctx->cbc, &au, pkt);
+    err = ff_cbs_read_packet(ctx->cbc, frag, pkt);
 
-    ff_cbs_fragment_uninit(ctx->cbc, &au);
+    ff_cbs_fragment_uninit(ctx->cbc, frag);
 
     if (err < 0)
         av_packet_unref(pkt);