read a key without blocking */
| 252 | |
| 253 | /* read a key without blocking */ |
| 254 | static int read_key(void) |
| 255 | { |
| 256 | #if HAVE_TERMIOS_H |
| 257 | int n = 1; |
| 258 | struct timeval tv; |
| 259 | fd_set rfds; |
| 260 | |
| 261 | FD_ZERO(&rfds); |
| 262 | FD_SET(0, &rfds); |
| 263 | tv.tv_sec = 0; |
| 264 | tv.tv_usec = 0; |
| 265 | n = select(1, &rfds, NULL, NULL, &tv); |
| 266 | if (n > 0) { |
| 267 | unsigned char ch; |
| 268 | n = read(0, &ch, 1); |
| 269 | if (n == 1) |
| 270 | return ch; |
| 271 | |
| 272 | return n; |
| 273 | } |
| 274 | #elif HAVE_KBHIT |
| 275 | # if HAVE_PEEKNAMEDPIPE && HAVE_GETSTDHANDLE |
| 276 | static int is_pipe; |
| 277 | static HANDLE input_handle; |
| 278 | DWORD dw, nchars; |
| 279 | if(!input_handle){ |
| 280 | input_handle = GetStdHandle(STD_INPUT_HANDLE); |
| 281 | is_pipe = !GetConsoleMode(input_handle, &dw); |
| 282 | } |
| 283 | |
| 284 | if (is_pipe) { |
| 285 | /* When running under a GUI, you will end here. */ |
| 286 | if (!PeekNamedPipe(input_handle, NULL, 0, NULL, &nchars, NULL)) { |
| 287 | // input pipe may have been closed by the program that ran ffmpeg |
| 288 | return -1; |
| 289 | } |
| 290 | //Read it |
| 291 | if(nchars != 0) { |
| 292 | unsigned char ch; |
| 293 | if (read(0, &ch, 1) == 1) |
| 294 | return ch; |
| 295 | return 0; |
| 296 | }else{ |
| 297 | return -1; |
| 298 | } |
| 299 | } |
| 300 | # endif |
| 301 | if(kbhit()) |
| 302 | return(getch()); |
| 303 | #endif |
| 304 | return -1; |
| 305 | } |
| 306 | |
| 307 | static int decode_interrupt_cb(void *ctx) |
| 308 | { |
no outgoing calls
no test coverage detected