提交 ca4d71b1 编写于 作者: M Michael Niedermayer

ffmpeg: fix reading from stdin on windows

Based on code by Rolf Siegrist
Signed-off-by: NMichael Niedermayer <michaelni@gmx.at>
上级 31dfc495
...@@ -1101,6 +1101,7 @@ HAVE_LIST=" ...@@ -1101,6 +1101,7 @@ HAVE_LIST="
memalign memalign
mkstemp mkstemp
mmap mmap
PeekNamedPipe
posix_memalign posix_memalign
round round
roundf roundf
...@@ -2842,6 +2843,7 @@ check_func strerror_r ...@@ -2842,6 +2843,7 @@ check_func strerror_r
check_func strptime check_func strptime
check_func strtok_r check_func strtok_r
check_func_headers conio.h kbhit check_func_headers conio.h kbhit
check_func_headers windows.h PeekNamedPipe
check_func_headers io.h setmode check_func_headers io.h setmode
check_func_headers lzo/lzo1x.h lzo1x_999_compress check_func_headers lzo/lzo1x.h lzo1x_999_compress
check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi
......
...@@ -487,9 +487,9 @@ static void term_init(void) ...@@ -487,9 +487,9 @@ static void term_init(void)
/* read a key without blocking */ /* read a key without blocking */
static int read_key(void) static int read_key(void)
{ {
unsigned char ch;
#if HAVE_TERMIOS_H #if HAVE_TERMIOS_H
int n = 1; int n = 1;
unsigned char ch;
struct timeval tv; struct timeval tv;
fd_set rfds; fd_set rfds;
...@@ -509,6 +509,32 @@ static int read_key(void) ...@@ -509,6 +509,32 @@ static int read_key(void)
return n; return n;
} }
#elif HAVE_KBHIT #elif HAVE_KBHIT
# if HAVE_PEEKNAMEDPIPE
static int is_pipe;
static HANDLE input_handle;
DWORD dw, nchars;
if(!input_handle){
input_handle = GetStdHandle(STD_INPUT_HANDLE);
is_pipe = !GetConsoleMode(input_handle, &dw);
}
if (stdin->_cnt > 0) {
read(0, &ch, 1);
return ch;
}
if (is_pipe) {
/* When running under a GUI, you will end here. */
if (!PeekNamedPipe(input_handle, NULL, 0, NULL, &nchars, NULL))
return -1;
//Read it
if(nchars != 0) {
read(0, &ch, 1);
return ch;
}else{
return -1;
}
}
# endif
if(kbhit()) if(kbhit())
return(getch()); return(getch());
#endif #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册