summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-06-15 13:15:42 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-06-24 18:33:18 +0200
commitcf30b538e522703924ce3ef68ddfbd557a29d93f (patch)
tree6b62c4f5af8a2ded069aecd72995ed1c6f3cda25 /libavformat
parent745966ab81a46c492288a9b00bd92a9444162f53 (diff)
avformat/matroskaenc: Reuse dynamic buffer
Avoids some allocations. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/matroskaenc.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index a63e491b63..4f5afc1be4 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -222,7 +222,8 @@ typedef struct MatroskaMuxContext {
* to write the length field of EBML Masters.
* Every user has to reset the buffer after using it and
* different uses may not overlap. It is currently used in
- * mkv_write_tag(). */
+ * mkv_write_tag(), in mkv_assemble_cues() as well as in
+ * mkv_update_codecprivate() and mkv_write_track(). */
AVIOContext *tmp_bc;
AVPacket *cur_audio_pkt;
@@ -941,17 +942,10 @@ static int mkv_add_cuepoint(MatroskaMuxContext *mkv, int stream, int64_t ts,
return 0;
}
-static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp,
+static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp, AVIOContext *cuepoint,
const mkv_cues *cues, mkv_track *tracks, int num_tracks,
uint64_t offset)
{
- AVIOContext *cuepoint;
- int ret;
-
- ret = avio_open_dyn_buf(&cuepoint);
- if (ret < 0)
- return ret;
-
for (mkv_cuepoint *entry = cues->entries, *end = entry + cues->num_entries;
entry < end;) {
uint64_t pts = entry->pts;
@@ -981,14 +975,13 @@ static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp,
end_ebml_master(cuepoint, track_positions);
} while (++entry < end && entry->pts == pts);
size = avio_get_dyn_buf(cuepoint, &buf);
- if ((ret = cuepoint->error) < 0)
- break;
+ if (cuepoint->error < 0)
+ return cuepoint->error;
put_ebml_binary(dyn_cp, MATROSKA_ID_POINTENTRY, buf, size);
ffio_reset_dyn_buf(cuepoint);
}
- ffio_free_dyn_buf(&cuepoint);
- return ret;
+ return 0;
}
static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb,
@@ -2964,7 +2957,7 @@ redo_cues:
if (ret < 0)
return ret;
- ret = mkv_assemble_cues(s->streams, cues, &mkv->cues,
+ ret = mkv_assemble_cues(s->streams, cues, mkv->tmp_bc, &mkv->cues,
mkv->tracks, s->nb_streams, offset);
if (ret < 0) {
ffio_free_dyn_buf(&cues);