]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/flacenc.c
avcodec/alsdec: Fix integer overflow with buffer number
[ffmpeg] / libavformat / flacenc.c
index 3179f259e5d56acfc16bcb0e8827e9f6f8eb9859..a07260f426837cc801e3e4dfd63cd371f30a17c6 100644 (file)
@@ -65,7 +65,7 @@ static int flac_write_block_comment(AVIOContext *pb, AVDictionary **m,
 
     ff_metadata_conv(m, ff_vorbiscomment_metadata_conv, NULL);
 
-    len = ff_vorbiscomment_length(*m, vendor);
+    len = ff_vorbiscomment_length(*m, vendor, NULL, 0);
     if (len >= ((1<<24) - 4))
         return AVERROR(EINVAL);
     p0 = av_malloc(len+4);
@@ -75,7 +75,7 @@ static int flac_write_block_comment(AVIOContext *pb, AVDictionary **m,
 
     bytestream_put_byte(&p, last_block ? 0x84 : 0x04);
     bytestream_put_be24(&p, len);
-    ff_vorbiscomment_write(&p, m, vendor);
+    ff_vorbiscomment_write(&p, m, vendor, NULL, 0);
 
     avio_write(pb, p0, len+4);
     av_freep(&p0);
@@ -199,11 +199,11 @@ static int flac_finish_header(struct AVFormatContext *s)
     return 0;
 }
 
-static int flac_write_header(struct AVFormatContext *s)
+static int flac_init(struct AVFormatContext *s)
 {
     AVCodecParameters *par;
     FlacMuxerContext *c = s->priv_data;
-    int ret, i;
+    int i;
 
     c->audio_stream_idx = -1;
     for (i = 0; i < s->nb_streams; i++) {
@@ -238,14 +238,6 @@ static int flac_write_header(struct AVFormatContext *s)
         return AVERROR(EINVAL);
     }
 
-    if (!c->write_header)
-        return 0;
-
-    ret = ff_flac_write_header(s->pb, par->extradata,
-                               par->extradata_size, 0);
-    if (ret)
-        return ret;
-
     /* add the channel layout tag */
     if (par->channel_layout &&
         !(par->channel_layout & ~0x3ffffULL) &&
@@ -263,6 +255,23 @@ static int flac_write_header(struct AVFormatContext *s)
         }
     }
 
+    return 0;
+}
+
+static int flac_write_header(struct AVFormatContext *s)
+{
+    FlacMuxerContext *c = s->priv_data;
+    AVCodecParameters *par = s->streams[c->audio_stream_idx]->codecpar;
+    int ret;
+
+    if (!c->write_header)
+        return 0;
+
+    ret = ff_flac_write_header(s->pb, par->extradata,
+                               par->extradata_size, 0);
+    if (ret < 0)
+        return ret;
+
     if (!c->waiting_pics)
         ret = flac_finish_header(s);
 
@@ -412,6 +421,7 @@ AVOutputFormat ff_flac_muxer = {
     .extensions        = "flac",
     .audio_codec       = AV_CODEC_ID_FLAC,
     .video_codec       = AV_CODEC_ID_PNG,
+    .init              = flac_init,
     .write_header      = flac_write_header,
     .write_packet      = flac_write_packet,
     .write_trailer     = flac_write_trailer,