From d86b83f8ab8d9feec3322618eaabe96f03e46a40 Mon Sep 17 00:00:00 2001 From: Ramiro Polla Date: Wed, 22 Nov 2006 12:15:58 +0000 Subject: [PATCH] add interactive support for MinGW patch by Ramiro Polla % ramiro A lisha P ufsc P br % Orignial thread: date: Nov 5, 2006 1:55 AM subject: [Ffmpeg-devel] [PATCH] MinGW interactive support Originally committed as revision 7155 to svn://svn.ffmpeg.org/ffmpeg/trunk --- ffmpeg.c | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index c41b279b2a..ab0b689a6c 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #define HAVE_AV_CONFIG_H +#include #include #include "avformat.h" #include "swscale.h" @@ -27,14 +28,15 @@ #include "opt.h" #include "fifo.h" -#ifndef __MINGW32__ +#ifdef __MINGW32__ +#include +#else #include #include #include #include #include #include -#include #endif #ifdef CONFIG_OS2 #include @@ -292,10 +294,13 @@ typedef struct AVInputFile { /* init terminal so that we can grab keys */ static struct termios oldtty; +#endif static void term_exit(void) { +#ifndef __MINGW32__ tcsetattr (0, TCSANOW, &oldtty); +#endif } static volatile sig_atomic_t received_sigterm = 0; @@ -309,6 +314,7 @@ sigterm_handler(int sig) static void term_init(void) { +#ifndef __MINGW32__ struct termios tty; tcgetattr (0, &tty); @@ -324,9 +330,10 @@ static void term_init(void) tty.c_cc[VTIME] = 0; tcsetattr (0, TCSANOW, &tty); + signal(SIGQUIT, sigterm_handler); /* Quit (POSIX). */ +#endif signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */ - signal(SIGQUIT, sigterm_handler); /* Quit (POSIX). */ signal(SIGTERM, sigterm_handler); /* Termination (ANSI). */ /* register a function to be called at normal program termination @@ -340,6 +347,10 @@ static void term_init(void) /* read a key without blocking */ static int read_key(void) { +#ifdef __MINGW32__ + if(kbhit()) + return(getch()); +#else int n = 1; unsigned char ch; #ifndef CONFIG_BEOS_NETSERVER @@ -359,6 +370,7 @@ static int read_key(void) return n; } +#endif return -1; } @@ -367,26 +379,6 @@ static int decode_interrupt_cb(void) return q_pressed || (q_pressed = read_key() == 'q'); } -#else - -static volatile int received_sigterm = 0; - -/* no interactive support */ -static void term_exit(void) -{ -} - -static void term_init(void) -{ -} - -static int read_key(void) -{ - return 0; -} - -#endif - static int read_ffserver_streams(AVFormatContext *s, const char *filename) { int i, err; @@ -1832,12 +1824,10 @@ static int av_encode(AVFormatContext **output_files, } } -#ifndef __MINGW32__ if ( !using_stdin && verbose >= 0) { fprintf(stderr, "Press [q] to stop encoding\n"); url_set_interrupt_cb(decode_interrupt_cb); } -#endif term_init(); stream_no_data = 0; @@ -3971,14 +3961,13 @@ int main(int argc, char **argv) powerpc_display_perf_report(); #endif /* POWERPC_PERFORMANCE_REPORT */ -#ifndef __MINGW32__ if (received_sigterm) { fprintf(stderr, "Received signal %d: terminating.\n", (int) received_sigterm); exit (255); } -#endif + exit(0); /* not all OS-es handle main() return value */ return 0; }