module-loopback: check validity of source-output/sink-input properly
[platform/upstream/pulseaudio.git] / src / modules / module-loopback.c
index a287619..3f16cef 100644 (file)
@@ -463,7 +463,12 @@ static void enable_adjust_timer(struct userdata *u, bool enable) {
 
 /* Called from main context */
 static void update_adjust_timer(struct userdata *u) {
+#ifdef __TIZEN__
+    if ((u->sink_input && u->sink_input->state == PA_SINK_INPUT_CORKED) ||
+        (u->source_output && u->source_output->state == PA_SOURCE_OUTPUT_CORKED))
+#else
     if (u->sink_input->state == PA_SINK_INPUT_CORKED || u->source_output->state == PA_SOURCE_OUTPUT_CORKED)
+#endif
         enable_adjust_timer(u, false);
     else
         enable_adjust_timer(u, true);
@@ -738,6 +743,13 @@ static void source_output_moving_cb(pa_source_output *o, pa_source *dest) {
     pa_assert_ctl_context();
     pa_assert_se(u = o->userdata);
 
+#ifdef __TIZEN__
+    if (!u->sink_input) {
+        pa_log_warn("sink_input is already null now, do nothing");
+        return;
+    }
+#endif
+
     input_description = pa_sprintf_malloc("Loopback of %s",
                                           pa_strnull(pa_proplist_gets(dest->proplist, PA_PROP_DEVICE_DESCRIPTION)));
     pa_sink_input_set_property(u->sink_input, PA_PROP_MEDIA_NAME, input_description);
@@ -799,15 +811,25 @@ static void source_output_suspend_cb(pa_source_output *o, pa_source_state_t old_
     /* If the source has been suspended, we need to handle this like
      * a source change when the source is resumed */
     if (suspended) {
+#ifdef __TIZEN__
+        if (u->sink_input && u->sink_input->sink)
+#else
         if (u->sink_input->sink)
+#endif
             pa_asyncmsgq_send(u->sink_input->sink->asyncmsgq, PA_MSGOBJECT(u->sink_input), SINK_INPUT_MESSAGE_SOURCE_CHANGED, NULL, 0, NULL);
         else
             u->output_thread_info.push_called = false;
 
     } else
         /* Get effective source latency on unsuspend */
+#ifdef __TIZEN__
+        if (u->sink_input)
+#endif
         update_effective_source_latency(u, u->source_output->source, u->sink_input->sink);
 
+#ifdef __TIZEN__
+    if (u->sink_input)
+#endif
     pa_sink_input_cork(u->sink_input, suspended);
 
     update_adjust_timer(u);
@@ -1135,6 +1157,13 @@ static void sink_input_moving_cb(pa_sink_input *i, pa_sink *dest) {
     pa_assert_ctl_context();
     pa_assert_se(u = i->userdata);
 
+#ifdef __TIZEN__
+    if (!u->source_output) {
+        pa_log_warn("source_output is already null now, do nothing");
+        return;
+    }
+#endif
+
     output_description = pa_sprintf_malloc("Loopback to %s",
                                            pa_strnull(pa_proplist_gets(dest->proplist, PA_PROP_DEVICE_DESCRIPTION)));
     pa_source_output_set_property(u->source_output, PA_PROP_MEDIA_NAME, output_description);
@@ -1211,8 +1240,14 @@ static void sink_input_suspend_cb(pa_sink_input *i, pa_sink_state_t old_state, p
 
     } else
         /* Set effective source latency on unsuspend */
+#ifdef __TIZEN__
+        if (u->source_output)
+#endif
         update_effective_source_latency(u, u->source_output->source, u->sink_input->sink);
 
+#ifdef __TIZEN__
+    if (u->source_output)
+#endif
     pa_source_output_cork(u->source_output, suspended);
 
     update_adjust_timer(u);