plugins: simplify target_ handling

Drivers should only read the target_ values in the timeout, update the
timeout with the new duration and then update the position.

For the position we simply need to add the previous duration to the
position and then set the new duration + rate.

Otherwise, everything else should read the duration/rate and not use
the target_ values.
This commit is contained in:
Wim Taymans 2023-03-24 11:20:01 +01:00
parent f309543810
commit 7b6680ba57
13 changed files with 132 additions and 154 deletions

View file

@ -682,15 +682,6 @@ static int process_write(struct seq_state *state)
return res;
}
static void update_target(struct seq_state *state)
{
if (SPA_LIKELY(state->position)) {
struct spa_io_clock *clock = &state->position->clock;
clock->duration = clock->target_duration;
clock->rate = clock->target_rate;
}
}
static void update_position(struct seq_state *state)
{
if (SPA_LIKELY(state->position)) {
@ -753,7 +744,8 @@ static int update_time(struct seq_state *state, uint64_t nsec, bool follower)
if (!follower && state->clock) {
state->clock->nsec = nsec;
state->clock->position += state->duration;
state->clock->rate = state->rate;
state->clock->position += state->clock->duration;
state->clock->duration = state->duration;
state->clock->delay = state->duration * corr;
state->clock->rate_diff = corr;
@ -798,13 +790,21 @@ static void alsa_on_timeout_event(struct spa_source *source)
}
}
update_target(state);
state->current_time = state->next_time;
spa_log_trace(state->log, "timeout %"PRIu64, state->current_time);
update_position(state);
if (SPA_LIKELY(state->position)) {
struct spa_io_clock *clock = &state->position->clock;
state->rate = clock->target_rate;
if (state->rate.num == 0 || state->rate.denom == 0)
state->rate = SPA_FRACTION(1, 48000);
state->duration = clock->target_duration;
} else {
state->rate = SPA_FRACTION(1, 48000);
state->duration = 1024;
}
state->threshold = state->duration;
update_time(state, state->current_time, false);