Summary: | Pulse audio NOT USED multithreading | ||
---|---|---|---|
Product: | PulseAudio | Reporter: | Alessandro Ferri <alessandro.ferri> |
Component: | core | Assignee: | pulseaudio-bugs |
Status: | RESOLVED NOTABUG | QA Contact: | pulseaudio-bugs |
Severity: | critical | ||
Priority: | medium | CC: | alessandro.ferri, lennart |
Version: | unspecified | ||
Hardware: | ARM | ||
OS: | Linux (All) | ||
Whiteboard: | |||
i915 platform: | i915 features: | ||
Attachments: |
Daemon.conf
System.pa Pulseaudio init script Shairport-sync init script |
Description
Alessandro Ferri
2015-04-28 08:08:42 UTC
Why do you expect that PulseAudio would use all cores? PulseAudio will have one main thread, plus one thread per sink and source. To get PulseAudio use four threads simultaneously, you'd have to have three devices in use simultaneously. because when I perform the music streaming via Bluetooth with Bluez 5.23 with a resample-method=src-sinc-medium-quality, CPU usage by PulseAudio remains high and focused on a single core. Rightly as you made me realize is just only one thread, correct? For a best building on the raspberry Pi2, are fine the parameters that I use or I'd better do more specific? and if so, how and what? (In reply to Tanu Kaskinen from comment #1) > Why do you expect that PulseAudio would use all cores? > > PulseAudio will have one main thread, plus one thread per sink and source. > To get PulseAudio use four threads simultaneously, you'd have to have three > devices in use simultaneously. (In reply to Alessandro Ferri from comment #2) > because when I perform the music streaming via Bluetooth with Bluez 5.23 > with a resample-method=src-sinc-medium-quality, CPU usage by PulseAudio > remains high and focused on a single core. Rightly as you made me realize is > just only one thread, correct? There will be two threads active, but probably the resampling thread (i.e. the Bluetooth device thread) will have much higher CPU usage. > For a best building on the raspberry Pi2, are fine the parameters that I use > or I'd better do more specific? > and if so, how and what? I don't know any specific tunings for RP2. That said, src-sinc-medium-quality probably isn't the best choice anyway. I'd recommend staying with the default speex-float-1 resampler. > I don't know any specific tunings for RP2. That said,
> src-sinc-medium-quality probably isn't the best choice anyway. I'd recommend
> staying with the default speex-float-1 resampler.
Thanks for the info,
in my case, however, speex-float-1 resampler does not work, I have no audio output, you should consider whether raspberry is combined with a HiFiBerry AMP.
Did you build pulseaudio with speex support, and if not, why? > Did you build pulseaudio with speex support, and if not, why?
I think not! At this point, the question arises to me, how I have to build pulseaudio with speex support and ffmpeg support, as both do not work?
To enable speex, you just need the development headers to be installed. You can also pass --with-speex to configure, if you want configure to fail if speex can't be enabled. What do you mean by ffmpeg not working? It should always work, except when trying to use it in a context (e.g. module-loopback) that requires a resampler that can support dynamic sample rate changing. (In reply to Tanu Kaskinen from comment #7) > To enable speex, you just need the development headers to be installed. You > can also pass --with-speex to configure, if you want configure to fail if > speex can't be enabled. > you can explain to me how to enable speex step by step. I'd thank you infinitely > What do you mean by ffmpeg not working? It should always work, except when > trying to use it in a context (e.g. module-loopback) that requires a > resampler that can support dynamic sample rate changing. probably in the same manner of speex, is not enabled. The difference is that with ffmpeg something comes out from the speakers but it is totally distorted. (In reply to Alessandro Ferri from comment #8) > (In reply to Tanu Kaskinen from comment #7) > > To enable speex, you just need the development headers to be installed. You > > can also pass --with-speex to configure, if you want configure to fail if > > speex can't be enabled. > > > you can explain to me how to enable speex step by step. I'd thank you > infinitely Step 1: Install the speex development headers (on Raspbian they're in package libspeex-dev) Step 2: Run the configure script again, and build as usual. By the way, the parameters that you currently give to configure look strange: what purpose do "--disable-rpath" and "--with-module-dir=/usr/lib/pulse/modules" serve? > > What do you mean by ffmpeg not working? It should always work, except when > > trying to use it in a context (e.g. module-loopback) that requires a > > resampler that can support dynamic sample rate changing. > > probably in the same manner of speex, is not enabled. The difference is that > with ffmpeg something comes out from the speakers but it is totally > distorted. ffmpeg is different from speex, it's not possible to disable ffmpeg. In what way is the audio distorted? "Totally distorted" should never be the end result, no matter what resamplers are enabled, unless "totally distorted" means that the audio is pausing/skipping (which can be a result of buffer underruns, which can happen if the CPU load is too high). By the way, can you explain in more detail what you mean by "music streaming via Bluetooth"? Do you play files on the RP to a Bluetooth headset, or do you play music from e.g. a mobile phone to speakers connected to the RP? I guess the latter, since HifiBerry AMP is involved... > Step 1: Install the speex development headers (on Raspbian they're in > package libspeex-dev) > > Step 2: Run the configure script again, and build as usual. > > By the way, the parameters that you currently give to configure look > strange: what purpose do "--disable-rpath" and > "--with-module-dir=/usr/lib/pulse/modules" serve? Thanks for the info, the next few days I will try to configure Pulseuadio with speex. About the two configuration parameters, I did not place a lot of problems, I repeated what I found in the post of raspberry Pi forum with some of my personal adjustment, I'll carry the link, at the bottom there is the guide to install pulseaudio 5.0: https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=87138 At this point, you know what are those two parameters, since I do not know? > ffmpeg is different from speex, it's not possible to disable ffmpeg. > > In what way is the audio distorted? "Totally distorted" should never be the > end result, no matter what resamplers are enabled, unless "totally > distorted" means that the audio is pausing/skipping (which can be a result > of buffer underruns, which can happen if the CPU load is too high). > > By the way, can you explain in more detail what you mean by "music streaming > via Bluetooth"? Do you play files on the RP to a Bluetooth headset, or do > you play music from e.g. a mobile phone to speakers connected to the RP? I > guess the latter, since HifiBerry AMP is involved... I have connected the speakers to the raspberry, using HiFiBerry AMP. I play music from my iPad to raspberry Pi2, via Bluetooth and also via WiFi. In this latest case I use shairport connected to pulseaudio. When I play music, with resample-method = ffmpeg, via wifi (with shairport + pulseaudio) from my iPad to raspberry, I not have issues and I listen music really well, when instead I play music, with resample-method = ffmpeg, via Bluetooth from my iPad to raspberry, I do not hear any music and some times from the speakers comes a sound like "grrrrr" or "pzzzz". So it seems that with the Bluetooth the resample method = ffmpeg is not working. I attacked both my daemon.conf that system.pa Created attachment 115482 [details]
Daemon.conf
My daemon.conf configuration
Created attachment 115483 [details]
System.pa
My system.pa configuration
(In reply to Alessandro Ferri from comment #10) > > Step 1: Install the speex development headers (on Raspbian they're in > > package libspeex-dev) > > > > Step 2: Run the configure script again, and build as usual. > > > > By the way, the parameters that you currently give to configure look > > strange: what purpose do "--disable-rpath" and > > "--with-module-dir=/usr/lib/pulse/modules" serve? > > > Thanks for the info, > the next few days I will try to configure Pulseuadio with speex. > About the two configuration parameters, I did not place a lot of problems, I > repeated what I found in the post of raspberry Pi forum with some of my > personal adjustment, I'll carry the link, at the bottom there is the guide > to install pulseaudio 5.0: > > https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=87138 > > At this point, you know what are those two parameters, since I do not know? "RPATH" is an attribute stored in shared libraries that tells the dynamic linker what directories to search for the dependencies of the shared libraries, in addition to the default directories. I don't know why anyone would want to disable it. In my experience RPATH is necessary for some of the modules (such as the alsa modules) to work, because they depend on libraries in a non-standard location. Apparently my understanding of this thing is not perfect, since modules seem to be loading fine on your system despite --disable-rpath. --with-module-dir just sets the module directory to something else than the default. Setting it to /usr/lib/pulse/modules does no particular harm (other than making your setup non-standard, and therefore potentially harder to debug), but there's no reason to set that option, as far as I can see. By the way, something that I missed earlier: you set --prefix to /usr, which is something that you should never do. When you use /usr as the prefix, you overwrite the files that are managed by the distribution's package manager, and if you ever update the distribution's version of pulseaudio, the package manager will then overwrite the files that you installed from source. Using /usr as the prefix is a good way to mess up your system. You don't need to set prefix, the default prefix (/usr/local) works just fine. > I have connected the speakers to the raspberry, using HiFiBerry AMP. I play > music from my iPad to raspberry Pi2, via Bluetooth and also via WiFi. In > this latest case I use shairport connected to pulseaudio. > When I play music, with resample-method = ffmpeg, via wifi (with shairport + > pulseaudio) from my iPad to raspberry, I not have issues and I listen music > really well, when instead I play music, with resample-method = ffmpeg, via > Bluetooth from my iPad to raspberry, I do not hear any music and some times > from the speakers comes a sound like "grrrrr" or "pzzzz". So it seems that > with the Bluetooth the resample method = ffmpeg is not working. I attacked > both my daemon.conf that system.pa The resampler is not a likely cause of corrupted audio. What if you record audio from the a2dp source with this command: parecord --device=SOURCE --fix-rate --fix-channels --fix-format > ~/test.wav Does that file contain corrupted audio too? If it does, then there's something wrong in the bluetooth source. A couple of additional notes about using /usr/local as the prefix: since you run pulseaudio in the system mode, that means that you run it as root (either manually or via an init script), and root doesn't have /usr/local/bin in PATH (at least not in Fedora), so you need to supply the full path when starting pulseaudio: /usr/local/bin/pulseaudio If you use an init script to start pulseaudio, the script needs to be modified to use /usr/local/bin/pulseaudio too. Also, after installing, run "sudo ldconfig" to update library symlinks. Thanks Tanu, You've given a lot of information I did not know. At this point, before doing the tests that you suggested on-resample method = speex-float-1 or resample-method = ffmpeg, I must build pulseaudio 5.0 again. So first I see if these issues disappear. I want to ask if I have to first uninstall the previous installation from source, and if so how, or simply just build a new one and install it. In the latter case the procedure, from what you told me is: sudo apt-get install libspeex-dev or sudo apt-get install libspeex-dev:armhf what is the difference? I use raspberry Pi2. after cd pulseaudio-5.0 ./configure --sysconfdir=/etc --localstatedir=/var --disable-bluez4 make sudo make install and at the end sudo ldconfig I am attaching the init script with which I run pulseaudio as system mode. I also wanted to ask further explanation. I use shairport-sync as Airplay emulator. The audio output of shairport-sync is fixed on pulse. In this way I lose synchronization between Airplay devices and my raspberry. So I wanted to ask you: 1) Is there a way to run only pulseaudio as an Airplay emulator, eliminating shairport-sync? 2) Otherwise is there a way instead, working on the parameters of pulseaudio, to maintain synchronization and eliminate the latency of the audio output? Created attachment 115598 [details]
Pulseaudio init script
(In reply to Alessandro Ferri from comment #15) > Thanks Tanu, > You've given a lot of information I did not know. At this point, before > doing the tests that you suggested on-resample method = speex-float-1 or > resample-method = ffmpeg, I must build pulseaudio 5.0 again. So first I see > if these issues disappear. I want to ask if I have to first uninstall the > previous installation from source, and if so how, or simply just build a new > one and install it. You don't have to uninstall it. If you uninstall it, there will be "No such file or directory" errors if something tries to run /usr/bin/pulseaudio. That may be better than less obvious errors about linking failures or just crashes if you don't uninstall, and something tries to run /usr/bin/pulseaudio. How to uninstall: run "sudo make uninstall". That has to be done after you've run configure with the same parameters that you used when you originally ran "sudo make install". > In the latter case the procedure, from what you told me > is: > > sudo apt-get install libspeex-dev > or > sudo apt-get install libspeex-dev:armhf > what is the difference? I use raspberry Pi2. "libspeex-dev" is the version that matches your machine's primary architecture, and "libspeex-dev:armhf" is a version for the armhf architecture. If your machine's primary architecture is armhf, there's no difference. "dpkg --print-architecture" will show the primary architecture. In any case, installing "libspeex-dev" should do the right thing. > after > > cd pulseaudio-5.0 > ./configure --sysconfdir=/etc --localstatedir=/var --disable-bluez4 > make > sudo make install > > and at the end > > sudo ldconfig > > I am attaching the init script with which I run pulseaudio as system mode. The script has DAEMON=/usr/bin/pulseaudio, which needs to be changed to DAEMON=/usr/local/bin/pulseaudio. > I also wanted to ask further explanation. I use shairport-sync as Airplay > emulator. The audio output of shairport-sync is fixed on pulse. > In this way I lose synchronization between Airplay devices and my raspberry. > So I wanted to ask you: > > 1) Is there a way to run only pulseaudio as an Airplay emulator, eliminating > shairport-sync? No. > 2) Otherwise is there a way instead, working on the parameters of > pulseaudio, to maintain synchronization and eliminate the latency of the > audio output? Are you talking about audio-video sync in video playback? Is shairport-sync also the component that displays video? If it is, then shairport-sync should already get enough information from PulseAudio about the audio delay, and based on that shairport-sync should be able to sync audio and video. If it doesn't, that's a bug in shairport-sync. (In reply to Tanu Kaskinen from comment #17) Thanks for all the information. I now try to reinstall everything, as per your instructions. > > Are you talking about audio-video sync in video playback? Is shairport-sync > also the component that displays video? If it is, then shairport-sync should > already get enough information from PulseAudio about the audio delay, and > based on that shairport-sync should be able to sync audio and video. If it > doesn't, that's a bug in shairport-sync. Shairport-sync is the only component for audio playback, there is no video. Basically it's an Airplay emulator: https://github.com/mikebrady/shairport-sync When shairport-sync play music without pulseaudio, (iPad ---> Shaiport-sync ---> speakers) it remains in sync with other Airplay devices, such as the Apple Airport Express. But when shairport-sync plays music through pulseaudio, (iPad ---> Shaiport-sync ---> Pulseaudio --->speakers) the audio is not in sync with the other Airport device. You always think it's a bug on shairport? or that there are parameters to work. (In reply to Alessandro Ferri from comment #18) > When shairport-sync play music without pulseaudio, > (iPad ---> Shaiport-sync ---> speakers) > it remains in sync with other Airplay devices, such as the Apple Airport > Express. But when shairport-sync plays music through pulseaudio, > > (iPad ---> Shaiport-sync ---> Pulseaudio --->speakers) > > the audio is not in sync with the other Airport device. > You always think it's a bug on shairport? or that there are parameters to > work. shairport-sync gets latency information from PulseAudio, and that should be sufficient to keep the outputs in sync. If that doesn't happen, I believe it's either a bug in shairport-sync, or the latency information from PulseAudio is wrong, in which case it's of course PulseAudio's fault (or the alsa driver's, but if it works with plain alsa, that seems unlikely). Dear Tanu Kaskinen, I reinstalled Pulseuadio 5.0 with procedures as above. When I installed libspeex-dev sudo apt-get install libspeex-dev I found it already installed. Now I'm left with the following issues. 1) In the configuration: iPad--->Bluez 5.23 (Bluetooth A2DP)--->Pulseaudio 5.0--->HiFiBerryAmp--->Speakers does not work nor the resample-method speex-float-1 that ffmpeg. In this case, I hear the audio but is extremely disturbed (grzzzz). 2) In the configuration: iPad--->Shairport-sync--->Pulseaudio 5.0--->HiFiBerryAmp--->Speakers does work perfectly both the resample-method speex-float-1 and ffmpeg. With the resample-method = src-sinc works with both bluetooth and Shairport-sync. And I still have not sync between two or more Airplay devices. Thanks. (In reply to Tanu Kaskinen from comment #19) > (In reply to Alessandro Ferri from comment #18) > > When shairport-sync play music without pulseaudio, > > (iPad ---> Shaiport-sync ---> speakers) > > it remains in sync with other Airplay devices, such as the Apple Airport > > Express. But when shairport-sync plays music through pulseaudio, > > > > (iPad ---> Shaiport-sync ---> Pulseaudio --->speakers) > > > > the audio is not in sync with the other Airport device. > > You always think it's a bug on shairport? or that there are parameters to > > work. > > shairport-sync gets latency information from PulseAudio, and that should be > sufficient to keep the outputs in sync. If that doesn't happen, I believe > it's either a bug in shairport-sync, or the latency information from > PulseAudio is wrong, in which case it's of course PulseAudio's fault (or the > alsa driver's, but if it works with plain alsa, that seems unlikely). Hi there. I’m the developer of Shairport Sync and I just want to clear up a misunderstanding. Shairport Sync was developed from shairport specifically for use with the alsa back end. I realise that it works with the pulseaudio backend from the original shairport, but that’s just good fortune, to be honest. It does not use latency information coming back from pulseaudio. Maybe someday :) Kind regards Mike > Hi there. I’m the developer of Shairport Sync and I just want to clear up a
> misunderstanding. Shairport Sync was developed from shairport specifically
> for use with the alsa back end. I realise that it works with the pulseaudio
> backend from the original shairport, but that’s just good fortune, to be
> honest. It does not use latency information coming back from pulseaudio.
> Maybe someday :)
>
> Kind regards
> Mike
Dear Mike,
I was very pleased to see that you're following my bugs. This part has been clarified. you have done an excellent job with shairport-sync and I'm grateful.
I hope that soon, not later, you will face this part :)
Can I push a request on github for shirport relatively to another topic?
Many thanks.
(In reply to Alessandro Ferri from comment #22) > > Hi there. I’m the developer of Shairport Sync and I just want to clear up a > > misunderstanding. Shairport Sync was developed from shairport specifically > > for use with the alsa back end. I realise that it works with the pulseaudio > > backend from the original shairport, but that’s just good fortune, to be > > honest. It does not use latency information coming back from pulseaudio. > > Maybe someday :) > > > > Kind regards > > Mike > > Dear Mike, > I was very pleased to see that you're following my bugs. This part has been > clarified. you have done an excellent job with shairport-sync and I'm > grateful. > I hope that soon, not later, you will face this part :) > > Can I push a request on github for shirport relatively to another topic? > > Many thanks. Please do! In the meantime, could you list the command line arguments you using to route the output from Shairport Sync to PulseAudio? It would be something like – -o pulse ... Thanks. > Please do! In the meantime, could you list the command line arguments you
> using to route the output from Shairport Sync to PulseAudio? It would be
> something like – -o pulse ...
> Thanks.
Dear Mike,
Thanks again for the help. The command to run shairport-sync with init scrip is:
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- -d -a "MyAirPi" -o pulse || return 2
I attach the init script of shairport-sync.
Created attachment 116030 [details]
Shairport-sync init script
Shairport-sync init script.
(In reply to Alessandro Ferri from comment #24) > > Please do! In the meantime, could you list the command line arguments you > > using to route the output from Shairport Sync to PulseAudio? It would be > > something like – -o pulse ... > > Thanks. > > Dear Mike, > Thanks again for the help. The command to run shairport-sync with init scrip > is: > > start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- -d -a > "MyAirPi" -o pulse || return 2 > > I attach the init script of shairport-sync. Thanks for these. No promises, at least for a couple of weeks... > Thanks for these. No promises, at least for a couple of weeks...
Thanks again. I wait with impatience. If I can help you in some way, just say the word.
(In reply to Alessandro Ferri from comment #27) > > Thanks for these. No promises, at least for a couple of weeks... > > Thanks again. I wait with impatience. If I can help you in some way, just > say the word. Hi again. I spent a little time on this yesterday. It turns out that the pulseaudio back end uses the 'simple' pulseaudio interface. The problem with it is that the latency information it returns in the simple interface is very inaccurate. Shairport Sync monitors the latency every time it adds a packet of audio frame – i.e. about every 8 ms. Unfortunately, it seems that the latency information is completely unreliable at this level of interaction. So, getting a good quality pulseaudio system will essentially require a complete rewrite of the backend to avoid using the 'simple' interface. It might take some time ;) (In reply to Mike Brady from comment #28) > (In reply to Alessandro Ferri from comment #27) > > > Thanks for these. No promises, at least for a couple of weeks... > > > > Thanks again. I wait with impatience. If I can help you in some way, just > > say the word. > > Hi again. I spent a little time on this yesterday. It turns out that the > pulseaudio back end uses the 'simple' pulseaudio interface. The problem with > it is that the latency information it returns in the simple interface is > very inaccurate. I suppose you're using pa_simple_get_latency()? Yes, that's somehow broken (bug 81075). It's very sad that such basic functionality doesn't work... Unfortunately, I can't commit to fixing it any time soon, and I doubt anyone else will either. (In reply to Alessandro Ferri from comment #20) > With the resample-method = src-sinc works with both bluetooth and > Shairport-sync. Ok, that's weird. That would point to the resampler being at fault after all. I'll get a Pi2 soon, I should try A2DP streaming with that. (In reply to Mike Brady from comment #28) > (In reply to Alessandro Ferri from comment #27) > > > Thanks for these. No promises, at least for a couple of weeks... > > > > Thanks again. I wait with impatience. If I can help you in some way, just > > say the word. > > Hi again. I spent a little time on this yesterday. It turns out that the > pulseaudio back end uses the 'simple' pulseaudio interface. The problem with > it is that the latency information it returns in the simple interface is > very inaccurate. Shairport Sync monitors the latency every time it adds a > packet of audio frame – i.e. about every 8 ms. Unfortunately, it seems that > the latency information is completely unreliable at this level of > interaction. > > So, getting a good quality pulseaudio system will essentially require a > complete rewrite of the backend to avoid using the 'simple' interface. It > might take some time ;) Hi again Mike, I saw that came out of the Relise 2.3.x and that you are editing many aspects of shairport sync. There is hope that you review latency and sync with pulseaudio? I also need to ask for clarification on file shairport-sync.conf. Where can I send the request? (In reply to Tanu Kaskinen from comment #30) > (In reply to Alessandro Ferri from comment #20) > > With the resample-method = src-sinc works with both bluetooth and > > Shairport-sync. > > Ok, that's weird. That would point to the resampler being at fault after all. > > I'll get a Pi2 soon, I should try A2DP streaming with that. Dear Tanu, I can control the latency of pulseaudio by file: daemon.conf system.pa client.conf and if I can configure the latency which setup should I have done? I need to increase the latency of about 756ms. (In reply to Alessandro Ferri from comment #32) > Dear Tanu, > I can control the latency of pulseaudio by file: > > daemon.conf > system.pa > client.conf > > and if I can configure the latency which setup should I have done? > I need to increase the latency of about 756ms. Sorry for a late reply, I haven't had time to read bugmail for a while. Are you loading module-loopback manually, or is it getting loaded automatically? If you're loading it manually, you can try using the latency_msec parameter of module-loopback. If module-loopback is getting loaded automatically, then it's not possible to control module-loopback's latency, because module-bluetooth-policy (which handles loading module-loopback) loads module-looback always with the default latency. You could modify system.pa to not load module-bluetooth-policy, and then load module-loopback manually, but manual loading may of course not be practical, if you have to do it every time you connect a bluetooth device... Another possibility might be to force the alsa sink latency to be higher. To try this, add tsched=no to module-udev-detect's parameters, and increase default-fragments and/or default-fragment-size-msec in daemon.conf (those parameters only have effect when tsched is disabled). |
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.