From 01cf7feac7bef8b28605b98ef1e7438a995fc554 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 6 Mar 2009 00:42:03 +0100 Subject: pipe: added music_buffer, rewrite music_pipe Turn the music_pipe into a simple music_chunk queue. The music_chunk allocation code is moved to music_buffer, and is now managed with a linked list instead of a ring buffer. Two separate music_pipe objects are used by the decoder for the "current" and the "next" song, which greatly simplifies the cross-fading code. --- src/decoder_internal.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'src/decoder_internal.c') diff --git a/src/decoder_internal.c b/src/decoder_internal.c index 93ad80e5e..120115ed2 100644 --- a/src/decoder_internal.c +++ b/src/decoder_internal.c @@ -21,6 +21,7 @@ #include "player_control.h" #include "pipe.h" #include "input_stream.h" +#include "buffer.h" #include @@ -46,35 +47,32 @@ need_chunks(struct input_stream *is, bool do_wait) } struct music_chunk * -decoder_get_chunk(struct decoder *decoder) +decoder_get_chunk(struct decoder *decoder, struct input_stream *is) { + enum decoder_command cmd; + assert(decoder != NULL); if (decoder->chunk != NULL) return decoder->chunk; - decoder->chunk = music_pipe_allocate(); - return decoder->chunk; + do { + decoder->chunk = music_buffer_allocate(dc.buffer); + if (decoder->chunk != NULL) + return decoder->chunk; + + cmd = need_chunks(is, true); + } while (cmd == DECODE_COMMAND_NONE); + + return NULL; } -enum decoder_command -decoder_flush_chunk(struct decoder *decoder, struct input_stream *is) +void +decoder_flush_chunk(struct decoder *decoder) { - bool success; - enum decoder_command cmd; - assert(decoder != NULL); assert(decoder->chunk != NULL); - while (true) { - success = music_pipe_push(decoder->chunk); - if (success) { - decoder->chunk = NULL; - return DECODE_COMMAND_NONE; - } - - cmd = need_chunks(is, true); - if (cmd != DECODE_COMMAND_NONE) - return cmd; - } + music_pipe_push(dc.pipe, decoder->chunk); + decoder->chunk = NULL; } -- cgit v1.2.3