aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/matroskaenc.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-04-28 04:54:05 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-05-03 13:43:54 +0200
commit6397b4d6a241692a1c7bb611a3fd42b0de2d32b5 (patch)
tree1a9f9efdbb428d1727d0b917e36ad9eb587d4d94 /libavformat/matroskaenc.c
parent704d7c9f4616d71db1a1baa0a1726c77a9957521 (diff)
downloadffmpeg-6397b4d6a241692a1c7bb611a3fd42b0de2d32b5.tar.gz
avformat/vorbiscomment: Switch to AVIOContext from bytestream API
Up until now ff_vorbiscomment_write() used the bytestream API to write VorbisComments. Therefore the caller had to provide a sufficiently large buffer to write the output. Yet two of the three callers (namely the FLAC and the Matroska muxer) actually want the output to be written via an AVIOContext; therefore they allocated buffers of the right size just for this purpose (i.e. they get freed immediately afterwards). Only the Ogg muxer actually wants a buffer. But given that it is easy to wrap a buffer into an AVIOContext this commit changes ff_vorbiscomment_write() to use an AVIOContext for its output. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavformat/matroskaenc.c')
-rw-r--r--libavformat/matroskaenc.c18
1 files changed, 4 insertions, 14 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 80ff341a90..c07aa4f7e4 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -624,7 +624,7 @@ static int put_flac_codecpriv(AVFormatContext *s, AVIOContext *pb,
const char *vendor = (s->flags & AVFMT_FLAG_BITEXACT) ?
"Lavf" : LIBAVFORMAT_IDENT;
AVDictionary *dict = NULL;
- uint8_t buf[32], *data, *p;
+ uint8_t buf[32];
int64_t len;
snprintf(buf, sizeof(buf), "0x%"PRIx64, par->channel_layout);
@@ -633,21 +633,11 @@ static int put_flac_codecpriv(AVFormatContext *s, AVIOContext *pb,
len = ff_vorbiscomment_length(dict, vendor, NULL, 0);
av_assert1(len < (1 << 24) - 4);
- data = av_malloc(len + 4);
- if (!data) {
- av_dict_free(&dict);
- return AVERROR(ENOMEM);
- }
-
- data[0] = 0x84;
- AV_WB24(data + 1, len);
-
- p = data + 4;
- ff_vorbiscomment_write(&p, dict, vendor, NULL, 0);
+ avio_w8(pb, 0x84);
+ avio_wb24(pb, len);
- avio_write(pb, data, len + 4);
+ ff_vorbiscomment_write(pb, dict, vendor, NULL, 0);
- av_freep(&data);
av_dict_free(&dict);
}