[FFmpeg-devel] [PATCH] Support Ctrl+Break in ffmpeg.exe on Windows as if it was Ctrl+C

Roger Pack rogerdpack2 at gmail.com
Thu Jun 25 08:27:35 CEST 2015


On 6/25/15, James Almer <jamrial at gmail.com> wrote:
> On 24/06/15 7:19 AM, Roger Pack wrote:
>> +#ifdef HAVE_SETCONSOLECTRLHANDLER
>> +static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
>> +{
>> +    av_log(NULL, AV_LOG_DEBUG, "\nReceived windows signal %d\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);
>> +        return TRUE;
>> +
>> +    default:
>> +        av_log(NULL, AV_LOG_ERROR, "Received unknown windows signal
>> %d\n", fdwCtrlType);
>> +        return FALSE;
>> +    }
>> +}
>> +#endif
>> +
>>  void term_init(void)
>>  {
>>  #if HAVE_TERMIOS_H
>> @@ -358,6 +386,9 @@ void term_init(void)
>>  #ifdef SIGXCPU
>>      signal(SIGXCPU, sigterm_handler);
>>  #endif
>> +#ifdef HAVE_SETCONSOLECTRLHANDLER
>> +    SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE);
>> +#endif
>
> Why ffmpeg only? Can't this be in cmdutils.c to also work with the other
> tools?

It basically piggy backs on the existing signal handling code, which I
guess is FFmpeg only (probably each process needs to setup their own
signal handling).  At least it'll be a nice example for people to use
if they need to :)

-roger-


More information about the ffmpeg-devel mailing list