alsa: add option to configure period-size

api.alsa.period-size can be set to something else than 1024 with
this config option.
This commit is contained in:
Wim Taymans 2021-01-05 12:44:10 +01:00
parent bad9a36a84
commit 87292432b7
4 changed files with 8 additions and 3 deletions

View file

@ -793,6 +793,8 @@ impl_init(const struct spa_handle_factory *factory,
spa_alsa_channel_from_name(p, len);
p += len + strspn(p+len, ",");
}
} else if (!strcmp(info->items[i].key, "api.alsa.period-size")) {
this->default_period_size = atoi(info->items[i].value);
}
}
return 0;

View file

@ -814,6 +814,8 @@ impl_init(const struct spa_handle_factory *factory,
spa_alsa_channel_from_name(p, len);
p += len + strspn(p+len, ",");
}
} else if (!strcmp(info->items[i].key, "api.alsa.period-size")) {
this->default_period_size = atoi(info->items[i].value);
}
}
return 0;

View file

@ -560,7 +560,7 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_
state->frame_size *= info->channels;
dir = 0;
period_size = 1024;
period_size = state->default_period_size ? state->default_period_size : 1024;
is_batch = snd_pcm_hw_params_is_batch(params);
if (is_batch) {
const char *id;
@ -577,8 +577,8 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_
/* batch devices get their hw pointers updated every period. Make
* the period smaller and add one period of headroom */
period_size /= 2;
spa_log_info(state->log, NAME" %s: batch mode, period_size:%ld headroom:%u",
state->props.device, period_size, state->headroom);
spa_log_info(state->log, NAME" %s: batch mode, period_size:%ld",
state->props.device, period_size);
}
CHECK(snd_pcm_hw_params_set_period_size_near(hndl, params, &period_size, &dir), "set_period_size_near");

View file

@ -110,6 +110,7 @@ struct state {
bool have_format;
struct spa_audio_info current_format;
uint32_t default_period_size;
uint32_t default_format;
unsigned int default_channels;
unsigned int default_rate;