dheijl / swyh-rs

Stream What You Hear written in rust, inspired by SWYH.
MIT License
348 stars 15 forks source link

Autoreconnect does not work with multiple Sonos Devices #129

Closed BBRXMusic closed 4 months ago

BBRXMusic commented 5 months ago

I am testing with multiple Sonos Devices.

SSDP Discovers the devices but will only connect to one, depending on the device from the pairing there will sometimes be no audio. There will only be output on one of the two devices.

I can manually select both devices and everything works perfectly. However upon restart autoconnect only connects to one device again.

After selecting two devices. image

After restart (back to one device) Depending on the device there may be no audio image

If I try adding a custom radio station unchecking both devices and unchecking the "Autoreconnect" and 'Autoresume play" I just get blasts of static/noise and no stable connection.

I have tried FLAC and WAV with all StreamSize options.

Ideally I would hope to be able to select any number of devices and have Autoconnect restore the connections to all of them.

omoknen commented 5 months ago

I have a set of SONOS speakers, and the best way to get them to work together and stay in sync (if you don't have connections issues -Wireless can be finicky) with SWYH-RS is to use the SONOS application. Generally SONOS is where I have had problems.

Using the SONOS PC app or the phone Apps.... 1) I created an entry using Tune-IN -> My Radio for SWYH-RS 2) Make that entry a SONOS favorite. 3) You need to group all the speakers together, and then select your SWYH-RS favorite.

I only problems with SONOS when they update. Sometimes I have had to reboot the speakers.

BBRXMusic commented 5 months ago

You're described setup is precisely what I was trying first. This worked perfectly with the legacy(original) SWYH.

wIth -RS the stream attempts to start, static or momentary audio distortion then disconnect as a continuous loop.

Below are the logs when using radio, stream requested than stops immediately with both WAV and FLAC config. Again I have tested ever chunk size.

