aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-10-31 17:02:12 +0100
committerMax Kellermann <max@duempel.org>2009-10-31 17:02:12 +0100
commit25a806a347ce420126eb75d82c5fb875eb0a5e0d (patch)
tree0d39bed8c073a720acd42f17b04dbee91b0a8c01 /src/decoder
parent73cff374fd94a1c16e0201fcda020396c0f41962 (diff)
downloadmpd-25a806a347ce420126eb75d82c5fb875eb0a5e0d.tar.gz
mpd-25a806a347ce420126eb75d82c5fb875eb0a5e0d.tar.xz
mpd-25a806a347ce420126eb75d82c5fb875eb0a5e0d.zip
player_control: protect command, state, error with a mutex
Use GMutex/GCond instead of the notify library. Manually lock the player_control object before accessing the protected attributes. Use the GCond object to notify the player thread and the main thread.
Diffstat (limited to '')
-rw-r--r--src/decoder_api.c10
-rw-r--r--src/decoder_control.c36
-rw-r--r--src/decoder_control.h10
-rw-r--r--src/decoder_internal.c5
-rw-r--r--src/decoder_thread.c12
5 files changed, 29 insertions, 44 deletions
diff --git a/src/decoder_api.c b/src/decoder_api.c
index 4cff9916c..070151a67 100644
--- a/src/decoder_api.c
+++ b/src/decoder_api.c
@@ -61,7 +61,7 @@ void decoder_initialized(G_GNUC_UNUSED struct decoder * decoder,
dc.state = DECODE_STATE_DECODE;
decoder_unlock();
- notify_signal(&pc.notify);
+ player_lock_signal();
g_debug("audio_format=%u:%u:%u, seekable=%s",
dc.in_audio_format.sample_rate, dc.in_audio_format.bits,
@@ -112,7 +112,7 @@ void decoder_command_finished(G_GNUC_UNUSED struct decoder * decoder)
dc.command = DECODE_COMMAND_NONE;
decoder_unlock();
- notify_signal(&pc.notify);
+ player_lock_signal();
}
double decoder_seek_where(G_GNUC_UNUSED struct decoder * decoder)
@@ -184,7 +184,7 @@ do_send_tag(struct decoder *decoder, struct input_stream *is,
/* there is a partial chunk - flush it, we want the
tag in a new chunk */
decoder_flush_chunk(decoder);
- notify_signal(&pc.notify);
+ player_lock_signal();
}
assert(decoder->chunk == NULL);
@@ -297,7 +297,7 @@ decoder_data(struct decoder *decoder,
if (dest == NULL) {
/* the chunk is full, flush it */
decoder_flush_chunk(decoder);
- notify_signal(&pc.notify);
+ player_lock_signal();
continue;
}
@@ -324,7 +324,7 @@ decoder_data(struct decoder *decoder,
if (full) {
/* the chunk is full, flush it */
decoder_flush_chunk(decoder);
- notify_signal(&pc.notify);
+ player_lock_signal();
}
data += nbytes;
diff --git a/src/decoder_control.c b/src/decoder_control.c
index 3b993431c..d7f5808fc 100644
--- a/src/decoder_control.c
+++ b/src/decoder_control.c
@@ -18,7 +18,7 @@
*/
#include "decoder_control.h"
-#include "notify.h"
+#include "player_control.h"
#include <assert.h>
@@ -40,38 +40,34 @@ void dc_deinit(void)
}
static void
-dc_command_wait_locked(struct notify *notify)
+dc_command_wait_locked(void)
{
while (dc.command != DECODE_COMMAND_NONE) {
decoder_signal();
- decoder_unlock();
-
- notify_wait(notify);
-
- decoder_lock();
+ player_wait_decoder();
}
}
void
-dc_command_wait(struct notify *notify)
+dc_command_wait(void)
{
decoder_lock();
- dc_command_wait_locked(notify);
+ dc_command_wait_locked();
decoder_unlock();
}
static void
-dc_command_locked(struct notify *notify, enum decoder_command cmd)
+dc_command_locked(enum decoder_command cmd)
{
dc.command = cmd;
- dc_command_wait_locked(notify);
+ dc_command_wait_locked();
}
static void
-dc_command(struct notify *notify, enum decoder_command cmd)
+dc_command(enum decoder_command cmd)
{
decoder_lock();
- dc_command_locked(notify, cmd);
+ dc_command_locked(cmd);
decoder_unlock();
}
@@ -86,13 +82,13 @@ static void dc_command_async(enum decoder_command cmd)
}
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
@@ -106,7 +102,7 @@ dc_start_async(struct song *song)
}
void
-dc_stop(struct notify *notify)
+dc_stop(void)
{
decoder_lock();
@@ -115,16 +111,16 @@ dc_stop(struct notify *notify)
late and the decoder thread is already executing
the old command, we'll call STOP again in this
function (see below). */
- dc_command_locked(notify, DECODE_COMMAND_STOP);
+ dc_command_locked(DECODE_COMMAND_STOP);
if (dc.state != DECODE_STATE_STOP && dc.state != DECODE_STATE_ERROR)
- dc_command_locked(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);
@@ -135,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;
diff --git a/src/decoder_control.h b/src/decoder_control.h
index 7e861f970..6b65da2f2 100644
--- a/src/decoder_control.h
+++ b/src/decoder_control.h
@@ -30,8 +30,6 @@
#define DECODE_TYPE_FILE 0
#define DECODE_TYPE_URL 1
-struct notify;
-
enum decoder_state {
DECODE_STATE_STOP = 0,
DECODE_STATE_START,
@@ -205,19 +203,19 @@ decoder_current_song(void)
}
void
-dc_command_wait(struct notify *notify);
+dc_command_wait(void);
void
-dc_start(struct notify *notify, struct song *song);
+dc_start(struct song *song);
void
dc_start_async(struct song *song);
void
-dc_stop(struct notify *notify);
+dc_stop(void);
bool
-dc_seek(struct notify *notify, double where);
+dc_seek(double where);
void
dc_quit(void);
diff --git a/src/decoder_internal.c b/src/decoder_internal.c
index 1b064d0aa..db90333b4 100644
--- a/src/decoder_internal.c
+++ b/src/decoder_internal.c
@@ -58,10 +58,7 @@ need_chunks(struct input_stream *is, bool do_wait)
if ((is == NULL || decoder_input_buffer(is) <= 0) && do_wait) {
decoder_wait();
-
- decoder_unlock();
- notify_signal(&pc.notify);
- decoder_lock();
+ player_signal();
return dc.command;
}
diff --git a/src/decoder_thread.c b/src/decoder_thread.c
index 846b12353..712e4d20c 100644
--- a/src/decoder_thread.c
+++ b/src/decoder_thread.c
@@ -112,9 +112,7 @@ static void decoder_run_song(const struct song *song, const char *uri)
dc.state = DECODE_STATE_START;
dc.command = DECODE_COMMAND_NONE;
- decoder_unlock();
- notify_signal(&pc.notify);
- decoder_lock();
+ player_signal();
/* wait for the input stream to become ready; its metadata
will be available then */
@@ -294,17 +292,13 @@ static gpointer decoder_task(G_GNUC_UNUSED gpointer arg)
dc.command = DECODE_COMMAND_NONE;
- decoder_unlock();
- notify_signal(&pc.notify);
- decoder_lock();
+ player_signal();
break;
case DECODE_COMMAND_STOP:
dc.command = DECODE_COMMAND_NONE;
- decoder_unlock();
- notify_signal(&pc.notify);
- decoder_lock();
+ player_signal();
break;
case DECODE_COMMAND_NONE: