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/vaapi_encode_h264.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'libavcodec/vaapi_encode_h264.c') diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c index 4ea62d96f3..9f984ec60d 100644 --- a/libavcodec/vaapi_encode_h264.c +++ b/libavcodec/vaapi_encode_h264.c @@ -174,7 +174,7 @@ static int vaapi_encode_h264_write_sequence_header(AVCodecContext *avctx, err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au); fail: - ff_cbs_fragment_uninit(priv->cbc, au); + ff_cbs_fragment_reset(priv->cbc, au); return err; } @@ -200,7 +200,7 @@ static int vaapi_encode_h264_write_slice_header(AVCodecContext *avctx, err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au); fail: - ff_cbs_fragment_uninit(priv->cbc, au); + ff_cbs_fragment_reset(priv->cbc, au); return err; } @@ -264,7 +264,7 @@ static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx, if (err < 0) goto fail; - ff_cbs_fragment_uninit(priv->cbc, au); + ff_cbs_fragment_reset(priv->cbc, au); *type = VAEncPackedHeaderRawData; return 0; @@ -286,7 +286,7 @@ static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx, } fail: - ff_cbs_fragment_uninit(priv->cbc, au); + ff_cbs_fragment_reset(priv->cbc, au); return err; } @@ -1233,6 +1233,7 @@ static av_cold int vaapi_encode_h264_close(AVCodecContext *avctx) { VAAPIEncodeH264Context *priv = avctx->priv_data; + ff_cbs_fragment_free(priv->cbc, &priv->current_access_unit); ff_cbs_close(&priv->cbc); av_freep(&priv->sei_identifier_string); -- cgit v1.2.3