[FFmpeg-cvslog] avformat: refactor avformat_write_header

Luca Barbato git at videolan.org
Tue Oct 2 18:53:14 CEST 2012


ffmpeg | branch: master | Luca Barbato <lu_zero at gentoo.org> | Mon Oct  1 00:49:18 2012 +0200| [1e46c63eb72be752e044ba32257d77f35cbd9dac] | committer: Luca Barbato

avformat: refactor avformat_write_header

Split away option settings, sanity checks and general setup.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1e46c63eb72be752e044ba32257d77f35cbd9dac
---

 libavformat/mux.c |   53 ++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 38 insertions(+), 15 deletions(-)

diff --git a/libavformat/mux.c b/libavformat/mux.c
index 775b5f1..96eecb5 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -135,7 +135,8 @@ static int validate_codec_tag(AVFormatContext *s, AVStream *st)
     return 1;
 }
 
-int avformat_write_header(AVFormatContext *s, AVDictionary **options)
+
+static int init_muxer(AVFormatContext *s, AVDictionary **options)
 {
     int ret = 0, i;
     AVStream *st;
@@ -248,12 +249,23 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options)
         av_dict_set(&s->metadata, "encoder", LIBAVFORMAT_IDENT, 0);
     }
 
-    if (s->oformat->write_header) {
-        ret = s->oformat->write_header(s);
-        if (ret < 0)
-            goto fail;
+    if (options) {
+         av_dict_free(options);
+         *options = tmp;
     }
 
+    return 0;
+
+fail:
+    av_dict_free(&tmp);
+    return ret;
+}
+
+static int init_pts(AVFormatContext *s)
+{
+    int i;
+    AVStream *st;
+
     /* init PTS generation */
     for (i = 0; i < s->nb_streams; i++) {
         int64_t den = AV_NOPTS_VALUE;
@@ -270,22 +282,33 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options)
             break;
         }
         if (den != AV_NOPTS_VALUE) {
-            if (den <= 0) {
-                ret = AVERROR_INVALIDDATA;
-                goto fail;
-            }
+            if (den <= 0)
+                return AVERROR_INVALIDDATA;
+
             frac_init(&st->pts, 0, 0, den);
         }
     }
 
-    if (options) {
-        av_dict_free(options);
-        *options = tmp;
+    return 0;
+}
+
+int avformat_write_header(AVFormatContext *s, AVDictionary **options)
+{
+    int ret = 0;
+
+    if (ret = init_muxer(s, options))
+        return ret;
+
+    if (s->oformat->write_header) {
+        ret = s->oformat->write_header(s);
+        if (ret < 0)
+            return ret;
     }
+
+    if ((ret = init_pts(s) < 0))
+        return ret;
+
     return 0;
-fail:
-    av_dict_free(&tmp);
-    return ret;
 }
 
 //FIXME merge with compute_pkt_fields



More information about the ffmpeg-cvslog mailing list