From 6922a2f55e4c29f4db848e125f10073876fb69bf Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 17 May 2019 12:43:45 +0200 Subject: [PATCH 1/5] input/buffered: check error in IsAvailable() --- src/input/BufferedInputStream.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input/BufferedInputStream.cxx b/src/input/BufferedInputStream.cxx index 4c8374bd9..4e078485d 100644 --- a/src/input/BufferedInputStream.cxx +++ b/src/input/BufferedInputStream.cxx @@ -104,7 +104,7 @@ BufferedInputStream::IsEOF() noexcept bool BufferedInputStream::IsAvailable() noexcept { - return IsEOF() || buffer.Read(offset).HasData(); + return IsEOF() || buffer.Read(offset).HasData() || read_error; } size_t From ff3e2c05142c94efadee00812ec348c15f1be1ba Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 20 May 2019 16:20:59 +0200 Subject: [PATCH 2/5] player/Thread: remove unnecessary "pipe" check The "queued" flag can only possibly be set if the decoder is still decoding the current song or if the decoder is stopped. This is also what the following assert() checks. This check was not necessary. --- src/player/Thread.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx index 3e30fdf32..81271a142 100644 --- a/src/player/Thread.cxx +++ b/src/player/Thread.cxx @@ -996,7 +996,7 @@ Player::Run() noexcept } } - if (dc.IsIdle() && queued && dc.pipe == pipe) { + if (dc.IsIdle() && queued) { /* the decoder has finished the current song; make it decode the next song */ From 923e66738cb89590c3b83a853e3ece9964ffc56b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 20 May 2019 15:22:34 +0200 Subject: [PATCH 3/5] player/Thread: fix "single" mode race condition If the decoder finishes decoding the current song between the two IsIdle() checks, MPD stops playback instead of starting the decoder for the next song. This is usually not visible problem, because the main thread restarts it via playlist::ResumePlayback(), but that way it, ignores "single" mode. As a workaround, this commit adds another "queued" check which re-enters the player loop and checks again whether to start the decoder. Closes https://github.com/MusicPlayerDaemon/MPD/issues/556 --- NEWS | 1 + src/player/Thread.cxx | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/NEWS b/NEWS index 73fcfa4e7..6eda2de03 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ ver 0.21.9 (not yet released) * Android - fix crash on ARMv7 - request storage permission on Android 6+ +* fix spurious "single" mode bug ver 0.21.8 (2019/04/23) * input diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx index 81271a142..7d81011f6 100644 --- a/src/player/Thread.cxx +++ b/src/player/Thread.cxx @@ -1058,6 +1058,16 @@ Player::Run() noexcept SongBorder(); } else if (dc.IsIdle()) { + if (queued) + /* the decoder has just stopped, + between the two IsIdle() checks, + probably while UnlockCheckOutputs() + left the mutex unlocked; to restart + the decoder instead of stopping + playback completely, let's re-enter + this loop */ + continue; + /* check the size of the pipe again, because the decoder thread may have added something since we last checked */ From 1b902e00b45c209195fb6cd2d92775f1a34a593e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 20 May 2019 17:06:20 +0200 Subject: [PATCH 4/5] doc/protocol.rst: several clarifications Closes https://github.com/MusicPlayerDaemon/MPD/issues/340 --- doc/protocol.rst | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/doc/protocol.rst b/doc/protocol.rst index e67a60145..57c23dc13 100644 --- a/doc/protocol.rst +++ b/doc/protocol.rst @@ -14,6 +14,9 @@ Once the client is connected to the server, they conduct a conversation until the client closes the connection. The conversation flow is always initiated by the client. +All data between the client and the server is encoded in +UTF-8. + The client transmits a command sequence, terminated by the newline character ``\n``. The server will respond with one or more lines, the last of which will be a @@ -42,9 +45,6 @@ quotation marks. Argument strings are separated from the command and any other arguments by linear white-space (' ' or '\\t'). -All data between the client and the server is encoded in -UTF-8. - Responses ========= @@ -52,6 +52,28 @@ A command returns ``OK`` on completion or ``ACK some error`` on failure. These denote the end of command execution. +Some commands return more data before the response ends with ``OK``. +Each line is usually in the form ``NAME: VALUE``. Example:: + + foo: bar + OK + +.. _binary: + +Binary Responses +---------------- + +Some commands can return binary data. This is initiated by a line +containing ``binary: 1234`` (followed as usual by a newline). After +that, the specified number of bytes of binary data follows (without an +extra newline, because this binary data is not a text line), and +finally the ``OK`` line. Example:: + + foo: bar + binary: 42 + <42 bytes>OK + + Failure responses ----------------- @@ -112,9 +134,9 @@ list begins with `command_list_begin` or `command_list_ok_begin` and ends with `command_list_end`. -It does not execute any commands until the list has ended. -The return value is whatever the return for a list of commands -is. On success for all commands, +It does not execute any commands until the list has ended. The +response is a concatentation of all individual responses. +On success for all commands, ``OK`` is returned. If a command fails, no more commands are executed and the appropriate ``ACK`` error is returned. If @@ -794,7 +816,7 @@ The music database Returns the file size and actual number of bytes read at the requested offset, followed - by the chunk requested as raw bytes, then a + by the chunk requested as raw bytes (see :ref:`binary`), then a newline and the completion code. Example:: @@ -802,8 +824,7 @@ The music database albumart size: 1024768 binary: 8192 - <8192 bytes> - OK + <8192 bytes>OK :command:`count {FILTER} [group {GROUPTYPE}]` Count the number of songs and their total playtime in From 66a8fac25e1bc5d05705bdfdcc5a11fb5a299a19 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 20 May 2019 17:10:58 +0200 Subject: [PATCH 5/5] release v0.21.9 --- NEWS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 6eda2de03..3f74b5dcf 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,4 @@ -ver 0.21.9 (not yet released) +ver 0.21.9 (2019/05/20) * input - buffer: fix deadlock bug * Android