diff mbox

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

Message ID 1470144262-13167-6-git-send-email-sebechlebskyjan@gmail.com
State Superseded
Headers show

Commit Message

sebechlebskyjan@gmail.com Aug. 2, 2016, 1:24 p.m. UTC
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>
---
 libavformat/mux.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

Comments

Michael Niedermayer Aug. 10, 2016, 5:05 p.m. UTC | #1
On Tue, Aug 02, 2016 at 03:24:16PM +0200, sebechlebskyjan@gmail.com wrote:
> 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>
> ---
>  libavformat/mux.c | 31 ++++++++++++++++++++-----------
>  1 file changed, 20 insertions(+), 11 deletions(-)

LGTM, but this depends on the previous patch so i cannot push this
yet

[...]
diff mbox

Patch

diff --git a/libavformat/mux.c b/libavformat/mux.c
index b58e4c1..bc9c98f 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;
@@ -1241,20 +1259,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;
 }