This reverts commit cb48e245e6e770f146220fac0a8bd4dc1a5e006c. Reason being we like pressing "q" to quit ffmpeg. Conflicts: ffmpeg.c
Unified · Split
| @@ -1118,6 +1118,7 @@ HAVE_LIST=" · 1117 unmodified lines | ||
| 1118 | 1118 | sys_soundcard_h |
| 1119 | 1119 | sys_videoio_h |
| 1120 | 1120 | ten_operands |
| 1121 | + termios_h | |
| 1121 | 1122 | threads |
| 1122 | 1123 | truncf |
| 1123 | 1124 | vfp_args |
| @@ -2803,6 +2804,7 @@ check_header poll.h · 1679 unmodified lines | ||
| 2803 | 2804 | check_header sys/mman.h |
| 2804 | 2805 | check_header sys/resource.h |
| 2805 | 2806 | check_header sys/select.h |
| 2807 | +check_header termios.h | |
| 2806 | 2808 | check_header vdpau/vdpau.h |
| 2807 | 2809 | check_header vdpau/vdpau_x11.h |
| 2808 | 2810 | check_header X11/extensions/XvMClib.h |
| @@ -69,7 +69,12 @@ · 68 unmodified lines | ||
| 69 | 69 | #include <sys/select.h> |
| 70 | 70 | #endif |
| 71 | 71 | |
| 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 | |
| 73 | 78 | #include <conio.h> |
| 74 | 79 | #endif |
| 75 | 80 | #include <time.h> |
| @@ -338,6 +343,12 @@ typedef struct AVInputFile { · 262 unmodified lines | ||
| 338 | 343 | int nb_streams; /* nb streams we are aware of */ |
| 339 | 344 | } AVInputFile; |
| 340 | 345 | |
| 346 | +#if HAVE_TERMIOS_H | |
| 347 | + | |
| 348 | +/* init terminal so that we can grab keys */ | |
| 349 | +static struct termios oldtty; | |
| 350 | +#endif | |
| 351 | + | |
| 341 | 352 | #if CONFIG_AVFILTER |
| 342 | 353 | |
| 343 | 354 | static int configure_filters(AVInputStream *ist, AVOutputStream *ost) |
| @@ -425,6 +436,9 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost) · 81 unmodified lines | ||
| 425 | 436 | static void term_exit(void) |
| 426 | 437 | { |
| 427 | 438 | av_log(NULL, AV_LOG_QUIET, ""); |
| 439 | +#if HAVE_TERMIOS_H | |
| 440 | + tcsetattr (0, TCSANOW, &oldtty); | |
| 441 | +#endif | |
| 428 | 442 | } |
| 429 | 443 | |
| 430 | 444 | static volatile int received_sigterm = 0; |
| @@ -439,6 +453,26 @@ sigterm_handler(int sig) · 8 unmodified lines | ||
| 439 | 453 | |
| 440 | 454 | static void term_init(void) |
| 441 | 455 | { |
| 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 | + | |
| 442 | 476 | signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */ |
| 443 | 477 | signal(SIGTERM, sigterm_handler); /* Termination (ANSI). */ |
| 444 | 478 | #ifdef SIGXCPU |
| @@ -449,7 +483,25 @@ static void term_init(void) · 4 unmodified lines | ||
| 449 | 483 | /* read a key without blocking */ |
| 450 | 484 | static int read_key(void) |
| 451 | 485 | { |
| 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 | |
| 453 | 505 | if(kbhit()) |
| 454 | 506 | return(getch()); |
| 455 | 507 | #endif |
| @@ -2467,11 +2519,7 @@ static int transcode(AVFormatContext **output_files, · 2011 unmodified lines | ||
| 2467 | 2519 | |
| 2468 | 2520 | if (!using_stdin) { |
| 2469 | 2521 | if(verbose >= 0) |
| 2470 | −#if HAVE_KBHIT | |
| 2471 | 2522 | fprintf(stderr, "Press [q] to stop encoding\n"); |
| 2472 | −#else | |
| 2473 | − fprintf(stderr, "Press ctrl-c to stop encoding\n"); | |
| 2474 | −#endif | |
| 2475 | 2523 | url_set_interrupt_cb(decode_interrupt_cb); |
| 2476 | 2524 | } |
| 2477 | 2525 | term_init(); |