--- a/fftools/ffmpeg.c 2026-11-03 13:24:21 +++ b/fftools/ffmpeg.c 2026-11-03 13:24:21 @@ -233,10 +233,13 @@ tcsetattr (0, TCSANOW, &tty); } +#ifndef TB_FFMPEG_LIBRARY SIGNAL(SIGQUIT, sigterm_handler); /* Quit (POSIX). */ +#endif } #endif +#ifndef TB_FFMPEG_LIBRARY SIGNAL(SIGINT , sigterm_handler); /* Interrupt (ANSI). */ SIGNAL(SIGTERM, sigterm_handler); /* Termination (ANSI). */ #ifdef SIGXCPU @@ -245,6 +248,7 @@ #ifdef SIGPIPE signal(SIGPIPE, SIG_IGN); /* Broken pipe (POSIX). */ #endif +#endif /* TB_FFMPEG_LIBRARY */ #if HAVE_SETCONSOLECTRLHANDLER SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE); #endif @@ -310,6 +314,30 @@ } const AVIOInterruptCB int_cb = { decode_interrupt_cb, NULL }; + +#ifdef TB_FFMPEG_LIBRARY +/* TimeBolt: entry points for the host app (shim/ffmpeg_library.c). Prototypes keep -Wmissing-prototypes quiet. */ +int ffmpeg_main(int argc, char **argv); +void tb_ffmpeg_internal_cancel(void); +void tb_ffmpeg_internal_reset(void); + +/* TimeBolt: what Ctrl-C does, callable from the host app. */ +void tb_ffmpeg_internal_cancel(void) +{ + received_sigterm = SIGINT; + received_nb_signals++; +} + +/* TimeBolt: file-static state that would otherwise leak from one run into the next. */ +void tb_ffmpeg_internal_reset(void) +{ + received_sigterm = 0; + received_nb_signals = 0; + atomic_store(&transcode_init_done, 0); + ffmpeg_exited = 0; + copy_ts_first_pts = AV_NOPTS_VALUE; +} +#endif static void ffmpeg_cleanup(int ret) { @@ -978,7 +1006,7 @@ #endif } -int main(int argc, char **argv) +int ffmpeg_main(int argc, char **argv) { Scheduler *sch = NULL;