mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
alsa: reflow some code
Move common code outside the if branches. Only do the batch and timer stuff when using timers.
This commit is contained in:
parent
dbd97020da
commit
d08d05629b
1 changed files with 17 additions and 21 deletions
|
|
@ -1645,31 +1645,27 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_
|
||||||
|
|
||||||
dir = 0;
|
dir = 0;
|
||||||
period_size = state->default_period_size;
|
period_size = state->default_period_size;
|
||||||
is_batch = snd_pcm_hw_params_is_batch(params) &&
|
is_batch = snd_pcm_hw_params_is_batch(params) && !state->disable_batch;
|
||||||
!state->disable_batch;
|
|
||||||
|
|
||||||
/* no period size specified. If we are batch or not using timers,
|
/* no period size specified. If we are batch or not using timers,
|
||||||
* use the graph duration as the period */
|
* use the graph duration as the period */
|
||||||
if (period_size == 0 && (is_batch || state->disable_tsched))
|
if (period_size == 0 && (is_batch || state->disable_tsched))
|
||||||
period_size = state->position ? state->position->clock.duration : DEFAULT_PERIOD;
|
period_size = state->position ? state->position->clock.target_duration : DEFAULT_PERIOD;
|
||||||
|
if (period_size == 0)
|
||||||
|
period_size = DEFAULT_PERIOD;
|
||||||
|
|
||||||
if (is_batch) {
|
if (!state->disable_tsched) {
|
||||||
if (period_size == 0)
|
if (is_batch) {
|
||||||
period_size = DEFAULT_PERIOD;
|
/* batch devices get their hw pointers updated every period. Make
|
||||||
/* batch devices get their hw pointers updated every period. Make
|
* the period smaller and add one period of headroom. Limit the
|
||||||
* the period smaller and add one period of headroom. Limit the
|
* period size to our default so that we don't create too much
|
||||||
* period size to our default so that we don't create too much
|
* headroom. */
|
||||||
* headroom. */
|
|
||||||
if (!state->disable_tsched)
|
|
||||||
period_size = SPA_MIN(period_size, DEFAULT_PERIOD) / 2;
|
period_size = SPA_MIN(period_size, DEFAULT_PERIOD) / 2;
|
||||||
spa_log_info(state->log, "%s: batch mode, period_size:%ld",
|
} else {
|
||||||
state->props.device, period_size);
|
/* disable ALSA wakeups */
|
||||||
} else {
|
if (snd_pcm_hw_params_can_disable_period_wakeup(params))
|
||||||
if (period_size == 0)
|
CHECK(snd_pcm_hw_params_set_period_wakeup(hndl, params, 0), "set_period_wakeup");
|
||||||
period_size = DEFAULT_PERIOD;
|
}
|
||||||
/* disable ALSA wakeups, if we use a timer */
|
|
||||||
if (!state->disable_tsched && snd_pcm_hw_params_can_disable_period_wakeup(params))
|
|
||||||
CHECK(snd_pcm_hw_params_set_period_wakeup(hndl, params, 0), "set_period_wakeup");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK(snd_pcm_hw_params_set_period_size_near(hndl, params, &period_size, &dir), "set_period_size_near");
|
CHECK(snd_pcm_hw_params_set_period_size_near(hndl, params, &period_size, &dir), "set_period_size_near");
|
||||||
|
|
@ -1729,7 +1725,7 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_
|
||||||
|
|
||||||
spa_log_info(state->log, "%s (%s): format:%s access:%s-%s rate:%d channels:%d "
|
spa_log_info(state->log, "%s (%s): format:%s access:%s-%s rate:%d channels:%d "
|
||||||
"buffer frames %lu, period frames %lu, periods %u, frame_size %zd "
|
"buffer frames %lu, period frames %lu, periods %u, frame_size %zd "
|
||||||
"headroom %u start-delay:%u tsched:%u",
|
"headroom %u start-delay:%u batch:%u tsched:%u",
|
||||||
state->props.device,
|
state->props.device,
|
||||||
state->stream == SND_PCM_STREAM_CAPTURE ? "capture" : "playback",
|
state->stream == SND_PCM_STREAM_CAPTURE ? "capture" : "playback",
|
||||||
snd_pcm_format_name(state->format),
|
snd_pcm_format_name(state->format),
|
||||||
|
|
@ -1737,7 +1733,7 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_
|
||||||
planar ? "planar" : "interleaved",
|
planar ? "planar" : "interleaved",
|
||||||
state->rate, state->channels, state->buffer_frames, state->period_frames,
|
state->rate, state->channels, state->buffer_frames, state->period_frames,
|
||||||
periods, state->frame_size, state->headroom, state->start_delay,
|
periods, state->frame_size, state->headroom, state->start_delay,
|
||||||
!state->disable_tsched);
|
is_batch, !state->disable_tsched);
|
||||||
|
|
||||||
/* write the parameters to device */
|
/* write the parameters to device */
|
||||||
CHECK(snd_pcm_hw_params(hndl, params), "set_hw_params");
|
CHECK(snd_pcm_hw_params(hndl, params), "set_hw_params");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue