diff options
author | Max Kellermann <max@duempel.org> | 2009-03-06 00:42:03 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-03-06 00:42:03 +0100 |
commit | 01cf7feac7bef8b28605b98ef1e7438a995fc554 (patch) | |
tree | e1c4b7f5d0550d60d7fda8b4909353a47490fa4e /src/decoder | |
parent | 000b2d4f3a9c4f761ab918aaff4705621bb8559f (diff) | |
download | mpd-01cf7feac7bef8b28605b98ef1e7438a995fc554.tar.gz mpd-01cf7feac7bef8b28605b98ef1e7438a995fc554.tar.xz mpd-01cf7feac7bef8b28605b98ef1e7438a995fc554.zip |
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.
Diffstat (limited to '')
-rw-r--r-- | src/decoder_api.c | 37 | ||||
-rw-r--r-- | src/decoder_control.h | 6 | ||||
-rw-r--r-- | src/decoder_internal.c | 36 | ||||
-rw-r--r-- | src/decoder_internal.h | 13 | ||||
-rw-r--r-- | src/decoder_thread.c | 5 |
5 files changed, 52 insertions, 45 deletions
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; diff --git a/src/decoder_control.h b/src/decoder_control.h index d1d0625e1..f981074d4 100644 --- a/src/decoder_control.h +++ b/src/decoder_control.h @@ -66,6 +66,12 @@ struct decoder_control { struct song *current_song; struct song *next_song; float total_time; + + /** the #music_chunk allocator */ + struct music_buffer *buffer; + + /** the destination pipe for decoded chunks */ + struct music_pipe *pipe; }; extern struct decoder_control dc; 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 <assert.h> @@ -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; } diff --git a/src/decoder_internal.h b/src/decoder_internal.h index ab52ab037..cf46eb2c9 100644 --- a/src/decoder_internal.h +++ b/src/decoder_internal.h @@ -42,17 +42,16 @@ struct decoder { /** * Returns the current chunk the decoder writes to, or allocates a new * chunk if there is none. + * + * @return the chunk, or NULL if we have received a decoder command */ struct music_chunk * -decoder_get_chunk(struct decoder *decoder); +decoder_get_chunk(struct decoder *decoder, struct input_stream *is); /** - * Flushes a chunk. Waits for room in the music pipe if required. - * - * @return DECODE_COMMAND_NONE on success, any other command if we - * have received a decoder command while waiting + * Flushes the current chunk. */ -enum decoder_command -decoder_flush_chunk(struct decoder *decoder, struct input_stream *is); +void +decoder_flush_chunk(struct decoder *decoder); #endif diff --git a/src/decoder_thread.c b/src/decoder_thread.c index 97e92d295..a48f4160b 100644 --- a/src/decoder_thread.c +++ b/src/decoder_thread.c @@ -196,9 +196,8 @@ static void decoder_run_song(const struct song *song, const char *uri) pcm_convert_deinit(&decoder.conv_state); /* flush the last chunk */ - if (decoder.chunk != NULL && - decoder_flush_chunk(&decoder, NULL) != DECODE_COMMAND_NONE) - music_pipe_cancel(decoder.chunk); + if (decoder.chunk != NULL) + decoder_flush_chunk(&decoder); if (close_instream) input_stream_close(&input_stream); |