[FFmpeg-devel,v2,05/11] avformat/mux: Refactor muxer deinit from av_write_trailer

Submitted by sebechlebskyjan@gmail.com on Aug. 11, 2016, 12:39 p.m.

Details

Message ID 1470919189-3468-1-git-send-email-sebechlebskyjan@gmail.com
State New
Headers show

Commit Message

sebechlebskyjan@gmail.com Aug. 11, 2016, 12:39 p.m.
From: Jan Sebechlebsky <sebechlebskyjan@gmail.com>

Move muxer deinitialization and private resources freeing
in a separate static function free_muxer(AVFormatContext*).

Signed-off-by: Jan Sebechlebsky <sebechlebskyjan@gmail.com>
---
 No changes since the last version, just rebased because
 of changes in previous patch.

 libavformat/mux.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/mux.c b/libavformat/mux.c
index 3ae924c..45f1401 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -1197,9 +1197,27 @@  fail:
     return ret;
 }
 
+static void deinit_muxer(AVFormatContext *s)
+{
+    int i;
+
+    if (s->oformat->deinit)
+        s->oformat->deinit(s);
+
+    for (i = 0; i < s->nb_streams; i++) {
+        av_freep(&s->streams[i]->priv_data);
+        av_freep(&s->streams[i]->index_entries);
+    }
+
+    if (s->oformat->priv_class)
+        av_opt_free(s->priv_data);
+
+    av_freep(&s->priv_data);
+}
+
 int av_write_trailer(AVFormatContext *s)
 {
-    int ret, i;
+    int ret;
 
     for (;; ) {
         AVPacket pkt;
@@ -1244,20 +1262,11 @@  fail:
     if (ret == AVERROR(EAGAIN))
         return ret;
 
-    if (s->oformat->deinit)
-        s->oformat->deinit(s);
-
     if (s->pb)
        avio_flush(s->pb);
     if (ret == 0)
        ret = s->pb ? s->pb->error : 0;
-    for (i = 0; i < s->nb_streams; i++) {
-        av_freep(&s->streams[i]->priv_data);
-        av_freep(&s->streams[i]->index_entries);
-    }
-    if (s->oformat->priv_class)
-        av_opt_free(s->priv_data);
-    av_freep(&s->priv_data);
+    deinit_muxer(s);
     return ret;
 }