From 0a6e484b1ab7cb0175464103fc93f550fd7e1c8e Mon Sep 17 00:00:00 2001
From: Jacob Vosmaer <contact@jacobvosmaer.nl>
Date: Sat, 16 Mar 2019 21:00:01 +0100
Subject: [PATCH 1/6] output/plugins/OSXOutputPlugin: add boost meson
 dependency

---
 NEWS                           | 1 +
 src/output/plugins/meson.build | 5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 76523c37c..0060ff1ff 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ ver 0.21.6 (not yet released)
   - opus: fix replay gain when there are no other tags
 * output
   - pulse: work around error with unusual channel count
+  - osx: fix build failure
 * playlist
   - flac: fix use-after-free bug
 * support abstract sockets on Linux
diff --git a/src/output/plugins/meson.build b/src/output/plugins/meson.build
index 65883323b..bdfd47130 100644
--- a/src/output/plugins/meson.build
+++ b/src/output/plugins/meson.build
@@ -76,7 +76,10 @@ if is_darwin
   audiounit_dep = declare_dependency(
     link_args: [
       '-framework', 'AudioUnit', '-framework', 'CoreAudio', '-framework', 'CoreServices',
-    ]
+    ],
+    dependencies: [
+      boost_dep,
+    ],
   )
 else
   audiounit_dep = dependency('', required: false)

From b76d78e6aeae5a6e638194fed03bd003d5b9f49d Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Sun, 17 Mar 2019 18:04:40 +0100
Subject: [PATCH 2/6] output/sles: enable power saving mode

---
 NEWS                                         | 2 ++
 src/output/plugins/sles/SlesOutputPlugin.cxx | 8 ++++++++
 2 files changed, 10 insertions(+)

diff --git a/NEWS b/NEWS
index 0060ff1ff..d140a88bf 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,8 @@ ver 0.21.6 (not yet released)
 * support abstract sockets on Linux
 * Windows
   - remove the unused libwinpthread-1.dll dependency
+* Android
+  - enable SLES power saving mode
 
 ver 0.21.5 (2019/02/22)
 * protocol
diff --git a/src/output/plugins/sles/SlesOutputPlugin.cxx b/src/output/plugins/sles/SlesOutputPlugin.cxx
index 3ebe08dfd..f1ef758e4 100644
--- a/src/output/plugins/sles/SlesOutputPlugin.cxx
+++ b/src/output/plugins/sles/SlesOutputPlugin.cxx
@@ -229,6 +229,14 @@ SlesOutput::Open(AudioFormat &audio_format)
 						    SL_ANDROID_KEY_STREAM_TYPE,
 						    &stream_type,
 						    sizeof(stream_type));
+
+		/* MPD doesn't care much about latency, so let's
+		   configure power saving mode */
+		SLuint32 performance_mode = SL_ANDROID_PERFORMANCE_POWER_SAVING;
+		(*android_config)->SetConfiguration(android_config,
+						    SL_ANDROID_KEY_PERFORMANCE_MODE,
+						    &performance_mode,
+						    sizeof(performance_mode));
 	}
 
 	result = play_object.Realize(false);

From 6d12c2265372b621d8400e723238631ca9d2ebcf Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Sun, 17 Mar 2019 23:14:59 +0100
Subject: [PATCH 3/6] decoder/ogg: ignore the BOS packet after seek to the
 beginning of song

Previously, MPD would skip the current song after attempting to seek
to its beginnig, because that was a seek to offset 0.  At offset 0,
MPD will see the BOS packet again, which results in throwing
StopDecoder in MPDOpusDecoder::OnOggEnd().

Closes https://github.com/MusicPlayerDaemon/MPD/issues/470
---
 NEWS                        | 1 +
 src/lib/xiph/OggVisitor.cxx | 9 +++++++++
 src/lib/xiph/OggVisitor.hxx | 8 ++++++++
 3 files changed, 18 insertions(+)

diff --git a/NEWS b/NEWS
index d140a88bf..29a697bfc 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ ver 0.21.6 (not yet released)
   - cdio_paranoia: fix build failure due to missing #include
 * decoder
   - opus: fix replay gain when there are no other tags
+  - opus: fix seeking to beginning of song
 * output
   - pulse: work around error with unusual channel count
   - osx: fix build failure
diff --git a/src/lib/xiph/OggVisitor.cxx b/src/lib/xiph/OggVisitor.cxx
index 14ac666a0..b975d8d17 100644
--- a/src/lib/xiph/OggVisitor.cxx
+++ b/src/lib/xiph/OggVisitor.cxx
@@ -20,6 +20,7 @@
 #include "OggVisitor.hxx"
 
 #include <stdexcept>
+#include <utility>
 
 void
 OggVisitor::EndStream()
