[FFmpeg-cvslog] Do no modify terminal parameters using termios.h

Panagiotis H.M. Issaris git at videolan.org
Wed Mar 23 03:03:40 CET 2011


ffmpeg | branch: master | Panagiotis H.M. Issaris <takis at issaris.org> | Thu Mar 10 16:07:52 2011 +0100| [cb48e245e6e770f146220fac0a8bd4dc1a5e006c] | committer: Mans Rullgard

Do no modify terminal parameters using termios.h

Remove usage of tcgetattr and tcsetattr to modify terminal
parameters, and rely on ctrl-c to stop instead of pressing 'q'.
On systems with conio.h, keep the old behavior.

Changing the terminal settings causes problems if multiple instances
are running asynchronously on the same terminal, such as during a
parallel FATE run, or if the process crashes before restoring the
terminal.  In both cases, the terminal state is messed up requiring
a manual reset.

Signed-off-by: Mans Rullgard <mans at mansr.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cb48e245e6e770f146220fac0a8bd4dc1a5e006c
---

 configure |    2 --
 ffmpeg.c  |   60 ++++++------------------------------------------------------
 2 files changed, 6 insertions(+), 56 deletions(-)

diff --git a/configure b/configure
index 99c67c3..4fd71cd 100755
--- a/configure
+++ b/configure
@@ -1114,7 +1114,6 @@ HAVE_LIST="
     sys_soundcard_h
     sys_videoio_h
     ten_operands
-    termios_h
     threads
     truncf
     vfp_args
@@ -2791,7 +2790,6 @@ check_header poll.h
 check_header sys/mman.h
 check_header sys/resource.h
 check_header sys/select.h
-check_header termios.h
 check_header vdpau/vdpau.h
 check_header vdpau/vdpau_x11.h
 check_header X11/extensions/XvMClib.h
diff --git a/ffmpeg.c b/ffmpeg.c
index 02bc193..645fdb6 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -69,12 +69,7 @@
 #include <sys/select.h>
 #endif
 
-#if HAVE_TERMIOS_H
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/time.h>
-#include <termios.h>
-#elif HAVE_CONIO_H
+#if HAVE_CONIO_H
 #include <conio.h>
 #endif
 #include <time.h>
@@ -340,12 +335,6 @@ typedef struct AVInputFile {
     int nb_streams;       /* nb streams we are aware of */
 } AVInputFile;
 
-#if HAVE_TERMIOS_H
-
-/* init terminal so that we can grab keys */
-static struct termios oldtty;
-#endif
-
 #if CONFIG_AVFILTER
 
 static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
@@ -423,9 +412,6 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
 static void term_exit(void)
 {
     av_log(NULL, AV_LOG_QUIET, "");
-#if HAVE_TERMIOS_H
-    tcsetattr (0, TCSANOW, &oldtty);
-#endif
 }
 
 static volatile int received_sigterm = 0;
@@ -439,26 +425,6 @@ sigterm_handler(int sig)
 
 static void term_init(void)
 {
-#if HAVE_TERMIOS_H
-    struct termios tty;
-
-    tcgetattr (0, &tty);
-    oldtty = tty;
-    atexit(term_exit);
-
-    tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
-                          |INLCR|IGNCR|ICRNL|IXON);
-    tty.c_oflag |= OPOST;
-    tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
-    tty.c_cflag &= ~(CSIZE|PARENB);
-    tty.c_cflag |= CS8;
-    tty.c_cc[VMIN] = 1;
-    tty.c_cc[VTIME] = 0;
-
-    tcsetattr (0, TCSANOW, &tty);
-    signal(SIGQUIT, sigterm_handler); /* Quit (POSIX).  */
-#endif
-
     signal(SIGINT , sigterm_handler); /* Interrupt (ANSI).  */
     signal(SIGTERM, sigterm_handler); /* Termination (ANSI).  */
 #ifdef SIGXCPU
@@ -469,25 +435,7 @@ static void term_init(void)
 /* read a key without blocking */
 static int read_key(void)
 {
-#if HAVE_TERMIOS_H
-    int n = 1;
-    unsigned char ch;
-    struct timeval tv;
-    fd_set rfds;
-
-    FD_ZERO(&rfds);
-    FD_SET(0, &rfds);
-    tv.tv_sec = 0;
-    tv.tv_usec = 0;
-    n = select(1, &rfds, NULL, NULL, &tv);
-    if (n > 0) {
-        n = read(0, &ch, 1);
-        if (n == 1)
-            return ch;
-
-        return n;
-    }
-#elif HAVE_CONIO_H
+#if HAVE_CONIO_H
     if(kbhit())
         return(getch());
 #endif
@@ -2489,7 +2437,11 @@ static int transcode(AVFormatContext **output_files,
     }
 
     if (!using_stdin && verbose >= 0) {
+#if HAVE_CONIO_H
         fprintf(stderr, "Press [q] to stop encoding\n");
+#else
+        fprintf(stderr, "Press ctrl-c to stop encoding\n");
+#endif
         url_set_interrupt_cb(decode_interrupt_cb);
     }
     term_init();




More information about the ffmpeg-cvslog mailing list