You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
avformat/matroskaenc: Reuse dynamic buffer
Avoids some allocations. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@@ -222,7 +222,8 @@ typedef struct MatroskaMuxContext {
|
|||||||
* to write the length field of EBML Masters.
|
* to write the length field of EBML Masters.
|
||||||
* Every user has to reset the buffer after using it and
|
* Every user has to reset the buffer after using it and
|
||||||
* different uses may not overlap. It is currently used in
|
* 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;
|
AVIOContext *tmp_bc;
|
||||||
|
|
||||||
AVPacket *cur_audio_pkt;
|
AVPacket *cur_audio_pkt;
|
||||||
@@ -941,17 +942,10 @@ static int mkv_add_cuepoint(MatroskaMuxContext *mkv, int stream, int64_t ts,
|
|||||||
return 0;
|
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,
|
const mkv_cues *cues, mkv_track *tracks, int num_tracks,
|
||||||
uint64_t offset)
|
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;
|
for (mkv_cuepoint *entry = cues->entries, *end = entry + cues->num_entries;
|
||||||
entry < end;) {
|
entry < end;) {
|
||||||
uint64_t pts = entry->pts;
|
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);
|
end_ebml_master(cuepoint, track_positions);
|
||||||
} while (++entry < end && entry->pts == pts);
|
} while (++entry < end && entry->pts == pts);
|
||||||
size = avio_get_dyn_buf(cuepoint, &buf);
|
size = avio_get_dyn_buf(cuepoint, &buf);
|
||||||
if ((ret = cuepoint->error) < 0)
|
if (cuepoint->error < 0)
|
||||||
break;
|
return cuepoint->error;
|
||||||
put_ebml_binary(dyn_cp, MATROSKA_ID_POINTENTRY, buf, size);
|
put_ebml_binary(dyn_cp, MATROSKA_ID_POINTENTRY, buf, size);
|
||||||
ffio_reset_dyn_buf(cuepoint);
|
ffio_reset_dyn_buf(cuepoint);
|
||||||
}
|
}
|
||||||
ffio_free_dyn_buf(&cuepoint);
|
|
||||||
|
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb,
|
static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb,
|
||||||
@@ -2964,7 +2957,7 @@ redo_cues:
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
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);
|
mkv->tracks, s->nb_streams, offset);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
ffio_free_dyn_buf(&cues);
|
ffio_free_dyn_buf(&cues);
|
||||||
|
Reference in New Issue
Block a user