aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder_control.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-04-25 15:19:01 +0200
committerMax Kellermann <max@duempel.org>2009-04-25 15:19:01 +0200
commit3888ef2f5504ab5b6b92d9fe1a9a4c0cbabecf0b (patch)
treefedd39a1acb36ca533cb8aaaafe5d530771034e1 /src/decoder_control.c
parentceb00f787e2e0ea149a411dc7f2e1102e458dfba (diff)
downloadmpd-3888ef2f5504ab5b6b92d9fe1a9a4c0cbabecf0b.tar.gz
mpd-3888ef2f5504ab5b6b92d9fe1a9a4c0cbabecf0b.tar.xz
mpd-3888ef2f5504ab5b6b92d9fe1a9a4c0cbabecf0b.zip
decoder_control: properly cancel an existing command in dc_stop()
When the decoder thread has a pending command, send the STOP command to cancel this command. Send STOP again if the decoder thread is still running after that, just in case the decoder thread has executed the previous command (which was overwritten).
Diffstat (limited to '')
-rw-r--r--src/decoder_control.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/decoder_control.c b/src/decoder_control.c
index 7aa80c2c6..44bb63e15 100644
--- a/src/decoder_control.c
+++ b/src/decoder_control.c
@@ -80,8 +80,14 @@ dc_start_async(struct song *song)
void
dc_stop(struct notify *notify)
{
- if (dc.command == DECODE_COMMAND_START ||
- (dc.state != DECODE_STATE_STOP && dc.state != DECODE_STATE_ERROR))
+ if (dc.command != DECODE_COMMAND_NONE)
+ /* Attempt to cancel the current command. If it's too
+ late and the decoder thread is already executing
+ the old command, we'll call STOP again in this
+ function (see below). */
+ dc_command(notify, DECODE_COMMAND_STOP);
+
+ if (dc.state != DECODE_STATE_STOP && dc.state != DECODE_STATE_ERROR)
dc_command(notify, DECODE_COMMAND_STOP);
}