diff options
Diffstat (limited to 'src/decoder_control.c')
-rw-r--r-- | src/decoder_control.c | 60 |
1 files changed, 44 insertions, 16 deletions
diff --git a/src/decoder_control.c b/src/decoder_control.c index 44bb63e15..d7f5808fc 100644 --- a/src/decoder_control.c +++ b/src/decoder_control.c @@ -18,6 +18,7 @@ */ #include "decoder_control.h" +#include "player_control.h" #include <assert.h> @@ -25,46 +26,69 @@ struct decoder_control dc; void dc_init(void) { - notify_init(&dc.notify); + dc.mutex = g_mutex_new(); + dc.cond = g_cond_new(); + dc.state = DECODE_STATE_STOP; dc.command = DECODE_COMMAND_NONE; } void dc_deinit(void) { - notify_deinit(&dc.notify); + g_cond_free(dc.cond); + g_mutex_free(dc.mutex); } -void -dc_command_wait(struct notify *notify) +static void +dc_command_wait_locked(void) { while (dc.command != DECODE_COMMAND_NONE) { - notify_signal(&dc.notify); - notify_wait(notify); + decoder_signal(); + player_wait_decoder(); } } +void +dc_command_wait(void) +{ + decoder_lock(); + dc_command_wait_locked(); + decoder_unlock(); +} + static void -dc_command(struct notify *notify, enum decoder_command cmd) +dc_command_locked(enum decoder_command cmd) { dc.command = cmd; - dc_command_wait(notify); + dc_command_wait_locked(); +} + +static void +dc_command(enum decoder_command cmd) +{ + decoder_lock(); + dc_command_locked(cmd); + decoder_unlock(); } static void dc_command_async(enum decoder_command cmd) { + decoder_lock(); + dc.command = cmd; - notify_signal(&dc.notify); + decoder_signal(); + + decoder_unlock(); } void -dc_start(struct notify *notify, struct song *song) +dc_start(struct song *song) { assert(dc.pipe != NULL); assert(song != NULL); dc.next_song = song; - dc_command(notify, DECODE_COMMAND_START); + dc_command(DECODE_COMMAND_START); } void @@ -78,21 +102,25 @@ dc_start_async(struct song *song) } void -dc_stop(struct notify *notify) +dc_stop(void) { + decoder_lock(); + if (dc.command != DECODE_COMMAND_NONE) /* Attempt to cancel the current command. If it's too late and the decoder thread is already executing the old command, we'll call STOP again in this function (see below). */ - dc_command(notify, DECODE_COMMAND_STOP); + dc_command_locked(DECODE_COMMAND_STOP); if (dc.state != DECODE_STATE_STOP && dc.state != DECODE_STATE_ERROR) - dc_command(notify, DECODE_COMMAND_STOP); + dc_command_locked(DECODE_COMMAND_STOP); + + decoder_unlock(); } bool -dc_seek(struct notify *notify, double where) +dc_seek(double where) { assert(dc.state != DECODE_STATE_START); assert(where >= 0.0); @@ -103,7 +131,7 @@ dc_seek(struct notify *notify, double where) dc.seek_where = where; dc.seek_error = false; - dc_command(notify, DECODE_COMMAND_SEEK); + dc_command(DECODE_COMMAND_SEEK); if (dc.seek_error) return false; |