[pulseaudio-commits] 3 commits - src/modules

Tanu Kaskinen tanuk at kemper.freedesktop.org
Fri Sep 21 00:39:24 PDT 2012


 src/modules/module-loopback.c |   73 +++++++++++++++++++++++++++++++++++++-----
 1 file changed, 65 insertions(+), 8 deletions(-)

New commits:
commit 5412a69cac8af1f052d32c5b968ccf5639366a52
Author: Mikel Astiz <mikel.astiz at bmw-carit.de>
Date:   Thu Sep 20 14:28:34 2012 +0200

    loopback: Disable adjust timer when suspended
    
    Stop the rate adjustment timer when no audio is flowing.

diff --git a/src/modules/module-loopback.c b/src/modules/module-loopback.c
index ad03816..26d2e6a 100644
--- a/src/modules/module-loopback.c
+++ b/src/modules/module-loopback.c
@@ -131,6 +131,8 @@ enum {
     SOURCE_OUTPUT_MESSAGE_LATENCY_SNAPSHOT
 };
 
+static void enable_adjust_timer(struct userdata *u, bool enable);
+
 /* Called from main context */
 static void teardown(struct userdata *u) {
     pa_assert(u);
@@ -140,10 +142,7 @@ static void teardown(struct userdata *u) {
         pa_asyncmsgq_flush(u->asyncmsgq, 0);
 
     u->adjust_time = 0;
-    if (u->time_event) {
-        u->core->mainloop->time_free(u->time_event);
-        u->time_event = NULL;
-    }
+    enable_adjust_timer(u, false);
 
     if (u->sink_input)
         pa_sink_input_unlink(u->sink_input);
@@ -236,6 +235,30 @@ static void time_callback(pa_mainloop_api *a, pa_time_event *e, const struct tim
     adjust_rates(u);
 }
 
+/* Called from main context */
+static void enable_adjust_timer(struct userdata *u, bool enable) {
+    if (enable) {
+        if (u->time_event || u->adjust_time <= 0)
+            return;
+
+        u->time_event = pa_core_rttime_new(u->module->core, pa_rtclock_now() + u->adjust_time, time_callback, u);
+    } else {
+        if (!u->time_event)
+            return;
+
+        u->core->mainloop->time_free(u->time_event);
+        u->time_event = NULL;
+    }
+}
+
+/* Called from main context */
+static void update_adjust_timer(struct userdata *u) {
+    if (u->sink_input->state == PA_SINK_INPUT_CORKED || u->source_output->state == PA_SOURCE_OUTPUT_CORKED)
+        enable_adjust_timer(u, false);
+    else
+        enable_adjust_timer(u, true);
+}
+
 /* Called from input thread context */
 static void source_output_push_cb(pa_source_output *o, const pa_memchunk *chunk) {
     struct userdata *u;
@@ -398,6 +421,8 @@ static void source_output_suspend_cb(pa_source_output *o, pa_bool_t suspended) {
     pa_assert_se(u = o->userdata);
 
     pa_sink_input_cork(u->sink_input, suspended);
+
+    update_adjust_timer(u);
 }
 
 /* Called from output thread context */
@@ -540,7 +565,7 @@ static int sink_input_process_msg_cb(pa_msgobject *obj, int code, void *data, in
 
             pa_assert_ctl_context();
 
-            if (u->adjust_time > 0)
+            if (u->time_event)
                 adjust_rates(u);
             return 0;
         }
@@ -664,6 +689,8 @@ static void sink_input_suspend_cb(pa_sink_input *i, pa_bool_t suspended) {
     pa_assert_se(u = i->userdata);
 
     pa_source_output_cork(u->source_output, suspended);
+
+    update_adjust_timer(u);
 }
 
 int pa__init(pa_module *m) {
@@ -933,8 +960,7 @@ int pa__init(pa_module *m) {
     if (pa_sink_get_state(u->sink_input->sink) != PA_SINK_SUSPENDED)
 	    pa_source_output_cork(u->source_output, FALSE);
 
-    if (u->adjust_time > 0)
-        u->time_event = pa_core_rttime_new(m->core, pa_rtclock_now() + u->adjust_time, time_callback, u);
+    update_adjust_timer(u);
 
     pa_modargs_free(ma);
     return 0;

commit 6c916697bc2ee87be41d8a3dc5fee12689c63957
Author: Frédéric Dalleau <frederic.dalleau at linux.intel.com>
Date:   Thu Sep 20 14:28:33 2012 +0200

    loopback: Cork source-output if sink is suspended
    
    During initialization, the approach avoids having a needless short
    period of corked state in case the sink is suspended, by always creating
    the source-output corked and uncorking it immediately afterwards when
    the sink is not suspended.

diff --git a/src/modules/module-loopback.c b/src/modules/module-loopback.c
index 25a2ba8..ad03816 100644
--- a/src/modules/module-loopback.c
+++ b/src/modules/module-loopback.c
@@ -655,6 +655,17 @@ static pa_bool_t sink_input_may_move_to_cb(pa_sink_input *i, pa_sink *dest) {
     return dest != u->source_output->source->monitor_of;
 }
 
+/* Called from main thread */
+static void sink_input_suspend_cb(pa_sink_input *i, pa_bool_t suspended) {
+    struct userdata *u;
+
+    pa_sink_input_assert_ref(i);
+    pa_assert_ctl_context();
+    pa_assert_se(u = i->userdata);
+
+    pa_source_output_cork(u->source_output, suspended);
+}
+
 int pa__init(pa_module *m) {
     pa_modargs *ma = NULL;
     struct userdata *u;
@@ -817,6 +828,7 @@ int pa__init(pa_module *m) {
     u->sink_input->update_max_request = sink_input_update_max_request_cb;
     u->sink_input->may_move_to = sink_input_may_move_to_cb;
     u->sink_input->moving = sink_input_moving_cb;
+    u->sink_input->suspend = sink_input_suspend_cb;
     u->sink_input->userdata = u;
 
     pa_sink_input_set_requested_latency(u->sink_input, u->latency/3);
@@ -838,6 +850,7 @@ int pa__init(pa_module *m) {
 
     pa_source_output_new_data_set_sample_spec(&source_output_data, &ss);
     pa_source_output_new_data_set_channel_map(&source_output_data, &map);
+    source_output_data.flags = PA_SOURCE_OUTPUT_START_CORKED;
 
     if (!remix)
         source_output_data.flags |= PA_SOURCE_OUTPUT_NO_REMIX;
@@ -917,6 +930,9 @@ int pa__init(pa_module *m) {
     if (pa_source_get_state(u->source_output->source) != PA_SOURCE_SUSPENDED)
 	    pa_sink_input_cork(u->sink_input, FALSE);
 
+    if (pa_sink_get_state(u->sink_input->sink) != PA_SINK_SUSPENDED)
+	    pa_source_output_cork(u->source_output, FALSE);
+
     if (u->adjust_time > 0)
         u->time_event = pa_core_rttime_new(m->core, pa_rtclock_now() + u->adjust_time, time_callback, u);
 

commit e90e19f457dd1a9e2becd21a71a37236605de2df
Author: Frédéric Dalleau <frederic.dalleau at linux.intel.com>
Date:   Thu Sep 20 14:28:32 2012 +0200

    loopback: Cork sink-input if source is suspended
    
    During initialization, the approach avoids having a needless short
    period of corked state in case the source is suspended, by always
    creating the sink-input corked and uncorking it immediately afterwards
    when the source is not suspended.

diff --git a/src/modules/module-loopback.c b/src/modules/module-loopback.c
index 9054700..25a2ba8 100644
--- a/src/modules/module-loopback.c
+++ b/src/modules/module-loopback.c
@@ -389,6 +389,17 @@ static void source_output_moving_cb(pa_source_output *o, pa_source *dest) {
     pa_proplist_free(p);
 }
 
+/* Called from main thread */
+static void source_output_suspend_cb(pa_source_output *o, pa_bool_t suspended) {
+    struct userdata *u;
+
+    pa_source_output_assert_ref(o);
+    pa_assert_ctl_context();
+    pa_assert_se(u = o->userdata);
+
+    pa_sink_input_cork(u->sink_input, suspended);
+}
+
 /* Called from output thread context */
 static void update_min_memblockq_length(struct userdata *u) {
     size_t length;
@@ -767,7 +778,7 @@ int pa__init(pa_module *m) {
 
     pa_sink_input_new_data_set_sample_spec(&sink_input_data, &ss);
     pa_sink_input_new_data_set_channel_map(&sink_input_data, &map);
-    sink_input_data.flags = PA_SINK_INPUT_VARIABLE_RATE;
+    sink_input_data.flags = PA_SINK_INPUT_VARIABLE_RATE | PA_SINK_INPUT_START_CORKED;
 
     if (!remix)
         sink_input_data.flags |= PA_SINK_INPUT_NO_REMIX;
@@ -864,6 +875,7 @@ int pa__init(pa_module *m) {
     u->source_output->state_change = source_output_state_change_cb;
     u->source_output->may_move_to = source_output_may_move_to_cb;
     u->source_output->moving = source_output_moving_cb;
+    u->source_output->suspend = source_output_suspend_cb;
     u->source_output->userdata = u;
 
     pa_source_output_set_requested_latency(u->source_output, u->latency/3);
@@ -902,6 +914,9 @@ int pa__init(pa_module *m) {
     pa_sink_input_put(u->sink_input);
     pa_source_output_put(u->source_output);
 
+    if (pa_source_get_state(u->source_output->source) != PA_SOURCE_SUSPENDED)
+	    pa_sink_input_cork(u->sink_input, FALSE);
+
     if (u->adjust_time > 0)
         u->time_event = pa_core_rttime_new(m->core, pa_rtclock_now() + u->adjust_time, time_callback, u);
 



More information about the pulseaudio-commits mailing list