Configuration { server_port: Some(5901), auto_resume: false, sound_source: Some("Speakers / Headphones (Realtek Audio)"), sound_source_index: Some(0), log_level: Debug, ssdp_interval_mins: 10.0, auto_reconnect: false, _disable_chunked: true, lpcm_stream_size: Some(U64maxNotChunked), wav_stream_size: Some(U32maxNotChunked), rf64_stream_size: Some(U64maxNotChunked), flac_stream_size: Some(U32maxChunked), use_wave_format: true, bits_per_sample: Some(24), streaming_format: Some(Wav), monitor_rms: false, capture_timeout: Some(2000), inject_silence: Some(false), last_renderer: Some("Sonos Era 100 Office - Sonos Era 100 Media Renderer - RINCON_C4387599624801400"), last_network: Some("192.168.1.29"), config_dir: "C:\Users\RXM\.swyh-rs", config_id: Some(""), read_only: false } Setup audio sources Now running at ABOVE_NORMAL_PRIORITY_CLASS Capturing audio from: Speakers / Headphones (Realtek Audio) Default audio SupportedStreamConfig { channels: 2, sample_rate: SampleRate(48000), buffer_size: Range { min: 0, max: 4294967295 }, sample_format: F32 } Discover networks Starting SSDP discovery The streaming server is listening on http://192.168.1.29:5901/stream/swyh.wav Streaming sample rate: 48000, bits per sample: 24, format: Wav The wave_reader is now receiving samples AV Get Volume on Office - Sonos Era 100 Media Renderer - RINCON_C4387599850401400 host=192.168.1.44 port=1400 = 11% AV Get Volume on Office - Sonos Era 100 Media Renderer - RINCON_C4387599624801400 host=192.168.1.43 port=1400 = 11% Received request /stream/swyh.flac from 192.168.1.44:32826 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:32826 Streaming to 192.168.1.44:32826 has ended Received request /stream/swyh.flac from 192.168.1.44:32856 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:32856 Streaming to 192.168.1.44:32856 has ended Received request /stream/swyh.flac from 192.168.1.44:32882 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:32882 Streaming to 192.168.1.44:32882 has ended Received request /stream/swyh.flac from 192.168.1.44:32918 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:32918 Streaming to 192.168.1.44:32918 has ended Received request /stream/swyh.flac from 192.168.1.44:32944 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:32944 Streaming to 192.168.1.44:32944 has ended Received request /stream/swyh.flac from 192.168.1.44:32974 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:32974 Streaming to 192.168.1.44:32974 has ended Received request /stream/swyh.flac from 192.168.1.44:33006 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:33006 Streaming to 192.168.1.44:33006 has ended Received request /stream/swyh.flac from 192.168.1.44:33036 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:33036 Streaming to 192.168.1.44:33036 has ended Received request /stream/swyh.flac from 192.168.1.44:33062 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:33062 Streaming to 192.168.1.44:33062 has ended Received request /stream/swyh.flac from 192.168.1.44:33096 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:33096 Streaming to 192.168.1.44:33096 has ended Received request /stream/swyh.flac from 192.168.1.44:33126 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:33126 Streaming to 192.168.1.44:33126 has ended Received request /stream/swyh.flac from 192.168.1.44:33158 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:33158 Streaming to 192.168.1.44:33158 has ended Received request /stream/swyh.flac from 192.168.1.44:33186 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:33186 Streaming to 192.168.1.44:33186 has ended Received request /stream/swyh.flac from 192.168.1.44:33212 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:33212 Streaming to 192.168.1.44:33212 has ended Received request /stream/swyh.flac from 192.168.1.44:33238 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:33238 Streaming to 192.168.1.44:33238 has ended Received request /stream/swyh.flac from 192.168.1.44:33266 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:33266 Streaming to 192.168.1.44:33266 has ended Received request /stream/swyh.flac from 192.168.1.44:33296 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:33296 Streaming to 192.168.1.44:33296 has ended Received request /stream/swyh.flac from 192.168.1.44:33328 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:33328 Streaming to 192.168.1.44:33328 has ended Received request /stream/swyh.flac from 192.168.1.44:33362 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:33362 Streaming to 192.168.1.44:33362 has ended Received request /stream/swyh.flac from 192.168.1.44:33396 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:33396 Streaming to 192.168.1.44:33396 has ended Received request /stream/swyh.flac from 192.168.1.44:33452 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:33452 Streaming to 192.168.1.44:33452 has ended Received request /stream/swyh.flac from 192.168.1.44:33482 Streaming audio/FLAC, input sample format F32, channels=2, rate=48000, to 192.168.1.44:33482 Streaming to 192.168.1.44:33482 has ended Unrecognized request '/stream/syh.wav' from 192.168.1.44:33540' Unrecognized request '/stream/syh.wav' from 192.168.1.44:33556' Received request /stream/swyh.wav from 192.168.1.44:33578 Streaming audio/wave;codec=1 (WAV), input sample format F32, channels=2, rate=48000, to 192.168.1.44:33578 Received request /stream/swyh.wav from 192.168.1.44:33582 Streaming audio/wave;codec=1 (WAV), input sample format F32, channels=2, rate=48000, to 192.168.1.44:33582 Streaming to 192.168.1.44:33578 has ended Streaming to 192.168.1.44:33582 has ended Received request /stream/swyh.wav from 192.168.1.44:33614 Streaming audio/wave;codec=1 (WAV), input sample format F32, channels=2, rate=48000, to 192.168.1.44:33614 Streaming to 192.168.1.44:33614 has ended Received request /stream/swyh.wav from 192.168.1.44:33644 Streaming audio/wave;codec=1 (WAV), input sample format F32, channels=2, rate=48000, to 192.168.1.44:33644 Streaming to 192.168.1.44:33644 has ended Received request /stream/swyh.wav from 192.168.1.44:33676 Streaming audio/wave;codec=1 (WAV), input sample format F32, channels=2, rate=48000, to 192.168.1.44:33676 Streaming to 192.168.1.44:33676 has ended Received request /stream/swyh.wav from 192.168.1.44:33706 Streaming audio/wave;codec=1 (WAV), input sample format F32, channels=2, rate=48000, to 192.168.1.44:33706 Streaming to 192.168.1.44:33706 has ended Received request /stream/swyh.wav from 192.168.1.44:33734 Streaming audio/wave;codec=1 (WAV), input sample format F32, channels=2, rate=48000, to 192.168.1.44:33734 Streaming to 192.168.1.44:33734 has ended Received request /stream/swyh.wav from 192.168.1.44:33760 Streaming audio/wave;codec=1 (WAV), input sample format F32, channels=2, rate=48000, to 192.168.1.44:33760 Streaming to 192.168.1.44:33760 has ended

omoknen commented 5 months ago

I am not the author, but it has been working for me. I hope he can help you. I do see some difference (Windows 10) I use the virtual cable (VB-Audio Virtual Cable) driver he recommends, and then I redirect the audio directly from Music Application to the virtual cable (MusicBee). It works for everything if you make the Virtual Cable as the default speaker, but it will always lag at the pc so I separated it.

BBRXMusic commented 5 months ago

Same issue with VB-Cable. .wav stream picked up, brief connections and disconnect, audio cuts out. SSDP works perfectly but the system will not auto-connect to multiple devices on restart

BBRXMusic commented 5 months ago

As an additional note if I use VLC to test the http streams I can pickup FLAC and VLC fine. It is specifically the Sonos ERA 100 group that cannot keeps dropping and producing brief periods (ms) of audio (per logs).

Again if I go to the old SWYH project and stream as .mp3 everything works perfectly, but I would prefer a solution that can inject silence.

