aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder_internal.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-10-31 19:22:56 +0100
committerMax Kellermann <max@duempel.org>2009-10-31 19:22:56 +0100
commit6ef428af2e554089bc3ba4104b714cfb36bfc719 (patch)
tree949ac8f4abc93d86de2fb8391b30df6db6eae63b /src/decoder_internal.c
parent806496dfc937d9b55e00672d42928a25cfa67c90 (diff)
downloadmpd-6ef428af2e554089bc3ba4104b714cfb36bfc719.tar.gz
mpd-6ef428af2e554089bc3ba4104b714cfb36bfc719.tar.xz
mpd-6ef428af2e554089bc3ba4104b714cfb36bfc719.zip
decoder_control: removed the global variable "dc"
Allocate a decoder_control object where needed, and pass it around. This will allow more than one decoder thread one day.
Diffstat (limited to 'src/decoder_internal.c')
-rw-r--r--src/decoder_internal.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/src/decoder_internal.c b/src/decoder_internal.c
index db90333b4..d40ef89d7 100644
--- a/src/decoder_internal.c
+++ b/src/decoder_internal.c
@@ -34,13 +34,13 @@
* potentially blocking operation.
*/
static int
-decoder_input_buffer(struct input_stream *is)
+decoder_input_buffer(struct decoder_control *dc, struct input_stream *is)
{
int ret;
- decoder_unlock();
+ decoder_unlock(dc);
ret = input_stream_buffer(is) > 0;
- decoder_lock();
+ decoder_lock(dc);
return ret;
}
@@ -50,17 +50,17 @@ decoder_input_buffer(struct input_stream *is)
* one.
*/
static enum decoder_command
-need_chunks(struct input_stream *is, bool do_wait)
+need_chunks(struct decoder_control *dc, struct input_stream *is, bool do_wait)
{
- if (dc.command == DECODE_COMMAND_STOP ||
- dc.command == DECODE_COMMAND_SEEK)
- return dc.command;
+ if (dc->command == DECODE_COMMAND_STOP ||
+ dc->command == DECODE_COMMAND_SEEK)
+ return dc->command;
- if ((is == NULL || decoder_input_buffer(is) <= 0) && do_wait) {
- decoder_wait();
+ if ((is == NULL || decoder_input_buffer(dc, is) <= 0) && do_wait) {
+ decoder_wait(dc);
player_signal();
- return dc.command;
+ return dc->command;
}
return DECODE_COMMAND_NONE;
@@ -69,6 +69,7 @@ need_chunks(struct input_stream *is, bool do_wait)
struct music_chunk *
decoder_get_chunk(struct decoder *decoder, struct input_stream *is)
{
+ struct decoder_control *dc = decoder->dc;
enum decoder_command cmd;
assert(decoder != NULL);
@@ -77,13 +78,13 @@ decoder_get_chunk(struct decoder *decoder, struct input_stream *is)
return decoder->chunk;
do {
- decoder->chunk = music_buffer_allocate(dc.buffer);
+ decoder->chunk = music_buffer_allocate(dc->buffer);
if (decoder->chunk != NULL)
return decoder->chunk;
- decoder_lock();
- cmd = need_chunks(is, true);
- decoder_unlock();
+ decoder_lock(dc);
+ cmd = need_chunks(dc, is, true);
+ decoder_unlock(dc);
} while (cmd == DECODE_COMMAND_NONE);
return NULL;
@@ -92,13 +93,15 @@ decoder_get_chunk(struct decoder *decoder, struct input_stream *is)
void
decoder_flush_chunk(struct decoder *decoder)
{
+ struct decoder_control *dc = decoder->dc;
+
assert(decoder != NULL);
assert(decoder->chunk != NULL);
if (music_chunk_is_empty(decoder->chunk))
- music_buffer_return(dc.buffer, decoder->chunk);
+ music_buffer_return(dc->buffer, decoder->chunk);
else
- music_pipe_push(dc.pipe, decoder->chunk);
+ music_pipe_push(dc->pipe, decoder->chunk);
decoder->chunk = NULL;
}