Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [RFC PATCH] fftools/ffmpeg: make main function actually return
@ 2022-12-01 16:18 Zhao Zhili
  0 siblings, 0 replies; only message in thread
From: Zhao Zhili @ 2022-12-01 16:18 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Zhao Zhili

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 --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);
-- 
2.25.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-01 16:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-01 16:18 [FFmpeg-devel] [RFC PATCH] fftools/ffmpeg: make main function actually return Zhao Zhili

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git