GNOME Bugzilla – Bug 577498
Please cleanup ALSA backend
Last modified: 2020-06-06 16:29:25 UTC
Please describe the problem: I while back I sent a private email to Damien and the other Ekiga folks regarding some issues in the ALSA backend for Ekiga/libpt. To make sure that things don't lost or are forgotten here are a few excerpts: <snip> That said it would be a good idea if Ekiga would stop enumerating raw kernel sound cards and instead use the name hinting API. Also you should play event sounds with libcanberra instead of rolling your own. libcanberra is a blessed gnome dependency and is both simpler and more powerful for doing event sounds. </snip> And more importantly: <snip> Yes. You shouldn't misuse the fragments logic of sound devices. It's like this: The latency is defined by the buffer size. The wakeup interval is defined by the fragment size. The buffer fill level will oscillate between 'full buffer' and 'full buffer minus 1x fragment size minus OS scheduling latency'. Setting smaller fragment sizes will increase the CPU load and decrease battery time since you force the CPU to wake up more often. OTOH it increases drop out safety, since you fill up playback buffer earlier. Choosing the fragment size is hence something which you should do balancing out your needs between power consumption and drop-out safety. With modern processors and a good OS scheduler like the Linux one setting the fragment size to anything other than half the buffer size does not make much sense. Your ALSA output is configured to set the the fragment size to the size of your codec audio frames. And that's a bad idea. Because the codec frame size has not been chosen based on power consumption or drop-out safety reasoning. It has been chosen by the codec designers based on different reasoning, such as latency. You probably configured your backend this ways because the ALSA library docs say that it is recommended to write to the sound card in multiples of the fragment size. However deducing from this that you hence should configure the fragment size to the codec frame size is wrong! The best way to implement playback these days for ALSA is to write as much as snd_pcm_avail() tells you to each time you wake up due to POLLOUT on the sound card. If that is not a multiple of your codec frame size then you need to buffer the the remainder of the decoded data yourself in system memory. The ALSA fragment size you should noirmally set as large as possible but that you have at least two fragments in your buffer size. I hope this explains a bit how frag_size/buffer_size should be chosen. If you have questions, just ask. (Oh, ALSA uses the term 'period' for what I call 'fragment' above. It's synonymous) </snip> Steps to reproduce: Actual results: Expected results: Does this happen every time? Other information:
Oh, and one addition: the code in PSoundChannelALSA::Write() is not particular nice code. Firstly, the error message "Could not write" will usually call snd_strerror() with r=0. Which makes it kind of a useless message. Then, simply looping that call on any error condition is really bad. Also, use snd_pcm_recover() instead of manually checking for errors and then calling _resume() or _prepare(). Please don't do busy loops.
You spoke about three things: - the first one "That said it would be a good idea if Ekiga would stop enumerating raw" - this is a good point. - the second one, "Yes. You shouldn't misuse the fragments logic of sound devices. It's", has been discussed in http://bugzilla.gnome.org/show_bug.cgi?id=572953 and has been forwarder, please comment there from now on. - the third one, please create a bug on ptlib/opal bug tracker on sourceforge (https://sourceforge.net/tracker/?group_id=204472&atid=989748).
Sorry for the double posting and this many-issues-in-one report! Sorry for the noise.
Alternativelly, I would gladly welcome help towards making the experimental gstreamer code work, as it would fix every problem at once for ekiga, by pushing things to a more widely shared piece of code (in gstreamer...).
Ekiga is not under active development anymore: https://gitlab.gnome.org/Infrastructure/Infrastructure/-/issues/273 Ekiga saw its last release 7 years ago. The last code commits were 4 years ago. Closing this report as WONTFIX as part of Bugzilla Housekeeping to reflect reality. Please feel free to reopen this ticket (and transfer the project to GNOME Gitlab, as GNOME Bugzilla is deprecated) if anyone takes the responsibility for active Ekiga development again in the future.