From b8c45bbcbc207293f955e838ea66106f4b65b1ac Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Mon, 11 Feb 2019 23:47:43 +0100 Subject: 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 --- libavcodec/h264_redundant_pps_bsf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'libavcodec/h264_redundant_pps_bsf.c') diff --git a/libavcodec/h264_redundant_pps_bsf.c b/libavcodec/h264_redundant_pps_bsf.c index 0b7888c97e..db8717d69a 100644 --- a/libavcodec/h264_redundant_pps_bsf.c +++ b/libavcodec/h264_redundant_pps_bsf.c @@ -118,7 +118,7 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out) err = 0; fail: - ff_cbs_fragment_uninit(ctx->output, au); + ff_cbs_fragment_reset(ctx->output, au); av_packet_free(&in); if (err < 0) av_packet_unref(out); @@ -167,7 +167,7 @@ static int h264_redundant_pps_init(AVBSFContext *bsf) err = 0; fail: - ff_cbs_fragment_uninit(ctx->output, au); + ff_cbs_fragment_reset(ctx->output, au); return err; } @@ -180,6 +180,8 @@ static void h264_redundant_pps_flush(AVBSFContext *bsf) static void h264_redundant_pps_close(AVBSFContext *bsf) { H264RedundantPPSContext *ctx = bsf->priv_data; + + ff_cbs_fragment_free(ctx->input, &ctx->access_unit); ff_cbs_close(&ctx->input); ff_cbs_close(&ctx->output); } -- cgit v1.2.3