History

Revert "Do no modify terminal parameters using termios.h"

This reverts commit cb48e245e6e770f146220fac0a8bd4dc1a5e006c. Reason being we like pressing "q" to quit ffmpeg. Conflicts: ffmpeg.c

Michael Niedermayer committed 15 years ago

Commit 8b8bf891 parent 93dfda82 files · +56 −6Browse files

Unified · Split

2 files
  1. configure +2 −0
  2. ffmpeg.c +54 −6
configure+2−0
@@ -1118,6 +1118,7 @@ HAVE_LIST=" · 1117 unmodified lines
11181118 sys_soundcard_h
11191119 sys_videoio_h
11201120 ten_operands
1121+ termios_h
11211122 threads
11221123 truncf
11231124 vfp_args
@@ -2803,6 +2804,7 @@ check_header poll.h · 1679 unmodified lines
28032804 check_header sys/mman.h
28042805 check_header sys/resource.h
28052806 check_header sys/select.h
2807+check_header termios.h
28062808 check_header vdpau/vdpau.h
28072809 check_header vdpau/vdpau_x11.h
28082810 check_header X11/extensions/XvMClib.h
ffmpeg.c+54−6
@@ -69,7 +69,12 @@ · 68 unmodified lines
6969 #include <sys/select.h>
7070 #endif
7171
72−#if HAVE_KBHIT
72+#if HAVE_TERMIOS_H
73+#include <fcntl.h>
74+#include <sys/ioctl.h>
75+#include <sys/time.h>
76+#include <termios.h>
77+#elif HAVE_KBHIT
7378 #include <conio.h>
7479 #endif
7580 #include <time.h>
@@ -338,6 +343,12 @@ typedef struct AVInputFile { · 262 unmodified lines
338343 int nb_streams; /* nb streams we are aware of */
339344 } AVInputFile;
340345
346+#if HAVE_TERMIOS_H
347+
348+/* init terminal so that we can grab keys */
349+static struct termios oldtty;
350+#endif
351+
341352 #if CONFIG_AVFILTER
342353
343354 static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
@@ -425,6 +436,9 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost) · 81 unmodified lines
425436 static void term_exit(void)
426437 {
427438 av_log(NULL, AV_LOG_QUIET, "");
439+#if HAVE_TERMIOS_H
440+ tcsetattr (0, TCSANOW, &oldtty);
441+#endif
428442 }
429443
430444 static volatile int received_sigterm = 0;
@@ -439,6 +453,26 @@ sigterm_handler(int sig) · 8 unmodified lines
439453
440454 static void term_init(void)
441455 {
456+#if HAVE_TERMIOS_H
457+ struct termios tty;
458+
459+ tcgetattr (0, &tty);
460+ oldtty = tty;
461+ atexit(term_exit);
462+
463+ tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
464+ |INLCR|IGNCR|ICRNL|IXON);
465+ tty.c_oflag |= OPOST;
466+ tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
467+ tty.c_cflag &= ~(CSIZE|PARENB);
468+ tty.c_cflag |= CS8;
469+ tty.c_cc[VMIN] = 1;
470+ tty.c_cc[VTIME] = 0;
471+
472+ tcsetattr (0, TCSANOW, &tty);
473+ signal(SIGQUIT, sigterm_handler); /* Quit (POSIX). */
474+#endif
475+
442476 signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */
443477 signal(SIGTERM, sigterm_handler); /* Termination (ANSI). */
444478 #ifdef SIGXCPU
@@ -449,7 +483,25 @@ static void term_init(void) · 4 unmodified lines
449483 /* read a key without blocking */
450484 static int read_key(void)
451485 {
452−#if HAVE_KBHIT
486+#if HAVE_TERMIOS_H
487+ int n = 1;
488+ unsigned char ch;
489+ struct timeval tv;
490+ fd_set rfds;
491+
492+ FD_ZERO(&rfds);
493+ FD_SET(0, &rfds);
494+ tv.tv_sec = 0;
495+ tv.tv_usec = 0;
496+ n = select(1, &rfds, NULL, NULL, &tv);
497+ if (n > 0) {
498+ n = read(0, &ch, 1);
499+ if (n == 1)
500+ return ch;
501+
502+ return n;
503+ }
504+#elif HAVE_KBHIT
453505 if(kbhit())
454506 return(getch());
455507 #endif
@@ -2467,11 +2519,7 @@ static int transcode(AVFormatContext **output_files, · 2011 unmodified lines
24672519
24682520 if (!using_stdin) {
24692521 if(verbose >= 0)
2470−#if HAVE_KBHIT
24712522 fprintf(stderr, "Press [q] to stop encoding\n");
2472−#else
2473− fprintf(stderr, "Press ctrl-c to stop encoding\n");
2474−#endif
24752523 url_set_interrupt_cb(decode_interrupt_cb);
24762524 }
24772525 term_init();

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t