alsa: add option to disable mmap access mode

This commit is contained in:
Wim Taymans 2021-01-15 15:44:22 +01:00
parent 2ff4615e53
commit 482f96a644
5 changed files with 17 additions and 8 deletions

View file

@ -797,6 +797,8 @@ impl_init(const struct spa_handle_factory *factory,
this->default_period_size = atoi(info->items[i].value); this->default_period_size = atoi(info->items[i].value);
} else if (!strcmp(info->items[i].key, "api.alsa.headroom")) { } else if (!strcmp(info->items[i].key, "api.alsa.headroom")) {
this->default_headroom = atoi(info->items[i].value); this->default_headroom = atoi(info->items[i].value);
} else if (!strcmp(info->items[i].key, "api.alsa.disable-mmap")) {
this->disable_mmap = atoi(info->items[i].value);
} }
} }
return 0; return 0;

View file

@ -818,6 +818,8 @@ impl_init(const struct spa_handle_factory *factory,
this->default_period_size = atoi(info->items[i].value); this->default_period_size = atoi(info->items[i].value);
} else if (!strcmp(info->items[i].key, "api.alsa.headroom")) { } else if (!strcmp(info->items[i].key, "api.alsa.headroom")) {
this->default_headroom = atoi(info->items[i].value); this->default_headroom = atoi(info->items[i].value);
} else if (!strcmp(info->items[i].key, "api.alsa.disable-mmap")) {
this->disable_mmap = atoi(info->items[i].value);
} }
} }
return 0; return 0;

View file

@ -516,11 +516,17 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_
snd_pcm_access_mask_alloca(&amask); snd_pcm_access_mask_alloca(&amask);
snd_pcm_hw_params_get_access_mask(params, amask); snd_pcm_hw_params_get_access_mask(params, amask);
if ((err = snd_pcm_hw_params_set_access(hndl, params, state->use_mmap = !state->disable_mmap;
planar ? SND_PCM_ACCESS_MMAP_NONINTERLEAVED if (state->use_mmap) {
: SND_PCM_ACCESS_MMAP_INTERLEAVED)) < 0) { if ((err = snd_pcm_hw_params_set_access(hndl, params,
spa_log_debug(state->log, NAME" %p: MMAP not possible: %s", state, planar ? SND_PCM_ACCESS_MMAP_NONINTERLEAVED
snd_strerror(err)); : SND_PCM_ACCESS_MMAP_INTERLEAVED)) < 0) {
spa_log_debug(state->log, NAME" %p: MMAP not possible: %s", state,
snd_strerror(err));
state->use_mmap = false;
}
}
if (!state->use_mmap) {
if ((err = snd_pcm_hw_params_set_access(hndl, params, if ((err = snd_pcm_hw_params_set_access(hndl, params,
planar ? SND_PCM_ACCESS_RW_NONINTERLEAVED planar ? SND_PCM_ACCESS_RW_NONINTERLEAVED
: SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { : SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
@ -528,9 +534,6 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_
snd_strerror(err)); snd_strerror(err));
return err; return err;
} }
state->use_mmap = false;
} else {
state->use_mmap = true;
} }
/* disable ALSA wakeups, we use a timer */ /* disable ALSA wakeups, we use a timer */

View file

@ -116,6 +116,7 @@ struct state {
unsigned int default_channels; unsigned int default_channels;
unsigned int default_rate; unsigned int default_rate;
struct channel_map default_pos; struct channel_map default_pos;
unsigned int disable_mmap;
snd_pcm_uframes_t buffer_frames; snd_pcm_uframes_t buffer_frames;
snd_pcm_uframes_t period_frames; snd_pcm_uframes_t period_frames;

View file

@ -56,6 +56,7 @@ rules = [
#audio.position = "FL,FR" #audio.position = "FL,FR"
#api.alsa.period-size = 1024 #api.alsa.period-size = 1024
#api.alsa.headroom = 0 #api.alsa.headroom = 0
#api.alsa.disable-mmap = false
} }
} }
} }