Kodi Community Forum
Linux Pipewire backend does not switch samplerate - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: General Support (https://forum.kodi.tv/forumdisplay.php?fid=111)
+---- Forum: Linux (https://forum.kodi.tv/forumdisplay.php?fid=52)
+---- Thread: Linux Pipewire backend does not switch samplerate (/showthread.php?tid=375550)

Pages: 1 2


RE: Pipewire backend does not switch samplerate - fritsch - 2023-12-29

With a bit of luck, remove this entry: https://github.com/xbmc/xbmc/blob/master/xbmc/cores/AudioEngine/Sinks/pipewire/AESinkPipewire.cpp#L59 - the rest should then default to 32 bit Int.
Forget about the exclusive change above.

Btw. just for you to understand what this does:

Music File -> Kodi -> Float-Planar -> Kodi -> SN32 Integer -> Pipewire.

So you put an additional conversion from planar float to 32 bit Integer, while Pipewire would perfectly understand float input and kodi only would interleave the planes.


RE: Pipewire backend does not switch samplerate - fritsch - 2023-12-29

I left a comment in your bugreport and kindly asked what PW wants us to do and gave reasoning why kodi behaves like it behaves.


RE: Pipewire backend does not switch samplerate - unpo - 2023-12-29

Saw that, thank you.

I ripped out the 32 bit float formats from AESinkPipewire.cpp to satisfy my curiosity. Removing only this line resulted in the AESink not being initialized, though, so had to purge all references. Doing this resulted in...

exactly the same behaviour as with the float format still in place.

S   ID  QUANT   RATE    WAIT    BUSY   W/Q   B/Q  ERR FORMAT           NAME
R   41    512  48000 571.7us  22.7us  0.05  0.00    0    S32LE 2 48000 alsa_output.usb-miniDSP_miniDSP_Flex-00.analog-stereo
R   51    735  44100 125.5us 334.1us  0.01  0.03    0    S32LE 2 44100  + Kodi

Yes, I've put the default rate to 48000 to stop you from frowning.


RE: Pipewire backend does not switch samplerate - fritsch - 2023-12-29

Frowning ;-).

Great - that's a bit of a surprise to me. Let's see what upstream says in the report.


RE: Pipewire backend does not switch samplerate - fritsch - 2023-12-30

Additional idea:

Here: https://github.com/xbmc/xbmc/blob/master/xbmc/cores/AudioEngine/Sinks/pipewire/AESinkPipewire.cpp#L418 try to add

  std:Confusedtring 1bySampleRate =
      StringUtils::Format("{}/{}", "1", format.m_sampleRate);
SPA_DICT_ITEM_INIT(PW_KEY_NODE_RATE, 1bySampleRate.c_str());

Works now?


RE: Pipewire backend does not switch samplerate - fritsch - 2023-12-30

diff --git a/xbmc/cores/AudioEngine/Sinks/pipewire/AESinkPipewire.cpp b/xbmc/cores/AudioEngine/Sinks/pipewire/AESinkPipewire.cpp
index bc5e3d3f96..0fb3149a57 100644
--- a/xbmc/cores/AudioEngine/Sinks/pipewire/AESinkPipewire.cpp
+++ b/xbmc/cores/AudioEngine/Sinks/pipewire/AESinkPipewire.cpp
@@ -410,12 +410,15 @@ bool CAESinkPipewire::Initialize(AEAudioFormat& format, std::string& device)
   std::string fraction =
       StringUtils::Format("{}/{}", frames / DEFAULT_LATENCY_DIVIDER, format.m_sampleRate);
 
+  std::string srate = StringUtils::Format("{}/{}", 1, format.m_sampleRate);
+
   std::array<spa_dict_item, 5> items = {
       SPA_DICT_ITEM_INIT(PW_KEY_MEDIA_TYPE, "Audio"),
       SPA_DICT_ITEM_INIT(PW_KEY_MEDIA_CATEGORY, "Playback"),
       SPA_DICT_ITEM_INIT(PW_KEY_APP_NAME, CCompileInfo::GetAppName()),
       SPA_DICT_ITEM_INIT(PW_KEY_NODE_NAME, CCompileInfo::GetAppName()),
-      SPA_DICT_ITEM_INIT(PW_KEY_NODE_LATENCY, fraction.c_str())};
+      SPA_DICT_ITEM_INIT(PW_KEY_NODE_LATENCY, fraction.c_str()),
+      SPA_DICT_ITEM_INIT(PW_KEY_NODE_RATE, srate.c_str())};
 
   auto properties = SPA_DICT_INIT(items.data(), items.size());
   m_stream->UpdateProperties(&properties);


RE: Pipewire backend does not switch samplerate - fritsch - 2023-12-30

Here, you can cherry-pick the patch: https://github.com/xbmc/xbmc/pull/24363


RE: Pipewire backend does not switch samplerate - unpo - 2023-12-30

Closed the report upon testing your proposed diff, with one minor change added.


RE: Pipewire backend does not switch samplerate - fritsch - 2023-12-30

Awesome. Thanks for making our pipewire sink ready for primetime in upcoming v21.