[pulseaudio-discuss] [PATCH 2/2] loopback: Reset sink input rate when source or sink changes

Georg Chini georg at chini.tk
Fri Apr 7 07:37:27 UTC 2017


If source or sink are changed, the current sink input rate may be different
from the default rate. Switch sink input rate back to default to avoid the
influence of the previous combination of source and sink.
---
 src/modules/module-loopback.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/modules/module-loopback.c b/src/modules/module-loopback.c
index e21a3b3b..2f36846f 100644
--- a/src/modules/module-loopback.c
+++ b/src/modules/module-loopback.c
@@ -641,11 +641,18 @@ static void source_output_moving_cb(pa_source_output *o, pa_source *dest) {
 
     /* Send a mesage to the output thread that the source has changed.
      * If the sink is invalid here during a profile switching situation
-     * we can safely set push_called to false directly. */
-    if (u->sink_input->sink)
+     * we can safely set push_called to false directly.  Also, the current
+     * sampling rate may be far away from the default rate if we are still
+     * recovering from a previous source or sink change, so reset rate to
+     * default before moving the source. If the sink is not valid, only
+     * update the sink input sample spec.*/
+    if (u->sink_input->sink) {
         pa_asyncmsgq_send(u->sink_input->sink->asyncmsgq, PA_MSGOBJECT(u->sink_input), SINK_INPUT_MESSAGE_SOURCE_CHANGED, NULL, 0, NULL);
-    else
+        pa_sink_input_set_rate(u->sink_input, u->source_output->sample_spec.rate);
+    } else {
         u->output_thread_info.push_called = false;
+        u->sink_input->sample_spec.rate = u->source_output->sample_spec.rate;
+    }
 }
 
 /* Called from main thread */
@@ -1010,6 +1017,11 @@ static void sink_input_moving_cb(pa_sink_input *i, pa_sink *dest) {
 
     u->output_thread_info.pop_called = false;
     u->output_thread_info.first_pop_done = false;
+
+    /* Sample rate may be far away from the default rate if we are still
+     * recovering from a previous source or sink change, so reset rate to
+     * default before moving the sink. */
+    u->sink_input->sample_spec.rate = u->source_output->sample_spec.rate;
 }
 
 /* Called from main thread */
-- 
2.11.0



More information about the pulseaudio-discuss mailing list