diff mbox series

[FFmpeg-devel,v3,1/6] ffmpeg: deduplicate init_output_stream usage logic

Message ID 20201016131649.4361-2-jeebjp@gmail.com
State Accepted
Headers show
Series ffmpeg: late A/V encoder init, AVFrame metadata usage | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Jan Ekström Oct. 16, 2020, 1:16 p.m. UTC
Adds a wrapper function, which handles any errors depending on how
fatal a failure would be.
---
 fftools/ffmpeg.c | 51 ++++++++++++++++++++++++------------------------
 1 file changed, 25 insertions(+), 26 deletions(-)

Comments

Michael Niedermayer Oct. 16, 2020, 8:02 p.m. UTC | #1
On Fri, Oct 16, 2020 at 04:16:44PM +0300, Jan Ekström wrote:
> Adds a wrapper function, which handles any errors depending on how
> fatal a failure would be.
> ---
>  fftools/ffmpeg.c | 51 ++++++++++++++++++++++++------------------------
>  1 file changed, 25 insertions(+), 26 deletions(-)

LGTM

thx

[...]
Jan Ekström Oct. 17, 2020, 8:59 a.m. UTC | #2
On Fri, Oct 16, 2020 at 11:03 PM Michael Niedermayer
<michael@niedermayer.cc> wrote:
>
> On Fri, Oct 16, 2020 at 04:16:44PM +0300, Jan Ekström wrote:
> > Adds a wrapper function, which handles any errors depending on how
> > fatal a failure would be.
> > ---
> >  fftools/ffmpeg.c | 51 ++++++++++++++++++++++++------------------------
> >  1 file changed, 25 insertions(+), 26 deletions(-)
>
> LGTM
>
> thx
>

Thanks, applied as 86228ebdb2f1c9c066473710c7e14eb8331265bf .

Jan
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 84306818a2..cb7644de6a 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1392,6 +1392,26 @@  static void do_video_stats(OutputStream *ost, int frame_size)
 
 static int init_output_stream(OutputStream *ost, char *error, int error_len);
 
+static int init_output_stream_wrapper(OutputStream *ost, unsigned int fatal)
+{
+    int ret = AVERROR_BUG;
+    char error[1024] = {0};
+
+    if (ost->initialized)
+        return 0;
+
+    ret = init_output_stream(ost, error, sizeof(error));
+    if (ret < 0) {
+        av_log(NULL, AV_LOG_ERROR, "Error initializing output stream %d:%d -- %s\n",
+               ost->file_index, ost->index, error);
+
+        if (fatal)
+            exit_program(1);
+    }
+
+    return ret;
+}
+
 static void finish_output_stream(OutputStream *ost)
 {
     OutputFile *of = output_files[ost->file_index];
@@ -1428,15 +1448,7 @@  static int reap_filters(int flush)
             continue;
         filter = ost->filter->filter;
 
-        if (!ost->initialized) {
-            char error[1024] = "";
-            ret = init_output_stream(ost, error, sizeof(error));
-            if (ret < 0) {
-                av_log(NULL, AV_LOG_ERROR, "Error initializing output stream %d:%d -- %s\n",
-                       ost->file_index, ost->index, error);
-                exit_program(1);
-            }
-        }
+        init_output_stream_wrapper(ost, 1);
 
         if (!ost->filtered_frame && !(ost->filtered_frame = av_frame_alloc())) {
             return AVERROR(ENOMEM);
@@ -1860,7 +1872,6 @@  static void flush_encoders(void)
         // Maybe we should just let encoding fail instead.
         if (!ost->initialized) {
             FilterGraph *fg = ost->filter->graph;
-            char error[1024] = "";
 
             av_log(NULL, AV_LOG_WARNING,
                    "Finishing stream %d:%d without any data written to it.\n",
@@ -1886,12 +1897,7 @@  static void flush_encoders(void)
                 finish_output_stream(ost);
             }
 
-            ret = init_output_stream(ost, error, sizeof(error));
-            if (ret < 0) {
-                av_log(NULL, AV_LOG_ERROR, "Error initializing output stream %d:%d -- %s\n",
-                       ost->file_index, ost->index, error);
-                exit_program(1);
-            }
+            init_output_stream_wrapper(ost, 1);
         }
 
         if (enc->codec_type != AVMEDIA_TYPE_VIDEO && enc->codec_type != AVMEDIA_TYPE_AUDIO)
@@ -3669,7 +3675,7 @@  static int transcode_init(void)
         if (output_streams[i]->filter)
             continue;
 
-        ret = init_output_stream(output_streams[i], error, sizeof(error));
+        ret = init_output_stream_wrapper(output_streams[i], 0);
         if (ret < 0)
             goto dump_format;
     }
@@ -4580,15 +4586,8 @@  static int transcode_step(void)
     }
 
     if (ost->filter && ost->filter->graph->graph) {
-        if (!ost->initialized) {
-            char error[1024] = {0};
-            ret = init_output_stream(ost, error, sizeof(error));
-            if (ret < 0) {
-                av_log(NULL, AV_LOG_ERROR, "Error initializing output stream %d:%d -- %s\n",
-                       ost->file_index, ost->index, error);
-                exit_program(1);
-            }
-        }
+        init_output_stream_wrapper(ost, 1);
+
         if ((ret = transcode_from_filter(ost->filter->graph, &ist)) < 0)
             return ret;
         if (!ist)