History

ffmpeg: fix reading from stdin on windows

Based on code by Rolf Siegrist Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer committed 15 years ago

Commit ca4d71b1 parent 31dfc492 files · +29 −1Browse files

Unified · Split

2 files
  1. configure +2 −0
  2. ffmpeg.c +27 −1
configure+2−0
@@ -1101,6 +1101,7 @@ HAVE_LIST=" · 1100 unmodified lines
11011101 memalign
11021102 mkstemp
11031103 mmap
1104+ PeekNamedPipe
11041105 posix_memalign
11051106 round
11061107 roundf
@@ -2842,6 +2843,7 @@ check_func strerror_r · 1735 unmodified lines
28422843 check_func strptime
28432844 check_func strtok_r
28442845 check_func_headers conio.h kbhit
2846+check_func_headers windows.h PeekNamedPipe
28452847 check_func_headers io.h setmode
28462848 check_func_headers lzo/lzo1x.h lzo1x_999_compress
28472849 check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi
ffmpeg.c+27−1
@@ -487,9 +487,9 @@ static void term_init(void) · 486 unmodified lines
487487 /* read a key without blocking */
488488 static int read_key(void)
489489 {
490+ unsigned char ch;
490491 #if HAVE_TERMIOS_H
491492 int n = 1;
492− unsigned char ch;
493493 struct timeval tv;
494494 fd_set rfds;
495495
@@ -509,6 +509,32 @@ static int read_key(void) · 13 unmodified lines
509509 return n;
510510 }
511511 #elif HAVE_KBHIT
512+# if HAVE_PEEKNAMEDPIPE
513+ static int is_pipe;
514+ static HANDLE input_handle;
515+ DWORD dw, nchars;
516+ if(!input_handle){
517+ input_handle = GetStdHandle(STD_INPUT_HANDLE);
518+ is_pipe = !GetConsoleMode(input_handle, &dw);
519+ }
520+
521+ if (stdin->_cnt > 0) {
522+ read(0, &ch, 1);
523+ return ch;
524+ }
525+ if (is_pipe) {
526+ /* When running under a GUI, you will end here. */
527+ if (!PeekNamedPipe(input_handle, NULL, 0, NULL, &nchars, NULL))
528+ return -1;
529+ //Read it
530+ if(nchars != 0) {
531+ read(0, &ch, 1);
532+ return ch;
533+ }else{
534+ return -1;
535+ }
536+ }
537+# endif
512538 if(kbhit())
513539 return(getch());
514540 #endif

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