use our own portable version of usleep using select()

git-svn-id: https://svn.musicpd.org/mpd/trunk@578 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes 2004-04-01 03:48:51 +00:00
parent 917af619da
commit 3ab9841764
11 changed files with 41 additions and 24 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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; \

View File

@ -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;

View File

@ -27,13 +27,14 @@
#include "playlist.h"
#include "permission.h"
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/time.h>
#include <sys/param.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -18,8 +18,13 @@
#include "utils.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
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);
}

View File

@ -29,4 +29,6 @@ char * strDupToUpper(char * str);
void stripReturnChar(char * string);
void my_usleep(long usec);
#endif