aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/decode.c47
-rw-r--r--src/player.c101
-rw-r--r--src/player.h21
-rw-r--r--src/playerData.c1
4 files changed, 93 insertions, 77 deletions
diff --git a/src/decode.c b/src/decode.c
index ec69a2f46..7b9df996d 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -60,9 +60,7 @@ static void quitDecode(void)
stopDecode();
pc.state = PLAYER_STATE_STOP;
dc.command = DECODE_COMMAND_NONE;
- pc.play = 0;
- pc.stop = 0;
- pc.pause = 0;
+ pc.command = PLAYER_COMMAND_NONE;
wakeup_main_task();
}
@@ -141,8 +139,8 @@ static int decodeSeek(int *decodeWaitedOn, int *next)
ret = 0;
}
}
- pc.seek = 0;
- wakeup_main_task();
+
+ player_command_finished();
return ret;
}
@@ -152,17 +150,24 @@ static void processDecodeInput(int *pause_r, unsigned int *bbp_r,
int *decodeWaitedOn_r,
int *next_r)
{
- if(pc.lockQueue) {
+ switch (pc.command) {
+ case PLAYER_COMMAND_NONE:
+ case PLAYER_COMMAND_PLAY:
+ case PLAYER_COMMAND_STOP:
+ case PLAYER_COMMAND_CLOSE_AUDIO:
+ break;
+
+ case PLAYER_COMMAND_LOCK_QUEUE:
pc.queueLockState = PLAYER_QUEUE_LOCKED;
- pc.lockQueue = 0;
- wakeup_main_task();
- }
- if(pc.unlockQueue) {
+ player_command_finished();
+ break;
+
+ case PLAYER_COMMAND_UNLOCK_QUEUE:
pc.queueLockState = PLAYER_QUEUE_UNLOCKED;
- pc.unlockQueue = 0;
- wakeup_main_task();
- }
- if(pc.pause) {
+ player_command_finished();
+ break;
+
+ case PLAYER_COMMAND_PAUSE:
*pause_r = !*pause_r;
if (*pause_r) {
pc.state = PLAYER_STATE_PAUSE;
@@ -179,21 +184,22 @@ static void processDecodeInput(int *pause_r, unsigned int *bbp_r,
*pause_r = -1;
}
}
- pc.pause = 0;
- wakeup_main_task();
+ player_command_finished();
if (*pause_r == -1) {
*pause_r = 1;
} else if (*pause_r) {
dropBufferedAudio();
closeAudioDevice();
}
- }
- if(pc.seek) {
+ break;
+
+ case PLAYER_COMMAND_SEEK:
dropBufferedAudio();
if (decodeSeek(decodeWaitedOn_r, next_r) == 0) {
*do_xfade_r = XFADE_UNKNOWN;
*bbp_r = 0;
}
+ break;
}
}
@@ -410,13 +416,12 @@ static void decodeParent(void)
pc.elapsedTime = 0;
pc.state = PLAYER_STATE_PLAY;
- pc.play = 0;
- wakeup_main_task();
+ player_command_finished();
while (1) {
processDecodeInput(&do_pause, &bbp, &do_xfade,
&decodeWaitedOn, &next);
- if (pc.stop) {
+ if (pc.command == PLAYER_COMMAND_STOP) {
dropBufferedAudio();
break;
}
diff --git a/src/player.c b/src/player.c
index fd6d9ffbf..bcecce79a 100644
--- a/src/player.c
+++ b/src/player.c
@@ -28,41 +28,41 @@
static void playerCloseAudio(void);
-static void wakeup_player(void)
-{
- notify_signal(&pc.notify);
- wait_main_task();
-}
-
static void * player_task(mpd_unused void *arg)
{
notify_enter(&pc.notify);
while (1) {
- if (pc.play) {
+ switch (pc.command) {
+ case PLAYER_COMMAND_PLAY:
decode();
- continue; /* decode() calls wakeup_main_task */
- } else if (pc.stop) {
- pc.stop = 0;
- } else if (pc.seek) {
- pc.seek = 0;
- } else if (pc.pause) {
- pc.pause = 0;
- } else if (pc.closeAudio) {
+ break;
+
+ case PLAYER_COMMAND_STOP:
+ case PLAYER_COMMAND_SEEK:
+ case PLAYER_COMMAND_PAUSE:
+ player_command_finished();
+ break;
+
+ case PLAYER_COMMAND_CLOSE_AUDIO:
closeAudioDevice();
- pc.closeAudio = 0;
- } else if (pc.lockQueue) {
+ player_command_finished();
+ break;
+
+ case PLAYER_COMMAND_LOCK_QUEUE:
pc.queueLockState = PLAYER_QUEUE_LOCKED;
- pc.lockQueue = 0;
- } else if (pc.unlockQueue) {
+ player_command_finished();
+ break;
+
+ case PLAYER_COMMAND_UNLOCK_QUEUE:
pc.queueLockState = PLAYER_QUEUE_UNLOCKED;
- pc.unlockQueue = 0;
- } else {
+ player_command_finished();
+ break;
+
+ case PLAYER_COMMAND_NONE:
notify_wait(&pc.notify);
- continue;
+ break;
}
- /* we did something, tell the main task about it */
- wakeup_main_task();
}
return NULL;
}
@@ -94,26 +94,37 @@ static void set_current_song(Song *song)
pc.next_song = song;
}
+static void player_command(enum player_command cmd)
+{
+ pc.command = cmd;
+ while (pc.command != PLAYER_COMMAND_NONE)
+ /* FIXME: _nb() variant is probably wrong here, and everywhere... */
+ notify_signal(&pc.notify);
+}
+
+void player_command_finished()
+{
+ assert(pc.command != PLAYER_COMMAND_NONE);
+
+ pc.command = PLAYER_COMMAND_NONE;
+ wakeup_main_task();
+}
+
int playerPlay(int fd, Song * song)
{
if (playerStop(fd) < 0)
return -1;
set_current_song(song);
-
- pc.play = 1;
- /* FIXME: _nb() variant is probably wrong here, and everywhere... */
- do { notify_signal(&pc.notify); } while (pc.play);
+ player_command(PLAYER_COMMAND_PLAY);
return 0;
}
int playerStop(mpd_unused int fd)
{
- if (pc.state != PLAYER_STATE_STOP) {
- pc.stop = 1;
- do { wakeup_player(); } while (pc.stop);
- }
+ if (pc.state != PLAYER_STATE_STOP)
+ player_command(PLAYER_COMMAND_STOP);
pc.queueState = PLAYER_QUEUE_BLANK;
playerQueueUnlock();
@@ -128,10 +139,8 @@ void playerKill(void) /* deprecated */
int playerPause(mpd_unused int fd)
{
- if (pc.state != PLAYER_STATE_STOP) {
- pc.pause = 1;
- do { wakeup_player(); } while (pc.pause);
- }
+ if (pc.state != PLAYER_STATE_STOP)
+ player_command(PLAYER_COMMAND_PAUSE);
return 0;
}
@@ -217,8 +226,8 @@ static void playerCloseAudio(void)
{
if (playerStop(STDERR_FILENO) < 0)
return;
- pc.closeAudio = 1;
- do { wakeup_player(); } while (pc.closeAudio);
+
+ player_command(PLAYER_COMMAND_CLOSE_AUDIO);
}
int queueSong(Song * song)
@@ -245,18 +254,14 @@ void setQueueState(int queueState)
void playerQueueLock(void)
{
- if (pc.queueLockState == PLAYER_QUEUE_UNLOCKED) {
- pc.lockQueue = 1;
- do { wakeup_player(); } while (pc.lockQueue);
- }
+ if (pc.queueLockState == PLAYER_QUEUE_UNLOCKED)
+ player_command(PLAYER_COMMAND_LOCK_QUEUE);
}
void playerQueueUnlock(void)
{
- if (pc.queueLockState == PLAYER_QUEUE_LOCKED) {
- pc.unlockQueue = 1;
- do { wakeup_player(); } while (pc.unlockQueue);
- }
+ if (pc.queueLockState == PLAYER_QUEUE_LOCKED)
+ player_command(PLAYER_COMMAND_UNLOCK_QUEUE);
}
int playerSeek(int fd, Song * song, float seek_time)
@@ -274,9 +279,7 @@ int playerSeek(int fd, Song * song, float seek_time)
if (pc.error == PLAYER_ERROR_NOERROR) {
pc.seekWhere = seek_time;
- pc.seek = 1;
- /* FIXME: _nb() is probably wrong here, too */
- do { notify_signal(&pc.notify); } while (pc.seek);
+ player_command(PLAYER_COMMAND_SEEK);
}
return 0;
diff --git a/src/player.h b/src/player.h
index e204639e7..aee3b7264 100644
--- a/src/player.h
+++ b/src/player.h
@@ -28,6 +28,17 @@
#define PLAYER_STATE_PAUSE 1
#define PLAYER_STATE_PLAY 2
+enum player_command {
+ PLAYER_COMMAND_NONE = 0,
+ PLAYER_COMMAND_STOP,
+ PLAYER_COMMAND_PLAY,
+ PLAYER_COMMAND_PAUSE,
+ PLAYER_COMMAND_SEEK,
+ PLAYER_COMMAND_CLOSE_AUDIO,
+ PLAYER_COMMAND_LOCK_QUEUE,
+ PLAYER_COMMAND_UNLOCK_QUEUE
+};
+
#define PLAYER_ERROR_NOERROR 0
#define PLAYER_ERROR_FILE 1
#define PLAYER_ERROR_AUDIO 2
@@ -50,11 +61,8 @@
typedef struct _PlayerControl {
Notify notify;
- volatile mpd_sint8 stop;
- volatile mpd_sint8 play;
- volatile mpd_sint8 pause;
+ volatile enum player_command command;
volatile mpd_sint8 state;
- volatile mpd_sint8 closeAudio;
volatile mpd_sint8 error;
volatile mpd_uint16 bitRate;
volatile mpd_sint8 bits;
@@ -67,15 +75,14 @@ typedef struct _PlayerControl {
Song *errored_song;
volatile mpd_sint8 queueState;
volatile mpd_sint8 queueLockState;
- volatile mpd_sint8 lockQueue;
- volatile mpd_sint8 unlockQueue;
- volatile mpd_sint8 seek;
volatile double seekWhere;
volatile float crossFade;
volatile mpd_uint16 softwareVolume;
volatile double totalPlayTime;
} PlayerControl;
+void player_command_finished(void);
+
int playerPlay(int fd, Song * song);
int playerSetPause(int fd, int pause_flag);
diff --git a/src/playerData.c b/src/playerData.c
index 6af3c5955..441fe883f 100644
--- a/src/playerData.c
+++ b/src/playerData.c
@@ -75,6 +75,7 @@ void initPlayerData(void)
ob_init(buffered_chunks, &pc.notify);
notify_init(&pc.notify);
+ pc.command = PLAYER_COMMAND_NONE;
pc.error = PLAYER_ERROR_NOERROR;
pc.state = PLAYER_STATE_STOP;
pc.queueState = PLAYER_QUEUE_BLANK;