#include <windows.h>
#include <psapi.h>
#endif
+#if HAVE_SETCONSOLECTRLHANDLER
+#include <windows.h>
+#endif
+
#if HAVE_SYS_SELECT_H
#include <sys/select.h>
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
}
}
+#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
#ifdef SIGXCPU
signal(SIGXCPU, sigterm_handler);
#endif
+#if HAVE_SETCONSOLECTRLHANDLER
+ SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE);
+#endif
}
/* read a key without blocking */
if (do_benchmark) {
int maxrss = getmaxrss() / 1024;
- printf("bench: maxrss=%ikB\n", maxrss);
+ av_log(NULL, AV_LOG_INFO, "bench: maxrss=%ikB\n", maxrss);
}
for (i = 0; i < nb_filtergraphs; i++) {
/* close files */
for (i = 0; i < nb_output_files; i++) {
OutputFile *of = output_files[i];
- AVFormatContext *s = of->ctx;
+ AVFormatContext *s;
+ if (!of)
+ continue;
+ s = of->ctx;
if (s && s->oformat && !(s->oformat->flags & AVFMT_NOFILE))
avio_closep(&s->pb);
avformat_free_context(s);
}
for (i = 0; i < nb_output_streams; i++) {
OutputStream *ost = output_streams[i];
- AVBitStreamFilterContext *bsfc = ost->bitstream_filters;
+ AVBitStreamFilterContext *bsfc;
+
+ if (!ost)
+ continue;
+
+ bsfc = ost->bitstream_filters;
while (bsfc) {
AVBitStreamFilterContext *next = bsfc->next;
av_bitstream_filter_close(bsfc);
av_log(NULL, AV_LOG_INFO, "Conversion failed!\n");
}
term_exit();
+ ffmpeg_exited = 1;
}
void remove_avoptions(AVDictionary **a, AVDictionary *b)
va_start(va, fmt);
vsnprintf(buf, sizeof(buf), fmt, va);
va_end(va);
- printf("bench: %8"PRIu64" %s \n", t - current_time, buf);
+ av_log(NULL, AV_LOG_INFO, "bench: %8"PRIu64" %s \n", t - current_time, buf);
}
current_time = t;
}
if (!ost->last_frame)
ost->last_frame = av_frame_alloc();
av_frame_unref(ost->last_frame);
- if (next_picture)
+ if (next_picture && ost->last_frame)
av_frame_ref(ost->last_frame, next_picture);
else
av_frame_free(&ost->last_frame);
ret = AVERROR_INVALIDDATA;
}
- if (*got_output || ret<0 || pkt->size)
+ if (*got_output || ret<0)
decode_error_stat[ret<0] ++;
+ if (ret < 0 && exit_on_error)
+ exit_program(1);
+
if (!*got_output || ret < 0)
return ret;
);
}
- if (*got_output || ret<0 || pkt->size)
+ if (*got_output || ret<0)
decode_error_stat[ret<0] ++;
+ if (ret < 0 && exit_on_error)
+ exit_program(1);
+
if (*got_output && ret >= 0) {
if (ist->dec_ctx->width != decoded_frame->width ||
ist->dec_ctx->height != decoded_frame->height ||
int i, ret = avcodec_decode_subtitle2(ist->dec_ctx,
&subtitle, got_output, pkt);
- if (*got_output || ret<0 || pkt->size)
+ if (*got_output || ret<0)
decode_error_stat[ret<0] ++;
+ if (ret < 0 && exit_on_error)
+ exit_program(1);
+
if (ret < 0 || !*got_output) {
if (!pkt->size)
sub2video_flush(ist);
InputFile *f = input_files[i];
AVPacket pkt;
- if (!f->in_thread_queue)
+ if (!f || !f->in_thread_queue)
continue;
av_thread_message_queue_set_err_send(f->in_thread_queue, AVERROR_EOF);
while (av_thread_message_queue_recv(f->in_thread_queue, &pkt, 0) >= 0)
exit_program(1);
ti = getutime() - ti;
if (do_benchmark) {
- printf("bench: utime=%0.3fs\n", ti / 1000000.0);
+ av_log(NULL, AV_LOG_INFO, "bench: utime=%0.3fs\n", ti / 1000000.0);
}
av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" frames successfully decoded, %"PRIu64" decoding errors\n",
decode_error_stat[0], decode_error_stat[1]);