]> git.sesse.net Git - ffmpeg/commit
avformat/matroskaenc: Simplify writing Cues
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Mon, 30 Dec 2019 14:48:35 +0000 (15:48 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Mon, 30 Mar 2020 04:18:31 +0000 (06:18 +0200)
commit5e3b7bd56d2c476a508c03e2029675bfd2618122
tree0921bebc032600011f27190377844921a0653927
parent639728f51a9fa5e321effad5909c1e37df0e80bb
avformat/matroskaenc: Simplify writing Cues

When the Matroska muxer writes the Cues (the index), it groups index
entries with the same timestamp into the same CuePoint to save space.
But given Matroska's variable-length length fields, it either needs
to have an upper bound of the final size of the CuePoint before writing it
or the CuePoint has to be assembled in a different buffer, so that after
having assembled the CuePoint (when the real size is known), the CuePoint's
header can be written and its data copied after it.

The first of these approaches is the currently used one. This entails
finding out the number of entries in a CuePoint before starting the
CuePoint and therefore means that the list is read at least twice.
Furthermore, a worst-case upper-bound for the length of a single entry
was used, so that sometimes bytes are wasted on length fields.

This commit switches to the second approach. This is no longer more
expensive than the current approach if one only resets the dynamic
buffer used to write the CuePoint's content instead of opening a new
buffer for every CuePoint: Writing the trailer of a file with 540.000
CuePoints improved actually from 219054414 decicycles to 2164379394
decicycles (based upon 50 iterations).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavformat/matroskaenc.c