summaryrefslogtreecommitdiffstats
path: root/libavcodec/filter_units_bsf.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@googlemail.com>2019-02-11 23:47:43 +0100
committerMark Thompson <sw@jkqxz.net>2019-02-25 21:40:13 +0000
commitb8c45bbcbc207293f955e838ea66106f4b65b1ac (patch)
treee46eb58202941ad69cbd56f142a7900c7499ae13 /libavcodec/filter_units_bsf.c
parentc5b452ed2f16a0d7bf01d7d84097337f8756987b (diff)
downloadffmpeg-streaming-b8c45bbcbc207293f955e838ea66106f4b65b1ac.zip
ffmpeg-streaming-b8c45bbcbc207293f955e838ea66106f4b65b1ac.tar.gz
libavcodec/cbs: Stop needlessly reallocating the units array
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>
Diffstat (limited to 'libavcodec/filter_units_bsf.c')
-rw-r--r--libavcodec/filter_units_bsf.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/libavcodec/filter_units_bsf.c b/libavcodec/filter_units_bsf.c
index 0500dea..bc2ca28 100644
--- a/libavcodec/filter_units_bsf.c
+++ b/libavcodec/filter_units_bsf.c
@@ -139,7 +139,7 @@ static int filter_units_filter(AVBSFContext *bsf, AVPacket *out)
// Don't return packets with nothing in them.
av_packet_free(&in);
- ff_cbs_fragment_uninit(ctx->cbc, frag);
+ ff_cbs_fragment_reset(ctx->cbc, frag);
}
err = ff_cbs_write_packet(ctx->cbc, out, frag);
@@ -153,7 +153,7 @@ static int filter_units_filter(AVBSFContext *bsf, AVPacket *out)
goto fail;
fail:
- ff_cbs_fragment_uninit(ctx->cbc, frag);
+ ff_cbs_fragment_reset(ctx->cbc, frag);
av_packet_free(&in);
return err;
@@ -210,7 +210,7 @@ static int filter_units_init(AVBSFContext *bsf)
av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n");
}
- ff_cbs_fragment_uninit(ctx->cbc, frag);
+ ff_cbs_fragment_reset(ctx->cbc, frag);
}
return err;
@@ -222,6 +222,7 @@ static void filter_units_close(AVBSFContext *bsf)
av_freep(&ctx->type_list);
+ ff_cbs_fragment_free(ctx->cbc, &ctx->fragment);
ff_cbs_close(&ctx->cbc);
}
OpenPOWER on IntegriCloud