[PATCH 07/22] loopback: Reset sink input rate when source or sink changes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 2e165cd..c94f060 100644
--- a/src/modules/module-loopback.c
+++ b/src/modules/module-loopback.c
@@ -642,11 +642,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 */
@@ -989,6 +996,11 @@ static void sink_input_moving_cb(pa_sink_input *i, pa_sink *dest) {
 
     /* Send a message to the output thread that the sink has changed */
     pa_asyncmsgq_send(dest->asyncmsgq, PA_MSGOBJECT(u->sink_input), SINK_INPUT_MESSAGE_SINK_CHANGED, NULL, 0, NULL);
+
+    /* 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 sink. */
+    u->sink_input->sample_spec.rate = u->source_output->sample_spec.rate;
 }
 
 /* Called from main thread */
-- 
2.10.1



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux