summaryrefslogtreecommitdiffstats
path: root/plugins/alsa/alsa-softmixer.h
diff options
context:
space:
mode:
authorThierry Bultel <thierry.bultel@iot.bzh>2018-06-22 17:11:38 +0200
committerThierry Bultel <thierry.bultel@iot.bzh>2018-06-22 17:17:17 +0200
commitb124cc00e9714ac20fdf96f480fc7f08e06a2150 (patch)
tree9ef21b4aafe0164f7e9e1df078f73cda8e221f13 /plugins/alsa/alsa-softmixer.h
parentaa13829d133356cd5dabbfacc6127ae9368233fc (diff)
pcm core: fixed spurious XRUN issues
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>
Diffstat (limited to 'plugins/alsa/alsa-softmixer.h')
-rw-r--r--plugins/alsa/alsa-softmixer.h24
1 files changed, 16 insertions, 8 deletions
diff --git a/plugins/alsa/alsa-softmixer.h b/plugins/alsa/alsa-softmixer.h
index f435b3f..6c1519d 100644
--- a/plugins/alsa/alsa-softmixer.h
+++ b/plugins/alsa/alsa-softmixer.h
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <assert.h>
#include <alsa/asoundlib.h>
+#include <stdbool.h>
#include "ctl-plugin.h"
#include "wrap-json.h"
@@ -44,7 +45,7 @@
#define MAINLOOP_WATCHDOG 30000
#define ALSA_DEFAULT_PCM_RATE 48000
#define ALSA_DEFAULT_PCM_VOLUME 80
-#define ALSA_BUFFER_FRAMES_COUNT 1024
+
#define ALSA_CARDID_MAX_LEN 64
@@ -82,14 +83,22 @@ typedef struct {
snd_pcm_t *pcmOut;
AFB_ApiT api;
sd_event_source* evtsrc;
- void* buffer;
- size_t frameSize;
- unsigned int frameCount;
+
+ 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_size; /* buffer size in frames */
+
unsigned int channels;
sd_event *sdLoop;
pthread_t thread;
int tid;
char* info;
+
} AlsaPcmCopyHandleT;
typedef struct {
@@ -137,6 +146,7 @@ typedef struct {
AlsaDevInfoT cid;
snd_pcm_t *handle;
AlsaPcmHwInfoT *params;
+ uint32_t avail_min;
} AlsaPcmCtlT;
typedef struct {
@@ -258,12 +268,10 @@ PUBLIC int AlsaCtlSubscribe(SoftMixerT *mixer, const char *uid, AlsaSndCtlT *snd
PUBLIC int AlsaCtlRegister(SoftMixerT *mixer, AlsaSndCtlT *sndcard, AlsaPcmCtlT *pcmdev, RegistryNumidT type, int numid);
// alsa-core-pcm.c
-PUBLIC int AlsaPcmConf(SoftMixerT *mixer, AlsaPcmCtlT *pcm, AlsaPcmHwInfoT *opts);
+PUBLIC int AlsaPcmConf(SoftMixerT *mixer, AlsaPcmCtlT *pcm, AlsaPcmHwInfoT *opts, int mode);
PUBLIC int AlsaPcmCopy(SoftMixerT *mixer, AlsaStreamAudioT *stream, AlsaPcmCtlT *pcmIn, AlsaPcmCtlT *pcmOut, AlsaPcmHwInfoT * opts);
-
// alsa-plug-*.c _snd_pcm_PLUGIN_open_ see macro ALSA_PLUG_PROTO(plugin)
-PUBLIC int AlsaPcmConf(SoftMixerT *mixer, AlsaPcmCtlT *pcm, AlsaPcmHwInfoT *opts);
PUBLIC int AlsaPcmCopy(SoftMixerT *mixer, AlsaStreamAudioT *streamAudio, AlsaPcmCtlT *pcmIn, AlsaPcmCtlT *pcmOut, AlsaPcmHwInfoT * opts);
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);
@@ -290,4 +298,4 @@ PUBLIC int ApiZoneAttach(SoftMixerT *mixer, AFB_ReqT request, const char *uid, j
PUBLIC AlsaVolRampT *ApiRampGetByUid(SoftMixerT *mixer, const char *uid);
PUBLIC int AlsaVolRampApply(SoftMixerT *mixer, AlsaSndCtlT *sndcard, AlsaStreamAudioT *stream, json_object *rampJ);
-#endif \ No newline at end of file
+#endif