]> git.sesse.net Git - ffmpeg/commit
avcodec/movtextenc: Simplify writing to AVBPrint
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Thu, 15 Oct 2020 13:29:13 +0000 (15:29 +0200)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Mon, 19 Oct 2020 19:41:46 +0000 (21:41 +0200)
commit82c636313de07ecb11ed2100cc682e8503b24398
tree8ccf0c61a26c90b884261eb93ffafdcb12a31534
parent2f9fc35028364b0140fd6e0d2e4dbaffebed1acd
avcodec/movtextenc: Simplify writing to AVBPrint

The mov_text encoder uses an AVBPrint to assemble the subtitles;
yet mov_text subtitles are not pure text; they also have a binary
portion that was mostly handled as follows:

    uint32_t size = /* calculation */;
    size = AV_RB32(&size);
    av_bprint_append_data(bprint, (const char*)&size, 4);

Here AV_RB32() is a no-op on big-endian systems and a LE-BE swap
on little-endian systems, making the output endian-independent.

Yet this is ugly and unclean: On LE systems, the variable size from
the snippet above won't contain the correct value any more. Furthermore,
using this pattern leads to lots of small writes to the AVBPrint.

This commit therefore changes this to using a temporary buffer instead:

    uint8_t buf[4];
    AV_WB32(buf, /* size calculation */);
    av_bprint_append_data(bprint, buf, 4);

This method also allows to use bigger buffers holding more than one
element, saving calls to av_bprint_append_data() and reducing codesize.

Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavcodec/movtextenc.c