From 031387097a35d3592380821a120403db6d3d2ea4 Mon Sep 17 00:00:00 2001 From: Andrew Gainer-Dewar Date: Sat, 1 Jun 2024 13:54:56 -0400 Subject: [PATCH 1/8] Add support for `rodiojack` backend. The underlying `librespot` library already supports the JACK audio backend via `rodio`. Enabling it in `spotifyd` turns out to be dead simple--just needed to add the config enum elements to pass it through! --- Cargo.lock | 38 +++++++++++++++++++++++++- Cargo.toml | 1 + docs/src/installation/Feature-flags.md | 14 +++++++++- src/config.rs | 11 +++++++- 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 336f433a..f4b4032e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -483,7 +483,7 @@ checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f" dependencies = [ "glob", "libc", - "libloading", + "libloading 0.7.4", ] [[package]] @@ -619,6 +619,7 @@ dependencies = [ "alsa 0.6.0", "core-foundation-sys", "coreaudio-rs", + "jack", "jni", "js-sys", "lazy_static", @@ -1420,6 +1421,31 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +[[package]] +name = "jack" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d2ac12f11bb369f3c50d24dbb9fdb00dc987434c9dd622a12c13f618106e153" +dependencies = [ + "bitflags 1.3.2", + "jack-sys", + "lazy_static", + "libc", + "log", +] + +[[package]] +name = "jack-sys" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b91f2d2d10bc2bab38f4dfa4bc77123a988828af39dd3f30dd9db14d44f2cc1" +dependencies = [ + "lazy_static", + "libc", + "libloading 0.6.7", + "pkg-config", +] + [[package]] name = "jni" version = "0.19.0" @@ -1510,6 +1536,16 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "libloading" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "351a32417a12d5f7e82c368a66781e307834dae04c6ce0cd4456d52989229883" +dependencies = [ + "cfg-if", + "winapi", +] + [[package]] name = "libloading" version = "0.7.4" diff --git a/Cargo.toml b/Cargo.toml index 0dfddb28..71a3cd0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,6 +58,7 @@ default = ["alsa_backend"] portaudio_backend = ["librespot-playback/portaudio-backend"] pulseaudio_backend = ["librespot-playback/pulseaudio-backend"] rodio_backend = ["librespot-playback/rodio-backend"] +rodiojack_backend = ["librespot-playback/rodiojack-backend"] [package.metadata.deb] depends = "$auto, systemd, pulseaudio" diff --git a/docs/src/installation/Feature-flags.md b/docs/src/installation/Feature-flags.md index 65c5366e..ef78b287 100644 --- a/docs/src/installation/Feature-flags.md +++ b/docs/src/installation/Feature-flags.md @@ -59,4 +59,16 @@ cargo build --release --no-default-features --features="rodio_backend" On Linux you will need the development package for alsa and make/gcc. (`libasound2-dev`,`build-essential` on debian, `alsa-lib-devel`,`make`,`gcc` on fedora) -[mpris-specification]: https://specifications.freedesktop.org/mpris-spec/latest/ \ No newline at end of file +[mpris-specification]: https://specifications.freedesktop.org/mpris-spec/latest/ + +### JACK Audio Connection Kit + +To use the [JACK](http://jackaudio.org) backend on Linux, compile with the `--features` flag to enable it: + +```bash +cargo build --release --no-default-features --features="rodiojack_backend" +``` + +You will need the development packages for alsa, make/gcc, and JACK. (`libasound2-dev`, `build-essential`, and `libjack-dev` on Debian; `alsa-lib-devel`, `make`, `gcc`, and `jack-audio-connection-kit-devel` on Fedora.) + +> __Note__: when Spotifyd starts with this backend, it will create a JACK output device named `cpal_client_out` with two ports: `out_0` for the left channel and `out_1` for the right. diff --git a/src/config.rs b/src/config.rs index b62adf40..55c9606b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -25,7 +25,9 @@ const CONFIG_FILE_NAME: &str = "spotifyd.conf"; feature = "pulseaudio_backend", feature = "portaudio_backend", feature = "alsa_backend", - feature = "rodio_backend" + feature = "rodio_backend", + feature = "rodiojack_backend", + feature = "jackaudio_backend", )))] compile_error!("At least one of the backend features is required!"); static BACKEND_VALUES: &[&str] = &[ @@ -37,6 +39,10 @@ static BACKEND_VALUES: &[&str] = &[ "portaudio", #[cfg(feature = "rodio_backend")] "rodio", + #[cfg(feature = "rodiojack_backend")] + "rodiojack", + #[cfg(feature = "jackaudio_backend")] + "jackaudio", ]; /// The backend used by librespot @@ -47,6 +53,7 @@ pub enum Backend { PortAudio, PulseAudio, Rodio, + RodioJack, } fn default_backend() -> Backend { @@ -62,6 +69,7 @@ impl FromStr for Backend { "portaudio" => Ok(Backend::PortAudio), "pulseaudio" => Ok(Backend::PulseAudio), "rodio" => Ok(Backend::Rodio), + "rodiojack" => Ok(Backend::RodioJack), _ => unreachable!(), } } @@ -74,6 +82,7 @@ impl fmt::Display for Backend { Backend::PortAudio => write!(f, "portaudio"), Backend::PulseAudio => write!(f, "pulseaudio"), Backend::Rodio => write!(f, "rodio"), + Backend::RodioJack => write!(f, "rodiojack"), } } } From 3cac01ea766323369535296490f434cc868527ae Mon Sep 17 00:00:00 2001 From: Andrew Gainer-Dewar Date: Sat, 1 Jun 2024 13:57:24 -0400 Subject: [PATCH 2/8] Remove spurious references to `jackaudio` backend not actually implemented in this PR --- src/config.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index 55c9606b..1d14cb9a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,7 +27,6 @@ const CONFIG_FILE_NAME: &str = "spotifyd.conf"; feature = "alsa_backend", feature = "rodio_backend", feature = "rodiojack_backend", - feature = "jackaudio_backend", )))] compile_error!("At least one of the backend features is required!"); static BACKEND_VALUES: &[&str] = &[ @@ -41,8 +40,6 @@ static BACKEND_VALUES: &[&str] = &[ "rodio", #[cfg(feature = "rodiojack_backend")] "rodiojack", - #[cfg(feature = "jackaudio_backend")] - "jackaudio", ]; /// The backend used by librespot From e342328550779423382f35cd10a18b1c76b81f40 Mon Sep 17 00:00:00 2001 From: seth Date: Fri, 9 Aug 2024 21:53:27 -0400 Subject: [PATCH 3/8] Bump time from 0.3.28 to 0.3.36 --- Cargo.lock | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f4b4032e..c7533d3a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -554,7 +554,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7efb37c3e1ccb1ff97164ad95ac1606e8ccd35b3fa0a7d99a304c7f4a428cc24" dependencies = [ "percent-encoding", - "time 0.3.28", + "time 0.3.36", "version_check", ] @@ -571,7 +571,7 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "time 0.3.28", + "time 0.3.36", "url", ] @@ -762,9 +762,12 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.8" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] [[package]] name = "derivative" @@ -2051,6 +2054,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-derive" version = "0.3.3" @@ -2373,6 +2382,12 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -3138,7 +3153,7 @@ dependencies = [ "hostname", "libc", "log", - "time 0.3.28", + "time 0.3.36", ] [[package]] @@ -3226,14 +3241,16 @@ dependencies = [ [[package]] name = "time" -version = "0.3.28" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f6bb557fd245c28e6411aa56b6403c689ad95061f50e4be16c274e70a17e48" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", "libc", + "num-conv", "num_threads", + "powerfmt", "serde", "time-core", "time-macros", @@ -3241,16 +3258,17 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.14" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a942f44339478ef67935ab2bbaec2fb0322496cf3cbe84b261e06ac3814c572" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ + "num-conv", "time-core", ] From d22ae6e358def7814e6176b2bc5ac57fbff3e6a7 Mon Sep 17 00:00:00 2001 From: eladyn Date: Thu, 5 Sep 2024 17:14:09 -0400 Subject: [PATCH 4/8] clippy: use u16::MAX instead of max_value() --- src/alsa_mixer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/alsa_mixer.rs b/src/alsa_mixer.rs index 56645449..09c40ebf 100644 --- a/src/alsa_mixer.rs +++ b/src/alsa_mixer.rs @@ -25,9 +25,9 @@ impl AlsaMixer { let volume_steps = (max - min) as f64; let normalised_volume = if self.linear_scaling { - ((f64::from(volume) / f64::from(u16::max_value())) * volume_steps) as i64 + min + ((f64::from(volume) / f64::from(u16::MAX)) * volume_steps) as i64 + min } else { - (f64::from(volume).log(f64::from(u16::max_value())) * volume_steps).floor() as i64 + min + (f64::from(volume).log(f64::from(u16::MAX)) * volume_steps).floor() as i64 + min }; elem.set_playback_volume_all(normalised_volume)?; From 0a69c1120a0a9c29cd9c6cb8a47f3a31376df66b Mon Sep 17 00:00:00 2001 From: Alexander Zaitsev Date: Thu, 17 Oct 2024 02:19:28 +0300 Subject: [PATCH 5/8] feat: enable LTO --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 71a3cd0e..3c8bacfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,3 +68,6 @@ assets = [ ["README.md", "usr/share/doc/spotifyd/README", "644"], ["contrib/spotifyd.service", "etc/systemd/user/", "644"], ] + +[profile.release] +lto = true From 94913c6742c6d6a319c2a904122ae37da89483f9 Mon Sep 17 00:00:00 2001 From: Nils <31704359+mietzen@users.noreply.github.com> Date: Thu, 26 Sep 2024 18:53:30 +0200 Subject: [PATCH 6/8] Added add guide for cross compiling using docker Add documentation for e.g. building arm64 as described in #1053 --- .../cross-compile-using-docker.md | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 docs/src/installation/cross-compile-using-docker.md diff --git a/docs/src/installation/cross-compile-using-docker.md b/docs/src/installation/cross-compile-using-docker.md new file mode 100644 index 00000000..40dae8cc --- /dev/null +++ b/docs/src/installation/cross-compile-using-docker.md @@ -0,0 +1,33 @@ +We can also use `docker` to cross compile on every platform and OS that runs `docker` and `qemu`: + +1. Setup a docker [custom builder](https://docs.docker.com/build/building/multi-platform/#create-a-custom-builder) +```shell +docker buildx create \ + --name container-builder \ + --driver docker-container \ + --use --bootstrap +``` + +2. Create a docker `compose-file.yml`: +```yaml +services: + build-container: + image: rust:1.79-bookworm + platform: linux/arm64 + command: bash -c " + apt-get update && + apt-get install -y \ + libasound2-dev \ + libssl-dev \ + pkg-config && + curl -sSL https://api.github.com/repos/Spotifyd/spotifyd/tarball/v0.3.5 | tar xz -C /spotifyd --strip-components=1 && + cargo build --release && + cp /spotifyd/target/release/spotifyd /build/" + working_dir: /spotifyd + volumes: + - ./:/build +``` + +3. Run `docker compose up` + +This will copy the build `spotifyd` binary in the current directory. From 3dcde2e0d66fb5cc0bbedc6b2ed4d658bd1ac0c0 Mon Sep 17 00:00:00 2001 From: Nils Stein <31704359+mietzen@users.noreply.github.com> Date: Thu, 17 Oct 2024 18:07:11 +0200 Subject: [PATCH 7/8] Formatting and rewording --- .../cross-compile-using-docker.md | 62 +++++++++++-------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/docs/src/installation/cross-compile-using-docker.md b/docs/src/installation/cross-compile-using-docker.md index 40dae8cc..97277648 100644 --- a/docs/src/installation/cross-compile-using-docker.md +++ b/docs/src/installation/cross-compile-using-docker.md @@ -1,33 +1,41 @@ +# Cross Compilation using Docker + We can also use `docker` to cross compile on every platform and OS that runs `docker` and `qemu`: 1. Setup a docker [custom builder](https://docs.docker.com/build/building/multi-platform/#create-a-custom-builder) -```shell -docker buildx create \ - --name container-builder \ - --driver docker-container \ - --use --bootstrap -``` - -2. Create a docker `compose-file.yml`: -```yaml -services: - build-container: - image: rust:1.79-bookworm - platform: linux/arm64 - command: bash -c " - apt-get update && - apt-get install -y \ - libasound2-dev \ - libssl-dev \ - pkg-config && - curl -sSL https://api.github.com/repos/Spotifyd/spotifyd/tarball/v0.3.5 | tar xz -C /spotifyd --strip-components=1 && - cargo build --release && - cp /spotifyd/target/release/spotifyd /build/" - working_dir: /spotifyd - volumes: - - ./:/build -``` + + ```shell + docker buildx create \ + --name container-builder \ + --driver docker-container \ + --use --bootstrap + ``` + + If you are **not** using Docker-Desktop you might have to install [QEMU](https://docs.docker.com/build/building/multi-platform/#install-qemu-manually) + +2. Create a docker `compose-file.yml` + + Here we are building a `arm64` binary, so we set `platform: linux/arm64` + + ```yaml + services: + build-container: + image: rust:1.79-bookworm + platform: linux/arm64 + command: bash -c " + apt-get update && + apt-get install -y \ + libasound2-dev \ + libssl-dev \ + pkg-config && + curl -sSL https://api.github.com/repos/Spotifyd/spotifyd/tarball/v0.3.5 | tar xz -C /spotifyd --strip-components=1 && + cargo build --release && + cp /spotifyd/target/release/spotifyd /build/" + working_dir: /spotifyd + volumes: + - ./:/build + ``` 3. Run `docker compose up` -This will copy the build `spotifyd` binary in the current directory. + This will copy the build `spotifyd` binary in the current directory. From 3cf858b4e03e4640b94b8aed45bcb763f8398b2e Mon Sep 17 00:00:00 2001 From: Nils Stein <31704359+mietzen@users.noreply.github.com> Date: Thu, 17 Oct 2024 18:07:38 +0200 Subject: [PATCH 8/8] Added Cross Compilation using Docker to Summary --- docs/src/SUMMARY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index a01e51d9..c755633b 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -6,6 +6,7 @@ - [Installing on a Raspberry Pi](./installation/Raspberry-Pi.md) - [Installing on Ubuntu (from source)](./installation/Ubuntu.md) - [Cross Compiling on Ubuntu](./installation/Cross-Compiling-on-Ubuntu.md) + - [Cross Compilation using Docker](./installation/cross-compile-using-docker.md) - [Installing with Homebrew on macOS](./installation/MacOS.md) - [Installing on FreeBSD](./installation/FreeBSD.md) - [Installing on OpenBSD](./installation/OpenBSD.md)