aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder_api.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-03-06 00:42:01 +0100
committerMax Kellermann <max@duempel.org>2009-03-06 00:42:01 +0100
commit000b2d4f3a9c4f761ab918aaff4705621bb8559f (patch)
tree5009a5548c99155e00b4b14d52f50728a337960f /src/decoder_api.c
parent10be8a8714b49bec5e6f869975962cbc26cebe61 (diff)
downloadmpd-000b2d4f3a9c4f761ab918aaff4705621bb8559f.tar.gz
mpd-000b2d4f3a9c4f761ab918aaff4705621bb8559f.tar.xz
mpd-000b2d4f3a9c4f761ab918aaff4705621bb8559f.zip
music_pipe: added music_pipe_push()
Added music_pipe_allocate(), music_pipe_push() and music_pipe_cancel(). Those functions allow the caller (decoder thread in this case) to do its own chunk management. The functions music_pipe_flush() and music_pipe_tag() can now be removed.
Diffstat (limited to '')
-rw-r--r--src/decoder_api.c78
1 files changed, 45 insertions, 33 deletions
diff --git a/src/decoder_api.c b/src/decoder_api.c
index e6ea44088..88864befa 100644
--- a/src/decoder_api.c
+++ b/src/decoder_api.c
@@ -26,6 +26,7 @@
#include "normalize.h"
#include "pipe.h"
+#include "chunk.h"
#include <glib.h>
@@ -85,9 +86,16 @@ void decoder_command_finished(G_GNUC_UNUSED struct decoder * decoder)
assert(dc.command != DECODE_COMMAND_SEEK ||
dc.seek_error || decoder->seeking);
- if (dc.command == DECODE_COMMAND_SEEK)
+ if (dc.command == DECODE_COMMAND_SEEK) {
/* delete frames from the old song position */
+
+ if (decoder->chunk != NULL) {
+ music_pipe_cancel(decoder->chunk);
+ decoder->chunk = NULL;
+ }
+
music_pipe_clear();
+ }
dc.command = DECODE_COMMAND_NONE;
notify_signal(&pc.notify);
@@ -147,35 +155,28 @@ size_t decoder_read(struct decoder *decoder,
}
/**
- * All chunks are full of decoded data; wait for the player to free
- * one.
+ * Sends a #tag as-is to the music pipe. Flushes the current chunk
+ * (decoder.chunk) if there is one.
*/
static enum decoder_command
-need_chunks(struct input_stream *is, bool do_wait)
+do_send_tag(struct decoder *decoder, struct input_stream *is,
+ const struct tag *tag)
{
- if (dc.command == DECODE_COMMAND_STOP ||
- dc.command == DECODE_COMMAND_SEEK)
- return dc.command;
-
- if ((is == NULL || input_stream_buffer(is) <= 0) && do_wait) {
- notify_wait(&dc.notify);
- notify_signal(&pc.notify);
-
- return dc.command;
- }
+ struct music_chunk *chunk;
- return DECODE_COMMAND_NONE;
-}
-
-static enum decoder_command
-do_send_tag(struct input_stream *is, const struct tag *tag)
-{
- while (!music_pipe_tag(tag)) {
- enum decoder_command cmd = need_chunks(is, true);
+ 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;
}
+ assert(decoder->chunk == NULL);
+
+ chunk = decoder_get_chunk(decoder);
+ chunk->tag = tag_dup(tag);
return DECODE_COMMAND_NONE;
}
@@ -226,11 +227,11 @@ decoder_data(struct decoder *decoder,
tag = tag_merge(decoder->stream_tag,
decoder->decoder_tag);
- cmd = do_send_tag(is, tag);
+ cmd = do_send_tag(decoder, is, tag);
tag_free(tag);
} else
/* send only the stream tag */
- cmd = do_send_tag(is, decoder->stream_tag);
+ cmd = do_send_tag(decoder, is, decoder->stream_tag);
if (cmd != DECODE_COMMAND_NONE)
return cmd;
@@ -250,14 +251,18 @@ decoder_data(struct decoder *decoder,
}
while (length > 0) {
+ struct music_chunk *chunk;
+ char *dest;
size_t nbytes;
- char *dest = music_pipe_write(&dc.out_audio_format,
- data_time, bitRate,
- &nbytes);
+ bool full;
+
+ chunk = decoder_get_chunk(decoder);
+ dest = music_chunk_write(chunk, &dc.out_audio_format,
+ data_time, bitRate, &nbytes);
if (dest == NULL) {
- /* the music pipe is full: wait for more
- room */
- enum decoder_command cmd = need_chunks(is, true);
+ /* the chunk is full, flush it */
+ enum decoder_command cmd =
+ decoder_flush_chunk(decoder, is);
if (cmd != DECODE_COMMAND_NONE)
return cmd;
continue;
@@ -283,7 +288,14 @@ decoder_data(struct decoder *decoder,
/* expand the music pipe chunk */
- music_pipe_expand(&dc.out_audio_format, nbytes);
+ 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;
+ }
data += nbytes;
length -= nbytes;
@@ -318,11 +330,11 @@ decoder_tag(G_GNUC_UNUSED struct decoder *decoder, struct input_stream *is,
struct tag *merged;
merged = tag_merge(decoder->stream_tag, decoder->decoder_tag);
- cmd = do_send_tag(is, merged);
+ cmd = do_send_tag(decoder, is, merged);
tag_free(merged);
} else
/* send only the decoder tag */
- cmd = do_send_tag(is, tag);
+ cmd = do_send_tag(decoder, is, tag);
return cmd;
}