if (s->update_rate(s, desired_rate) == TRUE) {
/* update monitor source as well */
- if (s->monitor_source)
- pa_source_update_rate(s->monitor_source, desired_rate);
+ if (s->monitor_source && !passthrough)
+ pa_source_update_rate(s->monitor_source, desired_rate, FALSE);
pa_log_info("Changed sampling rate successfully");
return TRUE;
}
module-suspend-on-idle can resume a source */
pa_log_info("Trying to change sample rate");
- pa_source_update_rate(data->source, data->sample_spec.rate);
+ if (pa_source_update_rate(data->source, data->sample_spec.rate, pa_source_output_new_data_is_passthrough(data)) == TRUE)
+ pa_log_info("Rate changed to %u kHz",
+ data->source->sample_spec.rate);
+ else
+ pa_log_info("Resampling enabled to %u kHz", data->source->sample_spec.rate);
}
if (data->resample_method == PA_RESAMPLER_INVALID)
SOURCE_OUTPUT_MOVE_FINISH hook */
pa_log_info("Trying to change sample rate");
- if (pa_source_update_rate(dest, o->sample_spec.rate) == TRUE)
+ if (pa_source_update_rate(dest, o->sample_spec.rate, pa_source_output_is_passthrough(o)) == TRUE)
pa_log_info("Rate changed to %u kHz",
dest->sample_spec.rate);
else
}
/* Called from main thread */
-pa_bool_t pa_source_update_rate(pa_source *s, uint32_t rate)
+pa_bool_t pa_source_update_rate(pa_source *s, uint32_t rate, pa_bool_t passthrough)
{
-
if (s->update_rate) {
uint32_t desired_rate = rate;
uint32_t default_rate = s->default_sample_rate;
if (PA_SOURCE_IS_RUNNING(s->state)) {
pa_log_info("Cannot update rate, SOURCE_IS_RUNNING, will keep using %u kHz",
s->sample_spec.rate);
- return FALSE; /* cannot reconfigure a RUNNING source without glitches */
+ return FALSE;
}
if (PA_UNLIKELY (desired_rate < 8000 ||
desired_rate > PA_RATE_MAX))
return FALSE;
- pa_assert(default_rate % 4000 || default_rate % 11025);
- pa_assert(alternate_rate % 4000 || alternate_rate % 11025);
+ if (!passthrough) {
+ pa_assert(default_rate % 4000 || default_rate % 11025);
+ pa_assert(alternate_rate % 4000 || alternate_rate % 11025);
+
+ if (default_rate % 4000) {
+ /* default is a 11025 multiple */
+ 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 (default_rate % 4000) {
- /* default is a 11025 multiple */
- if ((alternate_rate % 4000 == 0) && (desired_rate % 4000 == 0))
- use_alternate=TRUE;
+ if (use_alternate)
+ desired_rate = alternate_rate;
+ else
+ desired_rate = default_rate;
} else {
- /* default is 4000 multiple */
- if ((alternate_rate % 11025 == 0) && (desired_rate % 11025 == 0))
- use_alternate=TRUE;
+ desired_rate = rate; /* use stream sampling rate, discard default/alternate settings */
}
- if (use_alternate)
- desired_rate = alternate_rate;
- else
- desired_rate = default_rate;
+ if (passthrough || pa_source_used_by(s) == 0) {
+ pa_source_suspend(s, TRUE, PA_SUSPEND_IDLE); /* needed before rate update, will be resumed automatically */
+ }
if (s->update_rate(s, desired_rate) == TRUE) {
pa_log_info("Changed sampling rate successfully ");
pa_bool_t pa_source_update_proplist(pa_source *s, pa_update_mode_t mode, pa_proplist *p);
int pa_source_set_port(pa_source *s, const char *name, pa_bool_t save);
-pa_bool_t pa_source_update_rate(pa_source *s, uint32_t rate);
+pa_bool_t pa_source_update_rate(pa_source *s, uint32_t rate, pa_bool_t passthrough);
unsigned pa_source_linked_by(pa_source *s); /* Number of connected streams */
unsigned pa_source_used_by(pa_source *s); /* Number of connected streams that are not corked */