Compare commits
280 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
94c196108d | ||
![]() |
263d1ba002 | ||
![]() |
2dba06dc34 | ||
![]() |
811860c3b4 | ||
![]() |
8439119e24 | ||
![]() |
b5b40d8235 | ||
![]() |
b904f8af03 | ||
![]() |
ebfbb74f9e | ||
![]() |
7b4225aa1f | ||
![]() |
71a5311b06 | ||
![]() |
a62a35e1db | ||
![]() |
ca2439f595 | ||
![]() |
f9a0db716a | ||
![]() |
cfe024ea13 | ||
![]() |
993d85125e | ||
![]() |
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 | ||
![]() |
14465be847 | ||
![]() |
0e49de867d | ||
![]() |
f2e4529707 | ||
![]() |
3547fc7e61 | ||
![]() |
466a05bc52 | ||
![]() |
6de4064cca | ||
![]() |
bcf0fdd3a8 | ||
![]() |
a8f05a7efc | ||
![]() |
c64a3b5dbb | ||
![]() |
16c38c438f | ||
![]() |
48cc4a6ced | ||
![]() |
a169a05e41 | ||
![]() |
a6cb3139db | ||
![]() |
239a83324e | ||
![]() |
8efa5c7641 | ||
![]() |
28e7be248f | ||
![]() |
c3f9b38c97 | ||
![]() |
dbb18a401b | ||
![]() |
e1e41708af | ||
![]() |
638dfc3981 | ||
![]() |
7c09e44ad4 | ||
![]() |
365b798f33 | ||
![]() |
6f51d910ee | ||
![]() |
1215818572 | ||
![]() |
514ed33a02 | ||
![]() |
bfed47b82d | ||
![]() |
8c51440057 | ||
![]() |
018858ec97 | ||
![]() |
3c1988b68f | ||
![]() |
5452428d69 | ||
![]() |
d6bf6e161a | ||
![]() |
a71b76bb3c | ||
![]() |
c1429500b2 | ||
![]() |
0f02bbc2fe | ||
![]() |
b885f358a5 | ||
![]() |
650a30d794 | ||
![]() |
1dc71f383a | ||
![]() |
6dfebf7df9 | ||
![]() |
4bcdcca7f5 | ||
![]() |
c08a8581ee | ||
![]() |
25b0194036 | ||
![]() |
77fe727e69 | ||
![]() |
73f9824ddf | ||
![]() |
1fe0c673bc | ||
![]() |
8a045207a7 | ||
![]() |
fe7c5a4208 | ||
![]() |
8024f7e84d | ||
![]() |
14f0134097 | ||
![]() |
1da27be84d | ||
![]() |
08135f2cb7 | ||
![]() |
5907656bbb | ||
![]() |
2ac2bd26f8 | ||
![]() |
a2be91aea5 | ||
![]() |
579428172e | ||
![]() |
3e484637f9 | ||
![]() |
3e93c392d7 | ||
![]() |
0a97e68aa9 | ||
![]() |
69783a44c8 | ||
![]() |
d72263d28d | ||
![]() |
24a205a1aa | ||
![]() |
3a948515ce | ||
![]() |
9ade93983c | ||
![]() |
6931ce9558 | ||
![]() |
d6fb07a3e4 | ||
![]() |
01d3c2705e | ||
![]() |
29346dc9c5 | ||
![]() |
d19b3df3b0 | ||
![]() |
798e68ef62 | ||
![]() |
79397db5b4 | ||
![]() |
9256190a9b | ||
![]() |
3a0dbb0a67 | ||
![]() |
3d6c9d1b88 | ||
![]() |
5823e79fe7 | ||
![]() |
5f656dffda | ||
![]() |
34d4d9157a | ||
![]() |
22c329cdb4 | ||
![]() |
980ef82216 | ||
![]() |
84a06a72df | ||
![]() |
4833d0891d | ||
![]() |
cd53ca22c6 | ||
![]() |
4d9af9a81b | ||
![]() |
d61341c0e3 | ||
![]() |
eff50b263a | ||
![]() |
2bebc79363 | ||
![]() |
e777fb4edb | ||
![]() |
3fb25d4062 | ||
![]() |
e227596c20 | ||
![]() |
ec76583c33 | ||
![]() |
927f1e03a3 | ||
![]() |
f2c679cfec | ||
![]() |
6a75c48dba | ||
![]() |
48bdd09f64 | ||
![]() |
cf108c389f | ||
![]() |
90d97053a8 | ||
![]() |
e1fe9ebcd6 | ||
![]() |
93016ac6ab | ||
![]() |
fc20a1f10a | ||
![]() |
a4257e51d5 | ||
![]() |
2f2b3f1cdc | ||
![]() |
2ff6a9ad2b | ||
![]() |
17d4873b60 | ||
![]() |
8b41c4f384 | ||
![]() |
17f7098e27 | ||
![]() |
9ff790b7bb | ||
![]() |
ebc1fe2821 | ||
![]() |
bc2988144e | ||
![]() |
b1a9958c66 | ||
![]() |
e6a81bb95c | ||
![]() |
9521c1ad58 | ||
![]() |
6d65cc48d7 | ||
![]() |
681956a963 | ||
![]() |
052f64d648 | ||
![]() |
afe621c25c | ||
![]() |
637cf8a039 | ||
![]() |
2011a6e2ee | ||
![]() |
d54830de12 | ||
![]() |
a7e7312cca | ||
![]() |
6b83fc6b57 | ||
![]() |
74f9e07151 | ||
![]() |
82a61ab3be | ||
![]() |
54c1794cee | ||
![]() |
c962a6be76 | ||
![]() |
922c4bf3f0 | ||
![]() |
932756efce | ||
![]() |
7838265482 | ||
![]() |
b14b0e5634 | ||
![]() |
4d2d0e7bb8 | ||
![]() |
44378b7dbe | ||
![]() |
da642b2890 | ||
![]() |
6f77af20d0 | ||
![]() |
010f65a1d6 | ||
![]() |
c46f97454a | ||
![]() |
844dbd2ec5 | ||
![]() |
db7caa2dac | ||
![]() |
2974737746 | ||
![]() |
b1d7567226 | ||
![]() |
5103eb3039 | ||
![]() |
0cccdcf9b2 | ||
![]() |
22b840c2f1 | ||
![]() |
ed1a995bff | ||
![]() |
0f39dc1edb | ||
![]() |
dc9103befe | ||
![]() |
67760f5283 | ||
![]() |
99405a4c93 | ||
![]() |
b833c5d2c7 | ||
![]() |
bca5d79f88 | ||
![]() |
6e1c8edf09 | ||
![]() |
32b7b2e2fa | ||
![]() |
cfb7f8ab84 | ||
![]() |
8d80280ab9 | ||
![]() |
c95e3dc065 | ||
![]() |
00a520a4c3 | ||
![]() |
6eba621045 | ||
![]() |
a9ad8fa505 | ||
![]() |
85427826aa | ||
![]() |
25e0a90402 | ||
![]() |
938728820b | ||
![]() |
80531ef8d8 | ||
![]() |
a91fba6a3d | ||
![]() |
f8be403c34 | ||
![]() |
28a5cdf319 | ||
![]() |
6b1d264b35 | ||
![]() |
a6c10e9a1c | ||
![]() |
19a46064e9 | ||
![]() |
b57eeaa720 | ||
![]() |
ad059d5804 | ||
![]() |
6e1940e930 | ||
![]() |
103194e32d | ||
![]() |
481c330c17 | ||
![]() |
7ef489e057 | ||
![]() |
d9e5d5ff5b | ||
![]() |
ca02fb7782 | ||
![]() |
d4d06da2f8 | ||
![]() |
efde78db77 | ||
![]() |
f1b8bcd6b2 | ||
![]() |
c2bc3704e1 | ||
![]() |
def120aca4 | ||
![]() |
6d2b09ac2b | ||
![]() |
78b43a9930 | ||
![]() |
da5ff779c6 | ||
![]() |
e7da5b104d | ||
![]() |
4be76f3c8f | ||
![]() |
c58c53293c | ||
![]() |
8695a2806a | ||
![]() |
a59f1b21a6 | ||
![]() |
9e2d09dabc | ||
![]() |
2719f62feb | ||
![]() |
234cedd6c6 | ||
![]() |
5b946e9d95 | ||
![]() |
b46ca50dcc |
.travis.ymlNEWSREADME.md
android
doc
meson.buildmeson_options.txtpython/build
src
CommandLine.cxxMain.cxxRemoteTagCache.cxxTagAny.cxx
android
archive
plugins
client
command
db
decoder
Bridge.cxx
plugins
event
filter
fs
DirectoryReader.hxxGlob.cxxGlob.hxxNarrowPath.cxxNarrowPath.hxxStandardDirectory.cxxTraits.cxxTraits.hxx
io
meson.buildinput
IcyInputStream.cxxInputStream.cxxLastInputStream.cxxLastInputStream.hxxRegistry.cxxmeson.build
plugins
io
lib
curl
ffmpeg
icu
CaseFold.cxxCaseFold.hxxCollate.cxxCompare.cxxCompare.hxxConverter.cxxConverter.hxxUtil.cxxUtil.hxxWin32.cxxWin32.hxx
jack
sqlite
mixer
neighbor
plugins
net
output
Control.cxxControl.hxxPrint.cxxRegistry.cxxThread.cxx
plugins
playlist
protocol
queue
song
sticker
storage
plugins
system
tag
thread
time
util
win32
Com.hxxComHeapPtr.hxxComPtr.hxxComWorker.cxxComWorker.hxxHResult.cxxHResult.hxxPropVariant.cxxPropVariant.hxxWin32Main.cxxWinEvent.cxxWinEvent.hxxmeson.build
zeroconf
subprojects
test
TestLookupFile.cxxrun_convert.cxxrun_input.cxxrun_output.cxxtest_mixramp.cxxtest_pcm_format.cxxtest_pcm_volume.cxx
win32
64
.travis.yml
64
.travis.yml
@@ -2,70 +2,37 @@ language: cpp
|
||||
|
||||
jobs:
|
||||
include:
|
||||
# Ubuntu Bionic (18.04) with GCC 7
|
||||
# Ubuntu Focal (20.04) with GCC 9.3
|
||||
- os: linux
|
||||
dist: bionic
|
||||
dist: focal
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'ppa:deadsnakes/ppa' # for Python 3.7 (required by Meson)
|
||||
packages:
|
||||
- meson
|
||||
- libgtest-dev
|
||||
- libboost-dev
|
||||
- python3.6
|
||||
- python3-urllib3
|
||||
- ninja-build
|
||||
before_install:
|
||||
- wget https://bootstrap.pypa.io/get-pip.py
|
||||
- /usr/bin/python3.6 get-pip.py --user --no-cache-dir
|
||||
install:
|
||||
- /usr/bin/python3.6 $HOME/.local/bin/pip install --user meson --no-cache-dir
|
||||
env:
|
||||
- MATRIX_EVAL="export PATH=\$HOME/.local/bin:\$PATH"
|
||||
|
||||
# Ubuntu Bionic (18.04) with GCC 7 on big-endian
|
||||
# Ubuntu Focal (20.04) with GCC 9.3 on big-endian
|
||||
- os: linux
|
||||
arch: s390x
|
||||
dist: bionic
|
||||
dist: focal
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'ppa:deadsnakes/ppa' # for Python 3.7 (required by Meson)
|
||||
packages:
|
||||
- meson
|
||||
- libgtest-dev
|
||||
- libboost-dev
|
||||
- python3.6
|
||||
- python3-urllib3
|
||||
- ninja-build
|
||||
before_install:
|
||||
- wget https://bootstrap.pypa.io/get-pip.py
|
||||
- /usr/bin/python3.6 get-pip.py --user --no-cache-dir
|
||||
install:
|
||||
- /usr/bin/python3.6 $HOME/.local/bin/pip install --user meson --no-cache-dir
|
||||
env:
|
||||
- MATRIX_EVAL="export PATH=\$HOME/.local/bin:\$PATH"
|
||||
|
||||
# Ubuntu Bionic (18.04) with GCC 7 on ARM64
|
||||
# Ubuntu Focal (20.04) with GCC 9.3 on ARM64
|
||||
- os: linux
|
||||
arch: arm64
|
||||
dist: bionic
|
||||
dist: focal
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'ppa:deadsnakes/ppa' # for Python 3.7 (required by Meson)
|
||||
packages:
|
||||
- meson
|
||||
- libgtest-dev
|
||||
- libboost-dev
|
||||
- python3.6
|
||||
- python3-urllib3
|
||||
- ninja-build
|
||||
before_install:
|
||||
- wget https://bootstrap.pypa.io/get-pip.py
|
||||
- /usr/bin/python3.6 get-pip.py --user --no-cache-dir
|
||||
install:
|
||||
- /usr/bin/python3.6 $HOME/.local/bin/pip install --user meson --no-cache-dir
|
||||
env:
|
||||
- MATRIX_EVAL="export PATH=\$HOME/.local/bin:\$PATH"
|
||||
|
||||
# Ubuntu Trusty (16.04) with GCC 8
|
||||
- os: linux
|
||||
@@ -75,7 +42,7 @@ jobs:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- sourceline: 'ppa:mhier/libboost-latest'
|
||||
- sourceline: 'ppa:mstipicevic/ninja-build-1-7-2'
|
||||
- sourceline: 'ppa:ricotz/toolchain'
|
||||
- sourceline: 'ppa:deadsnakes/ppa' # for Python 3.7 (required by Meson)
|
||||
packages:
|
||||
- g++-8
|
||||
@@ -94,12 +61,13 @@ jobs:
|
||||
- MATRIX_EVAL="export CC='ccache gcc-8' CXX='ccache g++-8' LDFLAGS=-fuse-ld=gold PATH=\$HOME/.local/bin:\$PATH"
|
||||
|
||||
- os: osx
|
||||
osx_image: xcode10.3
|
||||
osx_image: xcode11.6
|
||||
addons:
|
||||
homebrew:
|
||||
packages:
|
||||
- ccache
|
||||
- meson
|
||||
- googletest
|
||||
- icu4c
|
||||
- ffmpeg
|
||||
- libnfs
|
||||
@@ -117,7 +85,6 @@ jobs:
|
||||
- faad2
|
||||
- wavpack
|
||||
- libmpdclient
|
||||
update: true
|
||||
env:
|
||||
- MATRIX_EVAL="export PATH=/usr/local/opt/ccache/libexec:$PATH HOMEBREW_NO_ANALYTICS=1"
|
||||
|
||||
@@ -134,13 +101,6 @@ before_install:
|
||||
- eval "${MATRIX_EVAL}"
|
||||
|
||||
install:
|
||||
# C++14
|
||||
|
||||
# Work around "Target /usr/local/lib/libgtest.a is a symlink
|
||||
# belonging to nss. You can unlink it" during gtest install
|
||||
- test "$TRAVIS_OS_NAME" != "osx" || brew unlink nss
|
||||
|
||||
- test "$TRAVIS_OS_NAME" != "osx" || brew install https://gist.githubusercontent.com/Kronuz/96ac10fbd8472eb1e7566d740c4034f8/raw/gtest.rb
|
||||
|
||||
before_script:
|
||||
- ccache -s
|
||||
|
87
NEWS
87
NEWS
@@ -1,3 +1,90 @@
|
||||
ver 0.22.11 (2021/08/24)
|
||||
* protocol
|
||||
- fix "albumart" crash
|
||||
* filter
|
||||
- ffmpeg: pass "channel_layout" instead of "channels" to buffersrc
|
||||
- ffmpeg: fix "av_buffersink_get_frame() failed: Resource temporarily unavailable"
|
||||
- ffmpeg: support double-precision samples (by converting to single precision)
|
||||
* Android
|
||||
- build with NDK r23
|
||||
- playlist_directory defaults to "/sdcard/Android/data/org.musicpd/files/playlists"
|
||||
|
||||
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)
|
||||
* fix crash bug in "albumart" command (0.22.7 regression)
|
||||
|
||||
ver 0.22.7 (2021/05/19)
|
||||
* protocol
|
||||
- don't use glibc extension to parse time stamps
|
||||
- optimize the "albumart" command
|
||||
* input
|
||||
- curl: send user/password in the first request, save one roundtrip
|
||||
* decoder
|
||||
- ffmpeg: fix build problem with FFmpeg 3.4
|
||||
- gme: support RSN files
|
||||
* storage
|
||||
- curl: don't use glibc extension
|
||||
* database
|
||||
- simple: fix database corruption bug
|
||||
* output
|
||||
- fix crash when pausing with multiple partitions
|
||||
- jack: enable on Windows
|
||||
- httpd: send header "Access-Control-Allow-Origin: *"
|
||||
- wasapi: add algorithm for finding usable audio format
|
||||
- wasapi: use default device only if none was configured
|
||||
- wasapi: add DoP support
|
||||
|
||||
ver 0.22.6 (2021/02/16)
|
||||
* fix missing tags on songs in queue
|
||||
|
||||
ver 0.22.5 (2021/02/15)
|
||||
* protocol
|
||||
- error for malformed ranges instead of ignoring silently
|
||||
- better error message for open-ended range with "move"
|
||||
* database
|
||||
- simple: fix missing CUE sheet metadata in "addid" command
|
||||
* tags
|
||||
- id: translate TPE3 to Conductor, not Performer
|
||||
* archive
|
||||
- iso9660: another fix for unaligned reads
|
||||
* output
|
||||
- httpd: error handling on Windows improved
|
||||
- pulse: fix deadlock with "always_on"
|
||||
* Windows:
|
||||
- enable https:// support (via Schannel)
|
||||
* Android
|
||||
- work around "Permission denied" on mpd.conf
|
||||
|
||||
ver 0.22.4 (2021/01/21)
|
||||
* protocol
|
||||
- add command "binarylimit" to allow larger chunk sizes
|
||||
|
@@ -14,7 +14,7 @@ For basic installation instructions
|
||||
|
||||
- [Manual](http://www.musicpd.org/doc/user/)
|
||||
- [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/)
|
||||
|
||||
# Developers
|
||||
|
@@ -2,10 +2,10 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.musicpd"
|
||||
android:installLocation="auto"
|
||||
android:versionCode="51"
|
||||
android:versionName="0.22.1">
|
||||
android:versionCode="59"
|
||||
android:versionName="0.22.11">
|
||||
|
||||
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28"/>
|
||||
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29"/>
|
||||
|
||||
<uses-feature android:name="android.software.leanback"
|
||||
android:required="false" />
|
||||
@@ -19,6 +19,7 @@
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
|
||||
<application android:allowBackup="true"
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:icon="@drawable/icon"
|
||||
android:banner="@drawable/icon"
|
||||
android:label="@string/app_name">
|
||||
|
@@ -24,15 +24,13 @@ android_abis = {
|
||||
'armeabi-v7a': {
|
||||
'arch': 'arm-linux-androideabi',
|
||||
'ndk_arch': 'arm',
|
||||
'toolchain_arch': 'arm-linux-androideabi',
|
||||
'llvm_triple': 'armv7-linux-androideabi',
|
||||
'cflags': '-fpic -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp',
|
||||
'cflags': '-fpic -mfpu=neon -mfloat-abi=softfp',
|
||||
},
|
||||
|
||||
'arm64-v8a': {
|
||||
'arch': 'aarch64-linux-android',
|
||||
'ndk_arch': 'arm64',
|
||||
'toolchain_arch': 'aarch64-linux-android',
|
||||
'llvm_triple': 'aarch64-linux-android',
|
||||
'cflags': '-fpic',
|
||||
},
|
||||
@@ -40,7 +38,6 @@ android_abis = {
|
||||
'x86': {
|
||||
'arch': 'i686-linux-android',
|
||||
'ndk_arch': 'x86',
|
||||
'toolchain_arch': 'x86',
|
||||
'llvm_triple': 'i686-linux-android',
|
||||
'cflags': '-fPIC -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32',
|
||||
},
|
||||
@@ -48,7 +45,6 @@ android_abis = {
|
||||
'x86_64': {
|
||||
'arch': 'x86_64-linux-android',
|
||||
'ndk_arch': 'x86_64',
|
||||
'toolchain_arch': 'x86_64',
|
||||
'llvm_triple': 'x86_64-linux-android',
|
||||
'cflags': '-fPIC -m64',
|
||||
},
|
||||
@@ -84,36 +80,28 @@ class AndroidNdkToolchain:
|
||||
ndk_arch = abi_info['ndk_arch']
|
||||
android_api_level = '21'
|
||||
|
||||
# select the NDK compiler
|
||||
gcc_version = '4.9'
|
||||
|
||||
install_prefix = os.path.join(arch_path, 'root')
|
||||
|
||||
self.arch = arch
|
||||
self.install_prefix = install_prefix
|
||||
|
||||
toolchain_path = os.path.join(ndk_path, 'toolchains', abi_info['toolchain_arch'] + '-' + gcc_version, 'prebuilt', build_arch)
|
||||
llvm_path = os.path.join(ndk_path, 'toolchains', 'llvm', 'prebuilt', build_arch)
|
||||
llvm_triple = abi_info['llvm_triple'] + android_api_level
|
||||
|
||||
common_flags = '-Os -g'
|
||||
common_flags += ' ' + abi_info['cflags']
|
||||
|
||||
toolchain_bin = os.path.join(toolchain_path, 'bin')
|
||||
llvm_bin = os.path.join(llvm_path, 'bin')
|
||||
self.cc = os.path.join(llvm_bin, 'clang')
|
||||
self.cxx = os.path.join(llvm_bin, 'clang++')
|
||||
common_flags += ' -target ' + llvm_triple + ' -gcc-toolchain ' + toolchain_path
|
||||
common_flags += ' -target ' + llvm_triple
|
||||
|
||||
common_flags += ' -fvisibility=hidden -fdata-sections -ffunction-sections'
|
||||
|
||||
# required flags from https://android.googlesource.com/platform/ndk/+/ndk-release-r20/docs/BuildSystemMaintainers.md#additional-required-arguments
|
||||
common_flags += ' -fno-addrsig'
|
||||
|
||||
self.ar = os.path.join(toolchain_bin, arch + '-ar')
|
||||
self.ranlib = os.path.join(toolchain_bin, arch + '-ranlib')
|
||||
self.nm = os.path.join(toolchain_bin, arch + '-nm')
|
||||
self.strip = os.path.join(toolchain_bin, arch + '-strip')
|
||||
self.ar = os.path.join(llvm_bin, 'llvm-ar')
|
||||
self.ranlib = os.path.join(llvm_bin, 'llvm-ranlib')
|
||||
self.nm = os.path.join(llvm_bin, 'llvm-nm')
|
||||
self.strip = os.path.join(llvm_bin, 'llvm-strip')
|
||||
|
||||
self.cflags = common_flags
|
||||
self.cxxflags = common_flags
|
||||
|
@@ -5,8 +5,8 @@ android_ndk = get_option('android_ndk')
|
||||
android_sdk = get_option('android_sdk')
|
||||
android_abi = get_option('android_abi')
|
||||
|
||||
android_sdk_build_tools_version = '27.0.0'
|
||||
android_sdk_platform = 'android-23'
|
||||
android_sdk_build_tools_version = '29.0.3'
|
||||
android_sdk_platform = 'android-29'
|
||||
|
||||
android_build_tools_dir = join_paths(android_sdk, 'build-tools', android_sdk_build_tools_version)
|
||||
android_sdk_platform_dir = join_paths(android_sdk, 'platforms', android_sdk_platform)
|
||||
|
@@ -414,6 +414,15 @@ public class Main extends Service implements Runnable {
|
||||
* start Main service without any callback
|
||||
*/
|
||||
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.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '0.22.4'
|
||||
version = '0.22.11'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = version
|
||||
|
||||
|
@@ -68,11 +68,11 @@ There are two active branches in the git repository:
|
||||
|
||||
- the "unstable" branch called ``master`` where new features are
|
||||
merged. This will become the next major release eventually.
|
||||
- the "stable" branch (currently called ``v0.21.x``) where only bug
|
||||
- the "stable" branch (currently called ``v0.22.x``) where only bug
|
||||
fixes are merged.
|
||||
|
||||
Once :program:`MPD` 0.22 is released, a new branch called ``v0.22.x``
|
||||
will be created for 0.22 bug-fix releases; after that, ``v0.21.x``
|
||||
Once :program:`MPD` 0.23 is released, a new branch called ``v0.23.x``
|
||||
will be created for 0.23 bug-fix releases; after that, ``v0.22.x``
|
||||
will eventually cease to be maintained.
|
||||
|
||||
After bug fixes have been added to the "stable" branch, it will be
|
||||
|
@@ -22,20 +22,6 @@ if get_option('html_manual')
|
||||
install: true,
|
||||
install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()),
|
||||
)
|
||||
|
||||
custom_target(
|
||||
'upload',
|
||||
input: sphinx_output,
|
||||
output: 'upload',
|
||||
build_always_stale: true,
|
||||
command: [
|
||||
'rsync', '-vpruz', '--delete', meson.current_build_dir() + '/',
|
||||
'www.musicpd.org:/var/www/mpd/doc/',
|
||||
'--chmod=Dug+rwx,Do+rx,Fug+rw,Fo+r',
|
||||
'--include=html', '--include=html/**',
|
||||
'--exclude=*',
|
||||
],
|
||||
)
|
||||
endif
|
||||
|
||||
if get_option('manpages')
|
||||
|
@@ -295,37 +295,6 @@ in the form ``qobuz://track/ID``, e.g.:
|
||||
* - **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).
|
||||
|
||||
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
|
||||
@@ -715,7 +684,7 @@ A resampler using `libsamplerate <http://www.mega-nerd.com/SRC/>`_ a.k.a. Secret
|
||||
* - Name
|
||||
- Description
|
||||
* - **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:
|
||||
|
||||
@@ -910,6 +879,10 @@ jack
|
||||
|
||||
The jack plugin connects to a `JACK server <http://jackaudio.org/>`_.
|
||||
|
||||
On Windows, this plugin loads :file:`libjack64.dll` at runtime. This
|
||||
means you need to `download and install the JACK windows build
|
||||
<https://jackaudio.org/downloads/>`_.
|
||||
|
||||
.. list-table::
|
||||
:widths: 20 80
|
||||
:header-rows: 1
|
||||
@@ -1171,6 +1144,8 @@ The `Windows Audio Session API <https://docs.microsoft.com/en-us/windows/win32/c
|
||||
- Enumerate all devices in log while playing started. Useful for device configuration. The default value is "no".
|
||||
* - **exclusive yes|no**
|
||||
- Exclusive mode blocks all other audio source, and get best audio quality without resampling. Stopping playing release the exclusive control of the output device. The default value is "no".
|
||||
* - **dop yes|no**
|
||||
- Enable DSD over PCM. Require exclusive mode. The default value is "no".
|
||||
|
||||
|
||||
.. _filter_plugins:
|
||||
@@ -1194,7 +1169,7 @@ This plugin requires building with ``libavfilter`` (FFmpeg).
|
||||
* - **graph "..."**
|
||||
- Specifies the ``libavfilter`` graph; read the `FFmpeg
|
||||
documentation
|
||||
<https://libav.org/documentation/libavfilter.html#Filtergraph-syntax-1>`_
|
||||
<https://ffmpeg.org/ffmpeg-filters.html#Filtergraph-syntax-1>`_
|
||||
for details
|
||||
|
||||
|
||||
|
@@ -677,6 +677,11 @@ Whenever possible, ids should be used.
|
||||
(directories add recursively). ``URI``
|
||||
can also be a single file.
|
||||
|
||||
Clients that are connected via local socket may add arbitrary
|
||||
local files (URI is an absolute path). Example::
|
||||
|
||||
add "/home/foo/Music/bar.ogg"
|
||||
|
||||
.. _command_addid:
|
||||
|
||||
:command:`addid {URI} [POSITION]`
|
||||
|
25
doc/user.rst
25
doc/user.rst
@@ -55,7 +55,7 @@ and unpack it (or `clone the git repository
|
||||
|
||||
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
|
||||
<https://ninja-build.org/>`__
|
||||
* Boost 1.58
|
||||
@@ -141,6 +141,15 @@ Basically, there are two ways to compile :program:`MPD` for Windows:
|
||||
|
||||
This section is about the latter.
|
||||
|
||||
You need:
|
||||
|
||||
* `mingw-w64 <http://mingw-w64.org/doku.php>`__
|
||||
* `Meson 0.49.0 <http://mesonbuild.com/>`__ and `Ninja
|
||||
<https://ninja-build.org/>`__
|
||||
* cmake
|
||||
* pkg-config
|
||||
* quilt
|
||||
|
||||
Just like with the native build, unpack the :program:`MPD` source
|
||||
tarball and change into the directory. Then, instead of
|
||||
:program:`meson`, type:
|
||||
@@ -167,7 +176,12 @@ Compiling for Android
|
||||
You need:
|
||||
|
||||
* Android SDK
|
||||
* `Android NDK r22 <https://developer.android.com/ndk/downloads>`_
|
||||
* `Android NDK r23 <https://developer.android.com/ndk/downloads>`_
|
||||
* `Meson 0.49.0 <http://mesonbuild.com/>`__ and `Ninja
|
||||
<https://ninja-build.org/>`__
|
||||
* cmake
|
||||
* pkg-config
|
||||
* quilt
|
||||
|
||||
Just like with the native build, unpack the :program:`MPD` source
|
||||
tarball and change into the directory. Then, instead of
|
||||
@@ -614,7 +628,8 @@ By default, all clients are unauthenticated and have a full set of permissions.
|
||||
* - **control**
|
||||
- Allows all other player and playlist manipulations.
|
||||
* - **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.
|
||||
|
||||
@@ -674,6 +689,8 @@ The State File
|
||||
- Specify the state file location. The parent directory must be writable by the :program:`MPD` user (+wx).
|
||||
* - **state_file_interval SECONDS**
|
||||
- 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
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
@@ -1106,7 +1123,7 @@ Support
|
||||
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
|
||||
^^^^^^^^^^^^^^^
|
||||
|
107
meson.build
107
meson.build
@@ -1,7 +1,7 @@
|
||||
project(
|
||||
'mpd',
|
||||
['c', 'cpp'],
|
||||
version: '0.22.4',
|
||||
version: '0.22.11',
|
||||
meson_version: '>= 0.49.0',
|
||||
default_options: [
|
||||
'c_std=c11',
|
||||
@@ -24,8 +24,8 @@ c_compiler = meson.get_compiler('c')
|
||||
|
||||
if compiler.get_id() == 'gcc' and compiler.version().version_compare('<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')
|
||||
warning('Your clang version is too old. You need at least version 5.')
|
||||
elif compiler.get_id() == 'clang' and compiler.version().version_compare('<7')
|
||||
warning('Your clang version is too old. You need at least version 7.')
|
||||
endif
|
||||
|
||||
version_conf = configuration_data()
|
||||
@@ -42,57 +42,64 @@ common_cppflags = [
|
||||
'-D_GNU_SOURCE',
|
||||
]
|
||||
|
||||
common_cflags = [
|
||||
]
|
||||
|
||||
common_cxxflags = [
|
||||
test_global_common_flags = [
|
||||
'-fvisibility=hidden',
|
||||
]
|
||||
|
||||
test_common_flags = [
|
||||
'-Wvla',
|
||||
'-Wdouble-promotion',
|
||||
|
||||
'-fvisibility=hidden',
|
||||
|
||||
'-ffast-math',
|
||||
'-ftree-vectorize',
|
||||
]
|
||||
|
||||
test_global_cxxflags = test_global_common_flags + [
|
||||
]
|
||||
|
||||
test_global_cflags = test_global_common_flags + [
|
||||
]
|
||||
|
||||
test_cxxflags = test_common_flags + [
|
||||
'-fno-threadsafe-statics',
|
||||
'-fmerge-all-constants',
|
||||
|
||||
'-Wmissing-declarations',
|
||||
'-Wshadow',
|
||||
'-Wpointer-arith',
|
||||
'-Wcast-qual',
|
||||
'-Wwrite-strings',
|
||||
'-Wsign-compare',
|
||||
'-Wcomma',
|
||||
'-Wcomma-subscript',
|
||||
'-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',
|
||||
'-Winconsistent-missing-destructor-override',
|
||||
'-Wunreachable-code-break',
|
||||
'-Wunused',
|
||||
'-Wunreachable-code-aggressive',
|
||||
'-Wused-but-marked-unused',
|
||||
|
||||
'-Wno-non-virtual-dtor',
|
||||
]
|
||||
|
||||
if compiler.get_id() == 'clang'
|
||||
# Workaround for clang bug
|
||||
# https://bugs.llvm.org/show_bug.cgi?id=32611
|
||||
test_cxxflags += '-funwind-tables'
|
||||
if compiler.get_id() != 'gcc' or compiler.version().version_compare('>=9')
|
||||
# The GCC 8 implementation of this flag is buggy: it complains even
|
||||
# if "final" is present, which implies "override".
|
||||
test_cxxflags += '-Wsuggest-override'
|
||||
endif
|
||||
|
||||
test_cflags = test_common_flags + [
|
||||
'-Wcast-qual',
|
||||
'-Wmissing-prototypes',
|
||||
'-Wshadow',
|
||||
'-Wpointer-arith',
|
||||
'-Wstrict-prototypes',
|
||||
'-Wcast-qual',
|
||||
'-Wwrite-strings',
|
||||
'-pedantic',
|
||||
]
|
||||
|
||||
test_ldflags = [
|
||||
@@ -104,11 +111,11 @@ test_ldflags = [
|
||||
]
|
||||
|
||||
if get_option('buildtype') != 'debug'
|
||||
test_cxxflags += [
|
||||
test_global_cxxflags += [
|
||||
'-ffunction-sections',
|
||||
'-fdata-sections',
|
||||
]
|
||||
test_cflags += [
|
||||
test_global_cflags += [
|
||||
'-ffunction-sections',
|
||||
'-fdata-sections',
|
||||
]
|
||||
@@ -118,15 +125,20 @@ if get_option('buildtype') != 'debug'
|
||||
endif
|
||||
|
||||
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: 'c')
|
||||
add_global_link_arguments(fuzzer_flags, language: 'cpp')
|
||||
endif
|
||||
|
||||
add_global_arguments(common_cxxflags + compiler.get_supported_arguments(test_cxxflags), language: 'cpp')
|
||||
add_global_arguments(common_cflags + c_compiler.get_supported_arguments(test_cflags), language: 'c')
|
||||
add_global_link_arguments(compiler.get_supported_link_arguments(test_ldflags), language: 'cpp')
|
||||
add_global_arguments(compiler.get_supported_arguments(test_global_cxxflags), language: 'cpp')
|
||||
add_global_arguments(c_compiler.get_supported_arguments(test_global_cflags), language: 'c')
|
||||
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_android = get_option('android_ndk') != ''
|
||||
@@ -140,10 +152,29 @@ endif
|
||||
|
||||
if is_windows
|
||||
common_cppflags += [
|
||||
'-DWIN32_LEAN_AND_MEAN',
|
||||
# enable Windows Vista APIs
|
||||
'-DWINVER=0x0600', '-D_WIN32_WINNT=0x0600',
|
||||
'-DSTRICT',
|
||||
|
||||
# enable Unicode support (TCHAR=wchar_t) in the Windows API (macro
|
||||
# "UNICODE) and the C library (macro "_UNICODE")
|
||||
'-DUNICODE', '-D_UNICODE',
|
||||
|
||||
# enable strict type checking in the Windows API headers
|
||||
'-DSTRICT',
|
||||
|
||||
# reduce header bloat by disabling obscure and obsolete Windows
|
||||
# APIs
|
||||
'-DWIN32_LEAN_AND_MEAN',
|
||||
|
||||
# disable more Windows APIs which are not used by MPD
|
||||
'-DNOGDI', '-DNOBITMAP', '-DNOCOMM',
|
||||
'-DNOUSER',
|
||||
|
||||
# reduce COM header bloat
|
||||
'-DCOM_NO_WINDOWS_H',
|
||||
|
||||
# disable Internet Explorer specific APIs
|
||||
'-D_WIN32_IE=0',
|
||||
]
|
||||
|
||||
subdir('win32')
|
||||
@@ -272,7 +303,6 @@ sources = [
|
||||
'src/LogInit.cxx',
|
||||
'src/ls.cxx',
|
||||
'src/Instance.cxx',
|
||||
'src/win32/Win32Main.cxx',
|
||||
'src/MusicBuffer.cxx',
|
||||
'src/MusicPipe.cxx',
|
||||
'src/MusicChunk.cxx',
|
||||
@@ -320,6 +350,12 @@ sources = [
|
||||
'src/PlaylistFile.cxx',
|
||||
]
|
||||
|
||||
if is_windows
|
||||
sources += [
|
||||
'src/win32/Win32Main.cxx',
|
||||
]
|
||||
endif
|
||||
|
||||
if not is_android
|
||||
sources += [
|
||||
'src/CommandLine.cxx',
|
||||
@@ -354,6 +390,7 @@ subdir('src/system')
|
||||
subdir('src/thread')
|
||||
subdir('src/net')
|
||||
subdir('src/event')
|
||||
subdir('src/win32')
|
||||
|
||||
subdir('src/apple')
|
||||
|
||||
|
@@ -104,7 +104,6 @@ option('smbclient', type: 'feature', value: 'disabled', description: 'SMB suppor
|
||||
|
||||
option('qobuz', type: 'feature', description: 'Qobuz client')
|
||||
option('soundcloud', type: 'feature', description: 'SoundCloud client')
|
||||
option('tidal', type: 'feature', description: 'Tidal client')
|
||||
|
||||
#
|
||||
# Archive plugins
|
||||
|
@@ -21,3 +21,8 @@ class BoostProject(Project):
|
||||
dest = os.path.join(includedir, 'boost')
|
||||
shutil.rmtree(dest, ignore_errors=True)
|
||||
shutil.copytree(os.path.join(src, 'boost'), dest)
|
||||
|
||||
# touch the boost/version.hpp file to ensure it's newer than
|
||||
# the downloaded Boost tarball, to avoid reinstalling Boost on
|
||||
# every run
|
||||
os.utime(os.path.join(toolchain.install_prefix, self.installed))
|
||||
|
47
python/build/jack.py
Normal file
47
python/build/jack.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import os, shutil
|
||||
import re
|
||||
|
||||
from .project import Project
|
||||
|
||||
# This class installs just the public headers and a fake pkg-config
|
||||
# file which defines the macro "DYNAMIC_JACK". This tells MPD's JACK
|
||||
# output plugin to load the libjack64.dll dynamically using
|
||||
# LoadLibrary(). This kludge avoids the runtime DLL dependency for
|
||||
# users who don't use JACK, but still allows using the system JACK
|
||||
# client library.
|
||||
#
|
||||
# The problem with JACK is that it uses an extremely fragile shared
|
||||
# memory protocol to communicate with the daemon. One needs to use
|
||||
# daemon and client library from the same build. That's why we don't
|
||||
# build libjack statically here; it would probably not be compatible
|
||||
# with the user's JACK daemon.
|
||||
|
||||
class JackProject(Project):
|
||||
def __init__(self, url, md5, installed,
|
||||
**kwargs):
|
||||
m = re.match(r'.*/v([\d.]+)\.tar\.gz$', url)
|
||||
self.version = m.group(1)
|
||||
Project.__init__(self, url, md5, installed,
|
||||
name='jack2', version=self.version,
|
||||
base='jack2-' + self.version,
|
||||
**kwargs)
|
||||
|
||||
def build(self, toolchain):
|
||||
src = self.unpack(toolchain)
|
||||
|
||||
includes = ['jack.h', 'ringbuffer.h', 'systemdeps.h', 'transport.h', 'types.h', 'weakmacros.h']
|
||||
includedir = os.path.join(toolchain.install_prefix, 'include', 'jack')
|
||||
os.makedirs(includedir, exist_ok=True)
|
||||
|
||||
for i in includes:
|
||||
shutil.copyfile(os.path.join(src, 'common', 'jack', i),
|
||||
os.path.join(includedir, i))
|
||||
|
||||
with open(os.path.join(toolchain.install_prefix, 'lib', 'pkgconfig', 'jack.pc'), 'w') as f:
|
||||
print("prefix=" + toolchain.install_prefix, file=f)
|
||||
print("", file=f)
|
||||
print("Name: jack", file=f)
|
||||
print("Description: dummy", file=f)
|
||||
print("Version: " + self.version, file=f)
|
||||
print("Libs: ", file=f)
|
||||
print("Cflags: -DDYNAMIC_JACK", file=f)
|
@@ -9,6 +9,7 @@ from build.autotools import AutotoolsProject
|
||||
from build.ffmpeg import FfmpegProject
|
||||
from build.openssl import OpenSSLProject
|
||||
from build.boost import BoostProject
|
||||
from build.jack import JackProject
|
||||
|
||||
libmpdclient = MesonProject(
|
||||
'https://www.musicpd.org/download/libmpdclient/2/libmpdclient-2.19.tar.xz',
|
||||
@@ -149,8 +150,8 @@ gme = CmakeProject(
|
||||
)
|
||||
|
||||
ffmpeg = FfmpegProject(
|
||||
'http://ffmpeg.org/releases/ffmpeg-4.3.1.tar.xz',
|
||||
'ad009240d46e307b4e03a213a0f49c11b650e445b1f8be0dda2a9212b34d2ffb',
|
||||
'http://ffmpeg.org/releases/ffmpeg-4.4.tar.xz',
|
||||
'06b10a183ce5371f915c6bb15b7b1fffbe046e8275099c96affc29e17645d909',
|
||||
'lib/libavcodec.a',
|
||||
[
|
||||
'--disable-shared', '--enable-static',
|
||||
@@ -378,14 +379,14 @@ ffmpeg = FfmpegProject(
|
||||
)
|
||||
|
||||
openssl = OpenSSLProject(
|
||||
'https://www.openssl.org/source/openssl-3.0.0-alpha10.tar.gz',
|
||||
'b1699acf2148db31f12edf5ebfdf12a92bfd3f0e60538d169710408a3cd3b138',
|
||||
'https://www.openssl.org/source/openssl-3.0.0-beta2.tar.gz',
|
||||
'e76ab22879201b12f014393ee4becec7f264d8f6955b1036839128002868df71',
|
||||
'include/openssl/ossl_typ.h',
|
||||
)
|
||||
|
||||
curl = AutotoolsProject(
|
||||
'http://curl.haxx.se/download/curl-7.74.0.tar.xz',
|
||||
'999d5f2c403cf6e25d58319fdd596611e455dd195208746bc6e6d197a77e878b',
|
||||
'https://curl.se/download/curl-7.78.0.tar.xz',
|
||||
'be42766d5664a739c3974ee3dfbbcbe978a4ccb1fe628bb1d9b59ac79e445fb5',
|
||||
'lib/libcurl.a',
|
||||
[
|
||||
'--disable-shared', '--enable-static',
|
||||
@@ -407,6 +408,9 @@ curl = AutotoolsProject(
|
||||
'--disable-progress-meter',
|
||||
'--disable-alt-svc',
|
||||
'--without-gnutls', '--without-nss', '--without-libssh2',
|
||||
|
||||
# native Windows SSL/TLS support, option ignored on non-Windows builds
|
||||
'--with-schannel',
|
||||
],
|
||||
|
||||
patches='src/lib/curl/patches',
|
||||
@@ -440,8 +444,14 @@ libnfs = AutotoolsProject(
|
||||
autoreconf=True,
|
||||
)
|
||||
|
||||
jack = JackProject(
|
||||
'https://github.com/jackaudio/jack2/archive/v1.9.17.tar.gz',
|
||||
'38f674bbc57852a8eb3d9faa1f96a0912d26f7d5df14c11005ad499c8ae352f2',
|
||||
'lib/pkgconfig/jack.pc',
|
||||
)
|
||||
|
||||
boost = BoostProject(
|
||||
'https://dl.bintray.com/boostorg/release/1.75.0/source/boost_1_75_0.tar.bz2',
|
||||
'953db31e016db7bb207f11432bef7df100516eeb746843fa0486a222e3fd49cb',
|
||||
'https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.bz2',
|
||||
'f0397ba6e982c4450f27bf32a2a83292aba035b827a5623a14636ea583318c41',
|
||||
'include/boost/version.hpp',
|
||||
)
|
||||
|
@@ -17,6 +17,12 @@ class OpenSSLProject(MakeProject):
|
||||
'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):
|
||||
src = self.unpack(toolchain, out_of_tree=False)
|
||||
|
||||
|
@@ -20,7 +20,7 @@ class Project:
|
||||
self.base = base
|
||||
|
||||
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 version is None: version = m.group(2)
|
||||
|
||||
|
@@ -113,7 +113,7 @@ static void version()
|
||||
printf("Music Player Daemon " VERSION " (%s)"
|
||||
"\n"
|
||||
"Copyright 2003-2007 Warren Dukes <warren.dukes@gmail.com>\n"
|
||||
"Copyright 2008-2018 Max Kellermann <max.kellermann@gmail.com>\n"
|
||||
"Copyright 2008-2021 Max Kellermann <max.kellermann@gmail.com>\n"
|
||||
"This is free software; see the source for copying conditions. There is NO\n"
|
||||
"warranty; not even MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
|
||||
GIT_VERSION);
|
||||
|
16
src/Main.cxx
16
src/Main.cxx
@@ -157,7 +157,17 @@ glue_daemonize_init(const struct options *options,
|
||||
static void
|
||||
glue_mapper_init(const ConfigData &config)
|
||||
{
|
||||
mapper_init(config.GetPath(ConfigOption::PLAYLIST_DIR));
|
||||
auto playlist_directory = config.GetPath(ConfigOption::PLAYLIST_DIR);
|
||||
|
||||
#ifdef ANDROID
|
||||
/* if there is no explicit configuration, store playlists in
|
||||
"/sdcard/Android/data/org.musicpd/files/playlists" */
|
||||
if (playlist_directory.IsNull())
|
||||
playlist_directory = context->GetExternalFilesDir(Java::GetEnv(),
|
||||
"playlists");
|
||||
#endif
|
||||
|
||||
mapper_init(std::move(playlist_directory));
|
||||
}
|
||||
|
||||
#ifdef ENABLE_DATABASE
|
||||
@@ -477,6 +487,7 @@ MainConfigured(const struct options &options, const ConfigData &raw_config)
|
||||
#endif
|
||||
|
||||
ZeroconfInit(raw_config, instance.event_loop);
|
||||
AtScopeExit() { ZeroconfDeinit(); };
|
||||
|
||||
#ifdef ENABLE_DATABASE
|
||||
if (create_db) {
|
||||
@@ -537,9 +548,6 @@ MainConfigured(const struct options &options, const ConfigData &raw_config)
|
||||
instance.state_file->Write();
|
||||
|
||||
instance.BeginShutdownUpdate();
|
||||
|
||||
ZeroconfDeinit();
|
||||
|
||||
instance.BeginShutdownPartitions();
|
||||
}
|
||||
|
||||
|
@@ -42,9 +42,9 @@ RemoteTagCache::Lookup(const std::string &uri) noexcept
|
||||
std::unique_lock<Mutex> lock(mutex);
|
||||
|
||||
KeyMap::insert_commit_data hint;
|
||||
auto result = map.insert_check(uri, Item::Hash(), Item::Equal(), hint);
|
||||
if (result.second) {
|
||||
auto *item = new Item(*this, uri);
|
||||
auto [tag, value] = map.insert_check(uri, Item::Hash(), Item::Equal(), hint);
|
||||
if (value) {
|
||||
auto item = new Item(*this, uri);
|
||||
map.insert_commit(*item, hint);
|
||||
waiting_list.push_back(*item);
|
||||
lock.unlock();
|
||||
@@ -70,15 +70,13 @@ RemoteTagCache::Lookup(const std::string &uri) noexcept
|
||||
ItemResolved(*item);
|
||||
return;
|
||||
}
|
||||
} else if (result.first->scanner) {
|
||||
} else if (tag->scanner) {
|
||||
/* already scanning this one - no-op */
|
||||
} else {
|
||||
/* already finished: re-invoke the handler */
|
||||
|
||||
auto &item = *result.first;
|
||||
|
||||
idle_list.erase(waiting_list.iterator_to(item));
|
||||
invoke_list.push_back(item);
|
||||
idle_list.erase(waiting_list.iterator_to(*tag));
|
||||
invoke_list.push_back(*tag);
|
||||
|
||||
ScheduleInvokeHandlers();
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#include "client/Client.hxx"
|
||||
#include "protocol/Ack.hxx"
|
||||
#include "fs/AllocatedPath.hxx"
|
||||
#include "input/InputStream.hxx"
|
||||
#include "util/Compiler.h"
|
||||
#include "util/UriExtract.hxx"
|
||||
#include "LocateUri.hxx"
|
||||
@@ -32,8 +33,13 @@
|
||||
static void
|
||||
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");
|
||||
|
||||
ScanGenericTags(*is, handler);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -26,6 +26,25 @@
|
||||
|
||||
#include "AudioManager.hxx"
|
||||
|
||||
AllocatedPath
|
||||
Context::GetExternalFilesDir(JNIEnv *env, const char *_type) noexcept
|
||||
{
|
||||
assert(_type != nullptr);
|
||||
|
||||
Java::Class cls{env, env->GetObjectClass(Get())};
|
||||
jmethodID method = env->GetMethodID(cls, "getExternalFilesDir",
|
||||
"(Ljava/lang/String;)Ljava/io/File;");
|
||||
assert(method);
|
||||
|
||||
Java::String type{env, _type};
|
||||
|
||||
jobject file = env->CallObjectMethod(Get(), method, type.Get());
|
||||
if (Java::DiscardException(env) || file == nullptr)
|
||||
return nullptr;
|
||||
|
||||
return Java::File::ToAbsolutePath(env, file);
|
||||
}
|
||||
|
||||
AllocatedPath
|
||||
Context::GetCacheDir(JNIEnv *env) const noexcept
|
||||
{
|
||||
|
@@ -30,10 +30,14 @@ public:
|
||||
Context(JNIEnv *env, jobject obj) noexcept
|
||||
:Java::GlobalObject(env, obj) {}
|
||||
|
||||
gcc_pure
|
||||
[[gnu::pure]]
|
||||
AllocatedPath GetExternalFilesDir(JNIEnv *env,
|
||||
const char *type) noexcept;
|
||||
|
||||
[[gnu::pure]]
|
||||
AllocatedPath GetCacheDir(JNIEnv *env) const noexcept;
|
||||
|
||||
gcc_pure
|
||||
[[gnu::pure]]
|
||||
AudioManager *GetAudioManager(JNIEnv *env) noexcept;
|
||||
};
|
||||
|
||||
|
@@ -33,10 +33,10 @@ namespace Environment {
|
||||
/**
|
||||
* Determine the mount point of the external SD card.
|
||||
*/
|
||||
gcc_pure
|
||||
[[gnu::pure]]
|
||||
AllocatedPath getExternalStorageDirectory() noexcept;
|
||||
|
||||
gcc_pure
|
||||
[[gnu::pure]]
|
||||
AllocatedPath getExternalStoragePublicDirectory(const char *type) noexcept;
|
||||
}
|
||||
|
||||
|
@@ -221,8 +221,8 @@ public:
|
||||
if (new_offset > size)
|
||||
throw std::runtime_error("Invalid seek offset");
|
||||
|
||||
offset = new_offset;
|
||||
skip = new_offset % ISO_BLOCKSIZE;
|
||||
offset = new_offset - skip;
|
||||
buffer.Clear();
|
||||
}
|
||||
};
|
||||
@@ -260,13 +260,13 @@ Iso9660InputStream::Read(std::unique_lock<Mutex> &,
|
||||
if (r.empty()) {
|
||||
/* the buffer is empty - read more data from the ISO file */
|
||||
|
||||
assert(offset % ISO_BLOCKSIZE == 0);
|
||||
assert((offset - skip) % ISO_BLOCKSIZE == 0);
|
||||
|
||||
const ScopeUnlock unlock(mutex);
|
||||
|
||||
const lsn_t read_lsn = lsn + offset / ISO_BLOCKSIZE;
|
||||
|
||||
if (read_size >= ISO_BLOCKSIZE) {
|
||||
if (read_size >= ISO_BLOCKSIZE && skip == 0) {
|
||||
/* big read - read right into the caller's buffer */
|
||||
|
||||
auto nbytes = iso->SeekRead(ptr, read_lsn,
|
||||
|
@@ -23,6 +23,7 @@
|
||||
#include "Message.hxx"
|
||||
#include "command/CommandResult.hxx"
|
||||
#include "command/CommandListBuilder.hxx"
|
||||
#include "input/LastInputStream.hxx"
|
||||
#include "tag/Mask.hxx"
|
||||
#include "event/FullyBufferedSocket.hxx"
|
||||
#include "event/TimerEvent.hxx"
|
||||
@@ -90,6 +91,13 @@ public:
|
||||
*/
|
||||
size_t binary_limit = 8192;
|
||||
|
||||
/**
|
||||
* This caches the last "albumart" InputStream instance, to
|
||||
* avoid repeating the search for each chunk requested by this
|
||||
* client.
|
||||
*/
|
||||
LastInputStream last_album_art;
|
||||
|
||||
private:
|
||||
static constexpr size_t MAX_SUBSCRIPTIONS = 16;
|
||||
|
||||
|
@@ -44,7 +44,8 @@ Client::Client(EventLoop &_loop, Partition &_partition,
|
||||
partition(&_partition),
|
||||
permission(_permission),
|
||||
uid(_uid),
|
||||
num(_num)
|
||||
num(_num),
|
||||
last_album_art(_loop)
|
||||
{
|
||||
timeout_event.Schedule(client_timeout);
|
||||
}
|
||||
|
@@ -61,7 +61,12 @@ Response::WriteBinary(ConstBuffer<void> payload) noexcept
|
||||
{
|
||||
assert(payload.size <= client.binary_limit);
|
||||
|
||||
return Format("binary: %zu\n", payload.size) &&
|
||||
return
|
||||
#ifdef _WIN32
|
||||
Format("binary: %lu\n", (unsigned long)payload.size) &&
|
||||
#else
|
||||
Format("binary: %zu\n", payload.size) &&
|
||||
#endif
|
||||
Write(payload.data, payload.size) &&
|
||||
Write("\n");
|
||||
}
|
||||
|
@@ -34,8 +34,7 @@ Client::Subscribe(const char *channel) noexcept
|
||||
if (num_subscriptions >= MAX_SUBSCRIPTIONS)
|
||||
return Client::SubscribeResult::FULL;
|
||||
|
||||
auto r = subscriptions.insert(channel);
|
||||
if (!r.second)
|
||||
if (!subscriptions.insert(channel).second)
|
||||
return Client::SubscribeResult::ALREADY;
|
||||
|
||||
++num_subscriptions;
|
||||
|
@@ -27,11 +27,15 @@
|
||||
#include "client/Response.hxx"
|
||||
#include "util/CharUtil.hxx"
|
||||
#include "util/OffsetPointer.hxx"
|
||||
#include "util/ScopeExit.hxx"
|
||||
#include "util/StringCompare.hxx"
|
||||
#include "util/StringView.hxx"
|
||||
#include "util/UriExtract.hxx"
|
||||
#include "tag/Handler.hxx"
|
||||
#include "tag/Generic.hxx"
|
||||
#include "TagAny.hxx"
|
||||
#include "db/Interface.hxx"
|
||||
#include "song/LightSong.hxx"
|
||||
#include "storage/StorageInterface.hxx"
|
||||
#include "fs/AllocatedPath.hxx"
|
||||
#include "fs/FileInfo.hxx"
|
||||
@@ -187,13 +191,19 @@ find_stream_art(std::string_view directory, Mutex &mutex)
|
||||
}
|
||||
|
||||
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
|
||||
auto &client = const_cast<Client &>(r.GetClient());
|
||||
|
||||
Mutex mutex;
|
||||
|
||||
InputStreamPtr is = find_stream_art(art_directory, mutex);
|
||||
/* to avoid repeating the search for each chunk request by the
|
||||
same client, use the #LastInputStream class to cache the
|
||||
#InputStream instance */
|
||||
auto *is = client.last_album_art.Open(art_directory, [](std::string_view directory,
|
||||
Mutex &mutex){
|
||||
return find_stream_art(directory, mutex);
|
||||
});
|
||||
|
||||
if (is == nullptr) {
|
||||
r.Error(ACK_ERROR_NO_EXIST, "No file exists");
|
||||
@@ -219,18 +229,61 @@ read_stream_art(Response &r, const char *uri, size_t offset)
|
||||
|
||||
std::size_t read_size = 0;
|
||||
if (buffer_size > 0) {
|
||||
std::unique_lock<Mutex> lock(mutex);
|
||||
std::unique_lock<Mutex> lock(is->mutex);
|
||||
is->Seek(lock, offset);
|
||||
read_size = is->Read(lock, buffer.get(), buffer_size);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
r.Format("size: %lu\n", (unsigned long)art_file_size);
|
||||
#else
|
||||
r.Format("size: %" PRIoffset "\n", art_file_size);
|
||||
#endif
|
||||
|
||||
r.WriteBinary({buffer.get(), read_size});
|
||||
|
||||
return CommandResult::OK;
|
||||
}
|
||||
|
||||
#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); };
|
||||
|
||||
if (song->real_uri == nullptr)
|
||||
return directory_uri;
|
||||
|
||||
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
|
||||
read_db_art(Client &client, Response &r, const char *uri, const uint64_t offset)
|
||||
{
|
||||
@@ -240,7 +293,13 @@ read_db_art(Client &client, Response &r, const char *uri, const uint64_t offset)
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
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
|
||||
|
||||
@@ -261,7 +320,10 @@ handle_album_art(Client &client, Request args, Response &r)
|
||||
switch (located_uri.type) {
|
||||
case LocatedUri::Type::ABSOLUTE:
|
||||
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:
|
||||
#ifdef ENABLE_DATABASE
|
||||
return read_db_art(client, r, located_uri.canonical_uri, offset);
|
||||
@@ -306,7 +368,11 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
response.Format("size: %lu\n", (unsigned long)buffer.size);
|
||||
#else
|
||||
response.Format("size: %zu\n", buffer.size);
|
||||
#endif
|
||||
|
||||
if (mime_type != nullptr)
|
||||
response.Format("type: %s\n", mime_type);
|
||||
|
@@ -92,7 +92,7 @@ handle_load(Client &client, Request args, [[maybe_unused]] Response &r)
|
||||
auto &instance = client.GetInstance();
|
||||
const unsigned new_size = playlist.GetLength();
|
||||
for (unsigned i = old_size; i < new_size; ++i)
|
||||
instance.LookupRemoteTag(playlist.queue.Get(i).GetURI());
|
||||
instance.LookupRemoteTag(playlist.queue.Get(i).GetRealURI());
|
||||
|
||||
return CommandResult::OK;
|
||||
}
|
||||
|
@@ -326,6 +326,11 @@ CommandResult
|
||||
handle_move(Client &client, Request args, [[maybe_unused]] Response &r)
|
||||
{
|
||||
RangeArg range = args.ParseRange(0);
|
||||
if (range.IsOpenEnded()) {
|
||||
r.Error(ACK_ERROR_ARG, "Open-ended range not supported");
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
|
||||
int to = args.ParseInt(1);
|
||||
client.GetPartition().MoveRange(range.start, range.end, to);
|
||||
return CommandResult::OK;
|
||||
|
@@ -57,9 +57,9 @@ Print(Response &r, TagType group, const TagCountMap &m) noexcept
|
||||
{
|
||||
assert(unsigned(group) < TAG_NUM_OF_ITEM_TYPES);
|
||||
|
||||
for (const auto &i : m) {
|
||||
tag_print(r, group, i.first.c_str());
|
||||
PrintSearchStats(r, i.second);
|
||||
for (const auto &[tag, stats] : m) {
|
||||
tag_print(r, group, tag.c_str());
|
||||
PrintSearchStats(r, stats);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,8 +68,7 @@ stats_visitor_song(SearchStats &stats, const LightSong &song) noexcept
|
||||
{
|
||||
stats.n_songs++;
|
||||
|
||||
const auto duration = song.GetDuration();
|
||||
if (!duration.IsNegative())
|
||||
if (const auto duration = song.GetDuration(); !duration.IsNegative())
|
||||
stats.total_duration += duration;
|
||||
}
|
||||
|
||||
@@ -77,8 +76,7 @@ static void
|
||||
CollectGroupCounts(TagCountMap &map, const Tag &tag,
|
||||
const char *value) noexcept
|
||||
{
|
||||
auto r = map.insert(std::make_pair(value, SearchStats()));
|
||||
SearchStats &s = r.first->second;
|
||||
auto &s = map.insert(std::make_pair(value, SearchStats())).first->second;
|
||||
++s.n_songs;
|
||||
if (!tag.duration.IsNegative())
|
||||
s.total_duration += tag.duration;
|
||||
|
@@ -195,11 +195,11 @@ PrintUniqueTags(Response &r, ConstBuffer<TagType> tag_types,
|
||||
const char *const name = tag_item_names[tag_types.front()];
|
||||
tag_types.pop_front();
|
||||
|
||||
for (const auto &i : map) {
|
||||
r.Format("%s: %s\n", name, i.first.c_str());
|
||||
for (const auto &[key, tag] : map) {
|
||||
r.Format("%s: %s\n", name, key.c_str());
|
||||
|
||||
if (!tag_types.empty())
|
||||
PrintUniqueTags(r, tag_types, i.second);
|
||||
PrintUniqueTags(r, tag_types, tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -424,6 +424,7 @@ SendGroup(mpd_connection *connection, TagType group)
|
||||
return mpd_search_add_group_tag(connection, tag);
|
||||
#else
|
||||
(void)connection;
|
||||
(void)group;
|
||||
|
||||
throw std::runtime_error("Grouping requires libmpdclient 2.12");
|
||||
#endif
|
||||
|
@@ -109,6 +109,23 @@ Directory::FindChild(std::string_view name) const noexcept
|
||||
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
|
||||
Directory::PruneEmpty() noexcept
|
||||
{
|
||||
@@ -138,13 +155,10 @@ Directory::LookupDirectory(std::string_view _uri) noexcept
|
||||
|
||||
Directory *d = this;
|
||||
do {
|
||||
auto s = uri.Split(PathTraitsUTF8::SEPARATOR);
|
||||
if (s.first.empty())
|
||||
auto [name, rest] = uri.Split(PathTraitsUTF8::SEPARATOR);
|
||||
if (name.empty())
|
||||
break;
|
||||
|
||||
const auto name = s.first;
|
||||
const auto rest = s.second;
|
||||
|
||||
Directory *tmp = d->FindChild(name);
|
||||
if (tmp == nullptr)
|
||||
/* not found */
|
||||
|
@@ -118,13 +118,17 @@ public:
|
||||
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
|
||||
* directory?
|
||||
*/
|
||||
bool IsReallyAFile() const noexcept {
|
||||
return device == DEVICE_INARCHIVE ||
|
||||
device == DEVICE_PLAYLIST ||
|
||||
IsPlaylist() ||
|
||||
device == DEVICE_CONTAINER;
|
||||
}
|
||||
|
||||
@@ -206,11 +210,13 @@ public:
|
||||
* Looks up a directory by its relative URI.
|
||||
*
|
||||
* @param uri the relative URI
|
||||
* @return the Directory, or nullptr if none was found
|
||||
*/
|
||||
gcc_pure
|
||||
LookupResult LookupDirectory(std::string_view uri) noexcept;
|
||||
|
||||
[[gnu::pure]]
|
||||
bool TargetExists(std::string_view target) const noexcept;
|
||||
|
||||
gcc_pure
|
||||
bool IsEmpty() const noexcept {
|
||||
return children.empty() &&
|
||||
|
@@ -29,6 +29,12 @@
|
||||
* a #LightSong, e.g. a merged #Tag.
|
||||
*/
|
||||
class ExportedSong : public LightSong {
|
||||
/**
|
||||
* A reference target for LightSong::tag, but it is only used
|
||||
* if this instance "owns" the #Tag. For instances referring
|
||||
* to a foreign #Tag instance (e.g. a Song::tag), this field
|
||||
* is not used (and empty).
|
||||
*/
|
||||
Tag tag_buffer;
|
||||
|
||||
public:
|
||||
@@ -37,6 +43,25 @@ public:
|
||||
ExportedSong(const char *_uri, Tag &&_tag) noexcept
|
||||
:LightSong(_uri, tag_buffer),
|
||||
tag_buffer(std::move(_tag)) {}
|
||||
|
||||
/* this custom move constructor is necessary so LightSong::tag
|
||||
points to this instance's #Tag field instead of leaving a
|
||||
dangling reference to the source object's #Tag field */
|
||||
ExportedSong(ExportedSong &&src) noexcept
|
||||
:LightSong(src,
|
||||
/* refer to tag_buffer only if the
|
||||
moved-from instance also owned the Tag
|
||||
which its LightSong::tag field refers
|
||||
to */
|
||||
src.OwnsTag() ? tag_buffer : src.tag),
|
||||
tag_buffer(std::move(src.tag_buffer)) {}
|
||||
|
||||
ExportedSong &operator=(ExportedSong &&) = delete;
|
||||
|
||||
private:
|
||||
bool OwnsTag() const noexcept {
|
||||
return &tag == &tag_buffer;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include "playlist/SongEnumerator.hxx"
|
||||
#include "storage/FileInfo.hxx"
|
||||
#include "storage/StorageInterface.hxx"
|
||||
#include "fs/Traits.hxx"
|
||||
#include "util/StringFormat.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),
|
||||
*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",
|
||||
++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
|
||||
static bool
|
||||
update_directory_stat(Storage &storage, Directory &directory) noexcept
|
||||
@@ -312,6 +334,29 @@ UpdateWalk::SkipSymlink(const Directory *directory,
|
||||
#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
|
||||
UpdateWalk::UpdateDirectory(Directory &directory,
|
||||
const ExcludeList &exclude_list,
|
||||
@@ -331,17 +376,7 @@ UpdateWalk::UpdateDirectory(Directory &directory,
|
||||
}
|
||||
|
||||
ExcludeList child_exclude_list(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());
|
||||
}
|
||||
LoadExcludeListOrLog(storage, directory, child_exclude_list);
|
||||
|
||||
if (!child_exclude_list.IsEmpty())
|
||||
RemoveExcludedFromDirectory(directory, child_exclude_list);
|
||||
@@ -427,26 +462,46 @@ UpdateWalk::DirectoryMakeUriParentChecked(Directory &root,
|
||||
StringView uri(_uri);
|
||||
|
||||
while (true) {
|
||||
auto s = uri.Split('/');
|
||||
const std::string_view name = s.first;
|
||||
const auto rest = s.second;
|
||||
auto [name, rest] = uri.Split('/');
|
||||
if (rest == nullptr)
|
||||
break;
|
||||
|
||||
if (!name.empty()) {
|
||||
directory = DirectoryMakeChildChecked(*directory,
|
||||
std::string(name).c_str(),
|
||||
s.first);
|
||||
name);
|
||||
if (directory == nullptr)
|
||||
break;
|
||||
}
|
||||
|
||||
uri = s.second;
|
||||
uri = rest;
|
||||
}
|
||||
|
||||
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
|
||||
UpdateWalk::UpdateUri(Directory &root, const char *uri) noexcept
|
||||
try {
|
||||
@@ -467,9 +522,8 @@ try {
|
||||
return;
|
||||
}
|
||||
|
||||
ExcludeList exclude_list;
|
||||
|
||||
UpdateDirectoryChild(*parent, exclude_list, name, info);
|
||||
const auto exclude_lists = LoadExcludeLists(storage, *parent);
|
||||
UpdateDirectoryChild(*parent, exclude_lists.front(), name, info);
|
||||
} catch (...) {
|
||||
LogError(std::current_exception());
|
||||
}
|
||||
@@ -498,5 +552,10 @@ UpdateWalk::Walk(Directory &root, const char *path, bool discard) noexcept
|
||||
UpdateDirectory(root, exclude_list, info);
|
||||
}
|
||||
|
||||
{
|
||||
const ScopeDatabaseLock protect;
|
||||
PurgeDanglingFromPlaylists(root);
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
@@ -85,6 +85,12 @@ private:
|
||||
|
||||
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,
|
||||
const char *name, const char *suffix,
|
||||
const StorageFileInfo &info) noexcept;
|
||||
|
@@ -581,10 +581,6 @@ DecoderBridge::SubmitTag(InputStream *is, Tag &&tag) noexcept
|
||||
|
||||
decoder_tag = std::make_unique<Tag>(std::move(tag));
|
||||
|
||||
/* check for a new stream tag */
|
||||
|
||||
UpdateStreamTag(is);
|
||||
|
||||
/* check if we're seeking */
|
||||
|
||||
if (PrepareInitialSeek())
|
||||
@@ -593,6 +589,10 @@ DecoderBridge::SubmitTag(InputStream *is, Tag &&tag) noexcept
|
||||
function here */
|
||||
return DecoderCommand::SEEK;
|
||||
|
||||
/* check for a new stream tag */
|
||||
|
||||
UpdateStreamTag(is);
|
||||
|
||||
/* send tag to music pipe */
|
||||
|
||||
if (stream_tag != nullptr)
|
||||
|
@@ -464,6 +464,17 @@ FfmpegCheckTag(DecoderClient &client, InputStream *is,
|
||||
client.SubmitTag(is, tag.Commit());
|
||||
}
|
||||
|
||||
static bool
|
||||
IsSeekable(const AVFormatContext &format_context) noexcept
|
||||
{
|
||||
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 6, 100)
|
||||
return (format_context.ctx_flags & AVFMTCTX_UNSEEKABLE) != 0;
|
||||
#else
|
||||
(void)format_context;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
FfmpegDecode(DecoderClient &client, InputStream *input,
|
||||
AVFormatContext &format_context)
|
||||
@@ -521,7 +532,7 @@ FfmpegDecode(DecoderClient &client, InputStream *input,
|
||||
client.Ready(audio_format,
|
||||
input
|
||||
? input->IsSeekable()
|
||||
: (format_context.ctx_flags & AVFMTCTX_UNSEEKABLE) != 0,
|
||||
: IsSeekable(format_context),
|
||||
total_time);
|
||||
|
||||
FfmpegParseMetaData(client, format_context, audio_stream);
|
||||
@@ -648,6 +659,8 @@ ffmpeg_scan_stream(InputStream &is, TagHandler &handler)
|
||||
return FfmpegScanStream(*f, handler);
|
||||
}
|
||||
|
||||
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 9, 100)
|
||||
|
||||
static void
|
||||
ffmpeg_uri_decode(DecoderClient &client, const char *uri)
|
||||
{
|
||||
@@ -679,6 +692,8 @@ ffmpeg_protocols() noexcept
|
||||
return protocols;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -802,6 +817,8 @@ static const char *const ffmpeg_mime_types[] = {
|
||||
constexpr DecoderPlugin ffmpeg_decoder_plugin =
|
||||
DecoderPlugin("ffmpeg", ffmpeg_decode, ffmpeg_scan_stream)
|
||||
.WithInit(ffmpeg_init, ffmpeg_finish)
|
||||
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 9, 100)
|
||||
.WithProtocols(ffmpeg_protocols, ffmpeg_uri_decode)
|
||||
#endif
|
||||
.WithSuffixes(ffmpeg_suffixes)
|
||||
.WithMimeTypes(ffmpeg_mime_types);
|
||||
|
@@ -30,11 +30,22 @@ extern "C" {
|
||||
#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[] = {
|
||||
{ "year", TAG_DATE },
|
||||
{ "author-sort", TAG_ARTIST_SORT },
|
||||
/* from libavformat/id3v2.c, libavformat/mov.c */
|
||||
{ "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 */
|
||||
{ nullptr, TAG_NUM_OF_ITEM_TYPES }
|
||||
|
@@ -344,7 +344,7 @@ gme_container_scan(Path path_fs)
|
||||
|
||||
static const char *const gme_suffixes[] = {
|
||||
"ay", "gbs", "gym", "hes", "kss", "nsf",
|
||||
"nsfe", "sap", "spc", "vgm", "vgz",
|
||||
"nsfe", "rsn", "sap", "spc", "vgm", "vgz",
|
||||
nullptr
|
||||
};
|
||||
|
||||
|
@@ -889,8 +889,6 @@ inline bool
|
||||
MadDecoder::HandleCurrentFrame() noexcept
|
||||
{
|
||||
switch (mute_frame) {
|
||||
DecoderCommand cmd;
|
||||
|
||||
case MadDecoderMuteFrame::SKIP:
|
||||
mute_frame = MadDecoderMuteFrame::NONE;
|
||||
break;
|
||||
@@ -899,8 +897,8 @@ MadDecoder::HandleCurrentFrame() noexcept
|
||||
mute_frame = MadDecoderMuteFrame::NONE;
|
||||
UpdateTimerNextFrame();
|
||||
break;
|
||||
case MadDecoderMuteFrame::NONE:
|
||||
cmd = SynthAndSubmit();
|
||||
case MadDecoderMuteFrame::NONE: {
|
||||
const auto cmd = SynthAndSubmit();
|
||||
UpdateTimerNextFrame();
|
||||
if (cmd == DecoderCommand::SEEK) {
|
||||
assert(input_stream.IsSeekable());
|
||||
@@ -922,6 +920,7 @@ MadDecoder::HandleCurrentFrame() noexcept
|
||||
} else if (cmd != DecoderCommand::NONE)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -456,7 +456,7 @@ sidplay_file_decode(DecoderClient &client, Path path_fs)
|
||||
} while (cmd != DecoderCommand::STOP);
|
||||
}
|
||||
|
||||
static AllocatedString<char>
|
||||
static AllocatedString
|
||||
Windows1252ToUTF8(const char *s) noexcept
|
||||
{
|
||||
#ifdef HAVE_ICU_CONVERTER
|
||||
@@ -469,9 +469,9 @@ Windows1252ToUTF8(const char *s) noexcept
|
||||
* Fallback to not transcoding windows-1252 to utf-8, that may result
|
||||
* in invalid utf-8 unless nonprintable characters are replaced.
|
||||
*/
|
||||
auto t = AllocatedString<char>::Duplicate(s);
|
||||
AllocatedString t(s);
|
||||
|
||||
for (size_t i = 0; t[i] != AllocatedString<char>::SENTINEL; i++)
|
||||
for (size_t i = 0; t[i] != AllocatedString::SENTINEL; i++)
|
||||
if (!IsPrintableASCII(t[i]))
|
||||
t[i] = '?';
|
||||
|
||||
@@ -479,7 +479,7 @@ Windows1252ToUTF8(const char *s) noexcept
|
||||
}
|
||||
|
||||
gcc_pure
|
||||
static AllocatedString<char>
|
||||
static AllocatedString
|
||||
GetInfoString(const SidTuneInfo &info, unsigned i) noexcept
|
||||
{
|
||||
#ifdef HAVE_SIDPLAYFP
|
||||
@@ -496,7 +496,7 @@ GetInfoString(const SidTuneInfo &info, unsigned i) noexcept
|
||||
}
|
||||
|
||||
gcc_pure
|
||||
static AllocatedString<char>
|
||||
static AllocatedString
|
||||
GetDateString(const SidTuneInfo &info) noexcept
|
||||
{
|
||||
/*
|
||||
@@ -507,12 +507,12 @@ GetDateString(const SidTuneInfo &info) noexcept
|
||||
* author or group> may be for example Rob Hubbard. A full field
|
||||
* may be for example "1987 Rob Hubbard".
|
||||
*/
|
||||
AllocatedString<char> release = GetInfoString(info, 2);
|
||||
AllocatedString release = GetInfoString(info, 2);
|
||||
|
||||
/* Keep the <year> part only for the date. */
|
||||
for (size_t i = 0; release[i] != AllocatedString<char>::SENTINEL; i++)
|
||||
for (size_t i = 0; release[i] != AllocatedString::SENTINEL; i++)
|
||||
if (std::isspace(release[i])) {
|
||||
release[i] = AllocatedString<char>::SENTINEL;
|
||||
release[i] = AllocatedString::SENTINEL;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@@ -36,7 +36,7 @@ BufferedSocket::DirectRead(void *data, size_t length) noexcept
|
||||
}
|
||||
|
||||
const auto code = GetSocketError();
|
||||
if (IsSocketErrorAgain(code))
|
||||
if (IsSocketErrorReceiveWouldBlock(code))
|
||||
return 0;
|
||||
|
||||
if (IsSocketErrorClosed(code))
|
||||
|
@@ -31,7 +31,7 @@ FullyBufferedSocket::DirectWrite(const void *data, size_t length) noexcept
|
||||
const auto nbytes = GetSocket().Write((const char *)data, length);
|
||||
if (gcc_unlikely(nbytes < 0)) {
|
||||
const auto code = GetSocketError();
|
||||
if (IsSocketErrorAgain(code))
|
||||
if (IsSocketErrorSendWouldBlock(code))
|
||||
return 0;
|
||||
|
||||
IdleMonitor::Cancel();
|
||||
|
@@ -32,12 +32,12 @@ extern "C" {
|
||||
FfmpegFilter::FfmpegFilter(const AudioFormat &in_audio_format,
|
||||
const AudioFormat &_out_audio_format,
|
||||
Ffmpeg::FilterGraph &&_graph,
|
||||
Ffmpeg::FilterContext &&_buffer_src,
|
||||
Ffmpeg::FilterContext &&_buffer_sink) noexcept
|
||||
AVFilterContext &_buffer_src,
|
||||
AVFilterContext &_buffer_sink) noexcept
|
||||
:Filter(_out_audio_format),
|
||||
graph(std::move(_graph)),
|
||||
buffer_src(std::move(_buffer_src)),
|
||||
buffer_sink(std::move(_buffer_sink)),
|
||||
buffer_src(_buffer_src),
|
||||
buffer_sink(_buffer_sink),
|
||||
in_format(Ffmpeg::ToFfmpegSampleFormat(in_audio_format.format)),
|
||||
in_sample_rate(in_audio_format.sample_rate),
|
||||
in_channels(in_audio_format.channels),
|
||||
@@ -61,7 +61,7 @@ FfmpegFilter::FilterPCM(ConstBuffer<void> src)
|
||||
|
||||
memcpy(frame.GetData(0), src.data, src.size);
|
||||
|
||||
int err = av_buffersrc_add_frame(buffer_src.get(), frame.get());
|
||||
int err = av_buffersrc_add_frame(&buffer_src, frame.get());
|
||||
if (err < 0)
|
||||
throw MakeFfmpegError(err, "av_buffersrc_write_frame() failed");
|
||||
|
||||
@@ -69,7 +69,7 @@ FfmpegFilter::FilterPCM(ConstBuffer<void> src)
|
||||
|
||||
frame.Unref();
|
||||
|
||||
err = av_buffersink_get_frame(buffer_sink.get(), frame.get());
|
||||
err = av_buffersink_get_frame(&buffer_sink, frame.get());
|
||||
if (err < 0) {
|
||||
if (err == AVERROR(EAGAIN) || err == AVERROR_EOF)
|
||||
return nullptr;
|
||||
|
@@ -30,7 +30,7 @@
|
||||
*/
|
||||
class FfmpegFilter final : public Filter {
|
||||
Ffmpeg::FilterGraph graph;
|
||||
Ffmpeg::FilterContext buffer_src, buffer_sink;
|
||||
AVFilterContext &buffer_src, &buffer_sink;
|
||||
Ffmpeg::Frame frame;
|
||||
|
||||
FfmpegBuffer interleave_buffer;
|
||||
@@ -51,8 +51,8 @@ public:
|
||||
FfmpegFilter(const AudioFormat &in_audio_format,
|
||||
const AudioFormat &_out_audio_format,
|
||||
Ffmpeg::FilterGraph &&_graph,
|
||||
Ffmpeg::FilterContext &&_buffer_src,
|
||||
Ffmpeg::FilterContext &&_buffer_sink) noexcept;
|
||||
AVFilterContext &_buffer_src,
|
||||
AVFilterContext &_buffer_sink) noexcept;
|
||||
|
||||
/* virtual methods from class Filter */
|
||||
ConstBuffer<void> FilterPCM(ConstBuffer<void> src) override;
|
||||
|
@@ -37,39 +37,79 @@ public:
|
||||
std::unique_ptr<Filter> Open(AudioFormat &af) override;
|
||||
};
|
||||
|
||||
/**
|
||||
* Fallback for PreparedFfmpegFilter::Open() just in case the filter's
|
||||
* native output format could not be determined.
|
||||
*
|
||||
* TODO: improve the MPD filter API to allow returning the output
|
||||
* format later, and eliminate this kludge
|
||||
*/
|
||||
static auto
|
||||
OpenWithAformat(const char *graph_string, AudioFormat &in_audio_format)
|
||||
{
|
||||
Ffmpeg::FilterGraph graph;
|
||||
|
||||
auto &buffer_src =
|
||||
Ffmpeg::MakeAudioBufferSource(in_audio_format, *graph);
|
||||
|
||||
auto &buffer_sink = Ffmpeg::MakeAudioBufferSink(*graph);
|
||||
|
||||
AudioFormat out_audio_format = in_audio_format;
|
||||
auto &aformat = Ffmpeg::MakeAformat(out_audio_format, *graph);
|
||||
|
||||
int error = avfilter_link(&aformat, 0, &buffer_sink, 0);
|
||||
if (error < 0)
|
||||
throw MakeFfmpegError(error, "avfilter_link() failed");
|
||||
|
||||
graph.ParseSingleInOut(graph_string, aformat, buffer_src);
|
||||
graph.CheckAndConfigure();
|
||||
|
||||
return std::make_unique<FfmpegFilter>(in_audio_format,
|
||||
out_audio_format,
|
||||
std::move(graph),
|
||||
buffer_src,
|
||||
buffer_sink);
|
||||
}
|
||||
|
||||
std::unique_ptr<Filter>
|
||||
PreparedFfmpegFilter::Open(AudioFormat &in_audio_format)
|
||||
{
|
||||
Ffmpeg::FilterGraph graph;
|
||||
|
||||
auto buffer_src =
|
||||
Ffmpeg::FilterContext::MakeAudioBufferSource(in_audio_format,
|
||||
*graph);
|
||||
auto &buffer_src =
|
||||
Ffmpeg::MakeAudioBufferSource(in_audio_format, *graph);
|
||||
|
||||
auto buffer_sink = Ffmpeg::FilterContext::MakeAudioBufferSink(*graph);
|
||||
auto &buffer_sink = Ffmpeg::MakeAudioBufferSink(*graph);
|
||||
|
||||
Ffmpeg::FilterInOut io_sink("out", *buffer_sink);
|
||||
Ffmpeg::FilterInOut io_src("in", *buffer_src);
|
||||
auto io = graph.Parse(graph_string, std::move(io_sink),
|
||||
std::move(io_src));
|
||||
/* if the filter's output format is not supported by MPD, this
|
||||
"aformat" filter is inserted at the end and takes care for
|
||||
the required conversion */
|
||||
auto &aformat = Ffmpeg::MakeAutoAformat(*graph);
|
||||
|
||||
if (io.first.get() != nullptr)
|
||||
throw std::runtime_error("FFmpeg filter has an open input");
|
||||
|
||||
if (io.second.get() != nullptr)
|
||||
throw std::runtime_error("FFmpeg filter has an open output");
|
||||
int error = avfilter_link(&aformat, 0, &buffer_sink, 0);
|
||||
if (error < 0)
|
||||
throw MakeFfmpegError(error, "avfilter_link() failed");
|
||||
|
||||
graph.ParseSingleInOut(graph_string, aformat, buffer_src);
|
||||
graph.CheckAndConfigure();
|
||||
|
||||
const auto out_audio_format =
|
||||
Ffmpeg::DetectFilterOutputFormat(in_audio_format, *buffer_src,
|
||||
*buffer_sink);
|
||||
Ffmpeg::DetectFilterOutputFormat(in_audio_format, buffer_src,
|
||||
buffer_sink);
|
||||
|
||||
if (!out_audio_format.IsDefined())
|
||||
/* the filter's native output format could not be
|
||||
determined yet, but we need to know it now; as a
|
||||
workaround for this MPD API deficiency, try again
|
||||
with an "aformat" filter which forces a specific
|
||||
output format */
|
||||
return OpenWithAformat(graph_string, in_audio_format);
|
||||
|
||||
return std::make_unique<FfmpegFilter>(in_audio_format,
|
||||
out_audio_format,
|
||||
std::move(graph),
|
||||
std::move(buffer_src),
|
||||
std::move(buffer_sink));
|
||||
buffer_src,
|
||||
buffer_sink);
|
||||
}
|
||||
|
||||
static std::unique_ptr<PreparedFilter>
|
||||
|
@@ -42,24 +42,13 @@ OpenHdcdFilter(AudioFormat &in_audio_format)
|
||||
{
|
||||
Ffmpeg::FilterGraph graph;
|
||||
|
||||
auto buffer_src =
|
||||
Ffmpeg::FilterContext::MakeAudioBufferSource(in_audio_format,
|
||||
*graph);
|
||||
auto &buffer_src =
|
||||
Ffmpeg::MakeAudioBufferSource(in_audio_format,
|
||||
*graph);
|
||||
|
||||
auto buffer_sink = Ffmpeg::FilterContext::MakeAudioBufferSink(*graph);
|
||||
|
||||
Ffmpeg::FilterInOut io_sink("out", *buffer_sink);
|
||||
Ffmpeg::FilterInOut io_src("in", *buffer_src);
|
||||
|
||||
auto io = graph.Parse(hdcd_graph, std::move(io_sink),
|
||||
std::move(io_src));
|
||||
|
||||
if (io.first.get() != nullptr)
|
||||
throw std::runtime_error("FFmpeg filter has an open input");
|
||||
|
||||
if (io.second.get() != nullptr)
|
||||
throw std::runtime_error("FFmpeg filter has an open output");
|
||||
auto &buffer_sink = Ffmpeg::MakeAudioBufferSink(*graph);
|
||||
|
||||
graph.ParseSingleInOut(hdcd_graph, buffer_sink, buffer_src);
|
||||
graph.CheckAndConfigure();
|
||||
|
||||
auto out_audio_format = in_audio_format;
|
||||
@@ -69,8 +58,8 @@ OpenHdcdFilter(AudioFormat &in_audio_format)
|
||||
return std::make_unique<FfmpegFilter>(in_audio_format,
|
||||
out_audio_format,
|
||||
std::move(graph),
|
||||
std::move(buffer_src),
|
||||
std::move(buffer_sink));
|
||||
buffer_src,
|
||||
buffer_sink);
|
||||
}
|
||||
|
||||
class PreparedHdcdFilter final : public PreparedFilter {
|
||||
|
@@ -24,7 +24,7 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
#include <fileapi.h>
|
||||
#include <tchar.h>
|
||||
|
||||
/**
|
||||
|
36
src/fs/Glob.cxx
Normal file
36
src/fs/Glob.cxx
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
// COM needs the "MSG" typedef, and shlwapi.h includes COM headers
|
||||
#undef NOUSER
|
||||
#endif
|
||||
|
||||
#include "Glob.hxx"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <shlwapi.h>
|
||||
|
||||
bool
|
||||
Glob::Check(const char *name_fs) const noexcept
|
||||
{
|
||||
return PathMatchSpecA(name_fs, pattern.c_str());
|
||||
}
|
||||
|
||||
#endif
|
@@ -24,45 +24,44 @@
|
||||
|
||||
#ifdef HAVE_FNMATCH
|
||||
#define HAVE_CLASS_GLOB
|
||||
#include <string>
|
||||
#include <fnmatch.h>
|
||||
#elif defined(_WIN32)
|
||||
#define HAVE_CLASS_GLOB
|
||||
#include <string>
|
||||
#include <shlwapi.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CLASS_GLOB
|
||||
#include "util/Compiler.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* A pattern that matches file names. It may contain shell wildcards
|
||||
* (asterisk and question mark).
|
||||
*/
|
||||
class Glob {
|
||||
#if defined(HAVE_FNMATCH) || defined(_WIN32)
|
||||
std::string pattern;
|
||||
#endif
|
||||
|
||||
public:
|
||||
#if defined(HAVE_FNMATCH) || defined(_WIN32)
|
||||
explicit Glob(const char *_pattern)
|
||||
:pattern(_pattern) {}
|
||||
|
||||
Glob(Glob &&other)
|
||||
:pattern(std::move(other.pattern)) {}
|
||||
#endif
|
||||
Glob(Glob &&other) noexcept = default;
|
||||
Glob &operator=(Glob &&other) noexcept = default;
|
||||
|
||||
gcc_pure
|
||||
bool Check(const char *name_fs) const noexcept {
|
||||
#ifdef HAVE_FNMATCH
|
||||
return fnmatch(pattern.c_str(), name_fs, 0) == 0;
|
||||
#elif defined(_WIN32)
|
||||
return PathMatchSpecA(name_fs, pattern.c_str());
|
||||
#endif
|
||||
}
|
||||
bool Check(const char *name_fs) const noexcept;
|
||||
};
|
||||
|
||||
#endif
|
||||
#ifdef HAVE_FNMATCH
|
||||
|
||||
inline bool
|
||||
Glob::Check(const char *name_fs) const noexcept
|
||||
{
|
||||
return fnmatch(pattern.c_str(), name_fs, 0) == 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_CLASS_GLOB */
|
||||
|
||||
#endif
|
||||
|
@@ -29,7 +29,7 @@
|
||||
NarrowPath::NarrowPath(Path _path) noexcept
|
||||
:value(WideCharToMultiByte(CP_ACP, _path.c_str()))
|
||||
{
|
||||
if (value.IsNull())
|
||||
if (value == nullptr)
|
||||
/* fall back to empty string */
|
||||
value = Value::Empty();
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@
|
||||
*/
|
||||
class NarrowPath {
|
||||
#ifdef _UNICODE
|
||||
using Value = AllocatedString<>;
|
||||
using Value = AllocatedString;
|
||||
#else
|
||||
using Value = StringPointer<>;
|
||||
#endif
|
||||
|
@@ -17,6 +17,10 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#undef NOUSER // COM needs the "MSG" typedef, and shlobj.h includes COM headers
|
||||
#endif
|
||||
|
||||
#include "StandardDirectory.hxx"
|
||||
#include "FileSystem.hxx"
|
||||
#include "XDG.hxx"
|
||||
|
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "Traits.hxx"
|
||||
#include "util/StringCompare.hxx"
|
||||
#include "util/UriExtract.hxx"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -84,6 +85,22 @@ GetParentPathImpl(typename Traits::const_pointer p) noexcept
|
||||
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>
|
||||
typename Traits::const_pointer
|
||||
RelativePathImpl(typename Traits::string_view base,
|
||||
@@ -166,6 +183,12 @@ PathTraitsFS::GetParent(PathTraitsFS::const_pointer p) noexcept
|
||||
return GetParentPathImpl<PathTraitsFS>(p);
|
||||
}
|
||||
|
||||
PathTraitsFS::string_view
|
||||
PathTraitsFS::GetParent(string_view p) noexcept
|
||||
{
|
||||
return GetParentPathImpl<PathTraitsFS>(p);
|
||||
}
|
||||
|
||||
PathTraitsFS::const_pointer
|
||||
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);
|
||||
}
|
||||
|
||||
bool
|
||||
PathTraitsUTF8::IsAbsoluteOrHasScheme(const_pointer p) noexcept
|
||||
{
|
||||
return IsAbsolute(p) || uri_has_scheme(p);
|
||||
}
|
||||
|
||||
PathTraitsUTF8::const_pointer
|
||||
PathTraitsUTF8::GetBase(const_pointer p) noexcept
|
||||
{
|
||||
@@ -210,6 +239,12 @@ PathTraitsUTF8::GetParent(const_pointer p) noexcept
|
||||
return GetParentPathImpl<PathTraitsUTF8>(p);
|
||||
}
|
||||
|
||||
PathTraitsUTF8::string_view
|
||||
PathTraitsUTF8::GetParent(string_view p) noexcept
|
||||
{
|
||||
return GetParentPathImpl<PathTraitsUTF8>(p);
|
||||
}
|
||||
|
||||
PathTraitsUTF8::const_pointer
|
||||
PathTraitsUTF8::Relative(string_view base, const_pointer other) noexcept
|
||||
{
|
||||
|
@@ -88,6 +88,18 @@ struct PathTraitsFS {
|
||||
#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
|
||||
static const_pointer GetFilenameSuffix(const_pointer filename) noexcept {
|
||||
const_pointer dot = StringFindLast(filename, '.');
|
||||
@@ -106,6 +118,10 @@ struct PathTraitsFS {
|
||||
static constexpr bool IsDrive(const_pointer p) noexcept {
|
||||
return IsAlphaASCII(p[0]) && p[1] == ':';
|
||||
}
|
||||
|
||||
static constexpr bool IsDrive(string_view p) noexcept {
|
||||
return p.size() >= 2 && IsAlphaASCII(p[0]) && p[1] == ':';
|
||||
}
|
||||
#endif
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
@@ -153,6 +169,9 @@ struct PathTraitsFS {
|
||||
gcc_pure gcc_nonnull_all
|
||||
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
|
||||
* object, not including the directory separator. Returns an
|
||||
@@ -212,6 +231,11 @@ struct PathTraitsUTF8 {
|
||||
return std::strrchr(p, SEPARATOR);
|
||||
}
|
||||
|
||||
[[gnu::pure]]
|
||||
static const_pointer FindLastSeparator(string_view p) noexcept {
|
||||
return StringFindLast(p.data(), SEPARATOR, p.size());
|
||||
}
|
||||
|
||||
gcc_pure
|
||||
static const_pointer GetFilenameSuffix(const_pointer filename) noexcept {
|
||||
const_pointer dot = StringFindLast(filename, '.');
|
||||
@@ -230,6 +254,10 @@ struct PathTraitsUTF8 {
|
||||
static constexpr bool IsDrive(const_pointer p) noexcept {
|
||||
return IsAlphaASCII(p[0]) && p[1] == ':';
|
||||
}
|
||||
|
||||
static constexpr bool IsDrive(string_view p) noexcept {
|
||||
return p.size() >= 2 && IsAlphaASCII(p[0]) && p[1] == ':';
|
||||
}
|
||||
#endif
|
||||
|
||||
gcc_pure gcc_nonnull_all
|
||||
@@ -246,6 +274,13 @@ struct PathTraitsUTF8 {
|
||||
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
|
||||
static bool IsSpecialFilename(const_pointer name) noexcept {
|
||||
return (name[0] == '.' && name[1] == 0) ||
|
||||
@@ -277,6 +312,9 @@ struct PathTraitsUTF8 {
|
||||
gcc_pure gcc_nonnull_all
|
||||
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
|
||||
* object, not including the directory separator. Returns an
|
||||
|
@@ -42,7 +42,10 @@
|
||||
#include <cstdint>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <fileapi.h>
|
||||
#include <windef.h> // for HWND (needed by winbase.h)
|
||||
#include <handleapi.h> // for INVALID_HANDLE_VALUE
|
||||
#include <winbase.h> // for FILE_END
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) && !defined(ANDROID)
|
||||
|
@@ -35,7 +35,10 @@
|
||||
#include "util/Compiler.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <fileapi.h>
|
||||
#include <handleapi.h> // for INVALID_HANDLE_VALUE
|
||||
#include <windef.h> // for HWND (needed by winbase.h)
|
||||
#include <winbase.h> // for FILE_CURRENT
|
||||
#else
|
||||
#include "io/UniqueFileDescriptor.hxx"
|
||||
#endif
|
||||
|
@@ -3,6 +3,7 @@ fs_sources = [
|
||||
'Traits.cxx',
|
||||
'Config.cxx',
|
||||
'Charset.cxx',
|
||||
'Glob.cxx',
|
||||
'Path.cxx',
|
||||
'Path2.cxx',
|
||||
'AllocatedPath.cxx',
|
||||
|
@@ -104,8 +104,11 @@ IcyInputStream::Read(std::unique_lock<Mutex> &lock,
|
||||
|
||||
while (true) {
|
||||
size_t nbytes = ProxyInputStream::Read(lock, ptr, read_size);
|
||||
if (nbytes == 0)
|
||||
if (nbytes == 0) {
|
||||
assert(IsEOF());
|
||||
offset = override_offset;
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t result = parser->ParseInPlace(ptr, nbytes);
|
||||
if (result > 0) {
|
||||
|
@@ -57,7 +57,6 @@ static bool
|
||||
ExpensiveSeeking(const char *uri) noexcept
|
||||
{
|
||||
return StringStartsWithCaseASCII(uri, "http://") ||
|
||||
StringStartsWithCaseASCII(uri, "tidal://") ||
|
||||
StringStartsWithCaseASCII(uri, "qobuz://") ||
|
||||
StringStartsWithCaseASCII(uri, "https://");
|
||||
}
|
||||
|
46
src/input/LastInputStream.cxx
Normal file
46
src/input/LastInputStream.cxx
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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 "LastInputStream.hxx"
|
||||
#include "InputStream.hxx"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
LastInputStream::LastInputStream(EventLoop &event_loop) noexcept
|
||||
:close_timer(event_loop, BIND_THIS_METHOD(OnCloseTimer))
|
||||
{
|
||||
}
|
||||
|
||||
LastInputStream::~LastInputStream() noexcept = default;
|
||||
|
||||
void
|
||||
LastInputStream::Close() noexcept
|
||||
{
|
||||
uri.clear();
|
||||
is.reset();
|
||||
close_timer.Cancel();
|
||||
}
|
||||
|
||||
void
|
||||
LastInputStream::OnCloseTimer() noexcept
|
||||
{
|
||||
assert(is);
|
||||
|
||||
is.reset();
|
||||
}
|
86
src/input/LastInputStream.hxx
Normal file
86
src/input/LastInputStream.hxx
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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 MPD_LAST_INPUT_STREAM_HXX
|
||||
#define MPD_LAST_INPUT_STREAM_HXX
|
||||
|
||||
#include "Ptr.hxx"
|
||||
#include "thread/Mutex.hxx"
|
||||
#include "event/TimerEvent.hxx"
|
||||
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* A helper class which maintains an #InputStream that is opened once
|
||||
* and may be reused later for some time. It will be closed
|
||||
* automatically after some time.
|
||||
*
|
||||
* This class is not thread-safe. All methods must be called on the
|
||||
* thread which runs the #EventLoop.
|
||||
*/
|
||||
class LastInputStream {
|
||||
std::string uri;
|
||||
|
||||
Mutex mutex;
|
||||
|
||||
InputStreamPtr is;
|
||||
|
||||
TimerEvent close_timer;
|
||||
|
||||
public:
|
||||
explicit LastInputStream(EventLoop &event_loop) noexcept;
|
||||
~LastInputStream() noexcept;
|
||||
|
||||
/**
|
||||
* Open an #InputStream instance with the given opener
|
||||
* function, but returns the cached instance if it matches.
|
||||
*
|
||||
* This object keeps owning the #InputStream; the caller shall
|
||||
* not close it.
|
||||
*/
|
||||
template<typename U, typename O>
|
||||
InputStream *Open(U &&new_uri, O &&open) {
|
||||
if (new_uri == uri) {
|
||||
if (is)
|
||||
/* refresh the timeout */
|
||||
ScheduleClose();
|
||||
|
||||
return is.get();
|
||||
}
|
||||
|
||||
Close();
|
||||
|
||||
is = open(new_uri, mutex);
|
||||
uri = std::forward<U>(new_uri);
|
||||
if (is)
|
||||
ScheduleClose();
|
||||
return is.get();
|
||||
}
|
||||
|
||||
void Close() noexcept;
|
||||
|
||||
private:
|
||||
void ScheduleClose() noexcept {
|
||||
close_timer.Schedule(std::chrono::seconds(20));
|
||||
}
|
||||
|
||||
void OnCloseTimer() noexcept;
|
||||
};
|
||||
|
||||
#endif
|
@@ -20,7 +20,6 @@
|
||||
#include "Registry.hxx"
|
||||
#include "InputPlugin.hxx"
|
||||
#include "input/Features.h"
|
||||
#include "plugins/TidalInputPlugin.hxx"
|
||||
#include "plugins/QobuzInputPlugin.hxx"
|
||||
#include "config.h"
|
||||
|
||||
@@ -56,9 +55,6 @@ const InputPlugin *const input_plugins[] = {
|
||||
#ifdef ENABLE_ALSA
|
||||
&input_plugin_alsa,
|
||||
#endif
|
||||
#ifdef ENABLE_TIDAL
|
||||
&tidal_input_plugin,
|
||||
#endif
|
||||
#ifdef ENABLE_QOBUZ
|
||||
&qobuz_input_plugin,
|
||||
#endif
|
||||
|
@@ -8,6 +8,7 @@ input_api = static_library(
|
||||
'ThreadInputStream.cxx',
|
||||
'AsyncInputStream.cxx',
|
||||
'ProxyInputStream.cxx',
|
||||
'LastInputStream.cxx',
|
||||
include_directories: inc,
|
||||
dependencies: [
|
||||
boost_dep,
|
||||
|
@@ -402,8 +402,8 @@ CurlInputStream::CurlInputStream(EventLoop &event_loop, const char *_url,
|
||||
{
|
||||
request_headers.Append("Icy-Metadata: 1");
|
||||
|
||||
for (const auto &i : headers)
|
||||
request_headers.Append((i.first + ":" + i.second).c_str());
|
||||
for (const auto &[key, header] : headers)
|
||||
request_headers.Append((key + ":" + header).c_str());
|
||||
}
|
||||
|
||||
CurlInputStream::~CurlInputStream() noexcept
|
||||
@@ -421,6 +421,10 @@ CurlInputStream::InitEasy()
|
||||
request->SetOption(CURLOPT_MAXREDIRS, 5L);
|
||||
request->SetOption(CURLOPT_FAILONERROR, 1L);
|
||||
|
||||
/* this option eliminates the probe request when
|
||||
username/password are specified */
|
||||
request->SetOption(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||
|
||||
if (proxy != nullptr)
|
||||
request->SetOption(CURLOPT_PROXY, proxy);
|
||||
|
||||
|
@@ -174,8 +174,8 @@ QobuzClient::MakeUrl(const char *object, const char *method,
|
||||
uri += method;
|
||||
|
||||
QueryStringBuilder q;
|
||||
for (const auto &i : query)
|
||||
q(uri, i.first.c_str(), i.second.c_str());
|
||||
for (const auto &[key, url] : query)
|
||||
q(uri, key.c_str(), url.c_str());
|
||||
|
||||
q(uri, "app_id", app_id);
|
||||
return uri;
|
||||
@@ -195,11 +195,11 @@ QobuzClient::MakeSignedUrl(const char *object, const char *method,
|
||||
QueryStringBuilder q;
|
||||
std::string concatenated_query(object);
|
||||
concatenated_query += method;
|
||||
for (const auto &i : query) {
|
||||
q(uri, i.first.c_str(), i.second.c_str());
|
||||
for (const auto &[key, url] : query) {
|
||||
q(uri, key.c_str(), url.c_str());
|
||||
|
||||
concatenated_query += i.first;
|
||||
concatenated_query += i.second;
|
||||
concatenated_query += key;
|
||||
concatenated_query += url;
|
||||
}
|
||||
|
||||
q(uri, "app_id", app_id);
|
||||
|
@@ -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,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
|
||||
|
||||
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',
|
||||
input_plugins_sources,
|
||||
|
@@ -172,7 +172,15 @@ FileDescriptor::CreatePipe(FileDescriptor &r, FileDescriptor &w) noexcept
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
#ifdef _WIN32
|
||||
|
||||
void
|
||||
FileDescriptor::SetBinaryMode() noexcept
|
||||
{
|
||||
_setmode(fd, _O_BINARY);
|
||||
}
|
||||
|
||||
#else // !_WIN32
|
||||
|
||||
bool
|
||||
FileDescriptor::CreatePipeNonBlock(FileDescriptor &r,
|
||||
|
@@ -148,10 +148,13 @@ public:
|
||||
#ifdef _WIN32
|
||||
void EnableCloseOnExec() noexcept {}
|
||||
void DisableCloseOnExec() noexcept {}
|
||||
void SetBinaryMode() noexcept;
|
||||
#else
|
||||
static bool CreatePipeNonBlock(FileDescriptor &r,
|
||||
FileDescriptor &w) noexcept;
|
||||
|
||||
void SetBinaryMode() noexcept {}
|
||||
|
||||
/**
|
||||
* Enable non-blocking mode on this file descriptor.
|
||||
*/
|
||||
|
@@ -36,16 +36,16 @@ EncodeForm(CURL *curl,
|
||||
{
|
||||
std::string result;
|
||||
|
||||
for (const auto &i : fields) {
|
||||
for (const auto &[key, field] : fields) {
|
||||
if (!result.empty())
|
||||
result.push_back('&');
|
||||
|
||||
result.append(i.first);
|
||||
result.append(key);
|
||||
result.push_back('=');
|
||||
|
||||
if (!i.second.empty()) {
|
||||
CurlString value(curl_easy_escape(curl, i.second.data(),
|
||||
i.second.length()));
|
||||
if (!field.empty()) {
|
||||
CurlString value(
|
||||
curl_easy_escape(curl, field.data(), field.length()));
|
||||
if (value)
|
||||
result.append(value);
|
||||
}
|
||||
|
@@ -1,19 +1,20 @@
|
||||
diff -ur curl-7.63.0.orig/lib/url.c curl-7.63.0/lib/url.c
|
||||
--- curl-7.63.0.orig/lib/url.c 2019-01-21 10:15:51.368019445 +0100
|
||||
+++ curl-7.63.0/lib/url.c 2019-01-21 10:19:16.307523984 +0100
|
||||
@@ -3057,6 +3057,7 @@
|
||||
Index: curl-7.71.1/lib/url.c
|
||||
===================================================================
|
||||
--- curl-7.71.1.orig/lib/url.c
|
||||
+++ curl-7.71.1/lib/url.c
|
||||
@@ -2871,6 +2871,7 @@
|
||||
}
|
||||
|
||||
conn->bits.netrc = FALSE;
|
||||
+#ifndef __BIONIC__
|
||||
if(data->set.use_netrc != CURL_NETRC_IGNORED &&
|
||||
(!*userp || !**userp || !*passwdp || !**passwdp)) {
|
||||
if(data->set.use_netrc && !data->set.str[STRING_USERNAME]) {
|
||||
bool netrc_user_changed = FALSE;
|
||||
@@ -3090,6 +3091,7 @@
|
||||
}
|
||||
bool netrc_passwd_changed = FALSE;
|
||||
@@ -2895,6 +2896,7 @@
|
||||
conn->bits.user_passwd = TRUE; /* enable user+password */
|
||||
}
|
||||
}
|
||||
+#endif
|
||||
|
||||
/* for updated strings, we update them in the URL */
|
||||
if(user_changed) {
|
||||
if(*userp) {
|
||||
|
66
src/lib/ffmpeg/ChannelLayout.hxx
Normal file
66
src/lib/ffmpeg/ChannelLayout.hxx
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 MPD_FFMPEG_CHANNEL_LAYOUT_HXX
|
||||
#define MPD_FFMPEG_CHANNEL_LAYOUT_HXX
|
||||
|
||||
extern "C" {
|
||||
#include <libavutil/channel_layout.h>
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a MPD channel count to a libavutil channel_layout bit mask.
|
||||
*/
|
||||
static constexpr uint64_t
|
||||
ToFfmpegChannelLayout(unsigned channels) noexcept
|
||||
{
|
||||
switch (channels) {
|
||||
case 1:
|
||||
return AV_CH_LAYOUT_MONO;
|
||||
|
||||
case 2:
|
||||
return AV_CH_LAYOUT_STEREO;
|
||||
|
||||
case 3:
|
||||
return AV_CH_LAYOUT_SURROUND;
|
||||
|
||||
case 4:
|
||||
// TODO is this AV_CH_LAYOUT_2_2?
|
||||
return AV_CH_LAYOUT_QUAD;
|
||||
|
||||
case 5:
|
||||
// TODO is this AV_CH_LAYOUT_5POINT0_BACK?
|
||||
return AV_CH_LAYOUT_5POINT0;
|
||||
|
||||
case 6:
|
||||
return AV_CH_LAYOUT_5POINT1;
|
||||
|
||||
case 7:
|
||||
return AV_CH_LAYOUT_6POINT1;
|
||||
|
||||
case 8:
|
||||
return AV_CH_LAYOUT_7POINT1;
|
||||
|
||||
default:
|
||||
/* unreachable */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -62,8 +62,14 @@ DetectFilterOutputFormat(const AudioFormat &in_audio_format,
|
||||
frame.Unref();
|
||||
|
||||
err = av_buffersink_get_frame(&buffer_sink, frame.get());
|
||||
if (err < 0)
|
||||
if (err < 0) {
|
||||
if (err == AVERROR(EAGAIN))
|
||||
/* one sample was not enough input data for
|
||||
the given filter graph */
|
||||
return AudioFormat::Undefined();
|
||||
|
||||
throw MakeFfmpegError(err, "av_buffersink_get_frame() failed");
|
||||
}
|
||||
|
||||
const SampleFormat sample_format = FromFfmpegSampleFormat(AVSampleFormat(frame->format));
|
||||
if (sample_format == SampleFormat::UNDEFINED)
|
||||
|
@@ -35,6 +35,9 @@ namespace Ffmpeg {
|
||||
* between.
|
||||
*
|
||||
* This function can throw if the FFmpeg filter fails.
|
||||
*
|
||||
* @return the output format or AudioFormat::Undefined() if it was not
|
||||
* possible to determine the format
|
||||
*/
|
||||
AudioFormat
|
||||
DetectFilterOutputFormat(const AudioFormat &in_audio_format,
|
||||
|
@@ -18,10 +18,13 @@
|
||||
*/
|
||||
|
||||
#include "Filter.hxx"
|
||||
#include "ChannelLayout.hxx"
|
||||
#include "SampleFormat.hxx"
|
||||
#include "pcm/AudioFormat.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Ffmpeg {
|
||||
@@ -36,9 +39,32 @@ RequireFilterByName(const char *name)
|
||||
return *filter;
|
||||
}
|
||||
|
||||
FilterContext
|
||||
FilterContext::MakeAudioBufferSource(AudioFormat &audio_format,
|
||||
AVFilterGraph &graph_ctx)
|
||||
static AVFilterContext &
|
||||
CreateFilter(const AVFilter &filt,
|
||||
const char *name, const char *args, void *opaque,
|
||||
AVFilterGraph &graph_ctx)
|
||||
{
|
||||
AVFilterContext *context = nullptr;
|
||||
int err = avfilter_graph_create_filter(&context, &filt,
|
||||
name, args, opaque,
|
||||
&graph_ctx);
|
||||
if (err < 0)
|
||||
throw MakeFfmpegError(err, "avfilter_graph_create_filter() failed");
|
||||
|
||||
return *context;
|
||||
}
|
||||
|
||||
static AVFilterContext &
|
||||
CreateFilter(const AVFilter &filt,
|
||||
const char *name,
|
||||
AVFilterGraph &graph_ctx)
|
||||
{
|
||||
return CreateFilter(filt, name, nullptr, nullptr, graph_ctx);
|
||||
}
|
||||
|
||||
AVFilterContext &
|
||||
MakeAudioBufferSource(AudioFormat &audio_format,
|
||||
AVFilterGraph &graph_ctx)
|
||||
{
|
||||
AVSampleFormat src_format = ToFfmpegSampleFormat(audio_format.format);
|
||||
if (src_format == AV_SAMPLE_FMT_NONE) {
|
||||
@@ -57,19 +83,72 @@ FilterContext::MakeAudioBufferSource(AudioFormat &audio_format,
|
||||
|
||||
char abuffer_args[256];
|
||||
sprintf(abuffer_args,
|
||||
"sample_rate=%u:sample_fmt=%s:channels=%u:time_base=1/%u",
|
||||
"sample_rate=%u:sample_fmt=%s:channel_layout=0x%" PRIx64 ":time_base=1/%u",
|
||||
audio_format.sample_rate,
|
||||
av_get_sample_fmt_name(src_format),
|
||||
audio_format.channels,
|
||||
ToFfmpegChannelLayout(audio_format.channels),
|
||||
audio_format.sample_rate);
|
||||
|
||||
return {RequireFilterByName("abuffer"), "abuffer", abuffer_args, nullptr, graph_ctx};
|
||||
return CreateFilter(RequireFilterByName("abuffer"), "abuffer",
|
||||
abuffer_args, nullptr, graph_ctx);
|
||||
}
|
||||
|
||||
FilterContext
|
||||
FilterContext::MakeAudioBufferSink(AVFilterGraph &graph_ctx)
|
||||
AVFilterContext &
|
||||
MakeAudioBufferSink(AVFilterGraph &graph_ctx)
|
||||
{
|
||||
return {RequireFilterByName("abuffersink"), "abuffersink", graph_ctx};
|
||||
return CreateFilter(RequireFilterByName("abuffersink"), "abuffersink",
|
||||
graph_ctx);
|
||||
}
|
||||
|
||||
AVFilterContext &
|
||||
MakeAformat(AudioFormat &audio_format,
|
||||
AVFilterGraph &graph_ctx)
|
||||
{
|
||||
AVSampleFormat dest_format = ToFfmpegSampleFormat(audio_format.format);
|
||||
if (dest_format == AV_SAMPLE_FMT_NONE) {
|
||||
switch (audio_format.format) {
|
||||
case SampleFormat::S24_P32:
|
||||
audio_format.format = SampleFormat::S32;
|
||||
dest_format = AV_SAMPLE_FMT_S32;
|
||||
break;
|
||||
|
||||
default:
|
||||
audio_format.format = SampleFormat::S16;
|
||||
dest_format = AV_SAMPLE_FMT_S16;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char args[256];
|
||||
sprintf(args,
|
||||
"sample_rates=%u:sample_fmts=%s:channel_layouts=0x%" PRIx64,
|
||||
audio_format.sample_rate,
|
||||
av_get_sample_fmt_name(dest_format),
|
||||
ToFfmpegChannelLayout(audio_format.channels));
|
||||
|
||||
return CreateFilter(RequireFilterByName("aformat"), "aformat",
|
||||
args, nullptr, graph_ctx);
|
||||
}
|
||||
|
||||
AVFilterContext &
|
||||
MakeAutoAformat(AVFilterGraph &graph_ctx)
|
||||
{
|
||||
return CreateFilter(RequireFilterByName("aformat"), "aformat",
|
||||
"sample_fmts=flt|s32|s16",
|
||||
nullptr, graph_ctx);
|
||||
}
|
||||
|
||||
void
|
||||
FilterGraph::ParseSingleInOut(const char *filters, AVFilterContext &in,
|
||||
AVFilterContext &out)
|
||||
{
|
||||
auto [inputs, outputs] = Parse(filters, {"out", in}, {"in", out});
|
||||
|
||||
if (inputs.get() != nullptr)
|
||||
throw std::runtime_error("FFmpeg filter has an open input");
|
||||
|
||||
if (outputs.get() != nullptr)
|
||||
throw std::runtime_error("FFmpeg filter has an open output");
|
||||
}
|
||||
|
||||
} // namespace Ffmpeg
|
||||
|
@@ -77,63 +77,38 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class FilterContext {
|
||||
AVFilterContext *context = nullptr;
|
||||
/**
|
||||
* Create an "abuffer" filter.
|
||||
*
|
||||
* @param the input audio format; may be modified by the
|
||||
* function to ask the caller to do format conversion
|
||||
*/
|
||||
AVFilterContext &
|
||||
MakeAudioBufferSource(AudioFormat &audio_format,
|
||||
AVFilterGraph &graph_ctx);
|
||||
|
||||
public:
|
||||
FilterContext() = default;
|
||||
/**
|
||||
* Create an "abuffersink" filter.
|
||||
*/
|
||||
AVFilterContext &
|
||||
MakeAudioBufferSink(AVFilterGraph &graph_ctx);
|
||||
|
||||
FilterContext(const AVFilter &filt,
|
||||
const char *name, const char *args, void *opaque,
|
||||
AVFilterGraph &graph_ctx) {
|
||||
int err = avfilter_graph_create_filter(&context, &filt,
|
||||
name, args, opaque,
|
||||
&graph_ctx);
|
||||
if (err < 0)
|
||||
throw MakeFfmpegError(err, "avfilter_graph_create_filter() failed");
|
||||
}
|
||||
/**
|
||||
* Create an "aformat" filter.
|
||||
*
|
||||
* @param the output audio format; may be modified by the function if
|
||||
* the given format is not supported by libavfilter
|
||||
*/
|
||||
AVFilterContext &
|
||||
MakeAformat(AudioFormat &audio_format,
|
||||
AVFilterGraph &graph_ctx);
|
||||
|
||||
FilterContext(const AVFilter &filt,
|
||||
const char *name,
|
||||
AVFilterGraph &graph_ctx)
|
||||
:FilterContext(filt, name, nullptr, nullptr, graph_ctx) {}
|
||||
|
||||
FilterContext(FilterContext &&src) noexcept
|
||||
:context(std::exchange(src.context, nullptr)) {}
|
||||
|
||||
~FilterContext() noexcept {
|
||||
if (context != nullptr)
|
||||
avfilter_free(context);
|
||||
}
|
||||
|
||||
FilterContext &operator=(FilterContext &&src) noexcept {
|
||||
using std::swap;
|
||||
swap(context, src.context);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an "abuffer" filter.
|
||||
*
|
||||
* @param the input audio format; may be modified by the
|
||||
* function to ask the caller to do format conversion
|
||||
*/
|
||||
static FilterContext MakeAudioBufferSource(AudioFormat &audio_format,
|
||||
AVFilterGraph &graph_ctx);
|
||||
|
||||
/**
|
||||
* Create an "abuffersink" filter.
|
||||
*/
|
||||
static FilterContext MakeAudioBufferSink(AVFilterGraph &graph_ctx);
|
||||
|
||||
auto &operator*() noexcept {
|
||||
return *context;
|
||||
}
|
||||
|
||||
auto *get() noexcept {
|
||||
return context;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Create an "aformat" filter which automatically converts the output
|
||||
* to a format supported by MPD.
|
||||
*/
|
||||
AVFilterContext &
|
||||
MakeAutoAformat(AVFilterGraph &graph_ctx);
|
||||
|
||||
class FilterGraph {
|
||||
AVFilterGraph *graph = nullptr;
|
||||
@@ -180,6 +155,9 @@ public:
|
||||
return std::make_pair(std::move(inputs), std::move(outputs));
|
||||
}
|
||||
|
||||
void ParseSingleInOut(const char *filters, AVFilterContext &in,
|
||||
AVFilterContext &out);
|
||||
|
||||
std::pair<FilterInOut, FilterInOut> Parse(const char *filters) {
|
||||
AVFilterInOut *inputs, *outputs;
|
||||
int err = avfilter_graph_parse2(graph, filters,
|
||||
|
@@ -38,13 +38,13 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
AllocatedString<>
|
||||
AllocatedString
|
||||
IcuCaseFold(std::string_view src) noexcept
|
||||
try {
|
||||
#ifdef HAVE_ICU
|
||||
const auto u = UCharFromUTF8(src);
|
||||
if (u.IsNull())
|
||||
return AllocatedString<>::Duplicate(src);
|
||||
return AllocatedString(src);
|
||||
|
||||
AllocatedArray<UChar> folded(u.size() * 2U);
|
||||
|
||||
@@ -54,7 +54,7 @@ try {
|
||||
U_FOLD_CASE_DEFAULT,
|
||||
&error_code);
|
||||
if (folded_length == 0 || error_code != U_ZERO_ERROR)
|
||||
return AllocatedString<>::Duplicate(src);
|
||||
return AllocatedString(src);
|
||||
|
||||
folded.SetSize(folded_length);
|
||||
return UCharToUTF8({folded.begin(), folded.size()});
|
||||
@@ -63,7 +63,7 @@ try {
|
||||
#error not implemented
|
||||
#endif
|
||||
} catch (...) {
|
||||
return AllocatedString<>::Duplicate(src);
|
||||
return AllocatedString(src);
|
||||
}
|
||||
|
||||
#endif /* HAVE_ICU_CASE_FOLD */
|
||||
|
@@ -27,9 +27,9 @@
|
||||
|
||||
#include <string_view>
|
||||
|
||||
template<typename T> class AllocatedString;
|
||||
class AllocatedString;
|
||||
|
||||
AllocatedString<char>
|
||||
AllocatedString
|
||||
IcuCaseFold(std::string_view src) noexcept;
|
||||
|
||||
#endif
|
||||
|
@@ -88,7 +88,7 @@ IcuCollate(std::string_view a, std::string_view b) noexcept
|
||||
b.data(), b.size(), &code);
|
||||
|
||||
#elif defined(_WIN32)
|
||||
AllocatedString<wchar_t> wa = nullptr, wb = nullptr;
|
||||
BasicAllocatedString<wchar_t> wa, wb;
|
||||
|
||||
try {
|
||||
wa = MultiByteToWideChar(CP_UTF8, a);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user