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.
This commit is contained in:
Max Kellermann
2009-10-31 19:22:56 +01:00
parent 806496dfc9
commit 6ef428af2e
11 changed files with 377 additions and 317 deletions

View File

@@ -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;
}