diff options
author | Andreas Rheinhardt <andreas.rheinhardt@googlemail.com> | 2019-02-12 01:47:43 +0300 |
---|---|---|
committer | Mark Thompson <sw@jkqxz.net> | 2019-02-26 00:40:13 +0300 |
commit | b8c45bbcbc207293f955e838ea66106f4b65b1ac (patch) | |
tree | e46eb58202941ad69cbd56f142a7900c7499ae13 /libavcodec/cbs.h | |
parent | c5b452ed2f16a0d7bf01d7d84097337f8756987b (diff) |
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/cbs.h')
-rw-r--r-- | libavcodec/cbs.h | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h index 53ac360bb1..967dcd1468 100644 --- a/libavcodec/cbs.h +++ b/libavcodec/cbs.h @@ -145,10 +145,19 @@ typedef struct CodedBitstreamFragment { * and has not been decomposed. */ int nb_units; + + /** + * Number of allocated units. + * + * Must always be >= nb_units; designed for internal use by cbs. + */ + int nb_units_allocated; + /** - * Pointer to an array of units of length nb_units. + * Pointer to an array of units of length nb_units_allocated. + * Only the first nb_units are valid. * - * Must be NULL if nb_units is zero. + * Must be NULL if nb_units_allocated is zero. */ CodedBitstreamUnit *units; } CodedBitstreamFragment; @@ -231,6 +240,9 @@ void ff_cbs_close(CodedBitstreamContext **ctx); * This also updates the internal state, so will need to be called for * codecs with extradata to read parameter sets necessary for further * parsing even if the fragment itself is not desired. + * + * The fragment must have been zeroed or reset via ff_cbs_fragment_reset + * before use. */ int ff_cbs_read_extradata(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, @@ -243,6 +255,9 @@ int ff_cbs_read_extradata(CodedBitstreamContext *ctx, * This also updates the internal state of the coded bitstream context * with any persistent data from the fragment which may be required to * read following fragments (e.g. parameter sets). + * + * The fragment must have been zeroed or reset via ff_cbs_fragment_reset + * before use. */ int ff_cbs_read_packet(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, @@ -255,6 +270,9 @@ int ff_cbs_read_packet(CodedBitstreamContext *ctx, * This also updates the internal state of the coded bitstream context * with any persistent data from the fragment which may be required to * read following fragments (e.g. parameter sets). + * + * The fragment must have been zeroed or reset via ff_cbs_fragment_reset + * before use. */ int ff_cbs_read(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, @@ -294,11 +312,18 @@ int ff_cbs_write_packet(CodedBitstreamContext *ctx, /** - * Free all allocated memory in a fragment. + * Free the units contained in a fragment as well as the fragment's + * own data buffer, but not the units array itself. */ -void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx, +void ff_cbs_fragment_reset(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag); +/** + * Free the units array of a fragment in addition to what + * ff_cbs_fragment_reset does. + */ +void ff_cbs_fragment_free(CodedBitstreamContext *ctx, + CodedBitstreamFragment *frag); /** * Allocate a new internal content buffer of the given size in the unit. |