Fix up according to Coding Style
[platform/upstream/pulseaudio.git] / src / pulsecore / source.c
index 1c77e0b..92fb80e 100644 (file)
@@ -221,6 +221,7 @@ pa_source* pa_source_new(
     s->outputs = pa_idxset_new(NULL, NULL);
     s->n_corked = 0;
     s->monitor_of = NULL;
+    s->output_from_master = NULL;
 
     s->volume = data->volume;
     pa_cvolume_reset(&s->soft_volume, s->sample_spec.channels);
@@ -760,15 +761,22 @@ void pa_source_set_volume(
         pa_bool_t save) {
 
     pa_bool_t real_changed;
+    pa_cvolume old_volume;
 
     pa_source_assert_ref(s);
     pa_assert_ctl_context();
     pa_assert(PA_SOURCE_IS_LINKED(s->state));
     pa_assert(pa_cvolume_valid(volume));
-    pa_assert(pa_cvolume_compatible(volume, &s->sample_spec));
+    pa_assert(volume->channels == 1 || pa_cvolume_compatible(volume, &s->sample_spec));
 
-    real_changed = !pa_cvolume_equal(volume, &s->volume);
-    s->volume = *volume;
+    old_volume = s->volume;
+
+    if (pa_cvolume_compatible(volume, &s->sample_spec))
+        s->volume = *volume;
+    else
+        pa_cvolume_scale(&s->volume, pa_cvolume_max(volume));
+
+    real_changed = !pa_cvolume_equal(&old_volume, &s->volume);
     s->save_volume = (!real_changed && s->save_volume) || save;
 
     if (s->set_volume) {
@@ -989,7 +997,14 @@ unsigned pa_source_check_suspend(pa_source *s) {
         pa_source_output_state_t st;
 
         st = pa_source_output_get_state(o);
-        pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(st));
+
+        /* We do not assert here. It is perfectly valid for a source output to
+         * be in the INIT state (i.e. created, marked done but not yet put)
+         * and we should not care if it's unlinked as it won't contribute
+         * towarards our busy status.
+         */
+        if (!PA_SOURCE_OUTPUT_IS_LINKED(st))
+            continue;
 
         if (st == PA_SOURCE_OUTPUT_CORKED)
             continue;
@@ -1387,22 +1402,22 @@ void pa_source_set_latency_range(pa_source *s, pa_usec_t min_latency, pa_usec_t
 
 /* Called from main thread */
 void pa_source_get_latency_range(pa_source *s, pa_usec_t *min_latency, pa_usec_t *max_latency) {
-   pa_source_assert_ref(s);
-   pa_assert_ctl_context();
-   pa_assert(min_latency);
-   pa_assert(max_latency);
-
-   if (PA_SOURCE_IS_LINKED(s->state)) {
-       pa_usec_t r[2] = { 0, 0 };
-
-       pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_GET_LATENCY_RANGE, r, 0, NULL) == 0);
-
-       *min_latency = r[0];
-       *max_latency = r[1];
-   } else {
-       *min_latency = s->thread_info.min_latency;
-       *max_latency = s->thread_info.max_latency;
-   }
+    pa_source_assert_ref(s);
+    pa_assert_ctl_context();
+    pa_assert(min_latency);
+    pa_assert(max_latency);
+
+    if (PA_SOURCE_IS_LINKED(s->state)) {
+        pa_usec_t r[2] = { 0, 0 };
+
+        pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_GET_LATENCY_RANGE, r, 0, NULL) == 0);
+
+        *min_latency = r[0];
+        *max_latency = r[1];
+    } else {
+        *min_latency = s->thread_info.min_latency;
+        *max_latency = s->thread_info.max_latency;
+    }
 }
 
 /* Called from IO thread, and from main thread before pa_source_put() is called */
@@ -1556,5 +1571,7 @@ int pa_source_set_port(pa_source *s, const char *name, pa_bool_t save) {
     s->active_port = port;
     s->save_port = save;
 
+    pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_PORT_CHANGED], s);
+
     return 0;
 }