From 2860b1b60fdb99c714bf4041797982c4c32b594e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 13 Nov 2008 02:54:56 +0100 Subject: [PATCH] decoder: wait for the player only if the music pipe is full Prevent superfluous wakeups and a deadlock condition. --- src/decoder_api.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/decoder_api.c b/src/decoder_api.c index c8a13709c..ab8a5f961 100644 --- a/src/decoder_api.c +++ b/src/decoder_api.c @@ -159,13 +159,13 @@ tag_add_stream_tags(const struct tag *src_tag, const struct input_stream *is) * one. */ static enum decoder_command -need_chunks(struct input_stream *is) +need_chunks(struct input_stream *is, bool wait) { if (dc.command == DECODE_COMMAND_STOP || dc.command == DECODE_COMMAND_SEEK) return dc.command; - if (is == NULL || input_stream_buffer(is) <= 0) { + if ((is == NULL || input_stream_buffer(is) <= 0) && wait) { notify_wait(&dc.notify); notify_signal(&pc.notify); } @@ -255,7 +255,8 @@ decoder_data(struct decoder *decoder, data += nbytes; if (length > 0) { - enum decoder_command cmd = need_chunks(is); + enum decoder_command cmd = + need_chunks(is, nbytes == 0); if (cmd != DECODE_COMMAND_NONE) return cmd; } @@ -276,7 +277,7 @@ decoder_tag(mpd_unused struct decoder *decoder, struct input_stream *is, tag = tag2; while (!music_pipe_tag(tag)) { - enum decoder_command cmd = need_chunks(is); + enum decoder_command cmd = need_chunks(is, true); if (cmd != DECODE_COMMAND_NONE) return cmd; }