From ce743ce4c631fe78361b4ec4098fc1de72414adb Mon Sep 17 00:00:00 2001 From: badaix Date: Sun, 5 Jan 2025 17:50:58 +0100 Subject: [PATCH] Fix Linter issues --- .clang-tidy | 2 +- README.md | 26 +++++++++++++++++--------- doc/configuration.md | 5 ++--- doc/player_setup.md | 35 +++++++++++++++++++++++------------ test/CMakeLists.txt | 4 ++-- test/test_main.cpp | 30 +++++++++++++++--------------- 6 files changed, 60 insertions(+), 42 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index ecd886ef..38db92e3 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -4,7 +4,7 @@ WarningsAsErrors: '' HeaderFilterRegex: '' AnalyzeTemporaryDtors: false FormatStyle: file -User: johannes +User: badaix CheckOptions: - key: modernize-loop-convert.MaxCopySize value: '16' diff --git a/README.md b/README.md index 49f4ef58..947867a2 100644 --- a/README.md +++ b/README.md @@ -115,13 +115,13 @@ Available audio backends are configured using the `--player` command line parame | Backend | OS | Description | Parameters | | --------- | ------- | ------------ | ---------- | -| alsa | Linux | ALSA | `buffer_time=` (default 80, min 10)
`fragments=` (default 4, min 2) | -| pulse | Linux | PulseAudio | `buffer_time=` (default 100, min 10)
`server=` - default not-set: use the default server
`property==` set PA property, can be used multiple times (default `media.role=music`) | +| alsa | Linux | ALSA | `buffer_time=` (default 80, min 10)
`fragments=` (default 4, min 2) | +| pulse | Linux | PulseAudio | `buffer_time=` (default 100, min 10)
`server=` - default not-set: use the default server
`property==` set PA property, can be used multiple times (default `media.role=music`) | | oboe | Android | Oboe, using OpenSL ES on Android 4.1 and AAudio on 8.1 | | | opensl | Android | OpenSL ES | | | coreaudio | macOS | Core Audio | | | wasapi | Windows | Windows Audio Session API | | -| file | All | Write audio to file | `filename=` (`` = `stdout`, `stderr`, `null` or a filename)
`mode=[w|a]` (`w`: write (discarding the content), `a`: append (keeping the content) | +| file | All | Write audio to file | `filename=` (`` = `stdout`, `stderr`, `null` or a filename)
`mode=[w\|a]` (`w`: write (discarding the content), `a`: append (keeping the content) | Parameters are appended to the player name, e.g. `--player alsa:buffer_time=100`. Use `--player :?` to get a list of available options. For some audio backends you can configure the PCM device using the `-s` or `--soundcard` parameter, the device is chosen by index or name. Available PCM devices can be listed with `-l` or `--list` @@ -131,18 +131,24 @@ If you are running MPD and Shairport-sync into a soundcard that only supports 48 You can test your installation by copying random data into the server's fifo file - cat /dev/urandom > /tmp/snapfifo +```shell +cat /dev/urandom > /tmp/snapfifo +``` All connected clients should play random noise now. You might raise the client's volume with "alsamixer". It's also possible to let the server play a WAV file. Simply configure a `file` stream in `/etc/snapserver.conf`, and restart the server: - [stream] - source = file:///home/user/Musik/Some%20wave%20file.wav?name=test +```ini +[stream] +source = file:///home/user/Musik/Some%20wave%20file.wav?name=test +``` When you are using a Raspberry Pi, you might have to change your audio output to the 3.5mm jack: - #The last number is the audio output with 1 being the 3.5 jack, 2 being HDMI and 0 being auto. - amixer cset numid=3 1 +``` shell +# The last number is the audio output with 1 being the 3.5 jack, 2 being HDMI and 0 being auto. +amixer cset numid=3 1 +``` To setup WiFi on a Raspberry Pi, you can follow this [guide](https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md) @@ -195,7 +201,9 @@ The only requirement is that the player's audio can be redirected into the Snaps The goal is to build the following chain: - audio player software -> snapfifo -> snapserver -> network -> snapclient -> alsa +```plain +audio player software -> snapfifo -> snapserver -> network -> snapclient -> alsa +``` This [guide](doc/player_setup.md) shows how to configure different players/audio sources to redirect their audio signal into the Snapserver's fifo: diff --git a/doc/configuration.md b/doc/configuration.md index 05537026..70120594 100644 --- a/doc/configuration.md +++ b/doc/configuration.md @@ -50,7 +50,7 @@ pipe:///?name=[&mode=create] `mode` can be `create` or `read`. Sometimes your audio source might insist in creating the pipe itself. So the pipe creation mode can by changed to "not create, but only read mode", using the `mode` option set to `read` -**NOTE** With newer kernels using FIFO pipes in a world writeable sticky dir (e.g. `/tmp`) one might also have to turn off `fs.protected_fifos`, as default settings have changed recently: `sudo sysctl fs.protected_fifos=0`. +**NOTE** With newer kernels using FIFO pipes in a world writeable sticky dir (e.g. `/tmp`) one might also have to turn off `fs.protected_fifos`, as default settings have changed recently: `sudo sysctl fs.protected_fifos=0`. See [stackexchange](https://unix.stackexchange.com/questions/503111/group-permissions-for-root-not-working-in-tmp) for more details. You need to run this after each reboot or add it to /etc/sysctl.conf or /etc/sysctl.d/50-default.conf depending on distribution. @@ -292,7 +292,7 @@ have a Jack client named "system" with four output ports ("playback_1", could either autoconnect to the exact ports, or you use an `autoconnect` search term that returns all ports and use `autoconnect_skip` to pick the right one: -``` +```ini jack:///?name=Channel1&sampleformat=48000:16:1&autoconnect=system:playback_ jack:///?name=Channel2&sampleformat=48000:16:1&autoconnect=system:playback_&autoconnect_skip=1 jack:///?name=Channel3&sampleformat=48000:16:1&autoconnect=system:playback_&autoconnect_skip=2 @@ -306,7 +306,6 @@ jack:///?name=Channel4&sampleformat=48000:16:1&autoconnect=system:playback_&auto - The `chunk_ms` parameter is ignored for jack streams. The Jack buffer size (Frames/Period) is used instead. - ### meta Read and mix audio from other stream sources diff --git a/doc/player_setup.md b/doc/player_setup.md index fd97b1e9..150514e1 100644 --- a/doc/player_setup.md +++ b/doc/player_setup.md @@ -9,7 +9,7 @@ The goal is to build the following chain: audio player software -> snapfifo -> snapserver -> network -> snapclient -> alsa ``` -**NOTE** With newer kernels using FIFO pipes in a world writeable sticky dir (e.g. `/tmp`) one might also have to turn off `fs.protected_fifos`, as default settings have changed recently: `sudo sysctl fs.protected_fifos=0`. +**NOTE** With newer kernels using FIFO pipes in a world writeable sticky dir (e.g. `/tmp`) one might also have to turn off `fs.protected_fifos`, as default settings have changed recently: `sudo sysctl fs.protected_fifos=0`. See [stackexchange](https://unix.stackexchange.com/questions/503111/group-permissions-for-root-not-working-in-tmp) for more details. You need to run this after each reboot or add it to /etc/sysctl.conf or /etc/sysctl.d/50-default.conf depending on distribution. @@ -200,9 +200,9 @@ sudo apt install -y shairport-sync sudo systemctl disable --now shairport-sync ``` -Here is an example configuration line for /etc/snapserver.conf but please see [the Snapcast Airplay configuration guide](configuration.md#airplay) for more details on the syntax and options. +Here is an example configuration line for `/etc/snapserver.conf` but please see [the Snapcast Airplay configuration guide](configuration.md#airplay) for more details on the syntax and options. -```plaintext +```ini source = airplay:///shairport-sync?name=Airplay ``` @@ -212,11 +212,11 @@ Although this _might_ be a quick and convenient way to set up an Airplay source 1. Install dependencies. For debian derivates: `apt-get install autoconf libpopt-dev libconfig-dev libssl-dev` 2. Build shairport-sync (version 3.3 or later) with `stdout` backend: - * `autoreconf -i -f` + * `autoreconf -i -f` * `./configure --with-stdout --with-avahi --with-ssl=openssl --with-metadata` 3. Copy the `shairport-sync` binary somewhere to your `PATH`, e.g. `/usr/local/bin/` 4. Configure snapserver with `source = airplay:///shairport-sync?name=Airplay[&devicename=Snapcast][&port=PORT]` - * `PORT` is 5000 for Airplay 1 and 7000 for Airplay 2 + * `PORT` is 5000 for Airplay 1 and 7000 for Airplay 2 ### Spotify @@ -266,28 +266,39 @@ Audio can be played directly through the line-in via ALSA. The following guide w ``` 3. Edit the file `/etc/snapserver.conf` and add the following line, substituting `` for the value derived from the previous step. Pick whatever you'd like for ``. - ``` + + ```ini stream = alsa:///?name=&device=hw: ``` + 4. Restart the snapserver service. - ``` + + ```shell sudo service snapserver restart ``` + 5. You are done. Enjoy your new snapserver with line in. However, if you'd like to run the client on the same machine as the server then continue with the remaining steps. 6. Get the sound devices as far as snapclient is concerned. You are looking for the device name. This is probably the same as the `aplay -l` device names so may be able to use that instead. - ``` + + ```shell snapclient -l ``` + 7. In the output you are looking for the `hw:CARD` line that corresponds with the output device you want to use. Note the `` for the next step. - ``` + + ```plain hw:CARD=,DEV= ``` -8. Edit the file `/etc/default/snapclient` and modify the `SNAPCLIENT_OPTS`. - ``` + +8. Edit the file `/etc/default/snapclient` and modify the `SNAPCLIENT_OPTS`. + + ```ini SNAPCLIENT_OPTS=" --host -s " ``` + 9. Restart the snapclient service. - ``` + + ```shell sudo service snapclient restart ``` diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8e989f11..524fa278 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -28,5 +28,5 @@ if(ANDROID) target_link_libraries(snapcast_test log) endif(ANDROID) -target_link_libraries(snapcast_test Catch2::Catch2WithMain OpenSSL::Crypto - OpenSSL::SSL Catch2::Catch2) +target_link_libraries(snapcast_test OpenSSL::Crypto OpenSSL::SSL) +target_link_libraries(snapcast_test Catch2::Catch2WithMain Catch2::Catch2) diff --git a/test/test_main.cpp b/test/test_main.cpp index f7473f1f..0c696f15 100644 --- a/test/test_main.cpp +++ b/test/test_main.cpp @@ -53,14 +53,14 @@ TEST_CASE("String utils") strings = split("*", '*'); REQUIRE(strings.size() == 2); - REQUIRE(strings[0] == ""); - REQUIRE(strings[1] == ""); + REQUIRE(strings[0].empty()); + REQUIRE(strings[1].empty()); strings = split("**", '*'); REQUIRE(strings.size() == 3); - REQUIRE(strings[0] == ""); - REQUIRE(strings[1] == ""); - REQUIRE(strings[2] == ""); + REQUIRE(strings[0].empty()); + REQUIRE(strings[1].empty()); + REQUIRE(strings[2].empty()); strings = split("1*2", '*'); REQUIRE(strings.size() == 2); @@ -70,21 +70,21 @@ TEST_CASE("String utils") strings = split("1**2", '*'); REQUIRE(strings.size() == 3); REQUIRE(strings[0] == "1"); - REQUIRE(strings[1] == ""); + REQUIRE(strings[1].empty()); REQUIRE(strings[2] == "2"); strings = split("*1*2", '*'); REQUIRE(strings.size() == 3); - REQUIRE(strings[0] == ""); + REQUIRE(strings[0].empty()); REQUIRE(strings[1] == "1"); REQUIRE(strings[2] == "2"); strings = split("*1*2*", '*'); REQUIRE(strings.size() == 4); - REQUIRE(strings[0] == ""); + REQUIRE(strings[0].empty()); REQUIRE(strings[1] == "1"); REQUIRE(strings[2] == "2"); - REQUIRE(strings[3] == ""); + REQUIRE(strings[3].empty()); std::vector vec{"1", "2", "3"}; REQUIRE(container_to_string(vec) == "1, 2, 3"); @@ -442,11 +442,11 @@ TEST_CASE("Librespot2") size_t n = 0; size_t title_pos = 0; size_t ms_pos = 0; - if (((title_pos = line.find("<")) != std::string::npos) && ((n = line.find(">", title_pos)) != std::string::npos) && - ((ms_pos = line.find("(", n)) != std::string::npos) && ((n = line.find("ms) loaded", ms_pos)) != std::string::npos)) + if (((title_pos = line.find('<')) != std::string::npos) && ((n = line.find('>', title_pos)) != std::string::npos) && + ((ms_pos = line.find('(', n)) != std::string::npos) && ((n = line.find("ms) loaded", ms_pos)) != std::string::npos)) { title_pos += 1; - std::string title = line.substr(title_pos, line.find(">", title_pos) - title_pos); + std::string title = line.substr(title_pos, line.find('>', title_pos) - title_pos); REQUIRE(title == "Tunnel"); ms_pos += 1; std::string ms = line.substr(ms_pos, n - ms_pos - 1); @@ -616,11 +616,11 @@ TEST_CASE("Error") REQUIRE(ec); REQUIRE(ec == ControlErrc::can_not_control); REQUIRE(ec != ControlErrc::success); - std::cout << ec << std::endl; + std::cout << ec << '\n'; ec = make_error_code(ControlErrc::can_not_control); REQUIRE(ec.category() == snapcast::error::control::category()); - std::cout << "Category: " << ec.category().name() << ", " << ec.message() << std::endl; + std::cout << "Category: " << ec.category().name() << ", " << ec.message() << '\n'; snapcast::ErrorCode error_code{}; REQUIRE(!error_code); @@ -639,7 +639,7 @@ TEST_CASE("ErrorOr") // Move value out REQUIRE(error_or.takeValue() == "test"); // Value has been moved out, get will return an empty string - REQUIRE(error_or.getValue() == ""); + REQUIRE(error_or.getValue().empty()); } {