summaryrefslogtreecommitdiffstats
path: root/plugins/alsa/alsa-softmixer.h
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-softmixer.h
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-softmixer.h')
-rw-r--r--plugins/alsa/alsa-softmixer.h25
1 files changed, 17 insertions, 8 deletions
diff --git a/plugins/alsa/alsa-softmixer.h b/plugins/alsa/alsa-softmixer.h
index 8a8ad40..96df8f3 100644
--- a/plugins/alsa/alsa-softmixer.h
+++ b/plugins/alsa/alsa-softmixer.h
@@ -29,10 +29,12 @@
#include <alsa/asoundlib.h>
#include <stdbool.h>
#include <systemd/sd-event.h>
+#include <semaphore.h>
#include "ctl-plugin.h"
#include "wrap-json.h"
+#include "alsa-ringbuf.h"
#ifndef PUBLIC
#define PUBLIC
@@ -100,11 +102,14 @@ typedef struct {
typedef struct {
int ccount;
bool mute;
+ int muteFd;
AlsaDevInfoT cid;
snd_pcm_t *handle;
AlsaPcmHwInfoT *params;
void * mixer;
+
+ snd_pcm_uframes_t avail_min;
} AlsaPcmCtlT;
typedef struct {
@@ -115,24 +120,27 @@ typedef struct {
size_t frame_size;
snd_pcm_uframes_t latency; /* final latency in frames */
- unsigned int latency_reqtime; /* in us */
// IO Job
- void * buf;
- snd_pcm_uframes_t buf_count; /* filled samples */
- snd_pcm_uframes_t buf_pos; /* begin of data */
- snd_pcm_uframes_t buf_size; /* buffer size in frames */
+ alsa_ringbuf_t * rbuf;
+
uint32_t write_err_count;
uint32_t read_err_count;
unsigned int channels;
sd_event *sdLoop;
- pthread_t thread;
+
+ pthread_t rthread;
+ pthread_t wthread;
+
int tid;
char* info;
- struct pollfd * pollFds;
- int pcmInCount;
+ struct pollfd pollFds[2];
+
+ sem_t sem;
+ pthread_mutex_t mutex;
+ int saveFd;
} AlsaPcmCopyHandleT;
@@ -287,6 +295,7 @@ PUBLIC int AlsaPcmCopy(SoftMixerT *mixer, AlsaStreamAudioT *stream, AlsaPcmCtlT
// alsa-plug-*.c _snd_pcm_PLUGIN_open_ see macro ALSA_PLUG_PROTO(plugin)
PUBLIC int AlsaPcmCopy(SoftMixerT *mixer, AlsaStreamAudioT *streamAudio, AlsaPcmCtlT *pcmIn, AlsaPcmCtlT *pcmOut, AlsaPcmHwInfoT * opts);
+PUBLIC int AlsaPcmCopyMuteSignal(SoftMixerT *mixer, AlsaPcmCtlT *pcmIn, bool mute);
PUBLIC AlsaPcmCtlT* AlsaCreateSoftvol(SoftMixerT *mixer, AlsaStreamAudioT *stream, char *slaveid, AlsaSndCtlT *sndcard, char* ctlName, int max, int open);
PUBLIC AlsaPcmCtlT* AlsaCreateRoute(SoftMixerT *mixer, AlsaSndZoneT *zone, int open);
PUBLIC AlsaPcmCtlT* AlsaCreateRate(SoftMixerT *mixer, const char* pcmName, AlsaPcmCtlT *pcmSlave, AlsaPcmHwInfoT *params, int open);