From b93ed278362185ff980e0ce8f4ab3029f8fe395f Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Fri, 6 Apr 2012 14:24:26 +0300 Subject: input: stop trying to read terminal input on EOF Stop trying to read terminal input if a read attempt returns EOF. The most important case where this matters is when someone runs the player with stdin redirected from /dev/null and without specifying --no-consolecontrols. This used to cause 100% CPU load while paused, as select() would continuously trigger on stdin (the need for --no-consolecontrols was not apparent to people with older mplayer versions, as input reading was less efficient and latencies like hardcoded sleeps kept CPU use well below 100%). Now this will only cause a "Dead key input" error message. --- osdep/getch2-win.c | 3 ++- osdep/getch2.c | 11 +++++++++-- osdep/getch2.h | 4 +++- 3 files changed, 14 insertions(+), 4 deletions(-) (limited to 'osdep') diff --git a/osdep/getch2-win.c b/osdep/getch2-win.c index 326cf1a7d0..f1ccea6359 100644 --- a/osdep/getch2-win.c +++ b/osdep/getch2-win.c @@ -158,11 +158,12 @@ static int getch2_internal(void) return -1; } -void getch2(struct mp_fifo *fifo) +bool getch2(struct mp_fifo *fifo) { int r = getch2_internal(); if (r >= 0) mplayer_put_key(fifo, r); + return true; } void getch2_enable(void) diff --git a/osdep/getch2.c b/osdep/getch2.c index 1a92866afd..dcd5b1ad84 100644 --- a/osdep/getch2.c +++ b/osdep/getch2.c @@ -158,11 +158,17 @@ void get_screen_size(void){ #endif } -void getch2(struct mp_fifo *fifo) +bool getch2(struct mp_fifo *fifo) { int retval = read(0, &getch2_buf[getch2_len], BUF_LEN-getch2_len); + /* Return false on EOF to stop running select() on the FD, as it'd + * trigger all the time. Note that it's possible to get temporary + * EOF on terminal if the user presses ctrl-d, but that shouldn't + * happen if the terminal state change done in getch2_enable() + * works. + */ if (retval < 1) - return; + return retval; getch2_len += retval; while (getch2_len > 0 && (getch2_len > 1 || getch2_buf[0] != 27)) { @@ -279,6 +285,7 @@ void getch2(struct mp_fifo *fifo) getch2_buf[i] = getch2_buf[len+i]; mplayer_put_key(fifo, code); } + return true; } static int getch2_status=0; diff --git a/osdep/getch2.h b/osdep/getch2.h index 8fb346d4f7..458881c15f 100644 --- a/osdep/getch2.h +++ b/osdep/getch2.h @@ -24,6 +24,8 @@ #ifndef MPLAYER_GETCH2_H #define MPLAYER_GETCH2_H +#include + #include "config.h" /* Screen size. Initialized by load_termcap() and get_screen_size() */ @@ -45,7 +47,7 @@ void getch2_disable(void); /* Read a character or a special key code (see keycodes.h) */ struct mp_fifo; -void getch2(struct mp_fifo *fifo); +bool getch2(struct mp_fifo *fifo); #ifdef CONFIG_ICONV /** -- cgit v1.2.3 From e2fc1f640fdf473fdf8f1de6fd1212731b8ffa13 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Fri, 6 Apr 2012 16:58:39 +0300 Subject: build: remove OS/2 support --- osdep/getch2-os2.c | 200 -------------------------------------------------- osdep/getch2.c | 2 +- osdep/getch2.h | 4 +- osdep/mmap-os2.c | 211 ----------------------------------------------------- osdep/osdep.h | 50 ------------- osdep/priority.c | 2 - 6 files changed, 3 insertions(+), 466 deletions(-) delete mode 100644 osdep/getch2-os2.c delete mode 100644 osdep/mmap-os2.c delete mode 100644 osdep/osdep.h (limited to 'osdep') diff --git a/osdep/getch2-os2.c b/osdep/getch2-os2.c deleted file mode 100644 index 05e408ff45..0000000000 --- a/osdep/getch2-os2.c +++ /dev/null @@ -1,200 +0,0 @@ -/* - * OS/2 TermIO - * - * Copyright (c) 2007 KO Myung-Hun (komh@chollian.net) - * - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#define INCL_KBD -#define INCL_VIO -#define INCL_DOS -#include - -#include -#include - -#include "config.h" -#include "input/keycodes.h" -#include "input/input.h" -#include "mp_fifo.h" -#include "getch2.h" - -#if defined(HAVE_LANGINFO) && defined(CONFIG_ICONV) -#include -#include -#endif - -int mp_input_slave_cmd_func( int fd, char *dest, int size ) -{ - PPIB ppib; - CHAR szPipeName[ 100 ]; - HFILE hpipe; - ULONG ulAction; - ULONG cbActual; - ULONG rc; - - DosGetInfoBlocks( NULL, &ppib ); - - sprintf( szPipeName, "\\PIPE\\MPLAYER\\%lx", ppib->pib_ulpid ); - - rc = DosOpen( szPipeName, &hpipe, &ulAction, 0, FILE_NORMAL, - OPEN_ACTION_OPEN_IF_EXISTS, - OPEN_SHARE_DENYREADWRITE | OPEN_ACCESS_READWRITE, - NULL ); - if( rc ) - return MP_INPUT_NOTHING; - - rc = DosRead( hpipe, dest, size, &cbActual ); - if( rc ) - return MP_INPUT_NOTHING; - - rc = cbActual; - - // Send ACK - DosWrite( hpipe, &rc, sizeof( ULONG ), &cbActual ); - - DosClose( hpipe ); - - return rc; -} - - -int screen_width = 80; -int screen_height = 24; -char *erase_to_end_of_line = NULL; - -void get_screen_size( void ) -{ - VIOMODEINFO vmi; - - vmi.cb = sizeof( VIOMODEINFO ); - - VioGetMode( &vmi, 0 ); - - screen_width = vmi.col; - screen_height = vmi.row; -} - -static int getch2_status = 0; - -static int getch2_internal( void ) -{ - KBDKEYINFO kki; - - if( !getch2_status ) - return -1; - - if( KbdCharIn( &kki, IO_NOWAIT, 0 )) - return -1; - - // key pressed ? - if( kki.fbStatus ) - { - // extended key ? - if(( kki.chChar == 0x00 ) || ( kki.chChar == 0xE0 )) - { - switch( kki.chScan ) - { - case 0x4B : // Left - return KEY_LEFT; - - case 0x48 : // Up - return KEY_UP; - - case 0x4D : // Right - return KEY_RIGHT; - - case 0x50 : // Down - return KEY_DOWN; - - case 0x53 : // Delete - return KEY_DELETE; - - case 0x52 : // Insert - return KEY_INSERT; - - case 0x47 : // Home - return KEY_HOME; - - case 0x4F : // End - return KEY_END; - - case 0x49 : // Page Up - return KEY_PAGE_UP; - - case 0x51 : // Page Down - return KEY_PAGE_DOWN; - } - } - else - { - switch( kki.chChar ) - { - case 0x08 : // Backspace - return KEY_BS; - - case 0x1B : // Esc - return KEY_ESC; - - case 0x0D : // Enter - // Keypad Enter ? - if( kki.chScan == 0xE0 ) - return KEY_KPENTER; - break; - } - - return kki.chChar; - } - } - - return -1; -} - -void getch2(struct mp_fifo *fifo) -{ - int key; - - key = getch2_internal(); - if( key != -1 ) - mplayer_put_key(fifo, key); -} - -void getch2_enable( void ) -{ - getch2_status = 1; -} - -void getch2_disable( void ) -{ - getch2_status = 0; -} - -#ifdef CONFIG_ICONV -char *get_term_charset( void ) -{ - char *charset = NULL; - -#ifdef HAVE_LANGINFO - setlocale( LC_CTYPE, ""); - charset = strdup( nl_langinfo( CODESET )); - setlocale( LC_CTYPE, "C"); -#endif - - return charset; -} -#endif diff --git a/osdep/getch2.c b/osdep/getch2.c index dcd5b1ad84..0cbaa82a25 100644 --- a/osdep/getch2.c +++ b/osdep/getch2.c @@ -24,7 +24,7 @@ #include "config.h" //#define HAVE_TERMCAP -#if !defined(__OS2__) && !defined(__MORPHOS__) +#if !defined(__MORPHOS__) #define CONFIG_IOCTL #endif diff --git a/osdep/getch2.h b/osdep/getch2.h index 458881c15f..4442f1181d 100644 --- a/osdep/getch2.h +++ b/osdep/getch2.h @@ -60,8 +60,8 @@ bool getch2(struct mp_fifo *fifo); char *get_term_charset(void); #endif -#if defined(__MINGW32__) || defined(__OS2__) -/* slave cmd function for Windows and OS/2 */ +#if defined(__MINGW32__) +// slave cmd function for Windows int mp_input_slave_cmd_func(int fd,char* dest,int size); #define USE_FD0_CMD_SELECT 0 #define MP_INPUT_SLAVE_CMD_FUNC mp_input_slave_cmd_func diff --git a/osdep/mmap-os2.c b/osdep/mmap-os2.c deleted file mode 100644 index 61fcc4f5db..0000000000 --- a/osdep/mmap-os2.c +++ /dev/null @@ -1,211 +0,0 @@ -/* - * very simple implementation of mmap() for OS/2 - * - * Copyright (c) 2008 KO Myung-Hun (komh@chollian.net) - * - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#define INCL_DOS -#include - -#include -#include -#include -#include -#include - -#include "config.h" -#include "mmap.h" -#include "mmap_anon.h" - -typedef struct os2_mmap_s -{ - void *addr; - size_t len; - int flags; - struct os2_mmap_s *prev; - struct os2_mmap_s *next; -} os2_mmap; -static os2_mmap *m_mmap = NULL; - -void *mmap( void *addr, size_t len, int prot, int flags, int fildes, off_t off ) -{ - os2_mmap *new_mmap; - - ULONG fl; - ULONG rc; - - void *ret; - - if( prot & PROT_WRITE ) - { - if( flags & MAP_SHARED ) - return MAP_FAILED; - - if( !( flags & MAP_PRIVATE )) - return MAP_FAILED; - } - - if( flags & MAP_FIXED ) - { - ULONG cb; - - cb = len; - rc = DosQueryMem( addr, &cb, &fl ); - if( rc || ( cb < len )) - return MAP_FAILED; - - rc = DosSetMem( addr, len, fPERM ); - if( rc ) - return MAP_FAILED; - - ret = addr; - } - else - { - // Allocate tiled memory compatible with 16-bit selectors - // 'fs_seg' in 'ldt_keeper.c' need this attribute - rc = DosAllocMem( &ret, len, fALLOC ); - if( rc ) - return MAP_FAILED; - } - - new_mmap = malloc( sizeof( os2_mmap )); - new_mmap->addr = ret; - new_mmap->len = len; - new_mmap->flags = flags; - new_mmap->prev = m_mmap; - new_mmap->next = NULL; - - if( m_mmap ) - m_mmap->next = new_mmap; - m_mmap = new_mmap; - - if( !( flags & MAP_ANON )) - { - int pos; - - /* Now read in the file */ - if(( pos = lseek( fildes, off, SEEK_SET )) == -1) - { - munmap( ret, len ); - - return MAP_FAILED; - } - - read( fildes, ret, len ); - lseek( fildes, pos, SEEK_SET ); /* Restore the file pointer */ - } - - fl = 0; - - if( prot & PROT_READ ) - fl |= PAG_READ; - - if( prot & PROT_WRITE ) - fl |= PAG_WRITE; - - if( prot & PROT_EXEC ) - fl |= PAG_EXECUTE; - - if( prot & PROT_NONE ) - fl |= PAG_GUARD; - - rc = DosSetMem( ret, len, fl ); - if( rc ) - { - munmap( ret, len ); - - return MAP_FAILED; - } - - return ret; -} - -int munmap( void *addr, size_t len ) -{ - os2_mmap *mm; - - for( mm = m_mmap; mm; mm = mm->prev ) - { - if( mm->addr == addr ) - break; - } - - if( mm ) - { - - if( !( mm->flags & MAP_FIXED )) - DosFreeMem( addr ); - - if( mm->next ) - mm->next->prev = mm->prev; - - if( mm->prev ) - mm->prev->next = mm->next; - - if( m_mmap == mm ) - m_mmap = mm->prev; - - free( mm ); - - return 0; - } - - return -1; -} - -int mprotect( void *addr, size_t len, int prot ) -{ - os2_mmap *mm; - - for( mm = m_mmap; mm; mm = mm->prev ) - { - if( mm->addr == addr ) - break; - } - - if( mm ) - { - ULONG fl; - - fl = 0; - - if( prot & PROT_READ ) - fl |= PAG_READ; - - if( prot & PROT_WRITE ) - fl |= PAG_WRITE; - - if( prot & PROT_EXEC ) - fl |= PAG_EXECUTE; - - if( prot & PROT_NONE ) - fl |= PAG_GUARD; - - if( DosSetMem( addr, len, fl ) == 0 ) - return 0; - } - - return -1; -} - -void *mmap_anon( void *addr, size_t len, int prot, int flags, off_t off ) -{ - return mmap( addr, len, prot, flags | MAP_ANON, -1, off ); -} diff --git a/osdep/osdep.h b/osdep/osdep.h deleted file mode 100644 index 654309c015..0000000000 --- a/osdep/osdep.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Header in order to include OS-specific headers, macros, types and so on - * - * Copyright (c) 2010 by KO Myung-Hun (komh@chollian.net) - * - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPLAYER_OSDEP_H -#define MPLAYER_OSDEP_H - -#ifdef __OS2__ -#define INCL_DOS -#define INCL_DOSDEVIOCTL -#include - -#include /* getpid() */ - -#define REALTIME_PRIORITY_CLASS MAKESHORT(0, PRTYC_TIMECRITICAL) -#define HIGH_PRIORITY_CLASS MAKESHORT(PRTYD_MAXIMUM, PRTYC_REGULAR) -#define ABOVE_NORMAL_PRIORITY_CLASS MAKESHORT(PRTYD_MAXIMUM / 2, PRTYC_REGULAR) -#define NORMAL_PRIORITY_CLASS MAKESHORT(0, PRTYC_REGULAR) -#define BELOW_NORMAL_PRIORITY_CLASS MAKESHORT(PRTYD_MAXIMUM, PRTYC_IDLETIME) -#define IDLE_PRIORITY_CLASS MAKESHORT(0, PRTYC_IDLETIME) - -#define SetPriorityClass(pid, prio) \ - DosSetPriority(PRTYS_PROCESS, \ - HIBYTE(prio), \ - LOBYTE(prio), \ - pid) - -#define GetCurrentProcess() getpid() -#endif /* __OS2__ */ - -#endif /* MPLAYER_OSDEP_H */ - diff --git a/osdep/priority.c b/osdep/priority.c index 0803a3299e..dfa2c54ff5 100644 --- a/osdep/priority.c +++ b/osdep/priority.c @@ -20,8 +20,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "osdep.h" - #if defined(__MINGW32__) || defined(__CYGWIN__) #include #endif -- cgit v1.2.3