From 3ab984176452000cc845adfb4afc8808a404a3c6 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Thu, 1 Apr 2004 03:48:51 +0000 Subject: use our own portable version of usleep using select() git-svn-id: https://svn.musicpd.org/mpd/trunk@578 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/aac_decode.c | 2 +- src/audiofile_decode.c | 2 +- src/decode.c | 16 ++++++++-------- src/flac_decode.c | 2 +- src/interface.c | 5 +++-- src/mp3_decode.c | 2 +- src/mp4_decode.c | 2 +- src/ogg_decode.c | 2 +- src/player.c | 14 +++++++------- src/utils.c | 14 ++++++++++++++ src/utils.h | 2 ++ 11 files changed, 40 insertions(+), 23 deletions(-) diff --git a/src/aac_decode.c b/src/aac_decode.c index 03f291fcc..0610b774a 100644 --- a/src/aac_decode.c +++ b/src/aac_decode.c @@ -371,7 +371,7 @@ int aac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) { while(cb->begin==cb->end && cb->wrap && !dc->stop && !dc->seek) { - usleep(10000); + my_usleep(10000); } if(dc->seek) { dc->seekError = 1; diff --git a/src/audiofile_decode.c b/src/audiofile_decode.c index 595c9cea2..d34c029ee 100644 --- a/src/audiofile_decode.c +++ b/src/audiofile_decode.c @@ -111,7 +111,7 @@ int audiofile_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) else { while(cb->begin==cb->end && cb->wrap && !dc->stop && !dc->seek){ - usleep(10000); + my_usleep(10000); } if(dc->stop) break; else if(dc->seek) continue; diff --git a/src/decode.c b/src/decode.c index 2f557f932..a849b738d 100644 --- a/src/decode.c +++ b/src/decode.c @@ -79,7 +79,7 @@ void stopDecode(DecoderControl * dc) { (dc->start || dc->state==DECODE_STATE_DECODE)) { dc->stop = 1; - while(decode_pid && *decode_pid>0 && dc->stop) usleep(1000); + while(decode_pid && *decode_pid>0 && dc->stop) my_usleep(1000); } } @@ -112,7 +112,7 @@ int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af) { int waitOnDecode(PlayerControl * pc, AudioFormat * af, DecoderControl * dc, Buffer * cb) { - while(decode_pid && *decode_pid>0 && dc->start) usleep(1000); + while(decode_pid && *decode_pid>0 && dc->start) my_usleep(1000); if(dc->start || dc->error!=DECODE_ERROR_NOERROR) { strncpy(pc->erroredFile,pc->file,MAXPATHLEN); @@ -164,7 +164,7 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc, dc->seekError = 0; dc->seek = 1; pc->bitRate = 0; - while(*decode_pid>0 && dc->seek) usleep(1000); + while(*decode_pid>0 && dc->seek) my_usleep(1000); if(!dc->seekError) pc->elapsedTime = dc->seekWhere; } } @@ -272,7 +272,7 @@ int decoderInit(PlayerControl * pc, Buffer * cb, AudioFormat *af, dc->stop = 0; } else if(dc->seek) dc->start = 1; - else usleep(10000); + else my_usleep(10000); } exit(0); @@ -339,7 +339,7 @@ void decode() { { processDecodeInput(); if(quit) return; - usleep(1000); + my_usleep(1000); } while(!quit) { @@ -367,7 +367,7 @@ void decode() { } else doCrossFade = -1; } - if(pause) usleep(10000); + if(pause) my_usleep(10000); else if((cb->begin!=cb->end || cb->wrap) && cb->begin!=cb->next) { @@ -461,7 +461,7 @@ void decode() { quitDecode(pc,dc); return; } - usleep(1000); + my_usleep(1000); } if(pc->queueState!=PLAYER_QUEUE_PLAY) { quit = 1; @@ -484,7 +484,7 @@ void decode() { quit = 1; break; } - else usleep(1000); + else my_usleep(1000); } pc->totalPlayTime+= pc->elapsedTime-pc->beginTime; \ diff --git a/src/flac_decode.c b/src/flac_decode.c index 29f7dbdaa..afb5bcf74 100644 --- a/src/flac_decode.c +++ b/src/flac_decode.c @@ -182,7 +182,7 @@ int flacSendChunk(FlacData * data) { while(data->cb->begin==data->cb->end && data->cb->wrap && !data->dc->stop && !data->dc->seek) { - usleep(10000); + my_usleep(10000); } if(data->dc->stop) return -1; diff --git a/src/interface.c b/src/interface.c index 2ef2fafe6..79445c380 100644 --- a/src/interface.c +++ b/src/interface.c @@ -27,13 +27,14 @@ #include "playlist.h" #include "permission.h" -#include #include #include #include +#include #include +#include +#include #include -#include #include #include #include diff --git a/src/mp3_decode.c b/src/mp3_decode.c index e2bf2f6bf..d1bbb0c32 100644 --- a/src/mp3_decode.c +++ b/src/mp3_decode.c @@ -407,7 +407,7 @@ int openMp3(char * file, mp3DecodeData * data) { int mp3ChildSendData(mp3DecodeData * data, Buffer * cb, DecoderControl * dc) { while(cb->begin==cb->end && cb->wrap && !dc->stop && !dc->seek) - usleep(10000); + my_usleep(10000); if(dc->stop) return -1; /* just for now, so it doesn't hang */ if(dc->seek) return 0; diff --git a/src/mp4_decode.c b/src/mp4_decode.c index a697a8b3d..73e99215a 100644 --- a/src/mp4_decode.c +++ b/src/mp4_decode.c @@ -285,7 +285,7 @@ int mp4_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) { while(cb->begin==cb->end && cb->wrap && !dc->stop && !dc->seek) { - usleep(10000); + my_usleep(10000); } if(dc->stop) { eof = 1; diff --git a/src/ogg_decode.c b/src/ogg_decode.c index ff8d2024c..e5a9d58d5 100644 --- a/src/ogg_decode.c +++ b/src/ogg_decode.c @@ -112,7 +112,7 @@ int ogg_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) while(cb->begin==cb->end && cb->wrap && !dc->stop && !dc->seek) { - usleep(10000); + my_usleep(10000); } if(dc->stop) break; else if(dc->seek) continue; diff --git a/src/player.c b/src/player.c index 138a54a49..e0628de6c 100644 --- a/src/player.c +++ b/src/player.c @@ -134,7 +134,7 @@ int playerInit() { pc->queueLockState = PLAYER_QUEUE_UNLOCKED; pc->unlockQueue = 0; } - else usleep(10000); + else my_usleep(10000); } exit(0); @@ -206,7 +206,7 @@ int playerPlay(FILE * fp, char * utf8file) { return -1; } - while(player_pid>0 && pc->play) usleep(1000); + while(player_pid>0 && pc->play) my_usleep(1000); return 0; } @@ -216,7 +216,7 @@ int playerStop(FILE * fp) { if(player_pid>0 && pc->state!=PLAYER_STATE_STOP) { pc->stop = 1; - while(player_pid>0 && pc->stop) usleep(1000); + while(player_pid>0 && pc->stop) my_usleep(1000); } pc->queueState = PLAYER_QUEUE_BLANK; @@ -242,7 +242,7 @@ int playerPause(FILE * fp) { if(player_pid>0 && pc->state!=PLAYER_STATE_STOP) { pc->pause = 1; - while(player_pid>0 && pc->pause) usleep(1000); + while(player_pid>0 && pc->pause) my_usleep(1000); } return 0; @@ -361,7 +361,7 @@ void playerQueueLock() { if(player_pid>0 && pc->queueLockState==PLAYER_QUEUE_UNLOCKED) { pc->lockQueue = 1; - while(player_pid>0 && pc->lockQueue) usleep(1000); + while(player_pid>0 && pc->lockQueue) my_usleep(1000); } } @@ -371,7 +371,7 @@ void playerQueueUnlock() { if(player_pid>0 && pc->queueLockState==PLAYER_QUEUE_LOCKED) { pc->unlockQueue = 1; - while(player_pid>0 && pc->unlockQueue) usleep(1000); + while(player_pid>0 && pc->unlockQueue) my_usleep(1000); } } @@ -403,7 +403,7 @@ int playerSeek(FILE * fp, char * utf8file, float time) { if(pc->error==PLAYER_ERROR_NOERROR) { pc->seekWhere = time; pc->seek = 1; - while(player_pid>0 && pc->seek) usleep(1000); + while(player_pid>0 && pc->seek) my_usleep(1000); } return 0; diff --git a/src/utils.c b/src/utils.c index 63c57de26..6e2d6e1e3 100644 --- a/src/utils.c +++ b/src/utils.c @@ -18,8 +18,13 @@ #include "utils.h" +#include #include #include +#include +#include +#include +#include char * myFgets(char * buffer, int bufferSize, FILE * fp) { char * ret = fgets(buffer,bufferSize,fp); @@ -43,3 +48,12 @@ void stripReturnChar(char * string) { *string = ' '; } } + +void my_usleep(long usec) { + struct timeval tv; + + tv.tv_sec = 0; + tv.tv_usec = usec; + + select(0,NULL,NULL,NULL,&tv); +} diff --git a/src/utils.h b/src/utils.h index 025f469e5..932f075db 100644 --- a/src/utils.h +++ b/src/utils.h @@ -29,4 +29,6 @@ char * strDupToUpper(char * str); void stripReturnChar(char * string); +void my_usleep(long usec); + #endif -- cgit v1.2.3