This fixes assertion failures that manifest themselves with cards that support only weird rates such as 37286Hz. Tested with snd-pcsp. Signed-off-by: Alexander E. Patrakov <patrakov at gmail.com> BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=48109 --- src/daemon/daemon-conf.c | 6 ++---- src/modules/dbus/iface-core.c | 6 ++---- src/pulsecore/modargs.c | 3 --- src/pulsecore/sink.c | 32 ++++++++++++++------------------ src/pulsecore/source.c | 32 ++++++++++++++------------------ 5 files changed, 32 insertions(+), 47 deletions(-) diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index ce777a6..d0e177c 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -345,8 +345,7 @@ static int parse_sample_rate(pa_config_parser_state *state) { c = state->data; - if (pa_atou(state->rvalue, &r) < 0 || !pa_sample_rate_valid(r) || - !((r % 4000 == 0) || (r % 11025 == 0))) { + if (pa_atou(state->rvalue, &r) < 0 || !pa_sample_rate_valid(r)) { pa_log(_("[%s:%u] Invalid sample rate '%s'."), state->filename, state->lineno, state->rvalue); return -1; } @@ -363,8 +362,7 @@ static int parse_alternate_sample_rate(pa_config_parser_state *state) { c = state->data; - if (pa_atou(state->rvalue, &r) < 0 || !pa_sample_rate_valid(r) || - !((r % 4000==0) || (r % 11025 == 0))) { + if (pa_atou(state->rvalue, &r) < 0 || !pa_sample_rate_valid(r)) { pa_log(_("[%s:%u] Invalid sample rate '%s'."), state->filename, state->lineno, state->rvalue); return -1; } diff --git a/src/modules/dbus/iface-core.c b/src/modules/dbus/iface-core.c index c7853cc..90f862e 100644 --- a/src/modules/dbus/iface-core.c +++ b/src/modules/dbus/iface-core.c @@ -544,8 +544,7 @@ static void handle_set_default_sample_rate(DBusConnection *conn, DBusMessage *ms dbus_message_iter_get_basic(iter, &default_sample_rate); - if (!pa_sample_rate_valid(default_sample_rate) || - !((default_sample_rate % 4000 == 0) || (default_sample_rate % 11025 == 0))) { + if (!pa_sample_rate_valid(default_sample_rate)) { pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Invalid sample rate."); return; } @@ -579,8 +578,7 @@ static void handle_set_alternate_sample_rate(DBusConnection *conn, DBusMessage * dbus_message_iter_get_basic(iter, &alternate_sample_rate); - if (!pa_sample_rate_valid(alternate_sample_rate) || - !((alternate_sample_rate % 4000 == 0) || (alternate_sample_rate % 11025 == 0))) { + if (!pa_sample_rate_valid(alternate_sample_rate)) { pa_dbus_send_error(conn, msg, DBUS_ERROR_INVALID_ARGS, "Invalid sample rate."); return; } diff --git a/src/pulsecore/modargs.c b/src/pulsecore/modargs.c index a9c4e10..01ba5e4 100644 --- a/src/pulsecore/modargs.c +++ b/src/pulsecore/modargs.c @@ -418,9 +418,6 @@ int pa_modargs_get_alternate_sample_rate(pa_modargs *ma, uint32_t *alternate_rat !pa_sample_rate_valid(*alternate_rate)) return -1; - if (!((rate_local % 4000 == 0) || (rate_local % 11025 == 0))) - return -1; - *alternate_rate = rate_local; return 0; diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index fbb14d2..ccf6ea1 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -1387,7 +1387,8 @@ int pa_sink_update_rate(pa_sink *s, uint32_t rate, bool passthrough) { uint32_t alternate_rate = s->alternate_sample_rate; uint32_t idx; pa_sink_input *i; - bool use_alternate = false; + bool default_rate_is_usable = false; + bool alternate_rate_is_usable = false; if (rate == s->sample_spec.rate) return 0; @@ -1396,7 +1397,7 @@ int pa_sink_update_rate(pa_sink *s, uint32_t rate, bool passthrough) { return -1; if (PA_UNLIKELY(default_rate == alternate_rate && !passthrough)) { - pa_log_debug("Default and alternate sample rates are the same."); + pa_log_debug("Default and alternate sample rates are the same, so there is no point in switching."); return -1; } @@ -1416,25 +1417,20 @@ int pa_sink_update_rate(pa_sink *s, uint32_t rate, bool passthrough) { if (PA_UNLIKELY(!pa_sample_rate_valid(desired_rate))) return -1; - if (!passthrough) { - pa_assert((default_rate % 4000 == 0) || (default_rate % 11025 == 0)); - pa_assert((alternate_rate % 4000 == 0) || (alternate_rate % 11025 == 0)); - - if (default_rate % 11025 == 0) { - if ((alternate_rate % 4000 == 0) && (desired_rate % 4000 == 0)) - use_alternate=true; - } else { - /* default is 4000 multiple */ - if ((alternate_rate % 11025 == 0) && (desired_rate % 11025 == 0)) - use_alternate=true; - } - - if (use_alternate) + if (!passthrough && default_rate != desired_rate && alternate_rate != desired_rate) { + if (default_rate % 11025 == 0 && desired_rate % 11025 == 0) + default_rate_is_usable = true; + if (default_rate % 4000 == 0 && desired_rate % 4000 == 0) + default_rate_is_usable = true; + if (alternate_rate && alternate_rate % 11025 == 0 && desired_rate % 11025 == 0) + alternate_rate_is_usable = true; + if (alternate_rate && alternate_rate % 4000 == 0 && desired_rate % 4000 == 0) + alternate_rate_is_usable = true; + + if (alternate_rate_is_usable && !default_rate_is_usable) desired_rate = alternate_rate; else desired_rate = default_rate; - } else { - desired_rate = rate; /* use stream sampling rate, discard default/alternate settings */ } if (desired_rate == s->sample_spec.rate) diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index 61d42fa..d2b8375 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -975,7 +975,8 @@ int pa_source_update_rate(pa_source *s, uint32_t rate, bool passthrough) { uint32_t desired_rate = rate; uint32_t default_rate = s->default_sample_rate; uint32_t alternate_rate = s->alternate_sample_rate; - bool use_alternate = false; + bool default_rate_is_usable = false; + bool alternate_rate_is_usable = false; if (rate == s->sample_spec.rate) return 0; @@ -984,7 +985,7 @@ int pa_source_update_rate(pa_source *s, uint32_t rate, bool passthrough) { return -1; if (PA_UNLIKELY(default_rate == alternate_rate && !passthrough)) { - pa_log_debug("Default and alternate sample rates are the same."); + pa_log_debug("Default and alternate sample rates are the same, so there is no point in switching."); return -1; } @@ -1004,25 +1005,20 @@ int pa_source_update_rate(pa_source *s, uint32_t rate, bool passthrough) { if (PA_UNLIKELY(!pa_sample_rate_valid(desired_rate))) return -1; - if (!passthrough) { - pa_assert((default_rate % 4000 == 0) || (default_rate % 11025 == 0)); - pa_assert((alternate_rate % 4000 == 0) || (alternate_rate % 11025 == 0)); - - if (default_rate % 11025 == 0) { - if ((alternate_rate % 4000 == 0) && (desired_rate % 4000 == 0)) - use_alternate=true; - } else { - /* default is 4000 multiple */ - if ((alternate_rate % 11025 == 0) && (desired_rate % 11025 == 0)) - use_alternate=true; - } - - if (use_alternate) + if (!passthrough && default_rate != desired_rate && alternate_rate != desired_rate) { + if (default_rate % 11025 == 0 && desired_rate % 11025 == 0) + default_rate_is_usable = true; + if (default_rate % 4000 == 0 && desired_rate % 4000 == 0) + default_rate_is_usable = true; + if (alternate_rate && alternate_rate % 11025 == 0 && desired_rate % 11025 == 0) + alternate_rate_is_usable = true; + if (alternate_rate && alternate_rate % 4000 == 0 && desired_rate % 4000 == 0) + alternate_rate_is_usable = true; + + if (alternate_rate_is_usable && !default_rate_is_usable) desired_rate = alternate_rate; else desired_rate = default_rate; - } else { - desired_rate = rate; /* use stream sampling rate, discard default/alternate settings */ } if (desired_rate == s->sample_spec.rate) -- 1.9.3