aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/alsa/alsa-core-pcm.c
AgeCommit message (Collapse)AuthorFilesLines
2019-05-13core-pcm: fixed channels setting issuesThierry Bultel1-9/+16
Recent tries on the minnow board have show that the setting of channels on a PCM must be done -after- the setting of the rate. When not doing that, there can be issues (really, complicated to find) around the boundaries values (open intervals) on the period bytes. Additionally, the number of channels can now be forced in the json file. Change-Id: I2c20853daadf9ccab06be6e04d1a185440f57780 Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
2019-05-13core pcm: use the same model for writing and reading audioThierry Bultel1-65/+172
Reading sound frames relies on usage of poll before calling snd_pcm_writei Recent seeks for bugs and CPU load issues have shown that the same thing must be done on the write side. Thus this commit uses the same mechanism, including the dedicated event pipe for the thread termination. Change-Id: Ifd5407c9e27da7801623583a6f7d4a2e845b43ea Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
2018-12-22Implemented the bug cleanup at application exitStephane Desneux1-3/+21
Fixes most memory leaks in softmixer. The concept of 'transaction' for dynamic streams has been generalized to the objects created at startup. The cleanup is done via a handle set through a atexit() call. Also added a missing strdup in alsa-api-loop, that fixes a double free. Warning, the bluez-alsa PCM are not closed in this version. This is intentional due to a BUG in the bluealsa ioplug PCM, that crashes upon close (pthread_cancel is used to terminate the io_thread and things get very bad. I have a pending fix for that, relying on a cancellation pipe, but deeper testing must be done). As an effect, only one phone call can be made, else 4a needs to be restarted Change-Id: Idb84cafe15f17c0ef02fcc70296d541dc55a2dcf Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh> Signed-off-by: Stephane Desneux <stephane.desneux@iot.bzh>
2018-12-19Add support for bluetooth telephonyguppy_6.99.3guppy/6.99.36.99.3Thierry Bultel1-115/+192
This adds support for bluetooth telephony. A big rework in the softmixer internals has been mandatory, in order to support dynamic streams creation and deletions. Bluetooth telephony relies on the recent evolutions of bluez-alsa, the most important one being the support of HFP over Ofono. The softmixer opens PCM ioplugs provided by bluez-alsa. Bluetooth SCO needs 2 streams, one for listening and the other for talking. These streams are created upon requests sent by the hal-manager. The hal manager subscribes for bluez-alsa events and request the list of availalble transports. For each "attach" transaction verb, the softmixer maintains a list of the all created objects (sources, sinks, zones, ramps, streams, and more) Additionnally, it creates a new verb when the attach succeeds, that verb is typically something like "sco_XX:XX:XX:XX:XX:XX", and the only supported action at the present time is {"action":"remove"}, that performs all the cleanup of the registered objects. Change-Id: I1b119e6c079e60daf771e63c083a1ef33a39f379 Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
2018-11-13remove dead code and renamed unobvious variables6.9.0Thierry Bultel1-45/+35
Changed the ringbuffer "xxx_free" function to something more explicit, because it does not free anything. Changed "single letter" variables to nicer names Change-Id: I000c57aa5cc684d387105441889e011a45a6ccf3 Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
2018-11-07Handle too small card PCM buffer when writingJonathan Aillet1-1/+15
In the writing thread, handle the case when 'writing threshold' was smaller than ALSA sound card's PCM buffer (defined in the driver). This avoids waiting indefinitely for a buffer to contain a wanted number of frames that it cannot contain. Change-Id: Ie1aa69ea1a93471ed46d571c669ec08a1b827476 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
2018-11-07Tweaking debug printsJonathan Aillet1-11/+11
Replace some 'printf' by application framework debug functions. Improve 'ALSA_PCM_UID' macro. Correct minor errors in debug prints. Change-Id: I49899fd904d42b5b3bec46017eb319ed7d321dc5 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
2018-11-07alsa-core-pcm: fixed the mute logicThierry Bultel1-4/+6
This fixes the mute/unmute logic. This was broken due to a forgotten push for a commit Change-Id: I6cbdedefc11ebd508d30ece71df364d9b69c74f0 Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
2018-10-16Lower the verbosity when not in debug levelThierry Bultel1-2/+2
There were too many things printed in notice mode. Change-Id: Ia7841e219cb2e9ca71e0c4436a2048a812ef6b07 Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
2018-09-07fixed crash upon misconfiguration of capture/playback devicesThierry Bultel1-4/+4
The null pcmplug case was not correctly handled in various places. Also fixed some typos in the log Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
2018-08-31Added bluez sound playback supportThierry Bultel1-22/+46
This adds sound playback for incoming sound from connected bluetooth devices. In this version, the softmixer relies on a modified bluez-alsa version (https://github.com/iotbzh/bluez-alsa), that provides an ioplug PCM bluezalsa connection proxy. The softmixer api has a new verb to dynamically set the device to listen to: afb-client-demo ws://localhost:1234/api?token=\uuid=123 smixer bluezalsa_dev '{"interface":"hci0", "device":"F6:32:15:2A:80:70", "profile":"a2dp"}' In this way it is possible to switch from a bluezalsa audio source to another without any further configuration. For now, only interface hci0 is supported. This commit also migrates the softmixer binding to API v3 Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
2018-07-26Reduce verbosity of message "readThreadEntry..."Stephane Desneux1-6/+6
Moves the log level of the message from info to debug. Change-Id: I348421a17875b9061255c3b353e27070b0068c3b Signed-off-by: Stephane Desneux <stephane.desneux@iot.bzh>
2018-07-20rework the sound capture & playback modelThierry Bultel1-242/+301
Now uses two threads for in the playing loop The first one reads from the capture device (ie, a phys. capture, or snd_aloop) and writes data to a circular buffer. The second one gets data from the circular buffer and outputs it to the playback. This model solves a lot of correlated timing bugs between read & write tasks. The read tasks only wakes up the write task when the buffer is 80% full. The buffer size big enough to hold 2 seconds of sound. The mute implementation has also been simplified, since it has been found out that it was possible to recover from an interrupted read, by calling snd_pcm_start additionnally to snd_pcm_prepare. Thus, the mute code consists in listening to an extra file descriptor in the read loop. Reading from that descriptor gives the mute or unmute command sent at higher level (in the PCM control event callback). When a 'mute' order is get, the capture sound fd is simply backup and replaced by '-1' in the set of the poll of the read task. When a 'unmute' order is get, the fd is simply restored. The start threshold is only computed for capture, and hardcoded to 1 for playback. This removes most of the remaining EPIPE on playback. The stop threshold has been removed. It had bad side effects on the amount of writeable data returned by snd_pcm_avail_update (was returning too small chunks) Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
2018-07-17alsa-core-pcm: sets sw start & stop thresholdsThierry Bultel1-12/+90
Uses the same logic as 'aplay' to set the start & stop thresholds. With this fix, there are no more periodic EPIPE errors when writing to playback Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
2018-07-11stops the read/write loop when the stream is mutedThierry Bultel1-32/+138
when the stream is muted (due to the configuration, or due to a HAL request), the read/write loop is stopped. The benefit is that muting will work with capture devices that do not implement the mute in their driver. The inconvenient of stopping the read loop is that it has made appear an unexpected side-effect: the poll on capture does not trig for further incoming frames. The workaround is to completely close, then reopen and configure the capture PCM. Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
2018-06-26Rework the pcm copy loop and save a lot of CPUeelThierry Bultel1-140/+180
- removed the systemd polling usage - uses a while loop for reading - improved the write loop, leveraging the available space at each iteration Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
2018-06-22pcm core: fixed spurious XRUN issuesThierry Bultel1-87/+241
This fixes the numerous XRUN issues seen on some cards. The trick is to set the buffer_size & period size in hw parameters. These ones are calculated from an expected maximum latency. Also, the writei is done in a loop to be robust to overruns and partial writes. Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
2018-06-10Cleanup and added return of previous volume when setting new valuefulup1-2/+2
2018-06-07Code cleanup and fixed some typosThierry Bultel1-1/+3
Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
2018-06-06Move PCM write to synchronous write to remove XRUNfulup1-1/+1
2018-06-06Fixed the buffer copy size in read callbackThierry Bultel1-3/+5
Fixes the UNDERRUN issue (seen while playing radio, for instance) Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
2018-06-05Update info command and move HTML5 to new APIfulup1-2/+2
2018-06-04Move to Dynamic Mixer API (work in progress)Fulup Ar Foll1-46/+57
2018-05-18Implements volume rampingFulup Ar Foll1-19/+13
2018-05-13First testable version.Fulup Ar Foll1-17/+12
Mixing with volume and mute per audio role works.
2018-05-13Initial version with softvol,Route,Multi,DmixFulup Ar Foll1-10/+10
2018-05-11Initial version with softvol control and DMIXFulup Ar Foll1-0/+357