aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2019-11-27 13:22:11 +0100
committerJames Almer <jamrial@gmail.com>2019-11-28 15:20:37 -0300
commit4d97b2ad2fa6d851c70fd982ab300e4fd559f1d0 (patch)
tree4f8417b968d2b0a03fac106856768930fd5e4e77 /libavformat
parent3a58ec7c772563fbacba63289aa49bc56a496e3f (diff)
downloadffmpeg-4d97b2ad2fa6d851c70fd982ab300e4fd559f1d0.tar.gz
avformat/movenc: Avoid allocation for small dynamic buffers
By using avio_get_dyn_buf() + ffio_free_dyn_buf() instead of avio_close_dyn_buf() + av_free() one can avoid an allocation + copy for small dynamic buffers. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/movenc.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 715bec1c2f..dd144ae20a 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -3145,12 +3145,12 @@ static int mov_write_track_udta_tag(AVIOContext *pb, MOVMuxContext *mov,
if (mov->mode & (MODE_MP4|MODE_MOV))
mov_write_track_metadata(pb_buf, st, "name", "title");
- if ((size = avio_close_dyn_buf(pb_buf, &buf)) > 0) {
+ if ((size = avio_get_dyn_buf(pb_buf, &buf)) > 0) {
avio_wb32(pb, size + 8);
ffio_wfourcc(pb, "udta");
avio_write(pb, buf, size);
}
- av_free(buf);
+ ffio_free_dyn_buf(&pb_buf);
return 0;
}
@@ -3820,12 +3820,12 @@ static int mov_write_udta_tag(AVIOContext *pb, MOVMuxContext *mov,
if (s->nb_chapters && !(mov->flags & FF_MOV_FLAG_DISABLE_CHPL))
mov_write_chpl_tag(pb_buf, s);
- if ((size = avio_close_dyn_buf(pb_buf, &buf)) > 0) {
+ if ((size = avio_get_dyn_buf(pb_buf, &buf)) > 0) {
avio_wb32(pb, size + 8);
ffio_wfourcc(pb, "udta");
avio_write(pb, buf, size);
}
- av_free(buf);
+ ffio_free_dyn_buf(&pb_buf);
return 0;
}
@@ -5033,12 +5033,11 @@ static int mov_flush_fragment_interleaving(AVFormatContext *s, MOVTrack *track)
if ((ret = avio_open_dyn_buf(&mov->mdat_buf)) < 0)
return ret;
}
- buf_size = avio_close_dyn_buf(track->mdat_buf, &buf);
- track->mdat_buf = NULL;
+ buf_size = avio_get_dyn_buf(track->mdat_buf, &buf);
offset = avio_tell(mov->mdat_buf);
avio_write(mov->mdat_buf, buf, buf_size);
- av_free(buf);
+ ffio_free_dyn_buf(&track->mdat_buf);
for (i = track->entries_flushed; i < track->entry; i++)
track->cluster[i].pos += offset;
@@ -5135,12 +5134,11 @@ static int mov_flush_fragment(AVFormatContext *s, int force)
return 0;
}
- buf_size = avio_close_dyn_buf(mov->mdat_buf, &buf);
- mov->mdat_buf = NULL;
+ buf_size = avio_get_dyn_buf(mov->mdat_buf, &buf);
avio_wb32(s->pb, buf_size + 8);
ffio_wfourcc(s->pb, "mdat");
avio_write(s->pb, buf, buf_size);
- av_free(buf);
+ ffio_free_dyn_buf(&mov->mdat_buf);
if (mov->flags & FF_MOV_FLAG_GLOBAL_SIDX)
mov->reserved_header_pos = avio_tell(s->pb);