mirror of
https://gitlab.freedesktop.org/pipewire/pipewire
synced 2024-10-15 04:12:29 +00:00
alsa-seq: avoid division by 0
Make sure the rate in the state is updated in all cases and make sure that it never has anything with a 0 in it to avoid division by zero.
This commit is contained in:
parent
0e066e44fe
commit
71879961db
|
@ -702,6 +702,21 @@ static int process_write(struct seq_state *state)
|
|||
return res;
|
||||
}
|
||||
|
||||
static void update_position(struct seq_state *state)
|
||||
{
|
||||
if (state->position) {
|
||||
struct spa_io_clock *clock = &state->position->clock;
|
||||
state->rate = clock->rate;
|
||||
if (state->rate.num == 0 || state->rate.denom == 0)
|
||||
state->rate = SPA_FRACTION(1, 48000);
|
||||
state->duration = clock->duration;
|
||||
} else {
|
||||
state->rate = SPA_FRACTION(1, 48000);
|
||||
state->duration = 1024;
|
||||
}
|
||||
state->threshold = state->duration;
|
||||
}
|
||||
|
||||
static int update_time(struct seq_state *state, uint64_t nsec, bool follower)
|
||||
{
|
||||
snd_seq_queue_status_t *status;
|
||||
|
@ -710,16 +725,6 @@ static int update_time(struct seq_state *state, uint64_t nsec, bool follower)
|
|||
double err, corr;
|
||||
uint64_t queue_elapsed;
|
||||
|
||||
if (state->position) {
|
||||
struct spa_io_clock *clock = &state->position->clock;
|
||||
state->rate = clock->rate;
|
||||
state->duration = clock->duration;
|
||||
} else {
|
||||
state->rate = SPA_FRACTION(1, 48000);
|
||||
state->duration = 1024;
|
||||
}
|
||||
state->threshold = state->duration;
|
||||
|
||||
corr = 1.0 - (state->dll.z2 + state->dll.z3);
|
||||
|
||||
/* take queue time */
|
||||
|
@ -776,6 +781,8 @@ int spa_alsa_seq_process(struct seq_state *state)
|
|||
{
|
||||
int res;
|
||||
|
||||
update_position(state);
|
||||
|
||||
res = process_recycle(state);
|
||||
|
||||
if (state->following && state->position) {
|
||||
|
@ -800,6 +807,8 @@ static void alsa_on_timeout_event(struct spa_source *source)
|
|||
|
||||
spa_log_trace(state->log, "timeout %"PRIu64, state->current_time);
|
||||
|
||||
update_position(state);
|
||||
|
||||
update_time(state, state->current_time, false);
|
||||
|
||||
res = process_read(state);
|
||||
|
@ -878,15 +887,7 @@ int spa_alsa_seq_start(struct seq_state *state)
|
|||
while (snd_seq_drain_output(state->event.hndl) > 0)
|
||||
sleep(1);
|
||||
|
||||
if (state->position) {
|
||||
struct spa_io_clock *clock = &state->position->clock;
|
||||
state->rate = clock->rate;
|
||||
state->duration = clock->duration;
|
||||
} else {
|
||||
state->rate = SPA_FRACTION(1, 48000);
|
||||
state->duration = 1024;
|
||||
}
|
||||
state->threshold = state->duration;
|
||||
update_position(state);
|
||||
|
||||
state->started = true;
|
||||
|
||||
|
|
Loading…
Reference in a new issue