[pulseaudio-discuss] [PATCH] sink, source: Prevent unnecessary rate update attempts

Arun Raghavan arun.raghavan at collabora.co.uk
Thu Nov 15 02:28:37 PST 2012


We don't need to try a rate update if the desired sample rate is the
same as the one the sink or source is already using.
---
 src/pulsecore/sink-input.c    | 11 ++---------
 src/pulsecore/sink.c          |  3 +++
 src/pulsecore/source-output.c | 11 ++---------
 src/pulsecore/source.c        |  3 +++
 4 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
index 7a7575a..a5edd21 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -371,10 +371,7 @@ int pa_sink_input_new(
 
         pa_log_info("Trying to change sample rate");
         if (pa_sink_update_rate(data->sink, data->sample_spec.rate, pa_sink_input_new_data_is_passthrough(data)) == TRUE)
-            pa_log_info("Rate changed to %u Hz",
-                        data->sink->sample_spec.rate);
-        else
-            pa_log_info("Resampling enabled to %u Hz", data->sink->sample_spec.rate);
+            pa_log_info("Rate changed to %u Hz", data->sink->sample_spec.rate);
     }
 
     /* Due to the fixing of the sample spec the volume might not match anymore */
@@ -1662,11 +1659,7 @@ int pa_sink_input_finish_move(pa_sink_input *i, pa_sink *dest, pa_bool_t save) {
 
         pa_log_info("Trying to change sample rate");
         if (pa_sink_update_rate(dest, i->sample_spec.rate, pa_sink_input_is_passthrough(i)) == TRUE)
-            pa_log_info("Rate changed to %u Hz",
-                        dest->sample_spec.rate);
-        else
-            pa_log_info("Resampling enabled to %u Hz",
-                        dest->sample_spec.rate);
+            pa_log_info("Rate changed to %u Hz", dest->sample_spec.rate);
     }
 
     if (i->moving)
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 9958be6..1ccceb4 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -1392,6 +1392,9 @@ pa_bool_t pa_sink_update_rate(pa_sink *s, uint32_t rate, pa_bool_t passthrough)
             desired_rate = rate; /* use stream sampling rate, discard default/alternate settings */
         }
 
+        if (desired_rate == s->sample_spec.rate)
+            return FALSE;
+
         if (!passthrough && pa_sink_used_by(s) > 0)
             return FALSE;
 
diff --git a/src/pulsecore/source-output.c b/src/pulsecore/source-output.c
index 1297ec7..85045e7 100644
--- a/src/pulsecore/source-output.c
+++ b/src/pulsecore/source-output.c
@@ -350,10 +350,7 @@ int pa_source_output_new(
 
         pa_log_info("Trying to change sample 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 Hz",
-                        data->source->sample_spec.rate);
-        else
-            pa_log_info("Resampling enabled to %u Hz", data->source->sample_spec.rate);
+            pa_log_info("Rate changed to %u Hz", data->source->sample_spec.rate);
     }
 
     if (data->resample_method == PA_RESAMPLER_INVALID)
@@ -1425,11 +1422,7 @@ int pa_source_output_finish_move(pa_source_output *o, pa_source *dest, pa_bool_t
 
         pa_log_info("Trying to change sample rate");
         if (pa_source_update_rate(dest, o->sample_spec.rate, pa_source_output_is_passthrough(o)) == TRUE)
-            pa_log_info("Rate changed to %u Hz",
-                        dest->sample_spec.rate);
-        else
-            pa_log_info("Resampling enabled to %u Hz",
-                        dest->sample_spec.rate);
+            pa_log_info("Rate changed to %u Hz", dest->sample_spec.rate);
     }
 
     if (o->moving)
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index 7af86f5..e9c3669 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -1000,6 +1000,9 @@ pa_bool_t pa_source_update_rate(pa_source *s, uint32_t rate, pa_bool_t passthrou
             desired_rate = rate; /* use stream sampling rate, discard default/alternate settings */
         }
 
+        if (desired_rate == s->sample_spec.rate)
+            return FALSE;
+
         if (!passthrough && pa_source_used_by(s) > 0)
             return FALSE;
 
-- 
1.8.0



More information about the pulseaudio-discuss mailing list