summaryrefslogtreecommitdiffstats
path: root/plugins/alsa/alsa-core-ctl.c
diff options
context:
space:
mode:
authorThierry Bultel <thierry.bultel@iot.bzh>2018-07-20 13:02:37 +0200
committerThierry Bultel <thierry.bultel@iot.bzh>2018-07-20 13:02:37 +0200
commit1db355212e7d2d39e7cb150b83937200150477c9 (patch)
tree8b9fc75ccef47056c29a09d569a185f802907a97 /plugins/alsa/alsa-core-ctl.c
parent712b3a2cda69422931b26283054e476e3d554a06 (diff)
rework the sound capture & playback model
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>
Diffstat (limited to 'plugins/alsa/alsa-core-ctl.c')
-rw-r--r--plugins/alsa/alsa-core-ctl.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/plugins/alsa/alsa-core-ctl.c b/plugins/alsa/alsa-core-ctl.c
index dee8c0b..d128b6c 100644
--- a/plugins/alsa/alsa-core-ctl.c
+++ b/plugins/alsa/alsa-core-ctl.c
@@ -521,20 +521,22 @@ STATIC int CtlSubscribeEventCB(sd_event_source* src, int fd, uint32_t revents, v
for (index = 0; sndcard->registry[index]; index++) {
RegistryEntryPcmT * reg = sndcard->registry[index];
+ snd_pcm_t * pcm = reg->pcm->handle;
if (reg->numid == numid) {
int ret;
switch (reg->type) {
case FONTEND_NUMID_RUN:
- reg->pcm->mute = !value;
- ret = snd_pcm_pause(reg->pcm->handle, (int) (!value));
+ AlsaPcmCopyMuteSignal(mixer, reg->pcm, !value);
+ ret = snd_pcm_pause(pcm, (int) (!value));
AFB_ApiNotice(mixer->api, "%s:%s numid=%d name=%s active=%ld ret %d",
__func__, sHandle->uid, numid, name, value, ret);
if (ret < 0) {
AFB_ApiNotice(mixer->api, "%s error: %s", __func__, snd_strerror(ret));
}
+
break;
case FONTEND_NUMID_PAUSE:
- reg->pcm->mute = value;
+ AlsaPcmCopyMuteSignal(mixer, reg->pcm, value);
ret = snd_pcm_pause(reg->pcm->handle, (int) value);
AFB_ApiNotice(mixer->api, "%s:%s numid=%d name=%s pause=%ld ret %d",
__func__, sHandle->uid, numid, name, value, ret);