libavcodec/cbs: Stop needlessly reallocating the units array
authorAndreas Rheinhardt <andreas.rheinhardt@googlemail.com>
Mon, 11 Feb 2019 22:47:43 +0000 (23:47 +0100)
committerMark Thompson <sw@jkqxz.net>
Mon, 25 Feb 2019 21:40:13 +0000 (21:40 +0000)
commitb8c45bbcbc207293f955e838ea66106f4b65b1ac
treee46eb58202941ad69cbd56f142a7900c7499ae13
parentc5b452ed2f16a0d7bf01d7d84097337f8756987b
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>
15 files changed:
libavcodec/av1_metadata_bsf.c
libavcodec/av1_parser.c
libavcodec/cbs.c
libavcodec/cbs.h
libavcodec/filter_units_bsf.c
libavcodec/h264_metadata_bsf.c
libavcodec/h264_redundant_pps_bsf.c
libavcodec/h265_metadata_bsf.c
libavcodec/mpeg2_metadata_bsf.c
libavcodec/trace_headers_bsf.c
libavcodec/vaapi_encode_h264.c
libavcodec/vaapi_encode_h265.c
libavcodec/vaapi_encode_mjpeg.c
libavcodec/vaapi_encode_mpeg2.c
libavcodec/vp9_metadata_bsf.c