Commit 56274fd0 authored by Eric Wong's avatar Eric Wong

Once again get rid of busy waiting and use SIGSTOP for pause

The problems I had were related to the OSS driver and USB device I was using. The problems existed even with the old busy-waiting scheme enabled. OSS - Bithead USB => bad ALSA - Bithead USB => OK OSS - Onboard i8x0 => OK ALSA - Onboard i8x0 => OK bad - slow shutdown, pauses, dropped audio after pause/resume git-svn-id: https://svn.musicpd.org/mpd/trunk@6861 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent 7024700c
...@@ -71,6 +71,7 @@ static void stopDecode(DecoderControl * dc) ...@@ -71,6 +71,7 @@ static void stopDecode(DecoderControl * dc)
{ {
if (decode_pid > 0 && (dc->start || dc->state != DECODE_STATE_STOP)) { if (decode_pid > 0 && (dc->start || dc->state != DECODE_STATE_STOP)) {
dc->stop = 1; dc->stop = 1;
kill(decode_pid, SIGCONT);
while (decode_pid > 0 && dc->stop) while (decode_pid > 0 && dc->stop)
my_usleep(10000); my_usleep(10000);
} }
...@@ -126,7 +127,8 @@ static int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af) ...@@ -126,7 +127,8 @@ static int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af)
ERROR("problems opening audio device while playing \"%s\"\n", pc->utf8url); \ ERROR("problems opening audio device while playing \"%s\"\n", pc->utf8url); \
quitDecode(pc,dc); \ quitDecode(pc,dc); \
return; \ return; \
} \ } else if (decode_pid > 0) { \
kill(decode_pid, SIGCONT); }\
if (pause) { \ if (pause) { \
dropBufferedAudio(); \ dropBufferedAudio(); \
closeAudioDevice(); \ closeAudioDevice(); \
...@@ -238,6 +240,8 @@ static int decodeSeek(PlayerControl * pc, DecoderControl * dc, ...@@ -238,6 +240,8 @@ static int decodeSeek(PlayerControl * pc, DecoderControl * dc,
pc->state = PLAYER_STATE_PAUSE; \ pc->state = PLAYER_STATE_PAUSE; \
} else { \ } else { \
if (openAudioDevice(NULL) >= 0) { \ if (openAudioDevice(NULL) >= 0) { \
if (decode_pid > 0) \
kill(decode_pid, SIGCONT); \
pc->state = PLAYER_STATE_PLAY; \ pc->state = PLAYER_STATE_PLAY; \
} else { \ } else { \
pathcpy_trunc(pc->erroredUrl, pc->utf8url); \ pathcpy_trunc(pc->erroredUrl, pc->utf8url); \
...@@ -579,9 +583,11 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer * ...@@ -579,9 +583,11 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer *
race conditions and weirdness */ race conditions and weirdness */
end = cb->end; end = cb->end;
if (pause) if (pause) {
my_usleep(10000); if (decode_pid)
else if (cb->begin != end && cb->begin != next) { kill(decode_pid, SIGSTOP);
kill(getpid(), SIGSTOP);
} else if (cb->begin != end && cb->begin != next) {
if (doCrossFade == 1 && next >= 0 && if (doCrossFade == 1 && next >= 0 &&
((next > cb->begin && ((next > cb->begin &&
(fadePosition = next - cb->begin) (fadePosition = next - cb->begin)
......
...@@ -231,6 +231,8 @@ int playerPlay(int fd, Song * song) ...@@ -231,6 +231,8 @@ int playerPlay(int fd, Song * song)
} }
resetPlayerMetadata(); resetPlayerMetadata();
if (player_pid > 0 && pc->state == PLAYER_STATE_PAUSE)
kill(player_pid, SIGCONT);
while (player_pid > 0 && pc->play) while (player_pid > 0 && pc->play)
my_usleep(1000); my_usleep(1000);
...@@ -243,6 +245,8 @@ int playerStop(int fd) ...@@ -243,6 +245,8 @@ int playerStop(int fd)
if (player_pid > 0 && pc->state != PLAYER_STATE_STOP) { if (player_pid > 0 && pc->state != PLAYER_STATE_STOP) {
pc->stop = 1; pc->stop = 1;
if (pc->state == PLAYER_STATE_PAUSE)
kill(player_pid, SIGCONT);
while (player_pid > 0 && pc->stop) while (player_pid > 0 && pc->stop)
my_usleep(1000); my_usleep(1000);
} }
...@@ -270,6 +274,8 @@ int playerPause(int fd) ...@@ -270,6 +274,8 @@ int playerPause(int fd)
if (player_pid > 0 && pc->state != PLAYER_STATE_STOP) { if (player_pid > 0 && pc->state != PLAYER_STATE_STOP) {
pc->pause = 1; pc->pause = 1;
if (player_pid > 0 && pc->state == PLAYER_STATE_PAUSE)
kill(player_pid, SIGCONT);
while (player_pid > 0 && pc->pause) while (player_pid > 0 && pc->pause)
my_usleep(1000); my_usleep(1000);
} }
...@@ -377,6 +383,8 @@ void playerCloseAudio(void) ...@@ -377,6 +383,8 @@ void playerCloseAudio(void)
if (playerStop(STDERR_FILENO) < 0) if (playerStop(STDERR_FILENO) < 0)
return; return;
pc->closeAudio = 1; pc->closeAudio = 1;
if (pc->state == PLAYER_STATE_PAUSE)
kill(player_pid, SIGCONT);
while (player_pid > 0 && pc->closeAudio) while (player_pid > 0 && pc->closeAudio)
my_usleep(1000); my_usleep(1000);
} }
...@@ -422,6 +430,8 @@ void playerQueueLock(void) ...@@ -422,6 +430,8 @@ void playerQueueLock(void)
PlayerControl *pc = &(getPlayerData()->playerControl); PlayerControl *pc = &(getPlayerData()->playerControl);
if (player_pid > 0 && pc->queueLockState == PLAYER_QUEUE_UNLOCKED) { if (player_pid > 0 && pc->queueLockState == PLAYER_QUEUE_UNLOCKED) {
if (pc->state == PLAYER_STATE_PAUSE)
kill(player_pid, SIGCONT);
pc->lockQueue = 1; pc->lockQueue = 1;
while (player_pid > 0 && pc->lockQueue) while (player_pid > 0 && pc->lockQueue)
my_usleep(1000); my_usleep(1000);
...@@ -433,6 +443,8 @@ void playerQueueUnlock(void) ...@@ -433,6 +443,8 @@ void playerQueueUnlock(void)
PlayerControl *pc = &(getPlayerData()->playerControl); PlayerControl *pc = &(getPlayerData()->playerControl);
if (player_pid > 0 && pc->queueLockState == PLAYER_QUEUE_LOCKED) { if (player_pid > 0 && pc->queueLockState == PLAYER_QUEUE_LOCKED) {
if (pc->state == PLAYER_STATE_PAUSE)
kill(player_pid, SIGCONT);
pc->unlockQueue = 1; pc->unlockQueue = 1;
while (player_pid > 0 && pc->unlockQueue) while (player_pid > 0 && pc->unlockQueue)
my_usleep(1000); my_usleep(1000);
...@@ -464,6 +476,8 @@ int playerSeek(int fd, Song * song, float time) ...@@ -464,6 +476,8 @@ int playerSeek(int fd, Song * song, float time)
resetPlayerMetadata(); resetPlayerMetadata();
pc->seekWhere = time; pc->seekWhere = time;
pc->seek = 1; pc->seek = 1;
if (player_pid > 0 && pc->state == PLAYER_STATE_PAUSE)
kill(player_pid, SIGCONT);
while (player_pid > 0 && pc->seek) while (player_pid > 0 && pc->seek)
my_usleep(1000); my_usleep(1000);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment