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>
This commit is contained in:
Andreas Rheinhardt 2019-02-11 23:47:43 +01:00 committed by Mark Thompson
parent c5b452ed2f
commit b8c45bbcbc
15 changed files with 113 additions and 59 deletions

View file

@ -135,7 +135,7 @@ static int vaapi_encode_mpeg2_write_sequence_header(AVCodecContext *avctx,
err = vaapi_encode_mpeg2_write_fragment(avctx, data, data_len, frag);
fail:
ff_cbs_fragment_uninit(priv->cbc, frag);
ff_cbs_fragment_reset(priv->cbc, frag);
return 0;
}
@ -159,7 +159,7 @@ static int vaapi_encode_mpeg2_write_picture_header(AVCodecContext *avctx,
err = vaapi_encode_mpeg2_write_fragment(avctx, data, data_len, frag);
fail:
ff_cbs_fragment_uninit(priv->cbc, frag);
ff_cbs_fragment_reset(priv->cbc, frag);
return 0;
}
@ -628,6 +628,7 @@ static av_cold int vaapi_encode_mpeg2_close(AVCodecContext *avctx)
{
VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
ff_cbs_fragment_free(priv->cbc, &priv->current_fragment);
ff_cbs_close(&priv->cbc);
return ff_vaapi_encode_close(avctx);