You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
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>
This commit is contained in:
committed by
James Almer
parent
3a58ec7c77
commit
4d97b2ad2f
@@ -3145,12 +3145,12 @@ static int mov_write_track_udta_tag(AVIOContext *pb, MOVMuxContext *mov,
|
|||||||
if (mov->mode & (MODE_MP4|MODE_MOV))
|
if (mov->mode & (MODE_MP4|MODE_MOV))
|
||||||
mov_write_track_metadata(pb_buf, st, "name", "title");
|
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);
|
avio_wb32(pb, size + 8);
|
||||||
ffio_wfourcc(pb, "udta");
|
ffio_wfourcc(pb, "udta");
|
||||||
avio_write(pb, buf, size);
|
avio_write(pb, buf, size);
|
||||||
}
|
}
|
||||||
av_free(buf);
|
ffio_free_dyn_buf(&pb_buf);
|
||||||
|
|
||||||
return 0;
|
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))
|
if (s->nb_chapters && !(mov->flags & FF_MOV_FLAG_DISABLE_CHPL))
|
||||||
mov_write_chpl_tag(pb_buf, s);
|
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);
|
avio_wb32(pb, size + 8);
|
||||||
ffio_wfourcc(pb, "udta");
|
ffio_wfourcc(pb, "udta");
|
||||||
avio_write(pb, buf, size);
|
avio_write(pb, buf, size);
|
||||||
}
|
}
|
||||||
av_free(buf);
|
ffio_free_dyn_buf(&pb_buf);
|
||||||
|
|
||||||
return 0;
|
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)
|
if ((ret = avio_open_dyn_buf(&mov->mdat_buf)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
buf_size = avio_close_dyn_buf(track->mdat_buf, &buf);
|
buf_size = avio_get_dyn_buf(track->mdat_buf, &buf);
|
||||||
track->mdat_buf = NULL;
|
|
||||||
|
|
||||||
offset = avio_tell(mov->mdat_buf);
|
offset = avio_tell(mov->mdat_buf);
|
||||||
avio_write(mov->mdat_buf, buf, buf_size);
|
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++)
|
for (i = track->entries_flushed; i < track->entry; i++)
|
||||||
track->cluster[i].pos += offset;
|
track->cluster[i].pos += offset;
|
||||||
@@ -5135,12 +5134,11 @@ static int mov_flush_fragment(AVFormatContext *s, int force)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf_size = avio_close_dyn_buf(mov->mdat_buf, &buf);
|
buf_size = avio_get_dyn_buf(mov->mdat_buf, &buf);
|
||||||
mov->mdat_buf = NULL;
|
|
||||||
avio_wb32(s->pb, buf_size + 8);
|
avio_wb32(s->pb, buf_size + 8);
|
||||||
ffio_wfourcc(s->pb, "mdat");
|
ffio_wfourcc(s->pb, "mdat");
|
||||||
avio_write(s->pb, buf, buf_size);
|
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)
|
if (mov->flags & FF_MOV_FLAG_GLOBAL_SIDX)
|
||||||
mov->reserved_header_pos = avio_tell(s->pb);
|
mov->reserved_header_pos = avio_tell(s->pb);
|
||||||
|
Reference in New Issue
Block a user