summaryrefslogtreecommitdiffstats
path: root/ffmpeg.c
diff options
context:
space:
mode:
authorrogerdpack <rogerpack2005@gmail.com>2015-06-30 16:31:19 -0600
committerMichael Niedermayer <michaelni@gmx.at>2015-07-01 01:00:38 +0200
commit4ebb43f19c416e1601730ca9ae57749b1385c563 (patch)
treed5e600fa29160e55cb0deea9c0987d1fee5ce6e7 /ffmpeg.c
parentbd0f14123fd8c7ff1c27b726d143f84c67f3a522 (diff)
downloadffmpeg-streaming-4ebb43f19c416e1601730ca9ae57749b1385c563.zip
ffmpeg-streaming-4ebb43f19c416e1601730ca9ae57749b1385c563.tar.gz
ffmpeg: windows: respond to logoff and ctrl+break messages as well
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'ffmpeg.c')
-rw-r--r--ffmpeg.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/ffmpeg.c b/ffmpeg.c
index 37f096c..e592629 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -79,6 +79,10 @@
#include <windows.h>
#include <psapi.h>
#endif
+#if HAVE_SETCONSOLECTRLHANDLER
+#include <windows.h>
+#endif
+
#if HAVE_SYS_SELECT_H
#include <sys/select.h>
@@ -313,6 +317,7 @@ void term_exit(void)
static volatile int received_sigterm = 0;
static volatile int received_nb_signals = 0;
static volatile int transcode_init_done = 0;
+static volatile int ffmpeg_exited = 0;
static int main_return_code = 0;
static void
@@ -329,6 +334,38 @@ sigterm_handler(int sig)
}
}
+#if HAVE_SETCONSOLECTRLHANDLER
+static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
+{
+ av_log(NULL, AV_LOG_DEBUG, "\nReceived windows signal %ld\n", fdwCtrlType);
+
+ switch (fdwCtrlType)
+ {
+ case CTRL_C_EVENT:
+ case CTRL_BREAK_EVENT:
+ sigterm_handler(SIGINT);
+ return TRUE;
+
+ case CTRL_CLOSE_EVENT:
+ case CTRL_LOGOFF_EVENT:
+ case CTRL_SHUTDOWN_EVENT:
+ sigterm_handler(SIGTERM);
+ /* Basically, with these 3 events, when we return from this method the
+ process is hard terminated, so stall as long as we need to
+ to try and let the main thread(s) clean up and gracefully terminate
+ (we have at most 5 seconds, but should be done far before that). */
+ while (!ffmpeg_exited) {
+ Sleep(0);
+ }
+ return TRUE;
+
+ default:
+ av_log(NULL, AV_LOG_ERROR, "Received unknown windows signal %ld\n", fdwCtrlType);
+ return FALSE;
+ }
+}
+#endif
+
void term_init(void)
{
#if HAVE_TERMIOS_H
@@ -362,6 +399,9 @@ void term_init(void)
#ifdef SIGXCPU
signal(SIGXCPU, sigterm_handler);
#endif
+#if HAVE_SETCONSOLECTRLHANDLER
+ SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE);
+#endif
}
/* read a key without blocking */
@@ -537,6 +577,7 @@ static void ffmpeg_cleanup(int ret)
av_log(NULL, AV_LOG_INFO, "Conversion failed!\n");
}
term_exit();
+ ffmpeg_exited = 1;
}
void remove_avoptions(AVDictionary **a, AVDictionary *b)
OpenPOWER on IntegriCloud