aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-01-14 22:33:23 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-01-19 11:53:30 +0100
commit6221491f9027c55464c3995d67c30e000608ddb2 (patch)
treeb9f29db3b9d41fe6ea38284d98f09f89581658a6
parenta04c91739974754899faf6e3495f1bcfe8d8cee0 (diff)
downloadffmpeg-6221491f9027c55464c3995d67c30e000608ddb2.tar.gz
avformat/matroskaenc: Factor writing Info out
Avoids the surprise of using pb for the main AVIOContext at the beginning and end of mkv_write_header() and for for the dynamic buffer opened for the Info element in the middle of mkv_write_header(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r--libavformat/matroskaenc.c64
1 files changed, 35 insertions, 29 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index e44a775bcc..baf851f481 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2175,36 +2175,13 @@ static void ebml_write_header(AVIOContext *pb,
ebml_writer_write(&writer, pb);
}
-static int mkv_write_header(AVFormatContext *s)
+static int mkv_write_info(AVFormatContext *s)
{
MatroskaMuxContext *mkv = s->priv_data;
- AVIOContext *pb = s->pb;
const AVDictionaryEntry *tag;
- int ret, i, version = 2;
int64_t creation_time;
-
- if (!IS_WEBM(mkv) ||
- av_dict_get(s->metadata, "stereo_mode", NULL, 0) ||
- av_dict_get(s->metadata, "alpha_mode", NULL, 0))
- version = 4;
-
- for (i = 0; i < s->nb_streams; i++) {
- if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_OPUS ||
- av_dict_get(s->streams[i]->metadata, "stereo_mode", NULL, 0) ||
- av_dict_get(s->streams[i]->metadata, "alpha_mode", NULL, 0))
- version = 4;
- }
-
- ebml_write_header(pb, s->oformat->name, version);
- put_ebml_id(pb, MATROSKA_ID_SEGMENT);
- put_ebml_size_unknown(pb, 8);
- mkv->segment_offset = avio_tell(pb);
-
- // We write a SeekHead at the beginning to point to all other level
- // one elements (except Clusters).
- mkv_start_seekhead(mkv, pb);
-
- ret = start_ebml_master_crc32(&mkv->info.bc, mkv);
+ AVIOContext *pb;
+ int ret = start_ebml_master_crc32(&mkv->info.bc, mkv);
if (ret < 0)
return ret;
pb = mkv->info.bc;
@@ -2253,11 +2230,40 @@ static int mkv_write_header(AVFormatContext *s)
put_ebml_void(pb, 11); // assumes double-precision float to be written
}
}
- ret = end_ebml_master_crc32_tentatively(s->pb, &mkv->info,
- mkv, MATROSKA_ID_INFO);
+ return end_ebml_master_crc32_tentatively(s->pb, &mkv->info,
+ mkv, MATROSKA_ID_INFO);
+}
+
+static int mkv_write_header(AVFormatContext *s)
+{
+ MatroskaMuxContext *mkv = s->priv_data;
+ AVIOContext *pb = s->pb;
+ int ret, version = 2;
+
+ if (!IS_WEBM(mkv) ||
+ av_dict_get(s->metadata, "stereo_mode", NULL, 0) ||
+ av_dict_get(s->metadata, "alpha_mode", NULL, 0))
+ version = 4;
+
+ for (unsigned i = 0; i < s->nb_streams; i++) {
+ if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_OPUS ||
+ av_dict_get(s->streams[i]->metadata, "stereo_mode", NULL, 0) ||
+ av_dict_get(s->streams[i]->metadata, "alpha_mode", NULL, 0))
+ version = 4;
+ }
+
+ ebml_write_header(pb, s->oformat->name, version);
+ put_ebml_id(pb, MATROSKA_ID_SEGMENT);
+ put_ebml_size_unknown(pb, 8);
+ mkv->segment_offset = avio_tell(pb);
+
+ // We write a SeekHead at the beginning to point to all other level
+ // one elements (except Clusters).
+ mkv_start_seekhead(mkv, pb);
+
+ ret = mkv_write_info(s);
if (ret < 0)
return ret;
- pb = s->pb;
ret = mkv_write_tracks(s);
if (ret < 0)