For the other project I had to write my own program to run on startup and generate a continuous 2hz sample to keep the stream alive.

Below are the Sonos Specs

Associated Product: 192.168.1.44

Era 100: Office (L) Serial Number: C4-38-75-99-85-04:G Sonos OS: S2 Version: 16.1.1 (build 78152020) Hardware Version: 1.38.1.10-1.2 Series ID: A102 IP Address: 192.168.1.44 WM: 1

Era 100: Office (R) Serial Number: C4-38-75-99-62-48:F Sonos OS: S2 Version: 16.1.1 (build 78152020) Hardware Version: 1.38.1.10-1.2 Series ID: A102 IP Address: 192.168.1.43 WM: 1

dheijl commented 5 months ago

At present swyh-rs can only autoconnect to a single device, and that is the last one activated. Also, FLAC will probably cause less trouble than WAV or RF64. MP3 is not supported.

BBRXMusic commented 5 months ago

Thanks @dheijl unfortunately I'm still not sure why whether using VB-Cable or direct the speakers cannot connect via "Custom Radio Station" with swyh-rs, only SSDP. I'm not sure if there is a conflict there.

I couldn't find any switch do disable SSDP.

dheijl commented 5 months ago

I don't own any Sonos speakers, so I have to rely on information I receive.

There is no relationship between SSDP and using swyh-rs as a radio station, it should just work if you provide rhe correct URL.

If it doesn't work, the only thing that can help me diagnosing the problem is if you

dheijl commented 5 months ago

It is possible to disable ssdp if you use the cli exe with the -x (serve only) switch, but somehow I don't think it's going to help you here.

BBRXMusic commented 5 months ago

Hi @dheijl,

Please find the log attached.

log.txt

omoknen commented 5 months ago

Sorry for adding some more information this late, but I hope this might help you.

I hadn't realized that Era 100's are all wireless, my Sonos One's are now all wired because I had wireless problems (my sonos prefer hardwired ethernet).

You might be able to use this on your web browser. I had a Sonos Community link but they removed it so I don't know if it still works with Era 100's. (It has to be http not https)

http://***.***.***.***:1400/support/review

You then want to look at the "Network Matrix" link to see the signal strength and which unit is acting as the root bridge.

BBRXMusic commented 5 months ago

Thanks omoknen,

I have looked at this. Again, a key factor here is swyh 1.5 works perfectly, I just have to use my own silence injector app c#/NAudio to prevent disconnect, it's -rs which I would prefer to use [no memory leek and small memory and CPU footprint] especially we having to run a secondary program for silence injection.

Below are current references to the Sonos web interface for anyone interested.

https://bsteiner.info/articles/hidden-sonos-interface https://doitforme.solutions/blog/sonos-diagnostics-secret-web-menu/

dheijl commented 5 months ago

The internet radio url /swyh.flac always assumes 24 bit, the other ones 16 bit. If the configured value does not match this the streaming headers do not match the actual data and you will get garbage. It's a limitation. Just like the single autoreconnect player and the lack of mp3 support.

BBRXMusic commented 5 months ago

I have tested the URL's as you specified above (24Bit selected for FLAC, 16Bit for WAV) same results.

Of note I can pickup the streams on a mobile device and VLC with no issue. It's specifically an issue with the Sonos ERA-100 pair.

Again, what I find odd is SSDP works perfectly, unfortunately the single device selection on restart is a blocker here, as there is only 1 channel of audio after a restart and the playback source is headless so no convenient way to select the devices after a restart.

dheijl commented 5 months ago

Are you using swyh-rs Gui? In that case supporting reconnect to multiple devices on startup should be relatively easy.

BBRXMusic commented 5 months ago

I am using the GUI so if we could maintain an array of "Active or Selected" renderer in the config rather than just last renderer for auto_reconnect that would be great

dheijl commented 5 months ago

It will be in 1.10.4, within a few days I hope.

dheijl commented 5 months ago

It should work now from the GUI with 1.10.4. Any player still playing when you close swyh-rs GUI will be remembered in the config file before stopping it and it will be restarted when swyh-rs restarts with autoreconnect on.

BBRXMusic commented 5 months ago

Thanks @dheijl

This seems to be working well. I have it in the shell:startup and for whatever reason the first couple restarts SSDP discovery was failing after selecting the devices and rebooting or restarting.

It seems to have stabilized; I can now reboot the system or close and relaunch swyh-rs and playback resumes

log.txt

dheijl commented 5 months ago

I have it in the shell:startup...

It is dependent on the network being fully initialized before you start it, perhaps that is why the SSDP discovery sometimes fails in the shell::startup after a reboot?

BBRXMusic commented 5 months ago

It could be. I will wrap it in another launcher that will check the network status and test the active_renderers from the config before launching.

dheijl commented 4 months ago

I suppose this can be closed now? You can always reopen if needed.