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_api.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'src/decoder_api.c') diff --git a/src/decoder_api.c b/src/decoder_api.c index 88864befa..0992eac9a 100644 --- a/src/decoder_api.c +++ b/src/decoder_api.c @@ -23,6 +23,7 @@ #include "player_control.h" #include "audio.h" #include "song.h" +#include "buffer.h" #include "normalize.h" #include "pipe.h" @@ -90,11 +91,11 @@ void decoder_command_finished(G_GNUC_UNUSED struct decoder * decoder) /* delete frames from the old song position */ if (decoder->chunk != NULL) { - music_pipe_cancel(decoder->chunk); + music_buffer_return(dc.buffer, decoder->chunk); decoder->chunk = NULL; } - music_pipe_clear(); + music_pipe_clear(dc.pipe, dc.buffer); } dc.command = DECODE_COMMAND_NONE; @@ -167,15 +168,18 @@ do_send_tag(struct decoder *decoder, struct input_stream *is, if (decoder->chunk != NULL) { /* there is a partial chunk - flush it, we want the tag in a new chunk */ - enum decoder_command cmd = - decoder_flush_chunk(decoder, is); - if (cmd != DECODE_COMMAND_NONE) - return cmd; + decoder_flush_chunk(decoder); + notify_signal(&pc.notify); } assert(decoder->chunk == NULL); - chunk = decoder_get_chunk(decoder); + chunk = decoder_get_chunk(decoder, is); + if (chunk == NULL) { + assert(dc.command != DECODE_COMMAND_NONE); + return dc.command; + } + chunk->tag = tag_dup(tag); return DECODE_COMMAND_NONE; } @@ -256,15 +260,18 @@ decoder_data(struct decoder *decoder, size_t nbytes; bool full; - chunk = decoder_get_chunk(decoder); + chunk = decoder_get_chunk(decoder, is); + if (chunk == NULL) { + assert(dc.command != DECODE_COMMAND_NONE); + return dc.command; + } + dest = music_chunk_write(chunk, &dc.out_audio_format, data_time, bitRate, &nbytes); if (dest == NULL) { /* the chunk is full, flush it */ - enum decoder_command cmd = - decoder_flush_chunk(decoder, is); - if (cmd != DECODE_COMMAND_NONE) - return cmd; + decoder_flush_chunk(decoder); + notify_signal(&pc.notify); continue; } @@ -291,10 +298,8 @@ decoder_data(struct decoder *decoder, full = music_chunk_expand(chunk, &dc.out_audio_format, nbytes); if (full) { /* the chunk is full, flush it */ - enum decoder_command cmd = - decoder_flush_chunk(decoder, is); - if (cmd != DECODE_COMMAND_NONE) - return cmd; + decoder_flush_chunk(decoder); + notify_signal(&pc.notify); } data += nbytes; -- cgit v1.2.3