@@ -51,7 +52,13 @@ OggVisitor::ReadNextPage()
 inline void
 OggVisitor::HandlePacket(const ogg_packet &packet)
 {
+	const bool _post_seek = std::exchange(post_seek, false);
+
 	if (packet.b_o_s) {
+		if (_post_seek)
+			/* ignore the BOS packet after seeking */
+			return;
+
 		EndStream();
 		has_stream = true;
 		OnOggBeginning(packet);
@@ -97,4 +104,6 @@ OggVisitor::PostSeek()
 
 	/* find the next Ogg page and feed it into the stream */
 	sync.ExpectPageSeekIn(stream);
+
+	post_seek = true;
 }
diff --git a/src/lib/xiph/OggVisitor.hxx b/src/lib/xiph/OggVisitor.hxx
index 4c5e3f14e..a7e6eb9b8 100644
--- a/src/lib/xiph/OggVisitor.hxx
+++ b/src/lib/xiph/OggVisitor.hxx
@@ -39,6 +39,14 @@ class OggVisitor {
 
 	bool has_stream = false;
 
+	/**
+	 * This is true after seeking; its one-time effect is to
+	 * ignore the BOS packet, just in case we have been seeking to
+	 * the beginning of the file, because that would disrupt
+	 * playback.
+	 */
+	bool post_seek = false;
+
 public:
 	explicit OggVisitor(Reader &reader)
 		:sync(reader), stream(0) {}

From c18cd941aaa4c16ac713bc4f1e16ada5281d689e Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Sun, 17 Mar 2019 23:36:52 +0100
Subject: [PATCH 4/6] lib/xiph: disable Tremor detection if libvorbis was found

And disable libvorbis detection if Tremor was explicitly enabled.

This fixes a crash bug caused by libvorbis/Tremor ABI conflict caused
by commit 4f7d52dbf2eaee15a517363c846650d76f45739f
---
 NEWS                     |  1 +
 src/lib/xiph/meson.build | 17 +++++++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 29a697bfc..e9aad5a9c 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ ver 0.21.6 (not yet released)
 * decoder
   - opus: fix replay gain when there are no other tags
   - opus: fix seeking to beginning of song
+  - vorbis: fix Tremor conflict resulting in crash
 * output
   - pulse: work around error with unusual channel count
   - osx: fix build failure
diff --git a/src/lib/xiph/meson.build b/src/lib/xiph/meson.build
index 432958fee..4f3f46e64 100644
--- a/src/lib/xiph/meson.build
+++ b/src/lib/xiph/meson.build
@@ -1,7 +1,20 @@
 libflac_dep = dependency('flac', version: '>= 1.2', required: get_option('flac'))
 libopus_dep = dependency('opus', required: get_option('opus'))
-libvorbis_dep = dependency('vorbis', required: get_option('vorbis'))
-libvorbisidec_dep = dependency('vorbisidec', required: get_option('tremor'))
+
+if get_option('tremor').enabled()
+  # no libvorbis if Tremor was explicitly enabled
+  libvorbis_dep = dependency('', required: false)
+else
+  libvorbis_dep = dependency('vorbis', required: get_option('vorbis'))
+endif
+
+if libvorbis_dep.found()
+  # no Tremor if libvorbis is used
+  libvorbisidec_dep = dependency('', required: false)
+else
+  # attempt to auto-detect Tremor only if libvorbis was disabled or not found
+  libvorbisidec_dep = dependency('vorbisidec', required: get_option('tremor'))
+endif
 
 if get_option('vorbis').enabled() and get_option('tremor').enabled()
 	error('Cannot build both, the Vorbis decoder AND the Tremor (Vorbis fixed-point) decoder')

From 62a129c18f56b3199c938f2cfabd58d344cfe513 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Sun, 17 Mar 2019 23:46:36 +0100
Subject: [PATCH 5/6] PlaylistFile: ignore empty playlist names

Closes https://github.com/MusicPlayerDaemon/MPD/issues/465 and
https://github.com/MusicPlayerDaemon/MPD/pull/466
---
 NEWS                 | 1 +
 src/PlaylistFile.cxx | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index e9aad5a9c..bfa9e97e0 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ ver 0.21.6 (not yet released)
   - allow loading playlists specified as absolute filesystem paths
   - fix negated filter expressions with multiple tag values
   - fix "list" with filter expression
+  - omit empty playlist names in "listplaylists"
 * input
   - cdio_paranoia: fix build failure due to missing #include
 * decoder
diff --git a/src/PlaylistFile.cxx b/src/PlaylistFile.cxx
index c49ff8e1e..970190967 100644
--- a/src/PlaylistFile.cxx
+++ b/src/PlaylistFile.cxx
@@ -134,7 +134,9 @@ LoadPlaylistFileInfo(PlaylistInfo &info,
 	const auto *const name_fs_end =
 		FindStringSuffix(name_fs_str,
 				 PATH_LITERAL(PLAYLIST_FILE_SUFFIX));
-	if (name_fs_end == nullptr)
+	if (name_fs_end == nullptr ||
+	    /* no empty playlist names (raw file name = ".m3u") */
+	    name_fs_end == name_fs_str)
 		return false;
 
 	FileInfo fi;

From 808dd7cc54710285ac8dc58b3abebaab71feb269 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Sun, 17 Mar 2019 23:52:13 +0100
Subject: [PATCH 6/6] release v0.21.6

---
 NEWS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index bfa9e97e0..f59539972 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-ver 0.21.6 (not yet released)
+ver 0.21.6 (2019/03/17)
 * protocol
   - allow loading playlists specified as absolute filesystem paths
   - fix negated filter expressions with multiple tag values