diff mbox series

[FFmpeg-devel,RFC] fftools/ffmpeg: make main function actually return

Message ID tencent_929F62AB2F4E5E70082DE99AE040769A1008@qq.com
State New
Headers show
Series [FFmpeg-devel,RFC] fftools/ffmpeg: make main function actually return | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

zhilizhao(赵志立) Dec. 1, 2022, 4:18 p.m. UTC
From: Zhao Zhili <zhilizhao@tencent.com>

---
When working on mediacodec encoder, I test it by making fftools/ffmpeg
into a lib, since JNI requires a JVM environment. There are three steps
mostly:
1. Rename main() function
2. Reset global variables
3. Make main() function actuall return

There is no point for this patch, except making fftools/ffmpeg a little
"lib friendly". And I understand fftools/ffmpeg isn't a lib by design.
But sometimes it's quick and easier to hack it.

 fftools/ffmpeg.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 771219f7df..4b12ad1ef8 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -100,6 +100,7 @@ 
 #include <conio.h>
 #endif
 
+#include <setjmp.h>
 #include <time.h>
 
 #include "ffmpeg.h"
@@ -491,10 +492,13 @@  static int decode_interrupt_cb(void *ctx)
 
 const AVIOInterruptCB int_cb = { decode_interrupt_cb, NULL };
 
+static jmp_buf exit_buf;
+
 static void ffmpeg_cleanup(int ret)
 {
     int i, j;
 
+    main_return_code = ret;
     if (do_benchmark) {
         int maxrss = getmaxrss() / 1024;
         av_log(NULL, AV_LOG_INFO, "bench: maxrss=%ikB\n", maxrss);
@@ -571,6 +575,7 @@  static void ffmpeg_cleanup(int ret)
     }
     term_exit();
     ffmpeg_exited = 1;
+    longjmp(exit_buf, 1);
 }
 
 /* iterate over all output streams in all output files;
@@ -3868,6 +3873,11 @@  int main(int argc, char **argv)
     int ret;
     BenchmarkTimeStamps ti;
 
+    if (setjmp(exit_buf)) {
+        // longjmp from ffmpeg_cleanup
+        return main_return_code;
+    }
+
     init_dynload();
 
     register_exit(ffmpeg_cleanup);