Compare commits
75 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64c39af556 | ||
|
|
04eb911a51 | ||
|
|
351b39e0c5 | ||
|
|
3b6d4e6673 | ||
|
|
e8f328d8ad | ||
|
|
5f5b5f63af | ||
|
|
ad6e303047 | ||
|
|
b0e9538855 | ||
|
|
694debd4cc | ||
|
|
0f56ddb805 | ||
|
|
dde77ec6bd | ||
|
|
5d73eda115 | ||
|
|
1985786ed2 | ||
|
|
8e0d39ae94 | ||
|
|
1761fb14af | ||
|
|
ef2fc4e6f6 | ||
|
|
b979245d6c | ||
|
|
17b0ac75ca | ||
|
|
bde64a13e2 | ||
|
|
96875921b7 | ||
|
|
551c941b5a | ||
|
|
624c77ab43 | ||
|
|
ba13b4b5d6 | ||
|
|
4b2d9e544c | ||
|
|
97c43954e8 | ||
|
|
9fa3984a2f | ||
|
|
5355335f19 | ||
|
|
64fa76c568 | ||
|
|
19a44076cf | ||
|
|
809a18913a | ||
|
|
5eab2d96f4 | ||
|
|
716784f632 | ||
|
|
eb630ca655 | ||
|
|
18628bf89e | ||
|
|
2052b461af | ||
|
|
5019bdcd52 | ||
|
|
8be0bcbdb9 | ||
|
|
af72a22ed8 | ||
|
|
6ed9668fea | ||
|
|
175d2c6d29 | ||
|
|
ab487b9a99 | ||
|
|
ac59ec34f9 | ||
|
|
82da57b7ce | ||
|
|
aa6dac9bd2 | ||
|
|
a26bf261a9 | ||
|
|
c692286c67 | ||
|
|
3775766605 | ||
|
|
38e24208f6 | ||
|
|
fbaedf2262 | ||
|
|
8f3341cefb | ||
|
|
4ec4bab3a9 | ||
|
|
6d567bcd35 | ||
|
|
363d9f0180 | ||
|
|
db0682a469 | ||
|
|
7a6823dcdf | ||
|
|
bce144a232 | ||
|
|
0cef84cac6 | ||
|
|
56c0733b42 | ||
|
|
0b0acb3981 | ||
|
|
1375dcc4ec | ||
|
|
6aeb0e335b | ||
|
|
c1e2537851 | ||
|
|
8c690fb737 | ||
|
|
dad1c21b59 | ||
|
|
dd10b2bd61 | ||
|
|
48c7c540df | ||
|
|
281270cd2a | ||
|
|
02502514f6 | ||
|
|
1bc02123f9 | ||
|
|
3488a47c41 | ||
|
|
fd82d67678 | ||
|
|
e66c12105b | ||
|
|
dbe12a6b90 | ||
|
|
d3a680cc87 | ||
|
|
62fc4d5cf4 |
31
NEWS
31
NEWS
@@ -1,3 +1,34 @@
|
|||||||
|
ver 0.22.10 (2021/08/06)
|
||||||
|
* protocol
|
||||||
|
- support "albumart" for virtual tracks in CUE sheets
|
||||||
|
* database
|
||||||
|
- simple: fix crash bug
|
||||||
|
- simple: fix absolute paths in CUE "as_directory" entries
|
||||||
|
- simple: prune CUE entries from database for non-existent songs
|
||||||
|
* input
|
||||||
|
- curl: fix crash bug after stream with Icy metadata was closed by peer
|
||||||
|
- tidal: remove defunct unmaintained plugin
|
||||||
|
* tags
|
||||||
|
- fix crash caused by bug in TagBuilder and a few potential reference leaks
|
||||||
|
* output
|
||||||
|
- httpd: fix missing tag after seeking into a new song
|
||||||
|
- oss: fix channel order of multi-channel files
|
||||||
|
* mixer
|
||||||
|
- alsa: fix yet more rounding errors
|
||||||
|
|
||||||
|
ver 0.22.9 (2021/06/23)
|
||||||
|
* database
|
||||||
|
- simple: load all .mpdignore files of all parent directories
|
||||||
|
* tags
|
||||||
|
- fix "readcomments" and "readpicture" on remote files with ID3 tags
|
||||||
|
* decoder
|
||||||
|
- ffmpeg: support the tags "sort_album", "album-sort", "artist-sort"
|
||||||
|
- ffmpeg: fix build failure with FFmpeg 3.4
|
||||||
|
* Android
|
||||||
|
- fix auto-start on boot in Android 8 or later
|
||||||
|
* Windows
|
||||||
|
- fix build failure with SQLite
|
||||||
|
|
||||||
ver 0.22.8 (2021/05/22)
|
ver 0.22.8 (2021/05/22)
|
||||||
* fix crash bug in "albumart" command (0.22.7 regression)
|
* fix crash bug in "albumart" command (0.22.7 regression)
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ For basic installation instructions
|
|||||||
|
|
||||||
- [Manual](http://www.musicpd.org/doc/user/)
|
- [Manual](http://www.musicpd.org/doc/user/)
|
||||||
- [Forum](http://forum.musicpd.org/)
|
- [Forum](http://forum.musicpd.org/)
|
||||||
- [IRC](irc://chat.freenode.net/#mpd)
|
- [IRC](ircs://irc.libera.chat:6697/#mpd)
|
||||||
- [Bug tracker](https://github.com/MusicPlayerDaemon/MPD/issues/)
|
- [Bug tracker](https://github.com/MusicPlayerDaemon/MPD/issues/)
|
||||||
|
|
||||||
# Developers
|
# Developers
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="org.musicpd"
|
package="org.musicpd"
|
||||||
android:installLocation="auto"
|
android:installLocation="auto"
|
||||||
android:versionCode="56"
|
android:versionCode="58"
|
||||||
android:versionName="0.22.8">
|
android:versionName="0.22.10">
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29"/>
|
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29"/>
|
||||||
|
|
||||||
|
|||||||
@@ -91,8 +91,9 @@ class AndroidNdkToolchain:
|
|||||||
|
|
||||||
self.arch = arch
|
self.arch = arch
|
||||||
self.install_prefix = install_prefix
|
self.install_prefix = install_prefix
|
||||||
|
self.toolchain_arch = abi_info['toolchain_arch']
|
||||||
|
|
||||||
toolchain_path = os.path.join(ndk_path, 'toolchains', abi_info['toolchain_arch'] + '-' + gcc_version, 'prebuilt', build_arch)
|
toolchain_path = os.path.join(ndk_path, 'toolchains', self.toolchain_arch + '-' + gcc_version, 'prebuilt', build_arch)
|
||||||
llvm_path = os.path.join(ndk_path, 'toolchains', 'llvm', 'prebuilt', build_arch)
|
llvm_path = os.path.join(ndk_path, 'toolchains', 'llvm', 'prebuilt', build_arch)
|
||||||
llvm_triple = abi_info['llvm_triple'] + android_api_level
|
llvm_triple = abi_info['llvm_triple'] + android_api_level
|
||||||
|
|
||||||
|
|||||||
@@ -414,6 +414,15 @@ public class Main extends Service implements Runnable {
|
|||||||
* start Main service without any callback
|
* start Main service without any callback
|
||||||
*/
|
*/
|
||||||
public static void start(Context context, boolean wakelock) {
|
public static void start(Context context, boolean wakelock) {
|
||||||
context.startService(new Intent(context, Main.class).putExtra("wakelock", wakelock));
|
Intent intent = new Intent(context, Main.class)
|
||||||
|
.putExtra("wakelock", wakelock);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||||
|
/* in Android 8+, we need to use this method
|
||||||
|
or else we'll get "IllegalStateException:
|
||||||
|
app is in background" */
|
||||||
|
context.startForegroundService(intent);
|
||||||
|
else
|
||||||
|
context.startService(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ author = 'Max Kellermann'
|
|||||||
# built documents.
|
# built documents.
|
||||||
#
|
#
|
||||||
# The short X.Y version.
|
# The short X.Y version.
|
||||||
version = '0.22.8'
|
version = '0.22.10'
|
||||||
# The full version, including alpha/beta/rc tags.
|
# The full version, including alpha/beta/rc tags.
|
||||||
release = version
|
release = version
|
||||||
|
|
||||||
|
|||||||
@@ -295,37 +295,6 @@ in the form ``qobuz://track/ID``, e.g.:
|
|||||||
* - **format_id N**
|
* - **format_id N**
|
||||||
- The `Qobuz format identifier <https://github.com/Qobuz/api-documentation/blob/master/endpoints/track/getFileUrl.md#parameters>`_, i.e. a number which chooses the format and quality to be requested from Qobuz. The default is "5" (320 kbit/s MP3).
|
- The `Qobuz format identifier <https://github.com/Qobuz/api-documentation/blob/master/endpoints/track/getFileUrl.md#parameters>`_, i.e. a number which chooses the format and quality to be requested from Qobuz. The default is "5" (320 kbit/s MP3).
|
||||||
|
|
||||||
tidal
|
|
||||||
-----
|
|
||||||
|
|
||||||
Play songs from the commercial streaming service `Tidal
|
|
||||||
<http://tidal.com/>`_. It plays URLs in the form ``tidal://track/ID``,
|
|
||||||
e.g.:
|
|
||||||
|
|
||||||
.. warning::
|
|
||||||
|
|
||||||
This plugin is currently defunct because Tidal has changed the
|
|
||||||
protocol and decided not to share documentation.
|
|
||||||
|
|
||||||
.. code-block:: none
|
|
||||||
|
|
||||||
mpc add tidal://track/59727857
|
|
||||||
|
|
||||||
.. list-table::
|
|
||||||
:widths: 20 80
|
|
||||||
:header-rows: 1
|
|
||||||
|
|
||||||
* - Setting
|
|
||||||
- Description
|
|
||||||
* - **token TOKEN**
|
|
||||||
- The Tidal application token. Since Tidal is unwilling to assign a token to MPD, this needs to be reverse-engineered from another (approved) Tidal client.
|
|
||||||
* - **username USERNAME**
|
|
||||||
- The Tidal user name.
|
|
||||||
* - **password PASSWORD**
|
|
||||||
- The Tidal password.
|
|
||||||
* - **audioquality Q**
|
|
||||||
- The Tidal "audioquality" parameter. Possible values: HI_RES, LOSSLESS, HIGH, LOW. Default is HIGH.
|
|
||||||
|
|
||||||
.. _decoder_plugins:
|
.. _decoder_plugins:
|
||||||
|
|
||||||
Decoder plugins
|
Decoder plugins
|
||||||
@@ -715,7 +684,7 @@ A resampler using `libsamplerate <http://www.mega-nerd.com/SRC/>`_ a.k.a. Secret
|
|||||||
* - Name
|
* - Name
|
||||||
- Description
|
- Description
|
||||||
* - **type**
|
* - **type**
|
||||||
- The interpolator type. See below for a list of known types.
|
- The interpolator type. Defaults to :samp:`2`. See below for a list of known types.
|
||||||
|
|
||||||
The following converter types are provided by libsamplerate:
|
The following converter types are provided by libsamplerate:
|
||||||
|
|
||||||
@@ -1200,7 +1169,7 @@ This plugin requires building with ``libavfilter`` (FFmpeg).
|
|||||||
* - **graph "..."**
|
* - **graph "..."**
|
||||||
- Specifies the ``libavfilter`` graph; read the `FFmpeg
|
- Specifies the ``libavfilter`` graph; read the `FFmpeg
|
||||||
documentation
|
documentation
|
||||||
<https://libav.org/documentation/libavfilter.html#Filtergraph-syntax-1>`_
|
<https://ffmpeg.org/ffmpeg-filters.html#Filtergraph-syntax-1>`_
|
||||||
for details
|
for details
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ and unpack it (or `clone the git repository
|
|||||||
|
|
||||||
In any case, you need:
|
In any case, you need:
|
||||||
|
|
||||||
* a C++17 compiler (e.g. GCC 8 or clang 5)
|
* a C++17 compiler (e.g. GCC 8 or clang 7)
|
||||||
* `Meson 0.49.0 <http://mesonbuild.com/>`__ and `Ninja
|
* `Meson 0.49.0 <http://mesonbuild.com/>`__ and `Ninja
|
||||||
<https://ninja-build.org/>`__
|
<https://ninja-build.org/>`__
|
||||||
* Boost 1.58
|
* Boost 1.58
|
||||||
@@ -628,7 +628,8 @@ By default, all clients are unauthenticated and have a full set of permissions.
|
|||||||
* - **control**
|
* - **control**
|
||||||
- Allows all other player and playlist manipulations.
|
- Allows all other player and playlist manipulations.
|
||||||
* - **admin**
|
* - **admin**
|
||||||
- Allows database updates and allows shutting down :program:`MPD`.
|
- Allows manipulating outputs, stickers and partitions,
|
||||||
|
mounting/unmounting storage and shutting down :program:`MPD`.
|
||||||
|
|
||||||
:code:`local_permissions` may be used to assign other permissions to clients connecting on a local socket.
|
:code:`local_permissions` may be used to assign other permissions to clients connecting on a local socket.
|
||||||
|
|
||||||
@@ -688,6 +689,8 @@ The State File
|
|||||||
- Specify the state file location. The parent directory must be writable by the :program:`MPD` user (+wx).
|
- Specify the state file location. The parent directory must be writable by the :program:`MPD` user (+wx).
|
||||||
* - **state_file_interval SECONDS**
|
* - **state_file_interval SECONDS**
|
||||||
- Auto-save the state file this number of seconds after each state change. Defaults to 120 (2 minutes).
|
- Auto-save the state file this number of seconds after each state change. Defaults to 120 (2 minutes).
|
||||||
|
* - **restore_paused yes|no**
|
||||||
|
- If set to :samp:`yes`, then :program:`MPD` is put into pause mode instead of starting playback after startup. Default is :samp:`no`.
|
||||||
|
|
||||||
The Sticker Database
|
The Sticker Database
|
||||||
^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^
|
||||||
@@ -1120,7 +1123,7 @@ Support
|
|||||||
Getting Help
|
Getting Help
|
||||||
^^^^^^^^^^^^
|
^^^^^^^^^^^^
|
||||||
|
|
||||||
The :program:`MPD` project runs a `forum <https://forum.musicpd.org/>`_ and an IRC channel (#mpd on Freenode) for requesting help. Visit the MPD help page for details on how to get help.
|
The :program:`MPD` project runs a `forum <https://forum.musicpd.org/>`_ and an IRC channel (#mpd on Libera.Chat) for requesting help. Visit the MPD help page for details on how to get help.
|
||||||
|
|
||||||
Common Problems
|
Common Problems
|
||||||
^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^
|
||||||
|
|||||||
76
meson.build
76
meson.build
@@ -1,7 +1,7 @@
|
|||||||
project(
|
project(
|
||||||
'mpd',
|
'mpd',
|
||||||
['c', 'cpp'],
|
['c', 'cpp'],
|
||||||
version: '0.22.8',
|
version: '0.22.10',
|
||||||
meson_version: '>= 0.49.0',
|
meson_version: '>= 0.49.0',
|
||||||
default_options: [
|
default_options: [
|
||||||
'c_std=c11',
|
'c_std=c11',
|
||||||
@@ -24,8 +24,8 @@ c_compiler = meson.get_compiler('c')
|
|||||||
|
|
||||||
if compiler.get_id() == 'gcc' and compiler.version().version_compare('<8')
|
if compiler.get_id() == 'gcc' and compiler.version().version_compare('<8')
|
||||||
warning('Your GCC version is too old. You need at least version 8.')
|
warning('Your GCC version is too old. You need at least version 8.')
|
||||||
elif compiler.get_id() == 'clang' and compiler.version().version_compare('<5')
|
elif compiler.get_id() == 'clang' and compiler.version().version_compare('<7')
|
||||||
warning('Your clang version is too old. You need at least version 5.')
|
warning('Your clang version is too old. You need at least version 7.')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
version_conf = configuration_data()
|
version_conf = configuration_data()
|
||||||
@@ -42,57 +42,64 @@ common_cppflags = [
|
|||||||
'-D_GNU_SOURCE',
|
'-D_GNU_SOURCE',
|
||||||
]
|
]
|
||||||
|
|
||||||
common_cflags = [
|
test_global_common_flags = [
|
||||||
]
|
'-fvisibility=hidden',
|
||||||
|
|
||||||
common_cxxflags = [
|
|
||||||
]
|
]
|
||||||
|
|
||||||
test_common_flags = [
|
test_common_flags = [
|
||||||
'-Wvla',
|
'-Wvla',
|
||||||
'-Wdouble-promotion',
|
'-Wdouble-promotion',
|
||||||
|
|
||||||
'-fvisibility=hidden',
|
|
||||||
|
|
||||||
'-ffast-math',
|
'-ffast-math',
|
||||||
'-ftree-vectorize',
|
'-ftree-vectorize',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
test_global_cxxflags = test_global_common_flags + [
|
||||||
|
]
|
||||||
|
|
||||||
|
test_global_cflags = test_global_common_flags + [
|
||||||
|
]
|
||||||
|
|
||||||
test_cxxflags = test_common_flags + [
|
test_cxxflags = test_common_flags + [
|
||||||
'-fno-threadsafe-statics',
|
'-fno-threadsafe-statics',
|
||||||
'-fmerge-all-constants',
|
'-fmerge-all-constants',
|
||||||
|
|
||||||
'-Wmissing-declarations',
|
|
||||||
'-Wshadow',
|
|
||||||
'-Wpointer-arith',
|
|
||||||
'-Wcast-qual',
|
'-Wcast-qual',
|
||||||
'-Wwrite-strings',
|
'-Wcomma-subscript',
|
||||||
'-Wsign-compare',
|
|
||||||
'-Wcomma',
|
|
||||||
'-Wextra-semi',
|
'-Wextra-semi',
|
||||||
|
'-Wmismatched-tags',
|
||||||
|
'-Wmissing-declarations',
|
||||||
|
'-Woverloaded-virtual',
|
||||||
|
'-Wshadow',
|
||||||
|
'-Wsign-promo',
|
||||||
|
'-Wunused',
|
||||||
|
'-Wvolatile',
|
||||||
|
'-Wvirtual-inheritance',
|
||||||
|
'-Wwrite-strings',
|
||||||
|
|
||||||
|
# a vtable without a dtor is just fine
|
||||||
|
'-Wno-non-virtual-dtor',
|
||||||
|
|
||||||
|
# clang specific warning options:
|
||||||
|
'-Wcomma',
|
||||||
'-Wheader-hygiene',
|
'-Wheader-hygiene',
|
||||||
'-Winconsistent-missing-destructor-override',
|
'-Winconsistent-missing-destructor-override',
|
||||||
'-Wunreachable-code-break',
|
'-Wunreachable-code-aggressive',
|
||||||
'-Wunused',
|
|
||||||
'-Wused-but-marked-unused',
|
'-Wused-but-marked-unused',
|
||||||
|
|
||||||
'-Wno-non-virtual-dtor',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
if compiler.get_id() == 'clang'
|
if compiler.get_id() != 'gcc' or compiler.version().version_compare('>=9')
|
||||||
# Workaround for clang bug
|
# The GCC 8 implementation of this flag is buggy: it complains even
|
||||||
# https://bugs.llvm.org/show_bug.cgi?id=32611
|
# if "final" is present, which implies "override".
|
||||||
test_cxxflags += '-funwind-tables'
|
test_cxxflags += '-Wsuggest-override'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
test_cflags = test_common_flags + [
|
test_cflags = test_common_flags + [
|
||||||
|
'-Wcast-qual',
|
||||||
'-Wmissing-prototypes',
|
'-Wmissing-prototypes',
|
||||||
'-Wshadow',
|
'-Wshadow',
|
||||||
'-Wpointer-arith',
|
|
||||||
'-Wstrict-prototypes',
|
'-Wstrict-prototypes',
|
||||||
'-Wcast-qual',
|
|
||||||
'-Wwrite-strings',
|
'-Wwrite-strings',
|
||||||
'-pedantic',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
test_ldflags = [
|
test_ldflags = [
|
||||||
@@ -104,11 +111,11 @@ test_ldflags = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
if get_option('buildtype') != 'debug'
|
if get_option('buildtype') != 'debug'
|
||||||
test_cxxflags += [
|
test_global_cxxflags += [
|
||||||
'-ffunction-sections',
|
'-ffunction-sections',
|
||||||
'-fdata-sections',
|
'-fdata-sections',
|
||||||
]
|
]
|
||||||
test_cflags += [
|
test_global_cflags += [
|
||||||
'-ffunction-sections',
|
'-ffunction-sections',
|
||||||
'-fdata-sections',
|
'-fdata-sections',
|
||||||
]
|
]
|
||||||
@@ -118,15 +125,20 @@ if get_option('buildtype') != 'debug'
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
if get_option('fuzzer')
|
if get_option('fuzzer')
|
||||||
fuzzer_flags = ['-fsanitize=fuzzer,address,undefined']
|
fuzzer_flags = ['-fsanitize=fuzzer']
|
||||||
|
if get_option('b_sanitize') == 'none'
|
||||||
|
fuzzer_flags += ['-fsanitize=address,undefined']
|
||||||
|
endif
|
||||||
add_global_arguments(fuzzer_flags, language: 'cpp')
|
add_global_arguments(fuzzer_flags, language: 'cpp')
|
||||||
add_global_arguments(fuzzer_flags, language: 'c')
|
add_global_arguments(fuzzer_flags, language: 'c')
|
||||||
add_global_link_arguments(fuzzer_flags, language: 'cpp')
|
add_global_link_arguments(fuzzer_flags, language: 'cpp')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
add_global_arguments(common_cxxflags + compiler.get_supported_arguments(test_cxxflags), language: 'cpp')
|
add_global_arguments(compiler.get_supported_arguments(test_global_cxxflags), language: 'cpp')
|
||||||
add_global_arguments(common_cflags + c_compiler.get_supported_arguments(test_cflags), language: 'c')
|
add_global_arguments(c_compiler.get_supported_arguments(test_global_cflags), language: 'c')
|
||||||
add_global_link_arguments(compiler.get_supported_link_arguments(test_ldflags), language: 'cpp')
|
add_project_arguments(compiler.get_supported_arguments(test_cxxflags), language: 'cpp')
|
||||||
|
add_project_arguments(c_compiler.get_supported_arguments(test_cflags), language: 'c')
|
||||||
|
add_project_link_arguments(compiler.get_supported_link_arguments(test_ldflags), language: 'cpp')
|
||||||
|
|
||||||
is_linux = host_machine.system() == 'linux'
|
is_linux = host_machine.system() == 'linux'
|
||||||
is_android = get_option('android_ndk') != ''
|
is_android = get_option('android_ndk') != ''
|
||||||
|
|||||||
@@ -104,7 +104,6 @@ option('smbclient', type: 'feature', value: 'disabled', description: 'SMB suppor
|
|||||||
|
|
||||||
option('qobuz', type: 'feature', description: 'Qobuz client')
|
option('qobuz', type: 'feature', description: 'Qobuz client')
|
||||||
option('soundcloud', type: 'feature', description: 'SoundCloud client')
|
option('soundcloud', type: 'feature', description: 'SoundCloud client')
|
||||||
option('tidal', type: 'feature', description: 'Tidal client')
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Archive plugins
|
# Archive plugins
|
||||||
|
|||||||
@@ -379,14 +379,14 @@ ffmpeg = FfmpegProject(
|
|||||||
)
|
)
|
||||||
|
|
||||||
openssl = OpenSSLProject(
|
openssl = OpenSSLProject(
|
||||||
'https://www.openssl.org/source/openssl-3.0.0-alpha16.tar.gz',
|
'https://www.openssl.org/source/openssl-3.0.0-beta2.tar.gz',
|
||||||
'08ce8244b59d75f40f91170dfcb012bf25309cdcb1fef9502e39d694f883d1d1',
|
'e76ab22879201b12f014393ee4becec7f264d8f6955b1036839128002868df71',
|
||||||
'include/openssl/ossl_typ.h',
|
'include/openssl/ossl_typ.h',
|
||||||
)
|
)
|
||||||
|
|
||||||
curl = AutotoolsProject(
|
curl = AutotoolsProject(
|
||||||
'https://curl.se/download/curl-7.76.1.tar.xz',
|
'https://curl.se/download/curl-7.78.0.tar.xz',
|
||||||
'64bb5288c39f0840c07d077e30d9052e1cbb9fa6c2dc52523824cc859e679145',
|
'be42766d5664a739c3974ee3dfbbcbe978a4ccb1fe628bb1d9b59ac79e445fb5',
|
||||||
'lib/libcurl.a',
|
'lib/libcurl.a',
|
||||||
[
|
[
|
||||||
'--disable-shared', '--enable-static',
|
'--disable-shared', '--enable-static',
|
||||||
|
|||||||
@@ -17,6 +17,12 @@ class OpenSSLProject(MakeProject):
|
|||||||
'build_libs',
|
'build_libs',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def get_make_install_args(self, toolchain):
|
||||||
|
# OpenSSL's Makefile runs "ranlib" during installation
|
||||||
|
return MakeProject.get_make_install_args(self, toolchain) + [
|
||||||
|
'RANLIB=' + toolchain.ranlib,
|
||||||
|
]
|
||||||
|
|
||||||
def build(self, toolchain):
|
def build(self, toolchain):
|
||||||
src = self.unpack(toolchain, out_of_tree=False)
|
src = self.unpack(toolchain, out_of_tree=False)
|
||||||
|
|
||||||
@@ -42,6 +48,7 @@ class OpenSSLProject(MakeProject):
|
|||||||
}
|
}
|
||||||
|
|
||||||
openssl_arch = openssl_archs[toolchain.arch]
|
openssl_arch = openssl_archs[toolchain.arch]
|
||||||
|
cross_compile_prefix = toolchain.toolchain_arch + '-'
|
||||||
|
|
||||||
subprocess.check_call(['./Configure',
|
subprocess.check_call(['./Configure',
|
||||||
'no-shared',
|
'no-shared',
|
||||||
@@ -50,6 +57,7 @@ class OpenSSLProject(MakeProject):
|
|||||||
'no-tests',
|
'no-tests',
|
||||||
'no-asm', # "asm" causes build failures on Windows
|
'no-asm', # "asm" causes build failures on Windows
|
||||||
openssl_arch,
|
openssl_arch,
|
||||||
|
'--cross-compile-prefix=' + cross_compile_prefix,
|
||||||
'--prefix=' + toolchain.install_prefix],
|
'--prefix=' + toolchain.install_prefix],
|
||||||
cwd=src, env=toolchain.env)
|
cwd=src, env=toolchain.env)
|
||||||
MakeProject.build(self, toolchain, src)
|
MakeProject.build(self, toolchain, src)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class Project:
|
|||||||
self.base = base
|
self.base = base
|
||||||
|
|
||||||
if name is None or version is None:
|
if name is None or version is None:
|
||||||
m = re.match(r'^([-\w]+)-(\d[\d.]*[a-z]?[\d.]*(?:-alpha\d+)?)$', self.base)
|
m = re.match(r'^([-\w]+)-(\d[\d.]*[a-z]?[\d.]*(?:-(?:alpha|beta)\d+)?)$', self.base)
|
||||||
if name is None: name = m.group(1)
|
if name is None: name = m.group(1)
|
||||||
if version is None: version = m.group(2)
|
if version is None: version = m.group(2)
|
||||||
|
|
||||||
|
|||||||
@@ -477,6 +477,7 @@ MainConfigured(const struct options &options, const ConfigData &raw_config)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
ZeroconfInit(raw_config, instance.event_loop);
|
ZeroconfInit(raw_config, instance.event_loop);
|
||||||
|
AtScopeExit() { ZeroconfDeinit(); };
|
||||||
|
|
||||||
#ifdef ENABLE_DATABASE
|
#ifdef ENABLE_DATABASE
|
||||||
if (create_db) {
|
if (create_db) {
|
||||||
@@ -537,9 +538,6 @@ MainConfigured(const struct options &options, const ConfigData &raw_config)
|
|||||||
instance.state_file->Write();
|
instance.state_file->Write();
|
||||||
|
|
||||||
instance.BeginShutdownUpdate();
|
instance.BeginShutdownUpdate();
|
||||||
|
|
||||||
ZeroconfDeinit();
|
|
||||||
|
|
||||||
instance.BeginShutdownPartitions();
|
instance.BeginShutdownPartitions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "client/Client.hxx"
|
#include "client/Client.hxx"
|
||||||
#include "protocol/Ack.hxx"
|
#include "protocol/Ack.hxx"
|
||||||
#include "fs/AllocatedPath.hxx"
|
#include "fs/AllocatedPath.hxx"
|
||||||
|
#include "input/InputStream.hxx"
|
||||||
#include "util/Compiler.h"
|
#include "util/Compiler.h"
|
||||||
#include "util/UriExtract.hxx"
|
#include "util/UriExtract.hxx"
|
||||||
#include "LocateUri.hxx"
|
#include "LocateUri.hxx"
|
||||||
@@ -32,8 +33,13 @@
|
|||||||
static void
|
static void
|
||||||
TagScanStream(const char *uri, TagHandler &handler)
|
TagScanStream(const char *uri, TagHandler &handler)
|
||||||
{
|
{
|
||||||
if (!tag_stream_scan(uri, handler))
|
Mutex mutex;
|
||||||
|
|
||||||
|
auto is = InputStream::OpenReady(uri, mutex);
|
||||||
|
if (!tag_stream_scan(*is, handler))
|
||||||
throw ProtocolError(ACK_ERROR_NO_EXIST, "Failed to load file");
|
throw ProtocolError(ACK_ERROR_NO_EXIST, "Failed to load file");
|
||||||
|
|
||||||
|
ScanGenericTags(*is, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
@@ -27,11 +27,15 @@
|
|||||||
#include "client/Response.hxx"
|
#include "client/Response.hxx"
|
||||||
#include "util/CharUtil.hxx"
|
#include "util/CharUtil.hxx"
|
||||||
#include "util/OffsetPointer.hxx"
|
#include "util/OffsetPointer.hxx"
|
||||||
|
#include "util/ScopeExit.hxx"
|
||||||
|
#include "util/StringCompare.hxx"
|
||||||
#include "util/StringView.hxx"
|
#include "util/StringView.hxx"
|
||||||
#include "util/UriExtract.hxx"
|
#include "util/UriExtract.hxx"
|
||||||
#include "tag/Handler.hxx"
|
#include "tag/Handler.hxx"
|
||||||
#include "tag/Generic.hxx"
|
#include "tag/Generic.hxx"
|
||||||
#include "TagAny.hxx"
|
#include "TagAny.hxx"
|
||||||
|
#include "db/Interface.hxx"
|
||||||
|
#include "song/LightSong.hxx"
|
||||||
#include "storage/StorageInterface.hxx"
|
#include "storage/StorageInterface.hxx"
|
||||||
#include "fs/AllocatedPath.hxx"
|
#include "fs/AllocatedPath.hxx"
|
||||||
#include "fs/FileInfo.hxx"
|
#include "fs/FileInfo.hxx"
|
||||||
@@ -187,10 +191,9 @@ find_stream_art(std::string_view directory, Mutex &mutex)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CommandResult
|
static CommandResult
|
||||||
read_stream_art(Response &r, const char *uri, size_t offset)
|
read_stream_art(Response &r, const std::string_view art_directory,
|
||||||
|
size_t offset)
|
||||||
{
|
{
|
||||||
const auto art_directory = PathTraitsUTF8::GetParent(uri);
|
|
||||||
|
|
||||||
// TODO: eliminate this const_cast
|
// TODO: eliminate this const_cast
|
||||||
auto &client = const_cast<Client &>(r.GetClient());
|
auto &client = const_cast<Client &>(r.GetClient());
|
||||||
|
|
||||||
@@ -243,6 +246,41 @@ read_stream_art(Response &r, const char *uri, size_t offset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_DATABASE
|
#ifdef ENABLE_DATABASE
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to locate the "real" directory where the given song is
|
||||||
|
* stored. This attempts to resolve "virtual" directories/songs,
|
||||||
|
* e.g. expanded CUE sheet contents.
|
||||||
|
*/
|
||||||
|
[[gnu::pure]]
|
||||||
|
static std::string_view
|
||||||
|
RealDirectoryOfSong(Client &client, const char *song_uri,
|
||||||
|
std::string_view directory_uri) noexcept
|
||||||
|
try {
|
||||||
|
const auto *db = client.GetDatabase();
|
||||||
|
if (db == nullptr)
|
||||||
|
return directory_uri;
|
||||||
|
|
||||||
|
const auto *song = db->GetSong(song_uri);
|
||||||
|
if (song == nullptr)
|
||||||
|
return directory_uri;
|
||||||
|
|
||||||
|
AtScopeExit(db, song) { db->ReturnSong(song); };
|
||||||
|
|
||||||
|
const char *real_uri = song->real_uri;
|
||||||
|
|
||||||
|
/* this is a simplification which is just enough for CUE
|
||||||
|
sheets (but may be incomplete): for each "../", go one
|
||||||
|
level up */
|
||||||
|
while ((real_uri = StringAfterPrefix(real_uri, "../")) != nullptr)
|
||||||
|
directory_uri = PathTraitsUTF8::GetParent(directory_uri);
|
||||||
|
|
||||||
|
return directory_uri;
|
||||||
|
} catch (...) {
|
||||||
|
/* ignore all exceptions from Database::GetSong() */
|
||||||
|
return directory_uri;
|
||||||
|
}
|
||||||
|
|
||||||
static CommandResult
|
static CommandResult
|
||||||
read_db_art(Client &client, Response &r, const char *uri, const uint64_t offset)
|
read_db_art(Client &client, Response &r, const char *uri, const uint64_t offset)
|
||||||
{
|
{
|
||||||
@@ -252,7 +290,13 @@ read_db_art(Client &client, Response &r, const char *uri, const uint64_t offset)
|
|||||||
return CommandResult::ERROR;
|
return CommandResult::ERROR;
|
||||||
}
|
}
|
||||||
std::string uri2 = storage->MapUTF8(uri);
|
std::string uri2 = storage->MapUTF8(uri);
|
||||||
return read_stream_art(r, uri2.c_str(), offset);
|
|
||||||
|
std::string_view directory_uri =
|
||||||
|
RealDirectoryOfSong(client,
|
||||||
|
uri,
|
||||||
|
PathTraitsUTF8::GetParent(uri2.c_str()));
|
||||||
|
|
||||||
|
return read_stream_art(r, directory_uri, offset);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -273,7 +317,10 @@ handle_album_art(Client &client, Request args, Response &r)
|
|||||||
switch (located_uri.type) {
|
switch (located_uri.type) {
|
||||||
case LocatedUri::Type::ABSOLUTE:
|
case LocatedUri::Type::ABSOLUTE:
|
||||||
case LocatedUri::Type::PATH:
|
case LocatedUri::Type::PATH:
|
||||||
return read_stream_art(r, located_uri.canonical_uri, offset);
|
return read_stream_art(r,
|
||||||
|
PathTraitsUTF8::GetParent(located_uri.canonical_uri),
|
||||||
|
offset);
|
||||||
|
|
||||||
case LocatedUri::Type::RELATIVE:
|
case LocatedUri::Type::RELATIVE:
|
||||||
#ifdef ENABLE_DATABASE
|
#ifdef ENABLE_DATABASE
|
||||||
return read_db_art(client, r, located_uri.canonical_uri, offset);
|
return read_db_art(client, r, located_uri.canonical_uri, offset);
|
||||||
|
|||||||
@@ -424,6 +424,7 @@ SendGroup(mpd_connection *connection, TagType group)
|
|||||||
return mpd_search_add_group_tag(connection, tag);
|
return mpd_search_add_group_tag(connection, tag);
|
||||||
#else
|
#else
|
||||||
(void)connection;
|
(void)connection;
|
||||||
|
(void)group;
|
||||||
|
|
||||||
throw std::runtime_error("Grouping requires libmpdclient 2.12");
|
throw std::runtime_error("Grouping requires libmpdclient 2.12");
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -109,6 +109,23 @@ Directory::FindChild(std::string_view name) const noexcept
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Directory::TargetExists(std::string_view _target) const noexcept
|
||||||
|
{
|
||||||
|
StringView target{_target};
|
||||||
|
|
||||||
|
if (target.SkipPrefix("../")) {
|
||||||
|
if (parent == nullptr)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return parent->TargetExists(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* sorry for the const_cast ... */
|
||||||
|
const auto lr = const_cast<Directory *>(this)->LookupDirectory(target);
|
||||||
|
return lr.directory->FindSong(lr.rest) != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Directory::PruneEmpty() noexcept
|
Directory::PruneEmpty() noexcept
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -118,13 +118,17 @@ public:
|
|||||||
return new Directory(std::string(), nullptr);
|
return new Directory(std::string(), nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsPlaylist() const noexcept {
|
||||||
|
return device == DEVICE_PLAYLIST;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is this really a regular file which is being treated like a
|
* Is this really a regular file which is being treated like a
|
||||||
* directory?
|
* directory?
|
||||||
*/
|
*/
|
||||||
bool IsReallyAFile() const noexcept {
|
bool IsReallyAFile() const noexcept {
|
||||||
return device == DEVICE_INARCHIVE ||
|
return device == DEVICE_INARCHIVE ||
|
||||||
device == DEVICE_PLAYLIST ||
|
IsPlaylist() ||
|
||||||
device == DEVICE_CONTAINER;
|
device == DEVICE_CONTAINER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,11 +210,13 @@ public:
|
|||||||
* Looks up a directory by its relative URI.
|
* Looks up a directory by its relative URI.
|
||||||
*
|
*
|
||||||
* @param uri the relative URI
|
* @param uri the relative URI
|
||||||
* @return the Directory, or nullptr if none was found
|
|
||||||
*/
|
*/
|
||||||
gcc_pure
|
gcc_pure
|
||||||
LookupResult LookupDirectory(std::string_view uri) noexcept;
|
LookupResult LookupDirectory(std::string_view uri) noexcept;
|
||||||
|
|
||||||
|
[[gnu::pure]]
|
||||||
|
bool TargetExists(std::string_view target) const noexcept;
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
bool IsEmpty() const noexcept {
|
bool IsEmpty() const noexcept {
|
||||||
return children.empty() &&
|
return children.empty() &&
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public:
|
|||||||
moved-from instance also owned the Tag
|
moved-from instance also owned the Tag
|
||||||
which its LightSong::tag field refers
|
which its LightSong::tag field refers
|
||||||
to */
|
to */
|
||||||
OwnsTag() ? tag_buffer : src.tag),
|
src.OwnsTag() ? tag_buffer : src.tag),
|
||||||
tag_buffer(std::move(src.tag_buffer)) {}
|
tag_buffer(std::move(src.tag_buffer)) {}
|
||||||
|
|
||||||
ExportedSong &operator=(ExportedSong &&) = delete;
|
ExportedSong &operator=(ExportedSong &&) = delete;
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#include "playlist/SongEnumerator.hxx"
|
#include "playlist/SongEnumerator.hxx"
|
||||||
#include "storage/FileInfo.hxx"
|
#include "storage/FileInfo.hxx"
|
||||||
#include "storage/StorageInterface.hxx"
|
#include "storage/StorageInterface.hxx"
|
||||||
|
#include "fs/Traits.hxx"
|
||||||
#include "util/StringFormat.hxx"
|
#include "util/StringFormat.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
@@ -70,7 +71,14 @@ UpdateWalk::UpdatePlaylistFile(Directory &parent, std::string_view name,
|
|||||||
|
|
||||||
auto db_song = std::make_unique<Song>(std::move(*song),
|
auto db_song = std::make_unique<Song>(std::move(*song),
|
||||||
*directory);
|
*directory);
|
||||||
db_song->target = "../" + db_song->filename;
|
db_song->target =
|
||||||
|
PathTraitsUTF8::IsAbsoluteOrHasScheme(db_song->filename.c_str())
|
||||||
|
? db_song->filename
|
||||||
|
/* prepend "../" to relative paths to
|
||||||
|
go from the virtual directory
|
||||||
|
(DEVICE_PLAYLIST) to the containing
|
||||||
|
directory */
|
||||||
|
: "../" + db_song->filename;
|
||||||
db_song->filename = StringFormat<64>("track%04u",
|
db_song->filename = StringFormat<64>("track%04u",
|
||||||
++track);
|
++track);
|
||||||
|
|
||||||
|
|||||||
@@ -133,6 +133,28 @@ UpdateWalk::PurgeDeletedFromDirectory(Directory &directory) noexcept
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UpdateWalk::PurgeDanglingFromPlaylists(Directory &directory) noexcept
|
||||||
|
{
|
||||||
|
/* recurse */
|
||||||
|
for (Directory &child : directory.children)
|
||||||
|
PurgeDanglingFromPlaylists(child);
|
||||||
|
|
||||||
|
if (!directory.IsPlaylist())
|
||||||
|
/* this check is only for virtual directories
|
||||||
|
representing a playlist file */
|
||||||
|
return;
|
||||||
|
|
||||||
|
directory.ForEachSongSafe([&](Song &song){
|
||||||
|
if (!song.target.empty() &&
|
||||||
|
!PathTraitsUTF8::IsAbsoluteOrHasScheme(song.target.c_str()) &&
|
||||||
|
!directory.TargetExists(song.target)) {
|
||||||
|
editor.DeleteSong(directory, &song);
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
static bool
|
static bool
|
||||||
update_directory_stat(Storage &storage, Directory &directory) noexcept
|
update_directory_stat(Storage &storage, Directory &directory) noexcept
|
||||||
@@ -312,6 +334,29 @@ UpdateWalk::SkipSymlink(const Directory *directory,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
LoadExcludeListOrThrow(const Storage &storage, const Directory &directory,
|
||||||
|
ExcludeList &exclude_list)
|
||||||
|
{
|
||||||
|
Mutex mutex;
|
||||||
|
auto is = InputStream::OpenReady(storage.MapUTF8(PathTraitsUTF8::Build(directory.GetPath(),
|
||||||
|
".mpdignore")).c_str(),
|
||||||
|
mutex);
|
||||||
|
exclude_list.Load(std::move(is));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
LoadExcludeListOrLog(const Storage &storage, const Directory &directory,
|
||||||
|
ExcludeList &exclude_list) noexcept
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
LoadExcludeListOrThrow(storage, directory, exclude_list);
|
||||||
|
} catch (...) {
|
||||||
|
if (!IsFileNotFound(std::current_exception()))
|
||||||
|
LogError(std::current_exception());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
UpdateWalk::UpdateDirectory(Directory &directory,
|
UpdateWalk::UpdateDirectory(Directory &directory,
|
||||||
const ExcludeList &exclude_list,
|
const ExcludeList &exclude_list,
|
||||||
@@ -331,17 +376,7 @@ UpdateWalk::UpdateDirectory(Directory &directory,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ExcludeList child_exclude_list(exclude_list);
|
ExcludeList child_exclude_list(exclude_list);
|
||||||
|
LoadExcludeListOrLog(storage, directory, child_exclude_list);
|
||||||
try {
|
|
||||||
Mutex mutex;
|
|
||||||
auto is = InputStream::OpenReady(storage.MapUTF8(PathTraitsUTF8::Build(directory.GetPath(),
|
|
||||||
".mpdignore")).c_str(),
|
|
||||||
mutex);
|
|
||||||
child_exclude_list.Load(std::move(is));
|
|
||||||
} catch (...) {
|
|
||||||
if (!IsFileNotFound(std::current_exception()))
|
|
||||||
LogError(std::current_exception());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!child_exclude_list.IsEmpty())
|
if (!child_exclude_list.IsEmpty())
|
||||||
RemoveExcludedFromDirectory(directory, child_exclude_list);
|
RemoveExcludedFromDirectory(directory, child_exclude_list);
|
||||||
@@ -445,6 +480,28 @@ UpdateWalk::DirectoryMakeUriParentChecked(Directory &root,
|
|||||||
return directory;
|
return directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
LoadExcludeLists(std::forward_list<ExcludeList> &lists,
|
||||||
|
const Storage &storage, const Directory &directory) noexcept
|
||||||
|
{
|
||||||
|
assert(!lists.empty());
|
||||||
|
|
||||||
|
if (!directory.IsRoot())
|
||||||
|
LoadExcludeLists(lists, storage, *directory.parent);
|
||||||
|
|
||||||
|
lists.emplace_front();
|
||||||
|
LoadExcludeListOrLog(storage, directory, lists.front());
|
||||||
|
}
|
||||||
|
|
||||||
|
static auto
|
||||||
|
LoadExcludeLists(const Storage &storage, const Directory &directory) noexcept
|
||||||
|
{
|
||||||
|
std::forward_list<ExcludeList> lists;
|
||||||
|
lists.emplace_front();
|
||||||
|
LoadExcludeLists(lists, storage, directory);
|
||||||
|
return lists;
|
||||||
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
UpdateWalk::UpdateUri(Directory &root, const char *uri) noexcept
|
UpdateWalk::UpdateUri(Directory &root, const char *uri) noexcept
|
||||||
try {
|
try {
|
||||||
@@ -465,9 +522,8 @@ try {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExcludeList exclude_list;
|
const auto exclude_lists = LoadExcludeLists(storage, *parent);
|
||||||
|
UpdateDirectoryChild(*parent, exclude_lists.front(), name, info);
|
||||||
UpdateDirectoryChild(*parent, exclude_list, name, info);
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
LogError(std::current_exception());
|
LogError(std::current_exception());
|
||||||
}
|
}
|
||||||
@@ -496,5 +552,10 @@ UpdateWalk::Walk(Directory &root, const char *path, bool discard) noexcept
|
|||||||
UpdateDirectory(root, exclude_list, info);
|
UpdateDirectory(root, exclude_list, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const ScopeDatabaseLock protect;
|
||||||
|
PurgeDanglingFromPlaylists(root);
|
||||||
|
}
|
||||||
|
|
||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,12 @@ private:
|
|||||||
|
|
||||||
void PurgeDeletedFromDirectory(Directory &directory) noexcept;
|
void PurgeDeletedFromDirectory(Directory &directory) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all virtual songs inside playlists whose "target"
|
||||||
|
* field points to a non-existing song file.
|
||||||
|
*/
|
||||||
|
void PurgeDanglingFromPlaylists(Directory &directory) noexcept;
|
||||||
|
|
||||||
void UpdateSongFile2(Directory &directory,
|
void UpdateSongFile2(Directory &directory,
|
||||||
const char *name, const char *suffix,
|
const char *name, const char *suffix,
|
||||||
const StorageFileInfo &info) noexcept;
|
const StorageFileInfo &info) noexcept;
|
||||||
|
|||||||
@@ -581,10 +581,6 @@ DecoderBridge::SubmitTag(InputStream *is, Tag &&tag) noexcept
|
|||||||
|
|
||||||
decoder_tag = std::make_unique<Tag>(std::move(tag));
|
decoder_tag = std::make_unique<Tag>(std::move(tag));
|
||||||
|
|
||||||
/* check for a new stream tag */
|
|
||||||
|
|
||||||
UpdateStreamTag(is);
|
|
||||||
|
|
||||||
/* check if we're seeking */
|
/* check if we're seeking */
|
||||||
|
|
||||||
if (PrepareInitialSeek())
|
if (PrepareInitialSeek())
|
||||||
@@ -593,6 +589,10 @@ DecoderBridge::SubmitTag(InputStream *is, Tag &&tag) noexcept
|
|||||||
function here */
|
function here */
|
||||||
return DecoderCommand::SEEK;
|
return DecoderCommand::SEEK;
|
||||||
|
|
||||||
|
/* check for a new stream tag */
|
||||||
|
|
||||||
|
UpdateStreamTag(is);
|
||||||
|
|
||||||
/* send tag to music pipe */
|
/* send tag to music pipe */
|
||||||
|
|
||||||
if (stream_tag != nullptr)
|
if (stream_tag != nullptr)
|
||||||
|
|||||||
@@ -470,6 +470,7 @@ IsSeekable(const AVFormatContext &format_context) noexcept
|
|||||||
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 6, 100)
|
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 6, 100)
|
||||||
return (format_context.ctx_flags & AVFMTCTX_UNSEEKABLE) != 0;
|
return (format_context.ctx_flags & AVFMTCTX_UNSEEKABLE) != 0;
|
||||||
#else
|
#else
|
||||||
|
(void)format_context;
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -658,6 +659,8 @@ ffmpeg_scan_stream(InputStream &is, TagHandler &handler)
|
|||||||
return FfmpegScanStream(*f, handler);
|
return FfmpegScanStream(*f, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 9, 100)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ffmpeg_uri_decode(DecoderClient &client, const char *uri)
|
ffmpeg_uri_decode(DecoderClient &client, const char *uri)
|
||||||
{
|
{
|
||||||
@@ -689,6 +692,8 @@ ffmpeg_protocols() noexcept
|
|||||||
return protocols;
|
return protocols;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of extensions found for the formats supported by ffmpeg.
|
* A list of extensions found for the formats supported by ffmpeg.
|
||||||
* This list is current as of 02-23-09; To find out if there are more
|
* This list is current as of 02-23-09; To find out if there are more
|
||||||
@@ -812,6 +817,8 @@ static const char *const ffmpeg_mime_types[] = {
|
|||||||
constexpr DecoderPlugin ffmpeg_decoder_plugin =
|
constexpr DecoderPlugin ffmpeg_decoder_plugin =
|
||||||
DecoderPlugin("ffmpeg", ffmpeg_decode, ffmpeg_scan_stream)
|
DecoderPlugin("ffmpeg", ffmpeg_decode, ffmpeg_scan_stream)
|
||||||
.WithInit(ffmpeg_init, ffmpeg_finish)
|
.WithInit(ffmpeg_init, ffmpeg_finish)
|
||||||
|
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 9, 100)
|
||||||
.WithProtocols(ffmpeg_protocols, ffmpeg_uri_decode)
|
.WithProtocols(ffmpeg_protocols, ffmpeg_uri_decode)
|
||||||
|
#endif
|
||||||
.WithSuffixes(ffmpeg_suffixes)
|
.WithSuffixes(ffmpeg_suffixes)
|
||||||
.WithMimeTypes(ffmpeg_mime_types);
|
.WithMimeTypes(ffmpeg_mime_types);
|
||||||
|
|||||||
@@ -30,11 +30,22 @@ extern "C" {
|
|||||||
#include <libavutil/dict.h>
|
#include <libavutil/dict.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FFmpeg specific tag name mappings, as supported by
|
||||||
|
* libavformat/id3v2.c, libavformat/mov.c and others.
|
||||||
|
*/
|
||||||
static constexpr struct tag_table ffmpeg_tags[] = {
|
static constexpr struct tag_table ffmpeg_tags[] = {
|
||||||
{ "year", TAG_DATE },
|
/* from libavformat/id3v2.c, libavformat/mov.c */
|
||||||
{ "author-sort", TAG_ARTIST_SORT },
|
|
||||||
{ "album_artist", TAG_ALBUM_ARTIST },
|
{ "album_artist", TAG_ALBUM_ARTIST },
|
||||||
{ "album_artist-sort", TAG_ALBUM_ARTIST_SORT },
|
|
||||||
|
/* from libavformat/id3v2.c */
|
||||||
|
{ "album-sort", TAG_ALBUM_SORT },
|
||||||
|
{ "artist-sort", TAG_ARTIST_SORT },
|
||||||
|
|
||||||
|
/* from libavformat/mov.c */
|
||||||
|
{ "sort_album_artist", TAG_ALBUM_ARTIST_SORT },
|
||||||
|
{ "sort_album", TAG_ALBUM_SORT },
|
||||||
|
{ "sort_artist", TAG_ARTIST_SORT },
|
||||||
|
|
||||||
/* sentinel */
|
/* sentinel */
|
||||||
{ nullptr, TAG_NUM_OF_ITEM_TYPES }
|
{ nullptr, TAG_NUM_OF_ITEM_TYPES }
|
||||||
|
|||||||
@@ -889,8 +889,6 @@ inline bool
|
|||||||
MadDecoder::HandleCurrentFrame() noexcept
|
MadDecoder::HandleCurrentFrame() noexcept
|
||||||
{
|
{
|
||||||
switch (mute_frame) {
|
switch (mute_frame) {
|
||||||
DecoderCommand cmd;
|
|
||||||
|
|
||||||
case MadDecoderMuteFrame::SKIP:
|
case MadDecoderMuteFrame::SKIP:
|
||||||
mute_frame = MadDecoderMuteFrame::NONE;
|
mute_frame = MadDecoderMuteFrame::NONE;
|
||||||
break;
|
break;
|
||||||
@@ -899,8 +897,8 @@ MadDecoder::HandleCurrentFrame() noexcept
|
|||||||
mute_frame = MadDecoderMuteFrame::NONE;
|
mute_frame = MadDecoderMuteFrame::NONE;
|
||||||
UpdateTimerNextFrame();
|
UpdateTimerNextFrame();
|
||||||
break;
|
break;
|
||||||
case MadDecoderMuteFrame::NONE:
|
case MadDecoderMuteFrame::NONE: {
|
||||||
cmd = SynthAndSubmit();
|
const auto cmd = SynthAndSubmit();
|
||||||
UpdateTimerNextFrame();
|
UpdateTimerNextFrame();
|
||||||
if (cmd == DecoderCommand::SEEK) {
|
if (cmd == DecoderCommand::SEEK) {
|
||||||
assert(input_stream.IsSeekable());
|
assert(input_stream.IsSeekable());
|
||||||
@@ -922,6 +920,7 @@ MadDecoder::HandleCurrentFrame() noexcept
|
|||||||
} else if (cmd != DecoderCommand::NONE)
|
} else if (cmd != DecoderCommand::NONE)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "Traits.hxx"
|
#include "Traits.hxx"
|
||||||
#include "util/StringCompare.hxx"
|
#include "util/StringCompare.hxx"
|
||||||
|
#include "util/UriExtract.hxx"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -84,6 +85,22 @@ GetParentPathImpl(typename Traits::const_pointer p) noexcept
|
|||||||
return {p, size_t(sep - p)};
|
return {p, size_t(sep - p)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Traits>
|
||||||
|
typename Traits::string_view
|
||||||
|
GetParentPathImpl(typename Traits::string_view p) noexcept
|
||||||
|
{
|
||||||
|
auto sep = Traits::FindLastSeparator(p);
|
||||||
|
if (sep == nullptr)
|
||||||
|
return Traits::CURRENT_DIRECTORY;
|
||||||
|
if (sep == p.data())
|
||||||
|
return p.substr(0, 1);
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (Traits::IsDrive(p) && sep == p.data() + 2)
|
||||||
|
return p.substr(0, 3);
|
||||||
|
#endif
|
||||||
|
return p.substr(0, sep - p.data());
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Traits>
|
template<typename Traits>
|
||||||
typename Traits::const_pointer
|
typename Traits::const_pointer
|
||||||
RelativePathImpl(typename Traits::string_view base,
|
RelativePathImpl(typename Traits::string_view base,
|
||||||
@@ -166,6 +183,12 @@ PathTraitsFS::GetParent(PathTraitsFS::const_pointer p) noexcept
|
|||||||
return GetParentPathImpl<PathTraitsFS>(p);
|
return GetParentPathImpl<PathTraitsFS>(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PathTraitsFS::string_view
|
||||||
|
PathTraitsFS::GetParent(string_view p) noexcept
|
||||||
|
{
|
||||||
|
return GetParentPathImpl<PathTraitsFS>(p);
|
||||||
|
}
|
||||||
|
|
||||||
PathTraitsFS::const_pointer
|
PathTraitsFS::const_pointer
|
||||||
PathTraitsFS::Relative(string_view base, const_pointer other) noexcept
|
PathTraitsFS::Relative(string_view base, const_pointer other) noexcept
|
||||||
{
|
{
|
||||||
@@ -198,6 +221,12 @@ PathTraitsUTF8::Build(string_view a, string_view b) noexcept
|
|||||||
return BuildPathImpl<PathTraitsUTF8>(a, b);
|
return BuildPathImpl<PathTraitsUTF8>(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
PathTraitsUTF8::IsAbsoluteOrHasScheme(const_pointer p) noexcept
|
||||||
|
{
|
||||||
|
return IsAbsolute(p) || uri_has_scheme(p);
|
||||||
|
}
|
||||||
|
|
||||||
PathTraitsUTF8::const_pointer
|
PathTraitsUTF8::const_pointer
|
||||||
PathTraitsUTF8::GetBase(const_pointer p) noexcept
|
PathTraitsUTF8::GetBase(const_pointer p) noexcept
|
||||||
{
|
{
|
||||||
@@ -210,6 +239,12 @@ PathTraitsUTF8::GetParent(const_pointer p) noexcept
|
|||||||
return GetParentPathImpl<PathTraitsUTF8>(p);
|
return GetParentPathImpl<PathTraitsUTF8>(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PathTraitsUTF8::string_view
|
||||||
|
PathTraitsUTF8::GetParent(string_view p) noexcept
|
||||||
|
{
|
||||||
|
return GetParentPathImpl<PathTraitsUTF8>(p);
|
||||||
|
}
|
||||||
|
|
||||||
PathTraitsUTF8::const_pointer
|
PathTraitsUTF8::const_pointer
|
||||||
PathTraitsUTF8::Relative(string_view base, const_pointer other) noexcept
|
PathTraitsUTF8::Relative(string_view base, const_pointer other) noexcept
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -88,6 +88,18 @@ struct PathTraitsFS {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[gnu::pure]]
|
||||||
|
static const_pointer FindLastSeparator(string_view p) noexcept {
|
||||||
|
#ifdef _WIN32
|
||||||
|
const_pointer pos = p.data() + p.size();
|
||||||
|
while (p.data() != pos && !IsSeparator(*pos))
|
||||||
|
--pos;
|
||||||
|
return IsSeparator(*pos) ? pos : nullptr;
|
||||||
|
#else
|
||||||
|
return StringFindLast(p.data(), SEPARATOR, p.size());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
static const_pointer GetFilenameSuffix(const_pointer filename) noexcept {
|
static const_pointer GetFilenameSuffix(const_pointer filename) noexcept {
|
||||||
const_pointer dot = StringFindLast(filename, '.');
|
const_pointer dot = StringFindLast(filename, '.');
|
||||||
@@ -106,6 +118,10 @@ struct PathTraitsFS {
|
|||||||
static constexpr bool IsDrive(const_pointer p) noexcept {
|
static constexpr bool IsDrive(const_pointer p) noexcept {
|
||||||
return IsAlphaASCII(p[0]) && p[1] == ':';
|
return IsAlphaASCII(p[0]) && p[1] == ':';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static constexpr bool IsDrive(string_view p) noexcept {
|
||||||
|
return p.size() >= 2 && IsAlphaASCII(p[0]) && p[1] == ':';
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gcc_pure gcc_nonnull_all
|
gcc_pure gcc_nonnull_all
|
||||||
@@ -153,6 +169,9 @@ struct PathTraitsFS {
|
|||||||
gcc_pure gcc_nonnull_all
|
gcc_pure gcc_nonnull_all
|
||||||
static string_view GetParent(const_pointer p) noexcept;
|
static string_view GetParent(const_pointer p) noexcept;
|
||||||
|
|
||||||
|
[[gnu::pure]]
|
||||||
|
static string_view GetParent(string_view p) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine the relative part of the given path to this
|
* Determine the relative part of the given path to this
|
||||||
* object, not including the directory separator. Returns an
|
* object, not including the directory separator. Returns an
|
||||||
@@ -212,6 +231,11 @@ struct PathTraitsUTF8 {
|
|||||||
return std::strrchr(p, SEPARATOR);
|
return std::strrchr(p, SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[gnu::pure]]
|
||||||
|
static const_pointer FindLastSeparator(string_view p) noexcept {
|
||||||
|
return StringFindLast(p.data(), SEPARATOR, p.size());
|
||||||
|
}
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
static const_pointer GetFilenameSuffix(const_pointer filename) noexcept {
|
static const_pointer GetFilenameSuffix(const_pointer filename) noexcept {
|
||||||
const_pointer dot = StringFindLast(filename, '.');
|
const_pointer dot = StringFindLast(filename, '.');
|
||||||
@@ -230,6 +254,10 @@ struct PathTraitsUTF8 {
|
|||||||
static constexpr bool IsDrive(const_pointer p) noexcept {
|
static constexpr bool IsDrive(const_pointer p) noexcept {
|
||||||
return IsAlphaASCII(p[0]) && p[1] == ':';
|
return IsAlphaASCII(p[0]) && p[1] == ':';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static constexpr bool IsDrive(string_view p) noexcept {
|
||||||
|
return p.size() >= 2 && IsAlphaASCII(p[0]) && p[1] == ':';
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gcc_pure gcc_nonnull_all
|
gcc_pure gcc_nonnull_all
|
||||||
@@ -246,6 +274,13 @@ struct PathTraitsUTF8 {
|
|||||||
return IsSeparator(*p);
|
return IsSeparator(*p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this any kind of absolute URI? (Unlike IsAbsolute(),
|
||||||
|
* this includes URIs/URLs with a scheme)
|
||||||
|
*/
|
||||||
|
[[gnu::pure]] [[gnu::nonnull]]
|
||||||
|
static bool IsAbsoluteOrHasScheme(const_pointer p) noexcept;
|
||||||
|
|
||||||
gcc_pure gcc_nonnull_all
|
gcc_pure gcc_nonnull_all
|
||||||
static bool IsSpecialFilename(const_pointer name) noexcept {
|
static bool IsSpecialFilename(const_pointer name) noexcept {
|
||||||
return (name[0] == '.' && name[1] == 0) ||
|
return (name[0] == '.' && name[1] == 0) ||
|
||||||
@@ -277,6 +312,9 @@ struct PathTraitsUTF8 {
|
|||||||
gcc_pure gcc_nonnull_all
|
gcc_pure gcc_nonnull_all
|
||||||
static string_view GetParent(const_pointer p) noexcept;
|
static string_view GetParent(const_pointer p) noexcept;
|
||||||
|
|
||||||
|
[[gnu::pure]]
|
||||||
|
static string_view GetParent(string_view p) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine the relative part of the given path to this
|
* Determine the relative part of the given path to this
|
||||||
* object, not including the directory separator. Returns an
|
* object, not including the directory separator. Returns an
|
||||||
|
|||||||
@@ -104,8 +104,11 @@ IcyInputStream::Read(std::unique_lock<Mutex> &lock,
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
size_t nbytes = ProxyInputStream::Read(lock, ptr, read_size);
|
size_t nbytes = ProxyInputStream::Read(lock, ptr, read_size);
|
||||||
if (nbytes == 0)
|
if (nbytes == 0) {
|
||||||
|
assert(IsEOF());
|
||||||
|
offset = override_offset;
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
size_t result = parser->ParseInPlace(ptr, nbytes);
|
size_t result = parser->ParseInPlace(ptr, nbytes);
|
||||||
if (result > 0) {
|
if (result > 0) {
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ static bool
|
|||||||
ExpensiveSeeking(const char *uri) noexcept
|
ExpensiveSeeking(const char *uri) noexcept
|
||||||
{
|
{
|
||||||
return StringStartsWithCaseASCII(uri, "http://") ||
|
return StringStartsWithCaseASCII(uri, "http://") ||
|
||||||
StringStartsWithCaseASCII(uri, "tidal://") ||
|
|
||||||
StringStartsWithCaseASCII(uri, "qobuz://") ||
|
StringStartsWithCaseASCII(uri, "qobuz://") ||
|
||||||
StringStartsWithCaseASCII(uri, "https://");
|
StringStartsWithCaseASCII(uri, "https://");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ LastInputStream::~LastInputStream() noexcept = default;
|
|||||||
void
|
void
|
||||||
LastInputStream::Close() noexcept
|
LastInputStream::Close() noexcept
|
||||||
{
|
{
|
||||||
|
uri.clear();
|
||||||
is.reset();
|
is.reset();
|
||||||
close_timer.Cancel();
|
close_timer.Cancel();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,8 +64,7 @@ public:
|
|||||||
return is.get();
|
return is.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
is.reset();
|
Close();
|
||||||
close_timer.Cancel();
|
|
||||||
|
|
||||||
is = open(new_uri, mutex);
|
is = open(new_uri, mutex);
|
||||||
uri = std::forward<U>(new_uri);
|
uri = std::forward<U>(new_uri);
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
#include "Registry.hxx"
|
#include "Registry.hxx"
|
||||||
#include "InputPlugin.hxx"
|
#include "InputPlugin.hxx"
|
||||||
#include "input/Features.h"
|
#include "input/Features.h"
|
||||||
#include "plugins/TidalInputPlugin.hxx"
|
|
||||||
#include "plugins/QobuzInputPlugin.hxx"
|
#include "plugins/QobuzInputPlugin.hxx"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
@@ -56,9 +55,6 @@ const InputPlugin *const input_plugins[] = {
|
|||||||
#ifdef ENABLE_ALSA
|
#ifdef ENABLE_ALSA
|
||||||
&input_plugin_alsa,
|
&input_plugin_alsa,
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_TIDAL
|
|
||||||
&tidal_input_plugin,
|
|
||||||
#endif
|
|
||||||
#ifdef ENABLE_QOBUZ
|
#ifdef ENABLE_QOBUZ
|
||||||
&qobuz_input_plugin,
|
&qobuz_input_plugin,
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2003-2021 The Music Player Daemon Project
|
|
||||||
* http://www.musicpd.org
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TIDAL_ERROR_HXX
|
|
||||||
#define TIDAL_ERROR_HXX
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An error condition reported by the server.
|
|
||||||
*
|
|
||||||
* See http://developer.tidal.com/technical/errors/ for details (login
|
|
||||||
* required).
|
|
||||||
*/
|
|
||||||
class TidalError : public std::runtime_error {
|
|
||||||
/**
|
|
||||||
* The HTTP status code.
|
|
||||||
*/
|
|
||||||
unsigned status;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Tidal-specific "subStatus". 0 if none was found in the
|
|
||||||
* JSON response.
|
|
||||||
*/
|
|
||||||
unsigned sub_status;
|
|
||||||
|
|
||||||
public:
|
|
||||||
template<typename W>
|
|
||||||
TidalError(unsigned _status, unsigned _sub_status, W &&_what) noexcept
|
|
||||||
:std::runtime_error(std::forward<W>(_what)),
|
|
||||||
status(_status), sub_status(_sub_status) {}
|
|
||||||
|
|
||||||
unsigned GetStatus() const noexcept {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned GetSubStatus() const noexcept {
|
|
||||||
return sub_status;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsInvalidSession() const noexcept {
|
|
||||||
return sub_status == 6001 || sub_status == 6002;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2003-2021 The Music Player Daemon Project
|
|
||||||
* http://www.musicpd.org
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "TidalErrorParser.hxx"
|
|
||||||
#include "TidalError.hxx"
|
|
||||||
#include "lib/yajl/Callbacks.hxx"
|
|
||||||
#include "util/RuntimeError.hxx"
|
|
||||||
|
|
||||||
using Wrapper = Yajl::CallbacksWrapper<TidalErrorParser>;
|
|
||||||
static constexpr yajl_callbacks tidal_error_parser_callbacks = {
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
Wrapper::Integer,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
Wrapper::String,
|
|
||||||
nullptr,
|
|
||||||
Wrapper::MapKey,
|
|
||||||
Wrapper::EndMap,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
TidalErrorParser::TidalErrorParser(unsigned _status,
|
|
||||||
const std::multimap<std::string, std::string> &headers)
|
|
||||||
:YajlResponseParser(&tidal_error_parser_callbacks, nullptr, this),
|
|
||||||
status(_status)
|
|
||||||
{
|
|
||||||
auto i = headers.find("content-type");
|
|
||||||
if (i == headers.end() || i->second.find("/json") == i->second.npos)
|
|
||||||
throw FormatRuntimeError("Status %u from Tidal", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TidalErrorParser::OnEnd()
|
|
||||||
{
|
|
||||||
YajlResponseParser::OnEnd();
|
|
||||||
|
|
||||||
char what[1024];
|
|
||||||
|
|
||||||
if (!message.empty())
|
|
||||||
snprintf(what, sizeof(what), "Error from Tidal: %s",
|
|
||||||
message.c_str());
|
|
||||||
else
|
|
||||||
snprintf(what, sizeof(what), "Status %u from Tidal", status);
|
|
||||||
|
|
||||||
throw TidalError(status, sub_status, what);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
TidalErrorParser::Integer(long long value) noexcept
|
|
||||||
{
|
|
||||||
switch (state) {
|
|
||||||
case State::NONE:
|
|
||||||
case State::USER_MESSAGE:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case State::SUB_STATUS:
|
|
||||||
sub_status = value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
TidalErrorParser::String(StringView value) noexcept
|
|
||||||
{
|
|
||||||
switch (state) {
|
|
||||||
case State::NONE:
|
|
||||||
case State::SUB_STATUS:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case State::USER_MESSAGE:
|
|
||||||
message.assign(value.data, value.size);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
TidalErrorParser::MapKey(StringView value) noexcept
|
|
||||||
{
|
|
||||||
if (value.Equals("userMessage"))
|
|
||||||
state = State::USER_MESSAGE;
|
|
||||||
else if (value.Equals("subStatus"))
|
|
||||||
state = State::SUB_STATUS;
|
|
||||||
else
|
|
||||||
state = State::NONE;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
TidalErrorParser::EndMap() noexcept
|
|
||||||
{
|
|
||||||
state = State::NONE;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2003-2021 The Music Player Daemon Project
|
|
||||||
* http://www.musicpd.org
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TIDAL_ERROR_PARSER_HXX
|
|
||||||
#define TIDAL_ERROR_PARSER_HXX
|
|
||||||
|
|
||||||
#include "lib/yajl/ResponseParser.hxx"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
template<typename T> struct ConstBuffer;
|
|
||||||
struct StringView;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse an error JSON response and throw a #TidalError upon
|
|
||||||
* completion.
|
|
||||||
*/
|
|
||||||
class TidalErrorParser final : public YajlResponseParser {
|
|
||||||
const unsigned status;
|
|
||||||
|
|
||||||
enum class State {
|
|
||||||
NONE,
|
|
||||||
USER_MESSAGE,
|
|
||||||
SUB_STATUS,
|
|
||||||
} state = State::NONE;
|
|
||||||
|
|
||||||
unsigned sub_status = 0;
|
|
||||||
|
|
||||||
std::string message;
|
|
||||||
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* May throw if there is a formal error in the response
|
|
||||||
* headers.
|
|
||||||
*/
|
|
||||||
TidalErrorParser(unsigned status,
|
|
||||||
const std::multimap<std::string, std::string> &headers);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
/* virtual methods from CurlResponseParser */
|
|
||||||
[[noreturn]]
|
|
||||||
void OnEnd() override;
|
|
||||||
|
|
||||||
public:
|
|
||||||
/* yajl callbacks */
|
|
||||||
bool Integer(long long value) noexcept;
|
|
||||||
bool String(StringView value) noexcept;
|
|
||||||
bool MapKey(StringView value) noexcept;
|
|
||||||
bool EndMap() noexcept;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,256 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2003-2021 The Music Player Daemon Project
|
|
||||||
* http://www.musicpd.org
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "TidalInputPlugin.hxx"
|
|
||||||
#include "TidalSessionManager.hxx"
|
|
||||||
#include "TidalTrackRequest.hxx"
|
|
||||||
#include "TidalTagScanner.hxx"
|
|
||||||
#include "TidalError.hxx"
|
|
||||||
#include "CurlInputPlugin.hxx"
|
|
||||||
#include "PluginUnavailable.hxx"
|
|
||||||
#include "input/ProxyInputStream.hxx"
|
|
||||||
#include "input/FailingInputStream.hxx"
|
|
||||||
#include "input/InputPlugin.hxx"
|
|
||||||
#include "config/Block.hxx"
|
|
||||||
#include "thread/Mutex.hxx"
|
|
||||||
#include "util/Domain.hxx"
|
|
||||||
#include "util/Exception.hxx"
|
|
||||||
#include "util/StringCompare.hxx"
|
|
||||||
#include "Log.hxx"
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
static constexpr Domain tidal_domain("tidal");
|
|
||||||
|
|
||||||
static TidalSessionManager *tidal_session;
|
|
||||||
static const char *tidal_audioquality;
|
|
||||||
|
|
||||||
class TidalInputStream final
|
|
||||||
: public ProxyInputStream, TidalSessionHandler, TidalTrackHandler {
|
|
||||||
|
|
||||||
const std::string track_id;
|
|
||||||
|
|
||||||
std::unique_ptr<TidalTrackRequest> track_request;
|
|
||||||
|
|
||||||
std::exception_ptr error;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retry to login if TidalError::IsInvalidSession() returns
|
|
||||||
* true?
|
|
||||||
*/
|
|
||||||
bool retry_login = true;
|
|
||||||
|
|
||||||
public:
|
|
||||||
TidalInputStream(const char *_uri, const char *_track_id,
|
|
||||||
Mutex &_mutex) noexcept
|
|
||||||
:ProxyInputStream(_uri, _mutex),
|
|
||||||
track_id(_track_id)
|
|
||||||
{
|
|
||||||
tidal_session->AddLoginHandler(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
~TidalInputStream() override {
|
|
||||||
tidal_session->RemoveLoginHandler(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* virtual methods from InputStream */
|
|
||||||
|
|
||||||
void Check() override {
|
|
||||||
if (error)
|
|
||||||
std::rethrow_exception(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void Failed(const std::exception_ptr& e) {
|
|
||||||
SetInput(std::make_unique<FailingInputStream>(GetURI(), e,
|
|
||||||
mutex));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* virtual methods from TidalSessionHandler */
|
|
||||||
void OnTidalSession() noexcept override;
|
|
||||||
|
|
||||||
/* virtual methods from TidalTrackHandler */
|
|
||||||
void OnTidalTrackSuccess(std::string url) noexcept override;
|
|
||||||
void OnTidalTrackError(std::exception_ptr error) noexcept override;
|
|
||||||
};
|
|
||||||
|
|
||||||
void
|
|
||||||
TidalInputStream::OnTidalSession() noexcept
|
|
||||||
{
|
|
||||||
const std::lock_guard<Mutex> protect(mutex);
|
|
||||||
|
|
||||||
try {
|
|
||||||
TidalTrackHandler &h = *this;
|
|
||||||
track_request = std::make_unique<TidalTrackRequest>(tidal_session->GetCurl(),
|
|
||||||
tidal_session->GetBaseUrl(),
|
|
||||||
tidal_session->GetToken(),
|
|
||||||
tidal_session->GetSession().c_str(),
|
|
||||||
track_id.c_str(),
|
|
||||||
tidal_audioquality,
|
|
||||||
h);
|
|
||||||
track_request->Start();
|
|
||||||
} catch (...) {
|
|
||||||
Failed(std::current_exception());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TidalInputStream::OnTidalTrackSuccess(std::string url) noexcept
|
|
||||||
{
|
|
||||||
FormatDebug(tidal_domain, "Tidal track '%s' resolves to %s",
|
|
||||||
track_id.c_str(), url.c_str());
|
|
||||||
|
|
||||||
const std::lock_guard<Mutex> protect(mutex);
|
|
||||||
|
|
||||||
track_request.reset();
|
|
||||||
|
|
||||||
try {
|
|
||||||
SetInput(OpenCurlInputStream(url.c_str(), {},
|
|
||||||
mutex));
|
|
||||||
} catch (...) {
|
|
||||||
Failed(std::current_exception());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gcc_pure
|
|
||||||
static bool
|
|
||||||
IsInvalidSession(std::exception_ptr e) noexcept
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
std::rethrow_exception(std::move(e));
|
|
||||||
} catch (const TidalError &te) {
|
|
||||||
return te.IsInvalidSession();
|
|
||||||
} catch (...) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TidalInputStream::OnTidalTrackError(std::exception_ptr e) noexcept
|
|
||||||
{
|
|
||||||
const std::lock_guard<Mutex> protect(mutex);
|
|
||||||
|
|
||||||
if (retry_login && IsInvalidSession(e)) {
|
|
||||||
/* the session has expired - obtain a new session id
|
|
||||||
by logging in again */
|
|
||||||
|
|
||||||
FormatInfo(tidal_domain, "Session expired ('%s'), retrying to log in",
|
|
||||||
GetFullMessage(e).c_str());
|
|
||||||
|
|
||||||
retry_login = false;
|
|
||||||
tidal_session->AddLoginHandler(*this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Failed(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
InitTidalInput(EventLoop &event_loop, const ConfigBlock &block)
|
|
||||||
{
|
|
||||||
const char *base_url = block.GetBlockValue("base_url",
|
|
||||||
"https://api.tidal.com/v1");
|
|
||||||
|
|
||||||
const char *token = block.GetBlockValue("token");
|
|
||||||
if (token == nullptr)
|
|
||||||
throw PluginUnconfigured("No Tidal application token configured");
|
|
||||||
|
|
||||||
const char *username = block.GetBlockValue("username");
|
|
||||||
if (username == nullptr)
|
|
||||||
throw PluginUnconfigured("No Tidal username configured");
|
|
||||||
|
|
||||||
const char *password = block.GetBlockValue("password");
|
|
||||||
if (password == nullptr)
|
|
||||||
throw PluginUnconfigured("No Tidal password configured");
|
|
||||||
|
|
||||||
FormatWarning(tidal_domain, "The Tidal input plugin is deprecated because Tidal has changed the protocol and doesn't share documentation");
|
|
||||||
|
|
||||||
tidal_audioquality = block.GetBlockValue("audioquality", "HIGH");
|
|
||||||
|
|
||||||
tidal_session = new TidalSessionManager(event_loop, base_url, token,
|
|
||||||
username, password);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
FinishTidalInput() noexcept
|
|
||||||
{
|
|
||||||
delete tidal_session;
|
|
||||||
}
|
|
||||||
|
|
||||||
gcc_pure
|
|
||||||
static const char *
|
|
||||||
ExtractTidalTrackId(const char *uri)
|
|
||||||
{
|
|
||||||
const char *track_id = StringAfterPrefix(uri, "tidal://track/");
|
|
||||||
if (track_id == nullptr) {
|
|
||||||
track_id = StringAfterPrefix(uri, "https://listen.tidal.com/track/");
|
|
||||||
if (track_id == nullptr)
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*track_id == 0)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
return track_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
static InputStreamPtr
|
|
||||||
OpenTidalInput(const char *uri, Mutex &mutex)
|
|
||||||
{
|
|
||||||
assert(tidal_session != nullptr);
|
|
||||||
|
|
||||||
const char *track_id = ExtractTidalTrackId(uri);
|
|
||||||
if (track_id == nullptr)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
// TODO: validate track_id
|
|
||||||
|
|
||||||
return std::make_unique<TidalInputStream>(uri, track_id, mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::unique_ptr<RemoteTagScanner>
|
|
||||||
ScanTidalTags(const char *uri, RemoteTagHandler &handler)
|
|
||||||
{
|
|
||||||
assert(tidal_session != nullptr);
|
|
||||||
|
|
||||||
const char *track_id = ExtractTidalTrackId(uri);
|
|
||||||
if (track_id == nullptr)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
return std::make_unique<TidalTagScanner>(tidal_session->GetCurl(),
|
|
||||||
tidal_session->GetBaseUrl(),
|
|
||||||
tidal_session->GetToken(),
|
|
||||||
track_id, handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr const char *tidal_prefixes[] = {
|
|
||||||
"tidal://",
|
|
||||||
nullptr
|
|
||||||
};
|
|
||||||
|
|
||||||
const InputPlugin tidal_input_plugin = {
|
|
||||||
"tidal",
|
|
||||||
tidal_prefixes,
|
|
||||||
InitTidalInput,
|
|
||||||
FinishTidalInput,
|
|
||||||
OpenTidalInput,
|
|
||||||
nullptr,
|
|
||||||
ScanTidalTags,
|
|
||||||
};
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2003-2021 The Music Player Daemon Project
|
|
||||||
* http://www.musicpd.org
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef INPUT_TIDAL_HXX
|
|
||||||
#define INPUT_TIDAL_HXX
|
|
||||||
|
|
||||||
extern const struct InputPlugin tidal_input_plugin;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2003-2021 The Music Player Daemon Project
|
|
||||||
* http://www.musicpd.org
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "TidalLoginRequest.hxx"
|
|
||||||
#include "TidalErrorParser.hxx"
|
|
||||||
#include "lib/curl/Form.hxx"
|
|
||||||
#include "lib/yajl/Callbacks.hxx"
|
|
||||||
#include "lib/yajl/ResponseParser.hxx"
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
using Wrapper = Yajl::CallbacksWrapper<TidalLoginRequest::ResponseParser>;
|
|
||||||
static constexpr yajl_callbacks parse_callbacks = {
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
Wrapper::String,
|
|
||||||
nullptr,
|
|
||||||
Wrapper::MapKey,
|
|
||||||
Wrapper::EndMap,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
class TidalLoginRequest::ResponseParser final : public YajlResponseParser {
|
|
||||||
enum class State {
|
|
||||||
NONE,
|
|
||||||
SESSION_ID,
|
|
||||||
} state = State::NONE;
|
|
||||||
|
|
||||||
std::string session;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit ResponseParser() noexcept
|
|
||||||
:YajlResponseParser(&parse_callbacks, nullptr, this) {}
|
|
||||||
|
|
||||||
std::string &&GetSession() {
|
|
||||||
if (session.empty())
|
|
||||||
throw std::runtime_error("No sessionId in login response");
|
|
||||||
|
|
||||||
return std::move(session);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* yajl callbacks */
|
|
||||||
bool String(StringView value) noexcept;
|
|
||||||
bool MapKey(StringView value) noexcept;
|
|
||||||
bool EndMap() noexcept;
|
|
||||||
};
|
|
||||||
|
|
||||||
static std::string
|
|
||||||
MakeLoginUrl(const char *base_url)
|
|
||||||
{
|
|
||||||
return std::string(base_url) + "/login/username";
|
|
||||||
}
|
|
||||||
|
|
||||||
TidalLoginRequest::TidalLoginRequest(CurlGlobal &curl,
|
|
||||||
const char *base_url, const char *token,
|
|
||||||
const char *username, const char *password,
|
|
||||||
TidalLoginHandler &_handler)
|
|
||||||
:request(curl, MakeLoginUrl(base_url).c_str(), *this),
|
|
||||||
handler(_handler)
|
|
||||||
{
|
|
||||||
request_headers.Append((std::string("X-Tidal-Token:")
|
|
||||||
+ token).c_str());
|
|
||||||
request.SetOption(CURLOPT_HTTPHEADER, request_headers.Get());
|
|
||||||
|
|
||||||
request.SetOption(CURLOPT_COPYPOSTFIELDS,
|
|
||||||
EncodeForm(request.Get(),
|
|
||||||
{{"username", username}, {"password", password}}).c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
TidalLoginRequest::~TidalLoginRequest() noexcept
|
|
||||||
{
|
|
||||||
request.StopIndirect();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<CurlResponseParser>
|
|
||||||
TidalLoginRequest::MakeParser(unsigned status,
|
|
||||||
std::multimap<std::string, std::string> &&headers)
|
|
||||||
{
|
|
||||||
if (status != 200)
|
|
||||||
return std::make_unique<TidalErrorParser>(status, headers);
|
|
||||||
|
|
||||||
auto i = headers.find("content-type");
|
|
||||||
if (i == headers.end() || i->second.find("/json") == i->second.npos)
|
|
||||||
throw std::runtime_error("Not a JSON response from Tidal");
|
|
||||||
|
|
||||||
return std::make_unique<ResponseParser>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TidalLoginRequest::FinishParser(std::unique_ptr<CurlResponseParser> p)
|
|
||||||
{
|
|
||||||
assert(dynamic_cast<ResponseParser *>(p.get()) != nullptr);
|
|
||||||
auto &rp = (ResponseParser &)*p;
|
|
||||||
handler.OnTidalLoginSuccess(rp.GetSession());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TidalLoginRequest::OnError(std::exception_ptr e) noexcept
|
|
||||||
{
|
|
||||||
handler.OnTidalLoginError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
TidalLoginRequest::ResponseParser::String(StringView value) noexcept
|
|
||||||
{
|
|
||||||
switch (state) {
|
|
||||||
case State::NONE:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case State::SESSION_ID:
|
|
||||||
session.assign(value.data, value.size);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
TidalLoginRequest::ResponseParser::MapKey(StringView value) noexcept
|
|
||||||
{
|
|
||||||
if (value.Equals("sessionId"))
|
|
||||||
state = State::SESSION_ID;
|
|
||||||
else
|
|
||||||
state = State::NONE;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
TidalLoginRequest::ResponseParser::EndMap() noexcept
|
|
||||||
{
|
|
||||||
state = State::NONE;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2003-2021 The Music Player Daemon Project
|
|
||||||
* http://www.musicpd.org
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TIDAL_LOGIN_REQUEST_HXX
|
|
||||||
#define TIDAL_LOGIN_REQUEST_HXX
|
|
||||||
|
|
||||||
#include "lib/curl/Delegate.hxx"
|
|
||||||
#include "lib/curl/Slist.hxx"
|
|
||||||
#include "lib/curl/Request.hxx"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback class for #TidalLoginRequest.
|
|
||||||
*
|
|
||||||
* Its methods must be thread-safe.
|
|
||||||
*/
|
|
||||||
class TidalLoginHandler {
|
|
||||||
public:
|
|
||||||
virtual void OnTidalLoginSuccess(std::string session) noexcept = 0;
|
|
||||||
virtual void OnTidalLoginError(std::exception_ptr error) noexcept = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An asynchronous Tidal "login/username" request.
|
|
||||||
*
|
|
||||||
* After construction, call Start() to initiate the request.
|
|
||||||
*/
|
|
||||||
class TidalLoginRequest final : DelegateCurlResponseHandler {
|
|
||||||
CurlSlist request_headers;
|
|
||||||
|
|
||||||
CurlRequest request;
|
|
||||||
|
|
||||||
TidalLoginHandler &handler;
|
|
||||||
|
|
||||||
public:
|
|
||||||
class ResponseParser;
|
|
||||||
|
|
||||||
TidalLoginRequest(CurlGlobal &curl,
|
|
||||||
const char *base_url, const char *token,
|
|
||||||
const char *username, const char *password,
|
|
||||||
TidalLoginHandler &_handler);
|
|
||||||
|
|
||||||
~TidalLoginRequest() noexcept;
|
|
||||||
|
|
||||||
void Start() {
|
|
||||||
request.StartIndirect();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
/* virtual methods from DelegateCurlResponseHandler */
|
|
||||||
std::unique_ptr<CurlResponseParser> MakeParser(unsigned status,
|
|
||||||
std::multimap<std::string, std::string> &&headers) override;
|
|
||||||
void FinishParser(std::unique_ptr<CurlResponseParser> p) override;
|
|
||||||
|
|
||||||
/* virtual methods from CurlResponseHandler */
|
|
||||||
void OnError(std::exception_ptr e) noexcept override;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2003-2021 The Music Player Daemon Project
|
|
||||||
* http://www.musicpd.org
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "TidalSessionManager.hxx"
|
|
||||||
#include "util/Domain.hxx"
|
|
||||||
|
|
||||||
#include "Log.hxx"
|
|
||||||
|
|
||||||
static constexpr Domain tidal_domain("tidal");
|
|
||||||
|
|
||||||
TidalSessionManager::TidalSessionManager(EventLoop &event_loop,
|
|
||||||
const char *_base_url, const char *_token,
|
|
||||||
const char *_username,
|
|
||||||
const char *_password)
|
|
||||||
:base_url(_base_url), token(_token),
|
|
||||||
username(_username), password(_password),
|
|
||||||
curl(event_loop),
|
|
||||||
defer_invoke_handlers(event_loop,
|
|
||||||
BIND_THIS_METHOD(InvokeHandlers))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
TidalSessionManager::~TidalSessionManager() noexcept
|
|
||||||
{
|
|
||||||
assert(handlers.empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TidalSessionManager::AddLoginHandler(TidalSessionHandler &h) noexcept
|
|
||||||
{
|
|
||||||
const std::lock_guard<Mutex> protect(mutex);
|
|
||||||
assert(!h.is_linked());
|
|
||||||
|
|
||||||
const bool was_empty = handlers.empty();
|
|
||||||
handlers.push_front(h);
|
|
||||||
|
|
||||||
if (!was_empty || login_request)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (session.empty()) {
|
|
||||||
// TODO: throttle login attempts?
|
|
||||||
|
|
||||||
LogDebug(tidal_domain, "Sending login request");
|
|
||||||
|
|
||||||
std::string login_uri(base_url);
|
|
||||||
login_uri += "/login/username";
|
|
||||||
|
|
||||||
try {
|
|
||||||
TidalLoginHandler &handler = *this;
|
|
||||||
login_request =
|
|
||||||
std::make_unique<TidalLoginRequest>(*curl, base_url,
|
|
||||||
token,
|
|
||||||
username, password,
|
|
||||||
handler);
|
|
||||||
login_request->Start();
|
|
||||||
} catch (...) {
|
|
||||||
error = std::current_exception();
|
|
||||||
ScheduleInvokeHandlers();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
ScheduleInvokeHandlers();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TidalSessionManager::OnTidalLoginSuccess(std::string _session) noexcept
|
|
||||||
{
|
|
||||||
FormatDebug(tidal_domain, "Login successful, session=%s", _session.c_str());
|
|
||||||
|
|
||||||
{
|
|
||||||
const std::lock_guard<Mutex> protect(mutex);
|
|
||||||
login_request.reset();
|
|
||||||
session = std::move(_session);
|
|
||||||
}
|
|
||||||
|
|
||||||
ScheduleInvokeHandlers();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TidalSessionManager::OnTidalLoginError(std::exception_ptr e) noexcept
|
|
||||||
{
|
|
||||||
{
|
|
||||||
const std::lock_guard<Mutex> protect(mutex);
|
|
||||||
login_request.reset();
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
ScheduleInvokeHandlers();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TidalSessionManager::InvokeHandlers() noexcept
|
|
||||||
{
|
|
||||||
const std::lock_guard<Mutex> protect(mutex);
|
|
||||||
while (!handlers.empty()) {
|
|
||||||
auto &h = handlers.front();
|
|
||||||
handlers.pop_front();
|
|
||||||
|
|
||||||
const ScopeUnlock unlock(mutex);
|
|
||||||
h.OnTidalSession();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,161 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2003-2021 The Music Player Daemon Project
|
|
||||||
* http://www.musicpd.org
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TIDAL_SESSION_MANAGER_HXX
|
|
||||||
#define TIDAL_SESSION_MANAGER_HXX
|
|
||||||
|
|
||||||
#include "TidalLoginRequest.hxx"
|
|
||||||
#include "lib/curl/Init.hxx"
|
|
||||||
#include "thread/Mutex.hxx"
|
|
||||||
#include "event/DeferEvent.hxx"
|
|
||||||
|
|
||||||
#include <boost/intrusive/list.hpp>
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback class for #TidalSessionManager.
|
|
||||||
*
|
|
||||||
* Its methods must be thread-safe.
|
|
||||||
*/
|
|
||||||
class TidalSessionHandler
|
|
||||||
: public boost::intrusive::list_base_hook<boost::intrusive::link_mode<boost::intrusive::safe_link>>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* TidalSessionHandler::AddLoginHandler() has completed
|
|
||||||
* (successful or failed). This method may now call
|
|
||||||
* #TidalSessionHandler::GetSession().
|
|
||||||
*/
|
|
||||||
virtual void OnTidalSession() noexcept = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TidalSessionManager final : TidalLoginHandler {
|
|
||||||
/**
|
|
||||||
* The Tidal API base URL.
|
|
||||||
*/
|
|
||||||
const char *const base_url;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The configured Tidal application token.
|
|
||||||
*/
|
|
||||||
const char *const token;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The configured Tidal user name.
|
|
||||||
*/
|
|
||||||
const char *const username;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The configured Tidal password.
|
|
||||||
*/
|
|
||||||
const char *const password;
|
|
||||||
|
|
||||||
CurlInit curl;
|
|
||||||
|
|
||||||
DeferEvent defer_invoke_handlers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Protects #session, #error and #handlers.
|
|
||||||
*/
|
|
||||||
mutable Mutex mutex;
|
|
||||||
|
|
||||||
std::exception_ptr error;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The current Tidal session id, empty if none.
|
|
||||||
*/
|
|
||||||
std::string session;
|
|
||||||
|
|
||||||
typedef boost::intrusive::list<TidalSessionHandler,
|
|
||||||
boost::intrusive::constant_time_size<false>> LoginHandlerList;
|
|
||||||
|
|
||||||
LoginHandlerList handlers;
|
|
||||||
|
|
||||||
std::unique_ptr<TidalLoginRequest> login_request;
|
|
||||||
|
|
||||||
public:
|
|
||||||
TidalSessionManager(EventLoop &event_loop,
|
|
||||||
const char *_base_url, const char *_token,
|
|
||||||
const char *_username,
|
|
||||||
const char *_password);
|
|
||||||
|
|
||||||
~TidalSessionManager() noexcept;
|
|
||||||
|
|
||||||
auto &GetEventLoop() const noexcept {
|
|
||||||
return defer_invoke_handlers.GetEventLoop();
|
|
||||||
}
|
|
||||||
|
|
||||||
CurlGlobal &GetCurl() noexcept {
|
|
||||||
return *curl;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *GetBaseUrl() const noexcept {
|
|
||||||
return base_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ask the object to call back once the login to Tidal has
|
|
||||||
* completed. If no session exists currently, then one is
|
|
||||||
* created. Since the callback may occur in another thread,
|
|
||||||
* the it may have been completed already before this method
|
|
||||||
* returns.
|
|
||||||
*/
|
|
||||||
void AddLoginHandler(TidalSessionHandler &h) noexcept;
|
|
||||||
|
|
||||||
void RemoveLoginHandler(TidalSessionHandler &h) noexcept {
|
|
||||||
const std::lock_guard<Mutex> protect(mutex);
|
|
||||||
if (h.is_linked())
|
|
||||||
handlers.erase(handlers.iterator_to(h));
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *GetToken() const noexcept {
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Tidal session id, or rethrows an exception if an
|
|
||||||
* error has occurred while logging in.
|
|
||||||
*/
|
|
||||||
std::string GetSession() const {
|
|
||||||
const std::lock_guard<Mutex> protect(mutex);
|
|
||||||
|
|
||||||
if (error)
|
|
||||||
std::rethrow_exception(error);
|
|
||||||
|
|
||||||
if (session.empty())
|
|
||||||
throw std::runtime_error("No session");
|
|
||||||
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void InvokeHandlers() noexcept;
|
|
||||||
|
|
||||||
void ScheduleInvokeHandlers() noexcept {
|
|
||||||
defer_invoke_handlers.Schedule();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* virtual methods from TidalLoginHandler */
|
|
||||||
void OnTidalLoginSuccess(std::string session) noexcept override;
|
|
||||||
void OnTidalLoginError(std::exception_ptr error) noexcept override;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,244 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2003-2021 The Music Player Daemon Project
|
|
||||||
* http://www.musicpd.org
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "TidalTagScanner.hxx"
|
|
||||||
#include "TidalErrorParser.hxx"
|
|
||||||
#include "lib/yajl/Callbacks.hxx"
|
|
||||||
#include "tag/Builder.hxx"
|
|
||||||
#include "tag/Tag.hxx"
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
using Wrapper = Yajl::CallbacksWrapper<TidalTagScanner::ResponseParser>;
|
|
||||||
static constexpr yajl_callbacks parse_callbacks = {
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
Wrapper::Integer,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
Wrapper::String,
|
|
||||||
Wrapper::StartMap,
|
|
||||||
Wrapper::MapKey,
|
|
||||||
Wrapper::EndMap,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
class TidalTagScanner::ResponseParser final : public YajlResponseParser {
|
|
||||||
enum class State {
|
|
||||||
NONE,
|
|
||||||
TITLE,
|
|
||||||
DURATION,
|
|
||||||
ARTIST,
|
|
||||||
ARTIST_NAME,
|
|
||||||
ALBUM,
|
|
||||||
ALBUM_TITLE,
|
|
||||||
} state = State::NONE;
|
|
||||||
|
|
||||||
unsigned map_depth = 0;
|
|
||||||
|
|
||||||
TagBuilder tag;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit ResponseParser() noexcept
|
|
||||||
:YajlResponseParser(&parse_callbacks, nullptr, this) {}
|
|
||||||
|
|
||||||
Tag GetTag() {
|
|
||||||
return tag.Commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* yajl callbacks */
|
|
||||||
bool Integer(long long value) noexcept;
|
|
||||||
bool String(StringView value) noexcept;
|
|
||||||
bool StartMap() noexcept;
|
|
||||||
bool MapKey(StringView value) noexcept;
|
|
||||||
bool EndMap() noexcept;
|
|
||||||
};
|
|
||||||
|
|
||||||
static std::string
|
|
||||||
MakeTrackUrl(const char *base_url, const char *track_id)
|
|
||||||
{
|
|
||||||
return std::string(base_url)
|
|
||||||
+ "/tracks/"
|
|
||||||
+ track_id
|
|
||||||
// TODO: configurable countryCode?
|
|
||||||
+ "?countryCode=US";
|
|
||||||
}
|
|
||||||
|
|
||||||
TidalTagScanner::TidalTagScanner(CurlGlobal &curl,
|
|
||||||
const char *base_url, const char *token,
|
|
||||||
const char *track_id,
|
|
||||||
RemoteTagHandler &_handler)
|
|
||||||
:request(curl, MakeTrackUrl(base_url, track_id).c_str(), *this),
|
|
||||||
handler(_handler)
|
|
||||||
{
|
|
||||||
request_headers.Append((std::string("X-Tidal-Token:")
|
|
||||||
+ token).c_str());
|
|
||||||
request.SetOption(CURLOPT_HTTPHEADER, request_headers.Get());
|
|
||||||
}
|
|
||||||
|
|
||||||
TidalTagScanner::~TidalTagScanner() noexcept
|
|
||||||
{
|
|
||||||
request.StopIndirect();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<CurlResponseParser>
|
|
||||||
TidalTagScanner::MakeParser(unsigned status,
|
|
||||||
std::multimap<std::string, std::string> &&headers)
|
|
||||||
{
|
|
||||||
if (status != 200)
|
|
||||||
return std::make_unique<TidalErrorParser>(status, headers);
|
|
||||||
|
|
||||||
auto i = headers.find("content-type");
|
|
||||||
if (i == headers.end() || i->second.find("/json") == i->second.npos)
|
|
||||||
throw std::runtime_error("Not a JSON response from Tidal");
|
|
||||||
|
|
||||||
return std::make_unique<ResponseParser>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TidalTagScanner::FinishParser(std::unique_ptr<CurlResponseParser> p)
|
|
||||||
{
|
|
||||||
assert(dynamic_cast<ResponseParser *>(p.get()) != nullptr);
|
|
||||||
auto &rp = (ResponseParser &)*p;
|
|
||||||
handler.OnRemoteTag(rp.GetTag());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TidalTagScanner::OnError(std::exception_ptr e) noexcept
|
|
||||||
{
|
|
||||||
handler.OnRemoteTagError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
TidalTagScanner::ResponseParser::Integer(long long value) noexcept
|
|
||||||
{
|
|
||||||
switch (state) {
|
|
||||||
case State::NONE:
|
|
||||||
case State::TITLE:
|
|
||||||
case State::ARTIST:
|
|
||||||
case State::ARTIST_NAME:
|
|
||||||
case State::ALBUM:
|
|
||||||
case State::ALBUM_TITLE:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case State::DURATION:
|
|
||||||
if (map_depth == 1 && value > 0)
|
|
||||||
tag.SetDuration(SignedSongTime::FromS((unsigned)value));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
TidalTagScanner::ResponseParser::String(StringView value) noexcept
|
|
||||||
{
|
|
||||||
switch (state) {
|
|
||||||
case State::NONE:
|
|
||||||
case State::DURATION:
|
|
||||||
case State::ARTIST:
|
|
||||||
case State::ALBUM:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case State::TITLE:
|
|
||||||
if (map_depth == 1)
|
|
||||||
tag.AddItem(TAG_TITLE, value);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case State::ARTIST_NAME:
|
|
||||||
if (map_depth == 2)
|
|
||||||
tag.AddItem(TAG_ARTIST, value);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case State::ALBUM_TITLE:
|
|
||||||
if (map_depth == 2)
|
|
||||||
tag.AddItem(TAG_ALBUM, value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
TidalTagScanner::ResponseParser::StartMap() noexcept
|
|
||||||
{
|
|
||||||
++map_depth;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
TidalTagScanner::ResponseParser::MapKey(StringView value) noexcept
|
|
||||||
{
|
|
||||||
switch (map_depth) {
|
|
||||||
case 1:
|
|
||||||
if (value.Equals("title"))
|
|
||||||
state = State::TITLE;
|
|
||||||
else if (value.Equals("duration"))
|
|
||||||
state = State::DURATION;
|
|
||||||
else if (value.Equals("artist"))
|
|
||||||
state = State::ARTIST;
|
|
||||||
else if (value.Equals("album"))
|
|
||||||
state = State::ALBUM;
|
|
||||||
else
|
|
||||||
state = State::NONE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
switch (state) {
|
|
||||||
case State::NONE:
|
|
||||||
case State::TITLE:
|
|
||||||
case State::DURATION:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case State::ARTIST:
|
|
||||||
case State::ARTIST_NAME:
|
|
||||||
if (value.Equals("name"))
|
|
||||||
state = State::ARTIST_NAME;
|
|
||||||
else
|
|
||||||
state = State::ARTIST;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case State::ALBUM:
|
|
||||||
case State::ALBUM_TITLE:
|
|
||||||
if (value.Equals("title"))
|
|
||||||
state = State::ALBUM_TITLE;
|
|
||||||
else
|
|
||||||
state = State::ALBUM;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
TidalTagScanner::ResponseParser::EndMap() noexcept
|
|
||||||
{
|
|
||||||
switch (map_depth) {
|
|
||||||
case 2:
|
|
||||||
state = State::NONE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
--map_depth;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2003-2021 The Music Player Daemon Project
|
|
||||||
* http://www.musicpd.org
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TIDAL_TAG_SCANNER_HXX
|
|
||||||
#define TIDAL_TAG_SCANNER_HXX
|
|
||||||
|
|
||||||
#include "lib/curl/Delegate.hxx"
|
|
||||||
#include "lib/curl/Slist.hxx"
|
|
||||||
#include "lib/curl/Request.hxx"
|
|
||||||
#include "input/RemoteTagScanner.hxx"
|
|
||||||
|
|
||||||
class TidalTagScanner final
|
|
||||||
: public RemoteTagScanner, DelegateCurlResponseHandler
|
|
||||||
{
|
|
||||||
CurlSlist request_headers;
|
|
||||||
|
|
||||||
CurlRequest request;
|
|
||||||
|
|
||||||
RemoteTagHandler &handler;
|
|
||||||
|
|
||||||
public:
|
|
||||||
class ResponseParser;
|
|
||||||
|
|
||||||
TidalTagScanner(CurlGlobal &curl,
|
|
||||||
const char *base_url, const char *token,
|
|
||||||
const char *track_id,
|
|
||||||
RemoteTagHandler &_handler);
|
|
||||||
|
|
||||||
~TidalTagScanner() noexcept override;
|
|
||||||
|
|
||||||
void Start() override {
|
|
||||||
request.StartIndirect();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
/* virtual methods from DelegateCurlResponseHandler */
|
|
||||||
std::unique_ptr<CurlResponseParser> MakeParser(unsigned status,
|
|
||||||
std::multimap<std::string, std::string> &&headers) override;
|
|
||||||
void FinishParser(std::unique_ptr<CurlResponseParser> p) override;
|
|
||||||
|
|
||||||
/* virtual methods from CurlResponseHandler */
|
|
||||||
void OnError(std::exception_ptr e) noexcept override;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,160 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2003-2021 The Music Player Daemon Project
|
|
||||||
* http://www.musicpd.org
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "TidalTrackRequest.hxx"
|
|
||||||
#include "TidalErrorParser.hxx"
|
|
||||||
#include "lib/yajl/Callbacks.hxx"
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
using Wrapper = Yajl::CallbacksWrapper<TidalTrackRequest::ResponseParser>;
|
|
||||||
static constexpr yajl_callbacks parse_callbacks = {
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
Wrapper::String,
|
|
||||||
nullptr,
|
|
||||||
Wrapper::MapKey,
|
|
||||||
Wrapper::EndMap,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
class TidalTrackRequest::ResponseParser final : public YajlResponseParser {
|
|
||||||
enum class State {
|
|
||||||
NONE,
|
|
||||||
URLS,
|
|
||||||
} state = State::NONE;
|
|
||||||
|
|
||||||
std::string url;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit ResponseParser() noexcept
|
|
||||||
:YajlResponseParser(&parse_callbacks, nullptr, this) {}
|
|
||||||
|
|
||||||
std::string &&GetUrl() {
|
|
||||||
if (url.empty())
|
|
||||||
throw std::runtime_error("No url in track response");
|
|
||||||
|
|
||||||
return std::move(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* yajl callbacks */
|
|
||||||
bool String(StringView value) noexcept;
|
|
||||||
bool MapKey(StringView value) noexcept;
|
|
||||||
bool EndMap() noexcept;
|
|
||||||
};
|
|
||||||
|
|
||||||
static std::string
|
|
||||||
MakeTrackUrl(const char *base_url, const char *track_id,
|
|
||||||
const char *audioquality) noexcept
|
|
||||||
{
|
|
||||||
return std::string(base_url)
|
|
||||||
+ "/tracks/"
|
|
||||||
+ track_id
|
|
||||||
+ "/urlpostpaywall?assetpresentation=FULL&audioquality="
|
|
||||||
+ audioquality + "&urlusagemode=STREAM";
|
|
||||||
}
|
|
||||||
|
|
||||||
TidalTrackRequest::TidalTrackRequest(CurlGlobal &curl,
|
|
||||||
const char *base_url, const char *token,
|
|
||||||
const char *session,
|
|
||||||
const char *track_id,
|
|
||||||
const char *audioquality,
|
|
||||||
TidalTrackHandler &_handler)
|
|
||||||
:request(curl, MakeTrackUrl(base_url, track_id, audioquality).c_str(),
|
|
||||||
*this),
|
|
||||||
handler(_handler)
|
|
||||||
{
|
|
||||||
request_headers.Append((std::string("X-Tidal-Token:")
|
|
||||||
+ token).c_str());
|
|
||||||
request_headers.Append((std::string("X-Tidal-SessionId:")
|
|
||||||
+ session).c_str());
|
|
||||||
request.SetOption(CURLOPT_HTTPHEADER, request_headers.Get());
|
|
||||||
}
|
|
||||||
|
|
||||||
TidalTrackRequest::~TidalTrackRequest() noexcept
|
|
||||||
{
|
|
||||||
request.StopIndirect();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<CurlResponseParser>
|
|
||||||
TidalTrackRequest::MakeParser(unsigned status,
|
|
||||||
std::multimap<std::string, std::string> &&headers)
|
|
||||||
{
|
|
||||||
if (status != 200)
|
|
||||||
return std::make_unique<TidalErrorParser>(status, headers);
|
|
||||||
|
|
||||||
auto i = headers.find("content-type");
|
|
||||||
if (i == headers.end() || i->second.find("/json") == i->second.npos)
|
|
||||||
throw std::runtime_error("Not a JSON response from Tidal");
|
|
||||||
|
|
||||||
return std::make_unique<ResponseParser>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TidalTrackRequest::FinishParser(std::unique_ptr<CurlResponseParser> p)
|
|
||||||
{
|
|
||||||
assert(dynamic_cast<ResponseParser *>(p.get()) != nullptr);
|
|
||||||
auto &rp = (ResponseParser &)*p;
|
|
||||||
handler.OnTidalTrackSuccess(rp.GetUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TidalTrackRequest::OnError(std::exception_ptr e) noexcept
|
|
||||||
{
|
|
||||||
handler.OnTidalTrackError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
TidalTrackRequest::ResponseParser::String(StringView value) noexcept
|
|
||||||
{
|
|
||||||
switch (state) {
|
|
||||||
case State::NONE:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case State::URLS:
|
|
||||||
if (url.empty())
|
|
||||||
url.assign(value.data, value.size);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
TidalTrackRequest::ResponseParser::MapKey(StringView value) noexcept
|
|
||||||
{
|
|
||||||
if (value.Equals("urls"))
|
|
||||||
state = State::URLS;
|
|
||||||
else
|
|
||||||
state = State::NONE;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
|
||||||
TidalTrackRequest::ResponseParser::EndMap() noexcept
|
|
||||||
{
|
|
||||||
state = State::NONE;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2003-2021 The Music Player Daemon Project
|
|
||||||
* http://www.musicpd.org
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TIDAL_TRACK_REQUEST_HXX
|
|
||||||
#define TIDAL_TRACK_REQUEST_HXX
|
|
||||||
|
|
||||||
#include "lib/curl/Delegate.hxx"
|
|
||||||
#include "lib/curl/Slist.hxx"
|
|
||||||
#include "lib/curl/Request.hxx"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback class for #TidalTrackRequest.
|
|
||||||
*
|
|
||||||
* Its methods must be thread-safe.
|
|
||||||
*/
|
|
||||||
class TidalTrackHandler {
|
|
||||||
public:
|
|
||||||
virtual void OnTidalTrackSuccess(std::string url) noexcept = 0;
|
|
||||||
virtual void OnTidalTrackError(std::exception_ptr error) noexcept = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An asynchronous request for the streaming URL of a Tidal track.
|
|
||||||
*
|
|
||||||
* After construction, call Start() to initiate the request.
|
|
||||||
*/
|
|
||||||
class TidalTrackRequest final : DelegateCurlResponseHandler {
|
|
||||||
CurlSlist request_headers;
|
|
||||||
|
|
||||||
CurlRequest request;
|
|
||||||
|
|
||||||
TidalTrackHandler &handler;
|
|
||||||
|
|
||||||
public:
|
|
||||||
class ResponseParser;
|
|
||||||
|
|
||||||
TidalTrackRequest(CurlGlobal &curl,
|
|
||||||
const char *base_url, const char *token,
|
|
||||||
const char *session,
|
|
||||||
const char *track_id,
|
|
||||||
const char *audioquality,
|
|
||||||
TidalTrackHandler &_handler);
|
|
||||||
|
|
||||||
~TidalTrackRequest() noexcept;
|
|
||||||
|
|
||||||
void Start() {
|
|
||||||
request.StartIndirect();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
/* virtual methods from DelegateCurlResponseHandler */
|
|
||||||
std::unique_ptr<CurlResponseParser> MakeParser(unsigned status,
|
|
||||||
std::multimap<std::string, std::string> &&headers) override;
|
|
||||||
void FinishParser(std::unique_ptr<CurlResponseParser> p) override;
|
|
||||||
|
|
||||||
/* virtual methods from CurlResponseHandler */
|
|
||||||
void OnError(std::exception_ptr e) noexcept override;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -63,27 +63,6 @@ if enable_qobuz
|
|||||||
]
|
]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
tidal_feature = get_option('tidal')
|
|
||||||
if tidal_feature.disabled()
|
|
||||||
enable_tidal = false
|
|
||||||
else
|
|
||||||
enable_tidal = curl_dep.found() and yajl_dep.found()
|
|
||||||
if not enable_tidal and tidal_feature.enabled()
|
|
||||||
error('Tidal requires CURL and libyajl')
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
input_features.set('ENABLE_TIDAL', enable_tidal)
|
|
||||||
if enable_tidal
|
|
||||||
input_plugins_sources += [
|
|
||||||
'TidalErrorParser.cxx',
|
|
||||||
'TidalLoginRequest.cxx',
|
|
||||||
'TidalSessionManager.cxx',
|
|
||||||
'TidalTrackRequest.cxx',
|
|
||||||
'TidalTagScanner.cxx',
|
|
||||||
'TidalInputPlugin.cxx',
|
|
||||||
]
|
|
||||||
endif
|
|
||||||
|
|
||||||
input_plugins = static_library(
|
input_plugins = static_library(
|
||||||
'input_plugins',
|
'input_plugins',
|
||||||
input_plugins_sources,
|
input_plugins_sources,
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
if enable_database
|
if enable_database
|
||||||
sqlite_dep = dependency('sqlite3', version: '>= 3.7.3', required: get_option('sqlite'))
|
sqlite_dep = dependency('sqlite3', version: '>= 3.7.3',
|
||||||
|
fallback: ['sqlite3', 'sqlite3_dep'],
|
||||||
|
required: get_option('sqlite'))
|
||||||
else
|
else
|
||||||
sqlite_dep = dependency('', required: false)
|
sqlite_dep = dependency('', required: false)
|
||||||
endif
|
endif
|
||||||
@@ -21,4 +23,7 @@ sqlite = static_library(
|
|||||||
|
|
||||||
sqlite_dep = declare_dependency(
|
sqlite_dep = declare_dependency(
|
||||||
link_with: sqlite,
|
link_with: sqlite,
|
||||||
|
dependencies: [
|
||||||
|
sqlite_dep,
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -80,6 +80,24 @@ class AlsaMixer final : public Mixer {
|
|||||||
|
|
||||||
AlsaMixerMonitor *monitor;
|
AlsaMixerMonitor *monitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* These fields are our workaround for rounding errors when
|
||||||
|
* the resolution of a mixer knob isn't fine enough to
|
||||||
|
* represent all 101 possible values (0..100).
|
||||||
|
*
|
||||||
|
* "desired_volume" is the percent value passed to
|
||||||
|
* SetVolume(), and "resulting_volume" is the volume which was
|
||||||
|
* actually set, and would be returned by the next
|
||||||
|
* GetPercentVolume() call.
|
||||||
|
*
|
||||||
|
* When GetVolume() is called, we compare the
|
||||||
|
* "resulting_volume" with the value returned by
|
||||||
|
* GetPercentVolume(), and if it's the same, we're still on
|
||||||
|
* the same value that was previously set (but may have been
|
||||||
|
* rounded down or up).
|
||||||
|
*/
|
||||||
|
int desired_volume, resulting_volume;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AlsaMixer(EventLoop &_event_loop, MixerListener &_listener)
|
AlsaMixer(EventLoop &_event_loop, MixerListener &_listener)
|
||||||
:Mixer(alsa_mixer_plugin, _listener),
|
:Mixer(alsa_mixer_plugin, _listener),
|
||||||
@@ -95,6 +113,27 @@ public:
|
|||||||
void Close() noexcept override;
|
void Close() noexcept override;
|
||||||
int GetVolume() override;
|
int GetVolume() override;
|
||||||
void SetVolume(unsigned volume) override;
|
void SetVolume(unsigned volume) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
[[gnu::const]]
|
||||||
|
static unsigned NormalizedToPercent(double normalized) noexcept {
|
||||||
|
return lround(100 * normalized);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[gnu::pure]]
|
||||||
|
double GetNormalizedVolume() const noexcept {
|
||||||
|
return get_normalized_playback_volume(elem,
|
||||||
|
SND_MIXER_SCHN_FRONT_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[gnu::pure]]
|
||||||
|
unsigned GetPercentVolume() const noexcept {
|
||||||
|
return NormalizedToPercent(GetNormalizedVolume());
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ElemCallback(snd_mixer_elem_t *elem,
|
||||||
|
unsigned mask) noexcept;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr Domain alsa_mixer_domain("alsa_mixer");
|
static constexpr Domain alsa_mixer_domain("alsa_mixer");
|
||||||
@@ -138,18 +177,26 @@ AlsaMixerMonitor::DispatchSockets() noexcept
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int
|
int
|
||||||
alsa_mixer_elem_callback(snd_mixer_elem_t *elem, unsigned mask)
|
AlsaMixer::ElemCallback(snd_mixer_elem_t *elem, unsigned mask) noexcept
|
||||||
{
|
{
|
||||||
AlsaMixer &mixer = *(AlsaMixer *)
|
AlsaMixer &mixer = *(AlsaMixer *)
|
||||||
snd_mixer_elem_get_callback_private(elem);
|
snd_mixer_elem_get_callback_private(elem);
|
||||||
|
|
||||||
if (mask & SND_CTL_EVENT_MASK_VALUE) {
|
if (mask & SND_CTL_EVENT_MASK_VALUE) {
|
||||||
try {
|
int volume = mixer.GetPercentVolume();
|
||||||
int volume = mixer.GetVolume();
|
|
||||||
mixer.listener.OnMixerVolumeChanged(mixer, volume);
|
if (mixer.resulting_volume >= 0 &&
|
||||||
} catch (...) {
|
volume == mixer.resulting_volume)
|
||||||
}
|
/* still the same volume (this might be a
|
||||||
|
callback caused by SetVolume()) - switch to
|
||||||
|
desired_volume */
|
||||||
|
volume = mixer.desired_volume;
|
||||||
|
else
|
||||||
|
/* flush */
|
||||||
|
mixer.desired_volume = mixer.resulting_volume = -1;
|
||||||
|
|
||||||
|
mixer.listener.OnMixerVolumeChanged(mixer, volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -227,7 +274,7 @@ AlsaMixer::Setup()
|
|||||||
throw FormatRuntimeError("no such mixer control: %s", control);
|
throw FormatRuntimeError("no such mixer control: %s", control);
|
||||||
|
|
||||||
snd_mixer_elem_set_callback_private(elem, this);
|
snd_mixer_elem_set_callback_private(elem, this);
|
||||||
snd_mixer_elem_set_callback(elem, alsa_mixer_elem_callback);
|
snd_mixer_elem_set_callback(elem, ElemCallback);
|
||||||
|
|
||||||
monitor = new AlsaMixerMonitor(event_loop, handle);
|
monitor = new AlsaMixerMonitor(event_loop, handle);
|
||||||
}
|
}
|
||||||
@@ -235,6 +282,8 @@ AlsaMixer::Setup()
|
|||||||
void
|
void
|
||||||
AlsaMixer::Open()
|
AlsaMixer::Open()
|
||||||
{
|
{
|
||||||
|
desired_volume = resulting_volume = -1;
|
||||||
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = snd_mixer_open(&handle, 0);
|
err = snd_mixer_open(&handle, 0);
|
||||||
@@ -273,7 +322,12 @@ AlsaMixer::GetVolume()
|
|||||||
throw FormatRuntimeError("snd_mixer_handle_events() failed: %s",
|
throw FormatRuntimeError("snd_mixer_handle_events() failed: %s",
|
||||||
snd_strerror(err));
|
snd_strerror(err));
|
||||||
|
|
||||||
return lround(100 * get_normalized_playback_volume(elem, SND_MIXER_SCHN_FRONT_LEFT));
|
int volume = GetPercentVolume();
|
||||||
|
if (resulting_volume >= 0 && volume == resulting_volume)
|
||||||
|
/* we're still on the value passed to SetVolume() */
|
||||||
|
volume = desired_volume;
|
||||||
|
|
||||||
|
return volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -281,12 +335,13 @@ AlsaMixer::SetVolume(unsigned volume)
|
|||||||
{
|
{
|
||||||
assert(handle != nullptr);
|
assert(handle != nullptr);
|
||||||
|
|
||||||
double cur = get_normalized_playback_volume(elem, SND_MIXER_SCHN_FRONT_LEFT);
|
int err = set_normalized_playback_volume(elem, 0.01*volume, 1);
|
||||||
int delta = volume - lround(100.*cur);
|
|
||||||
int err = set_normalized_playback_volume(elem, cur + 0.01*delta, delta);
|
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
throw FormatRuntimeError("failed to set ALSA volume: %s",
|
throw FormatRuntimeError("failed to set ALSA volume: %s",
|
||||||
snd_strerror(err));
|
snd_strerror(err));
|
||||||
|
|
||||||
|
desired_volume = volume;
|
||||||
|
resulting_volume = GetPercentVolume();
|
||||||
}
|
}
|
||||||
|
|
||||||
const MixerPlugin alsa_mixer_plugin = {
|
const MixerPlugin alsa_mixer_plugin = {
|
||||||
|
|||||||
@@ -20,11 +20,13 @@
|
|||||||
#include "OssOutputPlugin.hxx"
|
#include "OssOutputPlugin.hxx"
|
||||||
#include "../OutputAPI.hxx"
|
#include "../OutputAPI.hxx"
|
||||||
#include "mixer/MixerList.hxx"
|
#include "mixer/MixerList.hxx"
|
||||||
|
#include "pcm/Export.hxx"
|
||||||
#include "io/UniqueFileDescriptor.hxx"
|
#include "io/UniqueFileDescriptor.hxx"
|
||||||
#include "system/Error.hxx"
|
#include "system/Error.hxx"
|
||||||
#include "util/ConstBuffer.hxx"
|
#include "util/ConstBuffer.hxx"
|
||||||
#include "util/Domain.hxx"
|
#include "util/Domain.hxx"
|
||||||
#include "util/ByteOrder.hxx"
|
#include "util/ByteOrder.hxx"
|
||||||
|
#include "util/Manual.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
@@ -53,15 +55,8 @@
|
|||||||
#undef AFMT_S24_NE
|
#undef AFMT_S24_NE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef AFMT_S24_PACKED
|
|
||||||
#include "pcm/Export.hxx"
|
|
||||||
#include "util/Manual.hxx"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class OssOutput final : AudioOutput {
|
class OssOutput final : AudioOutput {
|
||||||
#ifdef AFMT_S24_PACKED
|
|
||||||
Manual<PcmExport> pcm_export;
|
Manual<PcmExport> pcm_export;
|
||||||
#endif
|
|
||||||
|
|
||||||
FileDescriptor fd = FileDescriptor::Undefined();
|
FileDescriptor fd = FileDescriptor::Undefined();
|
||||||
const char *device;
|
const char *device;
|
||||||
@@ -78,11 +73,7 @@ class OssOutput final : AudioOutput {
|
|||||||
*/
|
*/
|
||||||
int oss_format;
|
int oss_format;
|
||||||
|
|
||||||
#ifdef AFMT_S24_PACKED
|
|
||||||
static constexpr unsigned oss_flags = FLAG_ENABLE_DISABLE;
|
static constexpr unsigned oss_flags = FLAG_ENABLE_DISABLE;
|
||||||
#else
|
|
||||||
static constexpr unsigned oss_flags = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit OssOutput(const char *_device=nullptr)
|
explicit OssOutput(const char *_device=nullptr)
|
||||||
@@ -92,7 +83,6 @@ public:
|
|||||||
static AudioOutput *Create(EventLoop &event_loop,
|
static AudioOutput *Create(EventLoop &event_loop,
|
||||||
const ConfigBlock &block);
|
const ConfigBlock &block);
|
||||||
|
|
||||||
#ifdef AFMT_S24_PACKED
|
|
||||||
void Enable() override {
|
void Enable() override {
|
||||||
pcm_export.Construct();
|
pcm_export.Construct();
|
||||||
}
|
}
|
||||||
@@ -100,7 +90,6 @@ public:
|
|||||||
void Disable() noexcept override {
|
void Disable() noexcept override {
|
||||||
pcm_export.Destruct();
|
pcm_export.Destruct();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void Open(AudioFormat &audio_format) override;
|
void Open(AudioFormat &audio_format) override;
|
||||||
|
|
||||||
@@ -428,11 +417,8 @@ sample_format_from_oss(int format) noexcept
|
|||||||
static bool
|
static bool
|
||||||
oss_probe_sample_format(FileDescriptor fd, SampleFormat sample_format,
|
oss_probe_sample_format(FileDescriptor fd, SampleFormat sample_format,
|
||||||
SampleFormat *sample_format_r,
|
SampleFormat *sample_format_r,
|
||||||
int *oss_format_r
|
int *oss_format_r,
|
||||||
#ifdef AFMT_S24_PACKED
|
PcmExport &pcm_export)
|
||||||
, PcmExport &pcm_export
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
int oss_format = sample_format_to_oss(sample_format);
|
int oss_format = sample_format_to_oss(sample_format);
|
||||||
if (oss_format == AFMT_QUERY)
|
if (oss_format == AFMT_QUERY)
|
||||||
@@ -464,15 +450,15 @@ oss_probe_sample_format(FileDescriptor fd, SampleFormat sample_format,
|
|||||||
*sample_format_r = sample_format;
|
*sample_format_r = sample_format;
|
||||||
*oss_format_r = oss_format;
|
*oss_format_r = oss_format;
|
||||||
|
|
||||||
#ifdef AFMT_S24_PACKED
|
|
||||||
PcmExport::Params params;
|
PcmExport::Params params;
|
||||||
params.alsa_channel_order = true;
|
params.alsa_channel_order = true;
|
||||||
|
#ifdef AFMT_S24_PACKED
|
||||||
params.pack24 = oss_format == AFMT_S24_PACKED;
|
params.pack24 = oss_format == AFMT_S24_PACKED;
|
||||||
params.reverse_endian = oss_format == AFMT_S24_PACKED &&
|
params.reverse_endian = oss_format == AFMT_S24_PACKED &&
|
||||||
!IsLittleEndian();
|
!IsLittleEndian();
|
||||||
|
#endif
|
||||||
|
|
||||||
pcm_export.Open(sample_format, 0, params);
|
pcm_export.Open(sample_format, 0, params);
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -483,19 +469,13 @@ oss_probe_sample_format(FileDescriptor fd, SampleFormat sample_format,
|
|||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
oss_setup_sample_format(FileDescriptor fd, AudioFormat &audio_format,
|
oss_setup_sample_format(FileDescriptor fd, AudioFormat &audio_format,
|
||||||
int *oss_format_r
|
int *oss_format_r,
|
||||||
#ifdef AFMT_S24_PACKED
|
PcmExport &pcm_export)
|
||||||
, PcmExport &pcm_export
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
SampleFormat mpd_format;
|
SampleFormat mpd_format;
|
||||||
if (oss_probe_sample_format(fd, audio_format.format,
|
if (oss_probe_sample_format(fd, audio_format.format,
|
||||||
&mpd_format, oss_format_r
|
&mpd_format, oss_format_r,
|
||||||
#ifdef AFMT_S24_PACKED
|
pcm_export)) {
|
||||||
, pcm_export
|
|
||||||
#endif
|
|
||||||
)) {
|
|
||||||
audio_format.format = mpd_format;
|
audio_format.format = mpd_format;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -518,11 +498,8 @@ oss_setup_sample_format(FileDescriptor fd, AudioFormat &audio_format,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (oss_probe_sample_format(fd, mpd_format,
|
if (oss_probe_sample_format(fd, mpd_format,
|
||||||
&mpd_format, oss_format_r
|
&mpd_format, oss_format_r,
|
||||||
#ifdef AFMT_S24_PACKED
|
pcm_export)) {
|
||||||
, pcm_export
|
|
||||||
#endif
|
|
||||||
)) {
|
|
||||||
audio_format.format = mpd_format;
|
audio_format.format = mpd_format;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -536,11 +513,7 @@ OssOutput::Setup(AudioFormat &_audio_format)
|
|||||||
{
|
{
|
||||||
oss_setup_channels(fd, _audio_format);
|
oss_setup_channels(fd, _audio_format);
|
||||||
oss_setup_sample_rate(fd, _audio_format);
|
oss_setup_sample_rate(fd, _audio_format);
|
||||||
oss_setup_sample_format(fd, _audio_format, &oss_format
|
oss_setup_sample_format(fd, _audio_format, &oss_format, pcm_export);
|
||||||
#ifdef AFMT_S24_PACKED
|
|
||||||
, pcm_export
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -595,9 +568,7 @@ OssOutput::Cancel() noexcept
|
|||||||
DoClose();
|
DoClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef AFMT_S24_PACKED
|
|
||||||
pcm_export->Reset();
|
pcm_export->Reset();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
@@ -611,23 +582,17 @@ OssOutput::Play(const void *chunk, size_t size)
|
|||||||
if (!fd.IsDefined())
|
if (!fd.IsDefined())
|
||||||
Reopen();
|
Reopen();
|
||||||
|
|
||||||
#ifdef AFMT_S24_PACKED
|
|
||||||
const auto e = pcm_export->Export({chunk, size});
|
const auto e = pcm_export->Export({chunk, size});
|
||||||
if (e.empty())
|
if (e.empty())
|
||||||
return size;
|
return size;
|
||||||
|
|
||||||
chunk = e.data;
|
chunk = e.data;
|
||||||
size = e.size;
|
size = e.size;
|
||||||
#endif
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
ret = fd.Write(chunk, size);
|
ret = fd.Write(chunk, size);
|
||||||
if (ret > 0) {
|
if (ret > 0)
|
||||||
#ifdef AFMT_S24_PACKED
|
return pcm_export->CalcInputSize(ret);
|
||||||
ret = pcm_export->CalcInputSize(ret);
|
|
||||||
#endif
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret < 0 && errno != EINTR)
|
if (ret < 0 && errno != EINTR)
|
||||||
throw FormatErrno("Write error on %s", device);
|
throw FormatErrno("Write error on %s", device);
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
#include <windef.h>
|
#include <windef.h>
|
||||||
#include <mmsystem.h>
|
#include <mmsystem.h>
|
||||||
|
|
||||||
struct WinmmOutput;
|
class WinmmOutput;
|
||||||
|
|
||||||
extern const struct AudioOutputPlugin winmm_output_plugin;
|
extern const struct AudioOutputPlugin winmm_output_plugin;
|
||||||
|
|
||||||
|
|||||||
@@ -92,8 +92,8 @@ playlist_check_translate_song(DetachedSong &song, std::string_view base_uri,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (base_uri.data() != nullptr && !uri_has_scheme(uri) &&
|
if (base_uri.data() != nullptr &&
|
||||||
!PathTraitsUTF8::IsAbsolute(uri))
|
!PathTraitsUTF8::IsAbsoluteOrHasScheme(uri))
|
||||||
song.SetURI(PathTraitsUTF8::Build(base_uri, uri));
|
song.SetURI(PathTraitsUTF8::Build(base_uri, uri));
|
||||||
|
|
||||||
return playlist_check_load_song(song, loader);
|
return playlist_check_load_song(song, loader);
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ DetachedSong::IsInDatabase() const noexcept
|
|||||||
GetRealURI() is never relative */
|
GetRealURI() is never relative */
|
||||||
|
|
||||||
const char *_uri = GetURI();
|
const char *_uri = GetURI();
|
||||||
return !uri_has_scheme(_uri) && !PathTraitsUTF8::IsAbsolute(_uri);
|
return !PathTraitsUTF8::IsAbsoluteOrHasScheme(_uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
SignedSongTime
|
SignedSongTime
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "Sticker.hxx"
|
#include "Sticker.hxx"
|
||||||
#include "lib/sqlite/Util.hxx"
|
#include "lib/sqlite/Util.hxx"
|
||||||
#include "fs/Path.hxx"
|
#include "fs/Path.hxx"
|
||||||
|
#include "fs/NarrowPath.hxx"
|
||||||
#include "Idle.hxx"
|
#include "Idle.hxx"
|
||||||
#include "util/StringCompare.hxx"
|
#include "util/StringCompare.hxx"
|
||||||
#include "util/ScopeExit.hxx"
|
#include "util/ScopeExit.hxx"
|
||||||
@@ -82,7 +83,7 @@ static const char sticker_sql_create[] =
|
|||||||
"";
|
"";
|
||||||
|
|
||||||
StickerDatabase::StickerDatabase(Path path)
|
StickerDatabase::StickerDatabase(Path path)
|
||||||
:db(path.c_str())
|
:db(NarrowPath(path))
|
||||||
{
|
{
|
||||||
assert(!path.IsNull());
|
assert(!path.IsNull());
|
||||||
|
|
||||||
|
|||||||
@@ -36,10 +36,12 @@ TagBuilder::TagBuilder(const Tag &other) noexcept
|
|||||||
{
|
{
|
||||||
items.reserve(other.num_items);
|
items.reserve(other.num_items);
|
||||||
|
|
||||||
const std::lock_guard<Mutex> protect(tag_pool_lock);
|
const std::size_t n = other.num_items;
|
||||||
|
if (n > 0) {
|
||||||
for (unsigned i = 0, n = other.num_items; i != n; ++i)
|
const std::lock_guard<Mutex> protect(tag_pool_lock);
|
||||||
items.push_back(tag_pool_dup_item(other.items[i]));
|
for (std::size_t i = 0; i != n; ++i)
|
||||||
|
items.push_back(tag_pool_dup_item(other.items[i]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TagBuilder::TagBuilder(Tag &&other) noexcept
|
TagBuilder::TagBuilder(Tag &&other) noexcept
|
||||||
@@ -63,12 +65,17 @@ TagBuilder::operator=(const TagBuilder &other) noexcept
|
|||||||
/* copy all attributes */
|
/* copy all attributes */
|
||||||
duration = other.duration;
|
duration = other.duration;
|
||||||
has_playlist = other.has_playlist;
|
has_playlist = other.has_playlist;
|
||||||
items = other.items;
|
|
||||||
|
|
||||||
/* increment the tag pool refcounters */
|
RemoveAll();
|
||||||
const std::lock_guard<Mutex> protect(tag_pool_lock);
|
|
||||||
for (auto i : items)
|
if (!other.items.empty()) {
|
||||||
tag_pool_dup_item(i);
|
items = other.items;
|
||||||
|
|
||||||
|
/* increment the tag pool refcounters */
|
||||||
|
const std::lock_guard<Mutex> protect(tag_pool_lock);
|
||||||
|
for (auto &i : items)
|
||||||
|
i = tag_pool_dup_item(i);
|
||||||
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -76,9 +83,14 @@ TagBuilder::operator=(const TagBuilder &other) noexcept
|
|||||||
TagBuilder &
|
TagBuilder &
|
||||||
TagBuilder::operator=(TagBuilder &&other) noexcept
|
TagBuilder::operator=(TagBuilder &&other) noexcept
|
||||||
{
|
{
|
||||||
|
using std::swap;
|
||||||
|
|
||||||
duration = other.duration;
|
duration = other.duration;
|
||||||
has_playlist = other.has_playlist;
|
has_playlist = other.has_playlist;
|
||||||
items = std::move(other.items);
|
|
||||||
|
/* swap the two TagItem lists so we don't need to touch the
|
||||||
|
tag pool just yet */
|
||||||
|
swap(items, other.items);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -92,7 +104,7 @@ TagBuilder::operator=(Tag &&other) noexcept
|
|||||||
/* move all TagItem pointers from the Tag object; we don't
|
/* move all TagItem pointers from the Tag object; we don't
|
||||||
need to contact the tag pool, because all we do is move
|
need to contact the tag pool, because all we do is move
|
||||||
references */
|
references */
|
||||||
items.clear();
|
RemoveAll();
|
||||||
items.reserve(other.num_items);
|
items.reserve(other.num_items);
|
||||||
std::copy_n(other.items, other.num_items, std::back_inserter(items));
|
std::copy_n(other.items, other.num_items, std::back_inserter(items));
|
||||||
|
|
||||||
@@ -174,11 +186,14 @@ TagBuilder::Complement(const Tag &other) noexcept
|
|||||||
|
|
||||||
items.reserve(items.size() + other.num_items);
|
items.reserve(items.size() + other.num_items);
|
||||||
|
|
||||||
const std::lock_guard<Mutex> protect(tag_pool_lock);
|
const std::size_t n = other.num_items;
|
||||||
for (unsigned i = 0, n = other.num_items; i != n; ++i) {
|
if (n > 0) {
|
||||||
TagItem *item = other.items[i];
|
const std::lock_guard<Mutex> protect(tag_pool_lock);
|
||||||
if (!present[item->type])
|
for (std::size_t i = 0; i != n; ++i) {
|
||||||
items.push_back(tag_pool_dup_item(item));
|
TagItem *item = other.items[i];
|
||||||
|
if (!present[item->type])
|
||||||
|
items.push_back(tag_pool_dup_item(item));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,6 +253,11 @@ TagBuilder::AddEmptyItem(TagType type) noexcept
|
|||||||
void
|
void
|
||||||
TagBuilder::RemoveAll() noexcept
|
TagBuilder::RemoveAll() noexcept
|
||||||
{
|
{
|
||||||
|
if (items.empty())
|
||||||
|
/* don't acquire the tag_pool_lock if we're not going
|
||||||
|
to call tag_pool_put_item() anyway */
|
||||||
|
return;
|
||||||
|
|
||||||
{
|
{
|
||||||
const std::lock_guard<Mutex> protect(tag_pool_lock);
|
const std::lock_guard<Mutex> protect(tag_pool_lock);
|
||||||
for (auto i : items)
|
for (auto i : items)
|
||||||
|
|||||||
@@ -28,9 +28,11 @@ extern Mutex tag_pool_lock;
|
|||||||
struct TagItem;
|
struct TagItem;
|
||||||
struct StringView;
|
struct StringView;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
TagItem *
|
TagItem *
|
||||||
tag_pool_get_item(TagType type, StringView value) noexcept;
|
tag_pool_get_item(TagType type, StringView value) noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
TagItem *
|
TagItem *
|
||||||
tag_pool_dup_item(TagItem *item) noexcept;
|
tag_pool_dup_item(TagItem *item) noexcept;
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifdef __clang__
|
#if defined(__clang__) || defined(__GNUC__)
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
// TODO: fix this warning properly
|
// TODO: fix this warning properly
|
||||||
#pragma GCC diagnostic ignored "-Wformat-security"
|
#pragma GCC diagnostic ignored "-Wformat-security"
|
||||||
@@ -59,7 +59,7 @@ FormatInvalidArgument(const char *fmt, Args&&... args) noexcept
|
|||||||
return std::invalid_argument(buffer);
|
return std::invalid_argument(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __clang__
|
#if defined(__clang__) || defined(__GNUC__)
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct AvahiTimeout final {
|
struct AvahiTimeout final {
|
||||||
TimerEvent timer;
|
TimerEvent event;
|
||||||
|
|
||||||
const AvahiTimeoutCallback callback;
|
const AvahiTimeoutCallback callback;
|
||||||
void *const userdata;
|
void *const userdata;
|
||||||
@@ -87,17 +87,17 @@ public:
|
|||||||
AvahiTimeout(const struct timeval *tv,
|
AvahiTimeout(const struct timeval *tv,
|
||||||
AvahiTimeoutCallback _callback, void *_userdata,
|
AvahiTimeoutCallback _callback, void *_userdata,
|
||||||
EventLoop &_loop)
|
EventLoop &_loop)
|
||||||
:timer(_loop, BIND_THIS_METHOD(OnTimeout)),
|
:event(_loop, BIND_THIS_METHOD(OnTimeout)),
|
||||||
callback(_callback), userdata(_userdata) {
|
callback(_callback), userdata(_userdata) {
|
||||||
if (tv != nullptr)
|
if (tv != nullptr)
|
||||||
timer.Schedule(ToSteadyClockDuration(*tv));
|
Schedule(*tv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TimeoutUpdate(AvahiTimeout *t, const struct timeval *tv) {
|
static void TimeoutUpdate(AvahiTimeout *t, const struct timeval *tv) {
|
||||||
if (tv != nullptr)
|
if (tv != nullptr)
|
||||||
t->timer.Schedule(ToSteadyClockDuration(*tv));
|
t->Schedule(*tv);
|
||||||
else
|
else
|
||||||
t->timer.Cancel();
|
t->event.Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TimeoutFree(AvahiTimeout *t) {
|
static void TimeoutFree(AvahiTimeout *t) {
|
||||||
@@ -105,6 +105,30 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
[[gnu::pure]]
|
||||||
|
Event::Duration AbsoluteToDuration(const struct timeval &tv) noexcept {
|
||||||
|
if (tv.tv_sec == 0)
|
||||||
|
/* schedule immediately */
|
||||||
|
return {};
|
||||||
|
|
||||||
|
struct timeval now;
|
||||||
|
if (gettimeofday(&now, nullptr) < 0)
|
||||||
|
/* shouldn't ever fail, but if it does, do
|
||||||
|
something reasonable */
|
||||||
|
return std::chrono::seconds(1);
|
||||||
|
|
||||||
|
auto d = ToSteadyClockDuration(tv)
|
||||||
|
- ToSteadyClockDuration(now);
|
||||||
|
if (d.count() < 0)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Schedule(const struct timeval &tv) noexcept {
|
||||||
|
event.Schedule(AbsoluteToDuration(tv));
|
||||||
|
}
|
||||||
|
|
||||||
void OnTimeout() noexcept {
|
void OnTimeout() noexcept {
|
||||||
callback(this, userdata);
|
callback(this, userdata);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,8 +157,6 @@ MyAvahiClientCallback(AvahiClient *c, AvahiClientState state,
|
|||||||
FormatDebug(avahi_domain, "Client changed to state %d", state);
|
FormatDebug(avahi_domain, "Client changed to state %d", state);
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
int reason;
|
|
||||||
|
|
||||||
case AVAHI_CLIENT_S_RUNNING:
|
case AVAHI_CLIENT_S_RUNNING:
|
||||||
LogDebug(avahi_domain, "Client is RUNNING");
|
LogDebug(avahi_domain, "Client is RUNNING");
|
||||||
|
|
||||||
@@ -169,8 +167,8 @@ MyAvahiClientCallback(AvahiClient *c, AvahiClientState state,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case AVAHI_CLIENT_FAILURE:
|
case AVAHI_CLIENT_FAILURE:
|
||||||
reason = avahi_client_errno(c);
|
if (int reason = avahi_client_errno(c);
|
||||||
if (reason == AVAHI_ERR_DISCONNECTED) {
|
reason == AVAHI_ERR_DISCONNECTED) {
|
||||||
LogNotice(avahi_domain,
|
LogNotice(avahi_domain,
|
||||||
"Client Disconnected, will reconnect shortly");
|
"Client Disconnected, will reconnect shortly");
|
||||||
if (avahi_group != nullptr) {
|
if (avahi_group != nullptr) {
|
||||||
|
|||||||
1
subprojects/.gitignore
vendored
1
subprojects/.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
/packagecache/
|
/packagecache/
|
||||||
|
|
||||||
/googletest-*/
|
/googletest-*/
|
||||||
|
/sqlite-*/
|
||||||
|
|||||||
12
subprojects/sqlite3.wrap
Normal file
12
subprojects/sqlite3.wrap
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[wrap-file]
|
||||||
|
directory = sqlite-amalgamation-3340100
|
||||||
|
source_url = https://www.sqlite.org/2021/sqlite-amalgamation-3340100.zip
|
||||||
|
source_filename = sqlite-amalgamation-3340100.zip
|
||||||
|
source_hash = e0b1c0345fe4338b936e17da8e1bd88366cd210e576834546977f040c12a8f68
|
||||||
|
patch_url = https://wrapdb.mesonbuild.com/v1/projects/sqlite3/3.34.1/1/get_zip
|
||||||
|
patch_filename = sqlite3-3.34.1-1-wrap.zip
|
||||||
|
patch_hash = cba9e47bdb4c02f88fadaae8deab357218d32562c6b86ce7ba0c72f107044360
|
||||||
|
|
||||||
|
[provide]
|
||||||
|
sqlite3 = sqlite3_dep
|
||||||
|
|
||||||
Reference in New Issue
Block a user