mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-18 07:00:06 -05: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
1 changed files with 20 additions and 19 deletions
|
|
@ -702,6 +702,21 @@ static int process_write(struct seq_state *state)
|
||||||
return res;
|
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)
|
static int update_time(struct seq_state *state, uint64_t nsec, bool follower)
|
||||||
{
|
{
|
||||||
snd_seq_queue_status_t *status;
|
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;
|
double err, corr;
|
||||||
uint64_t queue_elapsed;
|
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);
|
corr = 1.0 - (state->dll.z2 + state->dll.z3);
|
||||||
|
|
||||||
/* take queue time */
|
/* take queue time */
|
||||||
|
|
@ -776,6 +781,8 @@ int spa_alsa_seq_process(struct seq_state *state)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
|
update_position(state);
|
||||||
|
|
||||||
res = process_recycle(state);
|
res = process_recycle(state);
|
||||||
|
|
||||||
if (state->following && state->position) {
|
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);
|
spa_log_trace(state->log, "timeout %"PRIu64, state->current_time);
|
||||||
|
|
||||||
|
update_position(state);
|
||||||
|
|
||||||
update_time(state, state->current_time, false);
|
update_time(state, state->current_time, false);
|
||||||
|
|
||||||
res = process_read(state);
|
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)
|
while (snd_seq_drain_output(state->event.hndl) > 0)
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
if (state->position) {
|
update_position(state);
|
||||||
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;
|
|
||||||
|
|
||||||
state->started = true;
|
state->started = true;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue