1
0
mirror of http://mpg123.de/trunk/.git synced 2025-08-06 10:02:38 +03:00

merge in https://github.com/madebr/mpg123/pull/10 for reducing CPU load when just waiting for terminal input

git-svn-id: svn://scm.orgis.org/mpg123/trunk@5166 35dc7657-300d-0410-a2e5-dc2837fedb53
This commit is contained in:
thor
2022-10-05 21:33:10 +00:00
parent 8b44db8d88
commit bf896f1255
6 changed files with 12 additions and 9 deletions

2
NEWS
View File

@@ -26,6 +26,8 @@
- libout123: Add same interruption handling to out123_write() as to
unintr_write(), adding EAGAIN to fix bug 342 (thanks to Steffen Nurpmeso)
for certain ALSA setups.
- mpg123: Reduce CPU load while just waiting for terminal input
(thanks to bolshoytoster on github).
1.30.2
------

View File

@@ -153,7 +153,7 @@ off_t term_control(mpg123_handle *fr, out123_handle *ao)
do
{
off_t old_offset = offset;
term_handle_input(fr, ao, stopped|seeking);
term_handle_input(fr, ao, seeking);
if((offset < 0) && (-offset > framenum)) offset = - framenum;
if(param.verbose && offset != old_offset)
print_stat(fr,offset,ao,1,&param);
@@ -509,7 +509,7 @@ static void term_handle_input(mpg123_handle *fr, out123_handle *ao, int do_delay
{
char val;
/* Do we really want that while loop? This means possibly handling multiple inputs that come very rapidly in one go. */
while(term_get_key(do_delay, &val))
while(term_get_key(stopped, do_delay, &val))
{
term_handle_key(fr, ao, val);
}

View File

@@ -25,7 +25,7 @@ void term_restore(void)
{
}
int term_get_key(int do_delay, char *val)
int term_get_key(int stopped, int do_delay, char *val)
{
return 0;
}

View File

@@ -180,7 +180,7 @@ int term_setup(void)
/* Get the next pressed key, if any.
Returns 1 when there is a key, 0 if not. */
int term_get_key(int do_delay, char *val)
int term_get_key(int stopped, int do_delay, char *val)
{
#ifdef __OS2__
KBDKEYINFO key;
@@ -188,7 +188,7 @@ int term_get_key(int do_delay, char *val)
key.chScan = 0;
if(do_delay)
DosSleep(10);
if(!KbdCharIn(&key,IO_NOWAIT,0) && key.chChar)
if(!KbdCharIn(&key,(stopped) ? IO_WAIT : IO_NOWAIT,0) && key.chChar)
{
*val = key.chChar;
return 1;
@@ -211,7 +211,8 @@ int term_get_key(int do_delay, char *val)
FD_ZERO(&r);
FD_SET(term_fd,&r);
if(select(term_fd+1,&r,NULL,NULL,&t) > 0 && FD_ISSET(term_fd,&r))
/* No timeout if stopped */
if(select(term_fd+1,&r,NULL,NULL,(stopped) ? NULL : &t) > 0 && FD_ISSET(term_fd,&r))
{
if(read(term_fd,val,1) <= 0)
return 0; /* Well, we couldn't read the key, so there is none. */

View File

@@ -90,7 +90,7 @@ int term_present(void){
/* Get the next pressed key, if any.
Returns 1 when there is a key, 0 if not. */
int term_get_key(int do_delay, char *val){
int term_get_key(int stopped, int do_delay, char *val){
INPUT_RECORD record;
HANDLE input;
DWORD res;
@@ -99,7 +99,7 @@ int term_get_key(int do_delay, char *val){
if(input == NULL || input == INVALID_HANDLE_VALUE)
return 0;
while(WaitForSingleObject(input, do_delay ? 10 : 0) == WAIT_OBJECT_0){
while(WaitForSingleObject(input, stopped ? INFINITE : (do_delay ? 10 : 0)) == WAIT_OBJECT_0){
do_delay = 0;
if(!ReadConsoleInput(input, &record, 1, &res))
return 0;

View File

@@ -47,6 +47,6 @@ void term_restore(void);
* \param val address to store character to
* \return 1 if there is a key, 0 if not
*/
int term_get_key(int do_delay, char *val);
int term_get_key(int stopped, int do_delay, char *val);
#endif