[pulseaudio-discuss] [PATCH 3/3] sink, source: remove the state getters

Tanu Kaskinen tanuk at iki.fi
Tue Jun 26 13:25:58 UTC 2018


pa_sink_get_state() and pa_source_get_state() just return the state
variable. We can as well access the state variable directly.

There are no behaviour changes, except that module-virtual-source
accessed the main thread's sink state variable from its push() callback.
I fixed the module so that it uses the thread_info.state variable
instead. Also, the compiler started to complain about comparing a sink
state variable to a source state enum value in protocol-esound.c. The
underlying bug was that a source pointer was assigned to a variable
whose type was a sink pointer (somehow using the pa_source_get_state()
macro confused the compiler enough so that it didn't complain before).
I fixed the variable type.
---
 src/modules/alsa/alsa-sink.c                 |  2 +-
 src/modules/alsa/alsa-source.c               |  2 +-
 src/modules/dbus/iface-device.c              | 12 ++++++------
 src/modules/echo-cancel/module-echo-cancel.c | 18 +++++++++---------
 src/modules/module-combine-sink.c            | 16 ++++++++--------
 src/modules/module-equalizer-sink.c          |  4 ++--
 src/modules/module-intended-roles.c          |  8 ++++----
 src/modules/module-ladspa-sink.c             |  2 +-
 src/modules/module-loopback.c                |  8 ++++----
 src/modules/module-rescue-streams.c          |  4 ++--
 src/modules/module-stream-restore.c          |  8 ++++----
 src/modules/module-suspend-on-idle.c         | 10 ++++------
 src/modules/module-tunnel.c                  |  4 ++--
 src/modules/module-virtual-sink.c            |  4 ++--
 src/modules/module-virtual-source.c          |  6 +++---
 src/modules/module-virtual-surround-sink.c   |  4 ++--
 src/pulsecore/cli-command.c                  |  4 ++--
 src/pulsecore/cli-text.c                     |  4 ++--
 src/pulsecore/core.c                         |  4 ++--
 src/pulsecore/protocol-esound.c              |  7 ++++---
 src/pulsecore/protocol-native.c              | 20 ++++++++++----------
 src/pulsecore/sink-input.c                   |  6 +++---
 src/pulsecore/sink.h                         |  2 --
 src/pulsecore/source-output.c                |  6 +++---
 src/pulsecore/source.c                       |  2 +-
 src/pulsecore/source.h                       |  2 --
 26 files changed, 82 insertions(+), 87 deletions(-)

diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index 871c82922..9a616ea76 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -1256,7 +1256,7 @@ static int sink_set_state_in_main_thread_cb(pa_sink *s, pa_sink_state_t new_stat
             && !(new_suspend_cause & PA_SUSPEND_SESSION))
         sync_mixer(u, s->active_port);
 
-    old_state = pa_sink_get_state(u->sink);
+    old_state = u->sink->state;
 
     if (PA_SINK_IS_OPENED(old_state) && new_state == PA_SINK_SUSPENDED)
         reserve_done(u);
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index c32e7e98b..8c5740373 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -1111,7 +1111,7 @@ static int source_set_state_in_main_thread_cb(pa_source *s, pa_source_state_t ne
             && !(new_suspend_cause & PA_SUSPEND_SESSION))
         sync_mixer(u, s->active_port);
 
-    old_state = pa_source_get_state(u->source);
+    old_state = u->source->state;
 
     if (PA_SOURCE_IS_OPENED(old_state) && new_state == PA_SOURCE_SUSPENDED)
         reserve_done(u);
diff --git a/src/modules/dbus/iface-device.c b/src/modules/dbus/iface-device.c
index 2c370a822..775cf3ff6 100644
--- a/src/modules/dbus/iface-device.c
+++ b/src/modules/dbus/iface-device.c
@@ -849,7 +849,7 @@ static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdat
         latency = pa_sink_get_latency(d->sink);
         is_hardware_device = !!(d->sink->flags & PA_SINK_HARDWARE);
         is_network_device = !!(d->sink->flags & PA_SINK_NETWORK);
-        state = pa_sink_get_state(d->sink);
+        state = d->sink->state;
     } else {
         idx = d->source->index;
         name = d->source->name;
@@ -870,7 +870,7 @@ static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdat
         latency = pa_source_get_latency(d->source);
         is_hardware_device = !!(d->source->flags & PA_SOURCE_HARDWARE);
         is_network_device = !!(d->source->flags & PA_SOURCE_NETWORK);
-        state = pa_source_get_state(d->source);
+        state = d->source->state;
     }
     if (owner_module)
         owner_module_path = pa_dbusiface_core_get_module_path(d->core, owner_module);
@@ -1158,9 +1158,9 @@ static pa_hook_result_t state_changed_cb(void *hook_data, void *call_data, void
         return PA_HOOK_OK;
 
     if (d->type == PA_DEVICE_TYPE_SINK)
-        new_sink_state = pa_sink_get_state(d->sink);
+        new_sink_state = d->sink->state;
     else
-        new_source_state = pa_source_get_state(d->source);
+        new_source_state = d->source->state;
 
     if ((d->type == PA_DEVICE_TYPE_SINK && d->sink_state != new_sink_state)
         || (d->type == PA_DEVICE_TYPE_SOURCE && d->source_state != new_source_state)) {
@@ -1258,7 +1258,7 @@ pa_dbusiface_device *pa_dbusiface_device_new_sink(pa_dbusiface_core *core, pa_si
     d->path = pa_sprintf_malloc("%s/%s%u", PA_DBUS_CORE_OBJECT_PATH, SINK_OBJECT_NAME, sink->index);
     d->volume = *pa_sink_get_volume(sink, false);
     d->mute = pa_sink_get_mute(sink, false);
-    d->sink_state = pa_sink_get_state(sink);
+    d->sink_state = sink->state;
     d->ports = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) pa_dbusiface_device_port_free);
     d->next_port_index = 0;
     d->active_port = sink->active_port;
@@ -1301,7 +1301,7 @@ pa_dbusiface_device *pa_dbusiface_device_new_source(pa_dbusiface_core *core, pa_
     d->path = pa_sprintf_malloc("%s/%s%u", PA_DBUS_CORE_OBJECT_PATH, SOURCE_OBJECT_NAME, source->index);
     d->volume = *pa_source_get_volume(source, false);
     d->mute = pa_source_get_mute(source, false);
-    d->source_state = pa_source_get_state(source);
+    d->source_state = source->state;
     d->ports = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) pa_dbusiface_device_port_free);
     d->next_port_index = 0;
     d->active_port = source->active_port;
diff --git a/src/modules/echo-cancel/module-echo-cancel.c b/src/modules/echo-cancel/module-echo-cancel.c
index cbaec2b34..3a4c8c949 100644
--- a/src/modules/echo-cancel/module-echo-cancel.c
+++ b/src/modules/echo-cancel/module-echo-cancel.c
@@ -146,8 +146,8 @@ static const pa_echo_canceller ec_table[] = {
 #define MAX_LATENCY_BLOCKS 10
 
 /* Can only be used in main context */
-#define IS_ACTIVE(u) ((pa_source_get_state((u)->source) == PA_SOURCE_RUNNING) && \
-                      (pa_sink_get_state((u)->sink) == PA_SINK_RUNNING))
+#define IS_ACTIVE(u) (((u)->source->state == PA_SOURCE_RUNNING) && \
+                      ((u)->sink->state == PA_SINK_RUNNING))
 
 /* This module creates a new (virtual) source and sink.
  *
@@ -476,7 +476,7 @@ static int source_set_state_in_main_thread_cb(pa_source *s, pa_source_state_t st
 
     if (state == PA_SOURCE_RUNNING) {
         /* restart timer when both sink and source are active */
-        if ((pa_sink_get_state(u->sink) == PA_SINK_RUNNING) && u->adjust_time)
+        if ((u->sink->state == PA_SINK_RUNNING) && u->adjust_time)
             pa_core_rttime_restart(u->core, u->time_event, pa_rtclock_now() + u->adjust_time);
 
         pa_atomic_store(&u->request_resync, 1);
@@ -501,7 +501,7 @@ static int sink_set_state_in_main_thread_cb(pa_sink *s, pa_sink_state_t state, p
 
     if (state == PA_SINK_RUNNING) {
         /* restart timer when both sink and source are active */
-        if ((pa_source_get_state(u->source) == PA_SOURCE_RUNNING) && u->adjust_time)
+        if ((u->source->state == PA_SOURCE_RUNNING) && u->adjust_time)
             pa_core_rttime_restart(u->core, u->time_event, pa_rtclock_now() + u->adjust_time);
 
         pa_atomic_store(&u->request_resync, 1);
@@ -597,7 +597,7 @@ static void source_set_volume_cb(pa_source *s) {
     pa_source_assert_ref(s);
     pa_assert_se(u = s->userdata);
 
-    if (!PA_SOURCE_IS_LINKED(pa_source_get_state(s)) ||
+    if (!PA_SOURCE_IS_LINKED(s->state) ||
         !PA_SOURCE_OUTPUT_IS_LINKED(u->source_output->state))
         return;
 
@@ -611,7 +611,7 @@ static void sink_set_volume_cb(pa_sink *s) {
     pa_sink_assert_ref(s);
     pa_assert_se(u = s->userdata);
 
-    if (!PA_SINK_IS_LINKED(pa_sink_get_state(s)) ||
+    if (!PA_SINK_IS_LINKED(s->state) ||
         !PA_SINK_INPUT_IS_LINKED(u->sink_input->state))
         return;
 
@@ -626,7 +626,7 @@ static void source_get_volume_cb(pa_source *s) {
     pa_source_assert_ref(s);
     pa_assert_se(u = s->userdata);
 
-    if (!PA_SOURCE_IS_LINKED(pa_source_get_state(s)) ||
+    if (!PA_SOURCE_IS_LINKED(s->state) ||
         !PA_SOURCE_OUTPUT_IS_LINKED(u->source_output->state))
         return;
 
@@ -647,7 +647,7 @@ static void source_set_mute_cb(pa_source *s) {
     pa_source_assert_ref(s);
     pa_assert_se(u = s->userdata);
 
-    if (!PA_SOURCE_IS_LINKED(pa_source_get_state(s)) ||
+    if (!PA_SOURCE_IS_LINKED(s->state) ||
         !PA_SOURCE_OUTPUT_IS_LINKED(u->source_output->state))
         return;
 
@@ -661,7 +661,7 @@ static void sink_set_mute_cb(pa_sink *s) {
     pa_sink_assert_ref(s);
     pa_assert_se(u = s->userdata);
 
-    if (!PA_SINK_IS_LINKED(pa_sink_get_state(s)) ||
+    if (!PA_SINK_IS_LINKED(s->state) ||
         !PA_SINK_INPUT_IS_LINKED(u->sink_input->state))
         return;
 
diff --git a/src/modules/module-combine-sink.c b/src/modules/module-combine-sink.c
index b7dac8049..685e240f5 100644
--- a/src/modules/module-combine-sink.c
+++ b/src/modules/module-combine-sink.c
@@ -194,13 +194,13 @@ static void adjust_rates(struct userdata *u) {
     if (pa_idxset_size(u->outputs) <= 0)
         return;
 
-    if (!PA_SINK_IS_OPENED(pa_sink_get_state(u->sink)))
+    if (!PA_SINK_IS_OPENED(u->sink->state))
         return;
 
     PA_IDXSET_FOREACH(o, u->outputs, idx) {
         pa_usec_t sink_latency;
 
-        if (!o->sink_input || !PA_SINK_IS_OPENED(pa_sink_get_state(o->sink)))
+        if (!o->sink_input || !PA_SINK_IS_OPENED(o->sink->state))
             continue;
 
         o->total_latency = pa_sink_input_get_latency(o->sink_input, &sink_latency);
@@ -237,7 +237,7 @@ static void adjust_rates(struct userdata *u) {
         uint32_t new_rate = base_rate;
         uint32_t current_rate;
 
-        if (!o->sink_input || !PA_SINK_IS_OPENED(pa_sink_get_state(o->sink)))
+        if (!o->sink_input || !PA_SINK_IS_OPENED(o->sink->state))
             continue;
 
         current_rate = o->sink_input->sample_spec.rate;
@@ -273,7 +273,7 @@ static void time_callback(pa_mainloop_api *a, pa_time_event *e, const struct tim
 
     adjust_rates(u);
 
-    if (pa_sink_get_state(u->sink) == PA_SINK_SUSPENDED) {
+    if (u->sink->state == PA_SINK_SUSPENDED) {
         u->core->mainloop->time_free(e);
         u->time_event = NULL;
     } else
@@ -697,7 +697,7 @@ static int sink_set_state_in_main_thread_cb(pa_sink *sink, pa_sink_state_t state
 
     switch (state) {
         case PA_SINK_SUSPENDED:
-            pa_assert(PA_SINK_IS_OPENED(pa_sink_get_state(u->sink)));
+            pa_assert(PA_SINK_IS_OPENED(u->sink->state));
 
             suspend(u);
             break;
@@ -705,7 +705,7 @@ static int sink_set_state_in_main_thread_cb(pa_sink *sink, pa_sink_state_t state
         case PA_SINK_IDLE:
         case PA_SINK_RUNNING:
 
-            if (pa_sink_get_state(u->sink) == PA_SINK_SUSPENDED)
+            if (u->sink->state == PA_SINK_SUSPENDED)
                 unsuspend(u);
 
             break;
@@ -1126,7 +1126,7 @@ static void output_enable(struct output *o) {
 
     if (output_create_sink_input(o) >= 0) {
 
-        if (pa_sink_get_state(o->sink) != PA_SINK_INIT) {
+        if (o->sink->state != PA_SINK_INIT) {
             /* Enable the sink input. That means that the sink
              * is now asked for new data. */
             pa_sink_input_put(o->sink_input);
@@ -1162,7 +1162,7 @@ static void output_disable(struct output *o) {
 static void output_verify(struct output *o) {
     pa_assert(o);
 
-    if (PA_SINK_IS_OPENED(pa_sink_get_state(o->userdata->sink)))
+    if (PA_SINK_IS_OPENED(o->userdata->sink->state))
         output_enable(o);
     else
         output_disable(o);
diff --git a/src/modules/module-equalizer-sink.c b/src/modules/module-equalizer-sink.c
index fc561e81f..4cfe3ed48 100644
--- a/src/modules/module-equalizer-sink.c
+++ b/src/modules/module-equalizer-sink.c
@@ -343,7 +343,7 @@ static void sink_set_volume_cb(pa_sink *s) {
     pa_sink_assert_ref(s);
     pa_assert_se(u = s->userdata);
 
-    if (!PA_SINK_IS_LINKED(pa_sink_get_state(s)) ||
+    if (!PA_SINK_IS_LINKED(s->state) ||
         !PA_SINK_INPUT_IS_LINKED(u->sink_input->state))
         return;
 
@@ -357,7 +357,7 @@ static void sink_set_mute_cb(pa_sink *s) {
     pa_sink_assert_ref(s);
     pa_assert_se(u = s->userdata);
 
-    if (!PA_SINK_IS_LINKED(pa_sink_get_state(s)) ||
+    if (!PA_SINK_IS_LINKED(s->state) ||
         !PA_SINK_INPUT_IS_LINKED(u->sink_input->state))
         return;
 
diff --git a/src/modules/module-intended-roles.c b/src/modules/module-intended-roles.c
index cb7c1a768..adee51c20 100644
--- a/src/modules/module-intended-roles.c
+++ b/src/modules/module-intended-roles.c
@@ -99,7 +99,7 @@ static pa_hook_result_t sink_input_new_hook_callback(pa_core *c, pa_sink_input_n
         if (s == c->default_sink)
             continue;
 
-        if (!PA_SINK_IS_LINKED(pa_sink_get_state(s)))
+        if (!PA_SINK_IS_LINKED(s->state))
             continue;
 
         if (role_match(s->proplist, role) && pa_sink_input_new_data_set_sink(new_data, s, false, false))
@@ -147,7 +147,7 @@ static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_ou
         if (s == c->default_source)
             continue;
 
-        if (!PA_SOURCE_IS_LINKED(pa_source_get_state(s)))
+        if (!PA_SOURCE_IS_LINKED(s->state))
             continue;
 
         /* @todo: favour the highest priority device, not the first one we find? */
@@ -293,7 +293,7 @@ static pa_hook_result_t sink_unlink_hook_callback(pa_core *c, pa_sink *sink, str
             if (d == c->default_sink || d == sink)
                 continue;
 
-            if (!PA_SINK_IS_LINKED(pa_sink_get_state(d)))
+            if (!PA_SINK_IS_LINKED(d->state))
                 continue;
 
             if (role_match(d->proplist, role))
@@ -349,7 +349,7 @@ static pa_hook_result_t source_unlink_hook_callback(pa_core *c, pa_source *sourc
             if (d == c->default_source || d == source)
                 continue;
 
-            if (!PA_SOURCE_IS_LINKED(pa_source_get_state(d)))
+            if (!PA_SOURCE_IS_LINKED(d->state))
                 continue;
 
             /* If moving from a monitor, move to another monitor */
diff --git a/src/modules/module-ladspa-sink.c b/src/modules/module-ladspa-sink.c
index 284fabb82..c654530a3 100644
--- a/src/modules/module-ladspa-sink.c
+++ b/src/modules/module-ladspa-sink.c
@@ -452,7 +452,7 @@ static void sink_set_mute_cb(pa_sink *s) {
     pa_sink_assert_ref(s);
     pa_assert_se(u = s->userdata);
 
-    if (!PA_SINK_IS_LINKED(pa_sink_get_state(s)) ||
+    if (!PA_SINK_IS_LINKED(s->state) ||
             !PA_SINK_INPUT_IS_LINKED(u->sink_input->state))
         return;
 
diff --git a/src/modules/module-loopback.c b/src/modules/module-loopback.c
index 31702e32b..e1ab34166 100644
--- a/src/modules/module-loopback.c
+++ b/src/modules/module-loopback.c
@@ -714,7 +714,7 @@ static void source_output_moving_cb(pa_source_output *o, pa_source *dest) {
 
     /* Uncork the sink input unless the destination is suspended for other
      * reasons than idle. */
-    if (pa_source_get_state(dest) == PA_SOURCE_SUSPENDED)
+    if (dest->state == PA_SOURCE_SUSPENDED)
         pa_sink_input_cork(u->sink_input, (dest->suspend_cause != PA_SUSPEND_IDLE));
     else
         pa_sink_input_cork(u->sink_input, false);
@@ -1098,7 +1098,7 @@ static void sink_input_moving_cb(pa_sink_input *i, pa_sink *dest) {
 
     /* Uncork the source output unless the destination is suspended for other
      * reasons than idle */
-    if (pa_sink_get_state(dest) == PA_SINK_SUSPENDED)
+    if (dest->state == PA_SINK_SUSPENDED)
         pa_source_output_cork(u->source_output, (dest->suspend_cause != PA_SUSPEND_IDLE));
     else
         pa_source_output_cork(u->source_output, false);
@@ -1565,10 +1565,10 @@ 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)
+    if (u->source_output->source->state != PA_SOURCE_SUSPENDED)
         pa_sink_input_cork(u->sink_input, false);
 
-    if (pa_sink_get_state(u->sink_input->sink) != PA_SINK_SUSPENDED)
+    if (u->sink_input->sink->state != PA_SINK_SUSPENDED)
         pa_source_output_cork(u->source_output, false);
 
     update_adjust_timer(u);
diff --git a/src/modules/module-rescue-streams.c b/src/modules/module-rescue-streams.c
index 39549782c..52675ecf7 100644
--- a/src/modules/module-rescue-streams.c
+++ b/src/modules/module-rescue-streams.c
@@ -114,7 +114,7 @@ static pa_sink* find_evacuation_sink(pa_core *c, pa_sink_input *i, pa_sink *skip
         if (target == skip)
             continue;
 
-        if (!PA_SINK_IS_LINKED(pa_sink_get_state(target)))
+        if (!PA_SINK_IS_LINKED(target->state))
             continue;
 
         if (!pa_sink_input_may_move_to(i, target))
@@ -224,7 +224,7 @@ static pa_source* find_evacuation_source(pa_core *c, pa_source_output *o, pa_sou
         if (skip && !target->monitor_of != !skip->monitor_of)
             continue;
 
-        if (!PA_SOURCE_IS_LINKED(pa_source_get_state(target)))
+        if (!PA_SOURCE_IS_LINKED(target->state))
             continue;
 
         if (!pa_source_output_may_move_to(o, target))
diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c
index 9857a8ee1..228e9e447 100644
--- a/src/modules/module-stream-restore.c
+++ b/src/modules/module-stream-restore.c
@@ -1453,7 +1453,7 @@ static pa_hook_result_t sink_input_new_hook_callback(pa_core *c, pa_sink_input_n
         /* It might happen that a stream and a sink are set up at the
            same time, in which case we want to make sure we don't
            interfere with that */
-        if (s && PA_SINK_IS_LINKED(pa_sink_get_state(s)))
+        if (s && PA_SINK_IS_LINKED(s->state))
             if (pa_sink_input_new_data_set_sink(new_data, s, true, false))
                 pa_log_info("Restoring device for stream %s.", name);
 
@@ -1556,7 +1556,7 @@ static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_ou
         /* It might happen that a stream and a sink are set up at the
            same time, in which case we want to make sure we don't
            interfere with that */
-        if (s && PA_SOURCE_IS_LINKED(pa_source_get_state(s))) {
+        if (s && PA_SOURCE_IS_LINKED(s->state)) {
             pa_log_info("Restoring device for stream %s.", name);
             pa_source_output_new_data_set_source(new_data, s, true, false);
         }
@@ -1764,7 +1764,7 @@ static pa_hook_result_t sink_unlink_hook_callback(pa_core *c, pa_sink *sink, str
 
                 if ((d = pa_namereg_get(c, e->device, PA_NAMEREG_SINK)) &&
                     d != sink &&
-                    PA_SINK_IS_LINKED(pa_sink_get_state(d)))
+                    PA_SINK_IS_LINKED(d->state))
                     pa_sink_input_move_to(si, d, true);
             }
 
@@ -1815,7 +1815,7 @@ static pa_hook_result_t source_unlink_hook_callback(pa_core *c, pa_source *sourc
 
                 if ((d = pa_namereg_get(c, e->device, PA_NAMEREG_SOURCE)) &&
                     d != source &&
-                    PA_SOURCE_IS_LINKED(pa_source_get_state(d)))
+                    PA_SOURCE_IS_LINKED(d->state))
                     pa_source_output_move_to(so, d, true);
             }
 
diff --git a/src/modules/module-suspend-on-idle.c b/src/modules/module-suspend-on-idle.c
index 12702d1bd..08a1b1db8 100644
--- a/src/modules/module-suspend-on-idle.c
+++ b/src/modules/module-suspend-on-idle.c
@@ -390,18 +390,16 @@ static pa_hook_result_t device_state_changed_hook_cb(pa_core *c, pa_object *o, s
 
     if (pa_sink_isinstance(o)) {
         pa_sink *s = PA_SINK(o);
-        pa_sink_state_t state = pa_sink_get_state(s);
 
         if (pa_sink_check_suspend(s, NULL, NULL) <= 0)
-            if (PA_SINK_IS_OPENED(state))
+            if (PA_SINK_IS_OPENED(s->state))
                 restart(d);
 
     } else if (pa_source_isinstance(o)) {
         pa_source *s = PA_SOURCE(o);
-        pa_source_state_t state = pa_source_get_state(s);
 
         if (pa_source_check_suspend(s, NULL) <= 0)
-            if (PA_SOURCE_IS_OPENED(state))
+            if (PA_SOURCE_IS_OPENED(s->state))
                 restart(d);
     }
 
@@ -481,12 +479,12 @@ void pa__done(pa_module*m) {
     u = m->userdata;
 
     PA_HASHMAP_FOREACH(d, u->device_infos, state) {
-        if (d->sink && pa_sink_get_state(d->sink) == PA_SINK_SUSPENDED) {
+        if (d->sink && d->sink->state == PA_SINK_SUSPENDED) {
             pa_log_debug("Resuming sink %s on module unload.", d->sink->name);
             pa_sink_suspend(d->sink, false, PA_SUSPEND_IDLE);
         }
 
-        if (d->source && pa_source_get_state(d->source) == PA_SOURCE_SUSPENDED) {
+        if (d->source && d->source->state == PA_SOURCE_SUSPENDED) {
             pa_log_debug("Resuming source %s on module unload.", d->source->name);
             pa_source_suspend(d->source, false, PA_SUSPEND_IDLE);
         }
diff --git a/src/modules/module-tunnel.c b/src/modules/module-tunnel.c
index a9f26ad70..054d7d8f0 100644
--- a/src/modules/module-tunnel.c
+++ b/src/modules/module-tunnel.c
@@ -1669,7 +1669,7 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t
     pa_tagstruct_putu32(reply, PA_INVALID_INDEX);
     pa_tagstruct_puts(reply, u->sink_name);
     pa_tagstruct_putu32(reply, u->maxlength);
-    pa_tagstruct_put_boolean(reply, !PA_SINK_IS_OPENED(pa_sink_get_state(u->sink)));
+    pa_tagstruct_put_boolean(reply, !PA_SINK_IS_OPENED(u->sink->state));
     pa_tagstruct_putu32(reply, u->tlength);
     pa_tagstruct_putu32(reply, u->prebuf);
     pa_tagstruct_putu32(reply, u->minreq);
@@ -1688,7 +1688,7 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t
     pa_tagstruct_putu32(reply, PA_INVALID_INDEX);
     pa_tagstruct_puts(reply, u->source_name);
     pa_tagstruct_putu32(reply, u->maxlength);
-    pa_tagstruct_put_boolean(reply, !PA_SOURCE_IS_OPENED(pa_source_get_state(u->source)));
+    pa_tagstruct_put_boolean(reply, !PA_SOURCE_IS_OPENED(u->source->state));
     pa_tagstruct_putu32(reply, u->fragsize);
 #endif
 
diff --git a/src/modules/module-virtual-sink.c b/src/modules/module-virtual-sink.c
index 2f4445c26..bc109d54c 100644
--- a/src/modules/module-virtual-sink.c
+++ b/src/modules/module-virtual-sink.c
@@ -184,7 +184,7 @@ static void sink_set_volume_cb(pa_sink *s) {
     pa_sink_assert_ref(s);
     pa_assert_se(u = s->userdata);
 
-    if (!PA_SINK_IS_LINKED(pa_sink_get_state(s)) ||
+    if (!PA_SINK_IS_LINKED(s->state) ||
         !PA_SINK_INPUT_IS_LINKED(u->sink_input->state))
         return;
 
@@ -198,7 +198,7 @@ static void sink_set_mute_cb(pa_sink *s) {
     pa_sink_assert_ref(s);
     pa_assert_se(u = s->userdata);
 
-    if (!PA_SINK_IS_LINKED(pa_sink_get_state(s)) ||
+    if (!PA_SINK_IS_LINKED(s->state) ||
         !PA_SINK_INPUT_IS_LINKED(u->sink_input->state))
         return;
 
diff --git a/src/modules/module-virtual-source.c b/src/modules/module-virtual-source.c
index b6de7f499..ba8c52be7 100644
--- a/src/modules/module-virtual-source.c
+++ b/src/modules/module-virtual-source.c
@@ -232,7 +232,7 @@ static void source_set_volume_cb(pa_source *s) {
     pa_source_assert_ref(s);
     pa_assert_se(u = s->userdata);
 
-    if (!PA_SOURCE_IS_LINKED(pa_source_get_state(s)) ||
+    if (!PA_SOURCE_IS_LINKED(s->state) ||
         !PA_SOURCE_OUTPUT_IS_LINKED(u->source_output->state))
         return;
 
@@ -246,7 +246,7 @@ static void source_set_mute_cb(pa_source *s) {
     pa_source_assert_ref(s);
     pa_assert_se(u = s->userdata);
 
-    if (!PA_SOURCE_IS_LINKED(pa_source_get_state(s)) ||
+    if (!PA_SOURCE_IS_LINKED(s->state) ||
         !PA_SOURCE_OUTPUT_IS_LINKED(u->source_output->state))
         return;
 
@@ -273,7 +273,7 @@ static void source_output_push_cb(pa_source_output *o, const pa_memchunk *chunk)
 
     /* if uplink sink exists, pull data from there; simplify by using
        same length as chunk provided by source */
-    if (u->sink && (pa_sink_get_state(u->sink) == PA_SINK_RUNNING)) {
+    if (u->sink && (u->sink->thread_info.state == PA_SINK_RUNNING)) {
         pa_memchunk tchunk;
         size_t nbytes = chunk->length;
         pa_mix_info streams[2];
diff --git a/src/modules/module-virtual-surround-sink.c b/src/modules/module-virtual-surround-sink.c
index fe195cde5..d8e0fd94c 100644
--- a/src/modules/module-virtual-surround-sink.c
+++ b/src/modules/module-virtual-surround-sink.c
@@ -212,7 +212,7 @@ static void sink_set_volume_cb(pa_sink *s) {
     pa_sink_assert_ref(s);
     pa_assert_se(u = s->userdata);
 
-    if (!PA_SINK_IS_LINKED(pa_sink_get_state(s)) ||
+    if (!PA_SINK_IS_LINKED(s->state) ||
         !PA_SINK_INPUT_IS_LINKED(u->sink_input->state))
         return;
 
@@ -226,7 +226,7 @@ static void sink_set_mute_cb(pa_sink *s) {
     pa_sink_assert_ref(s);
     pa_assert_se(u = s->userdata);
 
-    if (!PA_SINK_IS_LINKED(pa_sink_get_state(s)) ||
+    if (!PA_SINK_IS_LINKED(s->state) ||
         !PA_SINK_INPUT_IS_LINKED(u->sink_input->state))
         return;
 
diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c
index defdac1ec..5205349bd 100644
--- a/src/pulsecore/cli-command.c
+++ b/src/pulsecore/cli-command.c
@@ -1829,7 +1829,7 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, bool
 
         pa_strbuf_printf(buf, "set-sink-volume %s 0x%03x\n", sink->name, pa_cvolume_max(pa_sink_get_volume(sink, false)));
         pa_strbuf_printf(buf, "set-sink-mute %s %s\n", sink->name, pa_yes_no(pa_sink_get_mute(sink, false)));
-        pa_strbuf_printf(buf, "suspend-sink %s %s\n", sink->name, pa_yes_no(pa_sink_get_state(sink) == PA_SINK_SUSPENDED));
+        pa_strbuf_printf(buf, "suspend-sink %s %s\n", sink->name, pa_yes_no(sink->state == PA_SINK_SUSPENDED));
     }
 
     nl = false;
@@ -1842,7 +1842,7 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, bool
 
         pa_strbuf_printf(buf, "set-source-volume %s 0x%03x\n", source->name, pa_cvolume_max(pa_source_get_volume(source, false)));
         pa_strbuf_printf(buf, "set-source-mute %s %s\n", source->name, pa_yes_no(pa_source_get_mute(source, false)));
-        pa_strbuf_printf(buf, "suspend-source %s %s\n", source->name, pa_yes_no(pa_source_get_state(source) == PA_SOURCE_SUSPENDED));
+        pa_strbuf_printf(buf, "suspend-source %s %s\n", source->name, pa_yes_no(source->state == PA_SOURCE_SUSPENDED));
     }
 
     nl = false;
diff --git a/src/pulsecore/cli-text.c b/src/pulsecore/cli-text.c
index 5be7c3cc9..14800514f 100644
--- a/src/pulsecore/cli-text.c
+++ b/src/pulsecore/cli-text.c
@@ -250,7 +250,7 @@ char *pa_sink_list_to_string(pa_core *c) {
             sink->flags & PA_SINK_LATENCY ? "LATENCY " : "",
             sink->flags & PA_SINK_FLAT_VOLUME ? "FLAT_VOLUME " : "",
             sink->flags & PA_SINK_DYNAMIC_LATENCY ? "DYNAMIC_LATENCY" : "",
-            pa_sink_state_to_string(pa_sink_get_state(sink)),
+            pa_sink_state_to_string(sink->state),
             pa_suspend_cause_to_string(sink->suspend_cause, suspend_cause_buf),
             sink->priority,
             pa_cvolume_snprint_verbose(cv,
@@ -361,7 +361,7 @@ char *pa_source_list_to_string(pa_core *c) {
             source->flags & PA_SOURCE_DECIBEL_VOLUME ? "DECIBEL_VOLUME " : "",
             source->flags & PA_SOURCE_LATENCY ? "LATENCY " : "",
             source->flags & PA_SOURCE_DYNAMIC_LATENCY ? "DYNAMIC_LATENCY" : "",
-            pa_source_state_to_string(pa_source_get_state(source)),
+            pa_source_state_to_string(source->state),
             pa_suspend_cause_to_string(source->suspend_cause, suspend_cause_buf),
             source->priority,
             pa_cvolume_snprint_verbose(cv,
diff --git a/src/pulsecore/core.c b/src/pulsecore/core.c
index da42a13e4..cc4a6f38b 100644
--- a/src/pulsecore/core.c
+++ b/src/pulsecore/core.c
@@ -481,12 +481,12 @@ void pa_core_maybe_vacuum(pa_core *c) {
 
         idx = 0;
         PA_IDXSET_FOREACH(si, c->sinks, idx)
-            if (pa_sink_get_state(si) != PA_SINK_SUSPENDED)
+            if (si->state != PA_SINK_SUSPENDED)
                 return;
 
         idx = 0;
         PA_IDXSET_FOREACH(so, c->sources, idx)
-            if (pa_source_get_state(so) != PA_SOURCE_SUSPENDED)
+            if (so->state != PA_SOURCE_SUSPENDED)
                 return;
 
         pa_log_info("All sinks and sources are suspended, vacuuming memory");
diff --git a/src/pulsecore/protocol-esound.c b/src/pulsecore/protocol-esound.c
index 708fa16b0..d54c7f845 100644
--- a/src/pulsecore/protocol-esound.c
+++ b/src/pulsecore/protocol-esound.c
@@ -966,18 +966,19 @@ static int esd_proto_standby_or_resume(connection *c, esd_proto_t request, const
 
 static int esd_proto_standby_mode(connection *c, esd_proto_t request, const void *data, size_t length) {
     int32_t mode;
-    pa_sink *sink, *source;
+    pa_sink *sink;
+    pa_source *source;
 
     connection_assert_ref(c);
 
     mode = ESM_RUNNING;
 
     if ((sink = pa_namereg_get(c->protocol->core, c->options->default_sink, PA_NAMEREG_SINK)))
-        if (pa_sink_get_state(sink) == PA_SINK_SUSPENDED)
+        if (sink->state == PA_SINK_SUSPENDED)
             mode = ESM_ON_STANDBY;
 
     if ((source = pa_namereg_get(c->protocol->core, c->options->default_source, PA_NAMEREG_SOURCE)))
-        if (pa_source_get_state(source) == PA_SOURCE_SUSPENDED)
+        if (source->state == PA_SOURCE_SUSPENDED)
             mode = ESM_ON_STANDBY;
 
     mode = PA_MAYBE_INT32_SWAP(c->swap_byte_order, mode);
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index 3def4a6ab..a52b976ee 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -1659,7 +1659,7 @@ static void sink_input_moving_cb(pa_sink_input *i, pa_sink *dest) {
     pa_tagstruct_putu32(t, s->index);
     pa_tagstruct_putu32(t, dest->index);
     pa_tagstruct_puts(t, dest->name);
-    pa_tagstruct_put_boolean(t, pa_sink_get_state(dest) == PA_SINK_SUSPENDED);
+    pa_tagstruct_put_boolean(t, dest->state == PA_SINK_SUSPENDED);
 
     if (s->connection->version >= 13) {
         pa_tagstruct_putu32(t, s->buffer_attr.maxlength);
@@ -1798,7 +1798,7 @@ static void source_output_moving_cb(pa_source_output *o, pa_source *dest) {
     pa_tagstruct_putu32(t, s->index);
     pa_tagstruct_putu32(t, dest->index);
     pa_tagstruct_puts(t, dest->name);
-    pa_tagstruct_put_boolean(t, pa_source_get_state(dest) == PA_SOURCE_SUSPENDED);
+    pa_tagstruct_put_boolean(t, dest->state == PA_SOURCE_SUSPENDED);
 
     if (s->connection->version >= 13) {
         pa_tagstruct_putu32(t, s->buffer_attr.maxlength);
@@ -2080,7 +2080,7 @@ static void command_create_playback_stream(pa_pdispatch *pd, uint32_t command, u
         pa_tagstruct_putu32(reply, s->sink_input->sink->index);
         pa_tagstruct_puts(reply, s->sink_input->sink->name);
 
-        pa_tagstruct_put_boolean(reply, pa_sink_get_state(s->sink_input->sink) == PA_SINK_SUSPENDED);
+        pa_tagstruct_put_boolean(reply, s->sink_input->sink->state == PA_SINK_SUSPENDED);
     }
 
     if (c->version >= 13)
@@ -2394,7 +2394,7 @@ static void command_create_record_stream(pa_pdispatch *pd, uint32_t command, uin
         pa_tagstruct_putu32(reply, s->source_output->source->index);
         pa_tagstruct_puts(reply, s->source_output->source->name);
 
-        pa_tagstruct_put_boolean(reply, pa_source_get_state(s->source_output->source) == PA_SOURCE_SUSPENDED);
+        pa_tagstruct_put_boolean(reply, s->source_output->source->state == PA_SOURCE_SUSPENDED);
     }
 
     if (c->version >= 13)
@@ -2879,7 +2879,7 @@ static void command_get_playback_latency(pa_pdispatch *pd, uint32_t command, uin
     pa_tagstruct_put_usec(reply, 0);
     pa_tagstruct_put_boolean(reply,
                              s->playing_for > 0 &&
-                             pa_sink_get_state(s->sink_input->sink) == PA_SINK_RUNNING &&
+                             s->sink_input->sink->state == PA_SINK_RUNNING &&
                              s->sink_input->state == PA_SINK_INPUT_RUNNING);
     pa_tagstruct_put_timeval(reply, &tv);
     pa_tagstruct_put_timeval(reply, pa_gettimeofday(&now));
@@ -2924,7 +2924,7 @@ static void command_get_record_latency(pa_pdispatch *pd, uint32_t command, uint3
                           s->current_source_latency +
                           pa_bytes_to_usec(s->on_the_fly_snapshot, &s->source_output->sample_spec));
     pa_tagstruct_put_boolean(reply,
-                             pa_source_get_state(s->source_output->source) == PA_SOURCE_RUNNING &&
+                             s->source_output->source->state == PA_SOURCE_RUNNING &&
                              s->source_output->state == PA_SOURCE_OUTPUT_RUNNING);
     pa_tagstruct_put_timeval(reply, &tv);
     pa_tagstruct_put_timeval(reply, pa_gettimeofday(&now));
@@ -3167,9 +3167,9 @@ static void sink_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_sin
 
     if (c->version >= 15) {
         pa_tagstruct_put_volume(t, sink->base_volume);
-        if (PA_UNLIKELY(pa_sink_get_state(sink) == PA_SINK_INVALID_STATE))
+        if (PA_UNLIKELY(sink->state == PA_SINK_INVALID_STATE))
             pa_log_error("Internal sink state is invalid.");
-        pa_tagstruct_putu32(t, pa_sink_get_state(sink));
+        pa_tagstruct_putu32(t, sink->state);
         pa_tagstruct_putu32(t, sink->n_volume_steps);
         pa_tagstruct_putu32(t, sink->card ? sink->card->index : PA_INVALID_INDEX);
     }
@@ -3237,9 +3237,9 @@ static void source_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_s
 
     if (c->version >= 15) {
         pa_tagstruct_put_volume(t, source->base_volume);
-        if (PA_UNLIKELY(pa_source_get_state(source) == PA_SOURCE_INVALID_STATE))
+        if (PA_UNLIKELY(source->state == PA_SOURCE_INVALID_STATE))
             pa_log_error("Internal source state is invalid.");
-        pa_tagstruct_putu32(t, pa_source_get_state(source));
+        pa_tagstruct_putu32(t, source->state);
         pa_tagstruct_putu32(t, source->n_volume_steps);
         pa_tagstruct_putu32(t, source->card ? source->card->index : PA_INVALID_INDEX);
     }
diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
index 2a8c6831d..312ec4a97 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -357,7 +357,7 @@ int pa_sink_input_new(
         return -PA_ERR_NOTSUPPORTED;
     }
 
-    pa_return_val_if_fail(PA_SINK_IS_LINKED(pa_sink_get_state(data->sink)), -PA_ERR_BADSTATE);
+    pa_return_val_if_fail(PA_SINK_IS_LINKED(data->sink->state), -PA_ERR_BADSTATE);
     pa_return_val_if_fail(!data->sync_base || (data->sync_base->sink == data->sink
                                                && data->sync_base->state == PA_SINK_INPUT_CORKED),
                           -PA_ERR_INVALID);
@@ -442,7 +442,7 @@ int pa_sink_input_new(
         return r;
 
     if ((data->flags & PA_SINK_INPUT_NO_CREATE_ON_SUSPEND) &&
-        pa_sink_get_state(data->sink) == PA_SINK_SUSPENDED) {
+        data->sink->state == PA_SINK_SUSPENDED) {
         pa_log_warn("Failed to create sink input: sink is suspended.");
         return -PA_ERR_BADSTATE;
     }
@@ -720,7 +720,7 @@ void pa_sink_input_unlink(pa_sink_input *i) {
     reset_callbacks(i);
 
     if (i->sink) {
-        if (PA_SINK_IS_LINKED(pa_sink_get_state(i->sink)))
+        if (PA_SINK_IS_LINKED(i->sink->state))
             pa_sink_update_status(i->sink);
 
         i->sink = NULL;
diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h
index 638d50693..8f254408f 100644
--- a/src/pulsecore/sink.h
+++ b/src/pulsecore/sink.h
@@ -494,8 +494,6 @@ unsigned pa_sink_used_by(pa_sink *s); /* Number of connected streams which are n
  * why "ignore_output" may be relevant). */
 unsigned pa_sink_check_suspend(pa_sink *s, pa_sink_input *ignore_input, pa_source_output *ignore_output);
 
-#define pa_sink_get_state(s) ((s)->state)
-
 const char *pa_sink_state_to_string(pa_sink_state_t state);
 
 /* Moves all inputs away, and stores them in pa_queue */
diff --git a/src/pulsecore/source-output.c b/src/pulsecore/source-output.c
index 7ee77cf93..955a2ac57 100644
--- a/src/pulsecore/source-output.c
+++ b/src/pulsecore/source-output.c
@@ -301,7 +301,7 @@ int pa_source_output_new(
         return -PA_ERR_NOTSUPPORTED;
     }
 
-    pa_return_val_if_fail(PA_SOURCE_IS_LINKED(pa_source_get_state(data->source)), -PA_ERR_BADSTATE);
+    pa_return_val_if_fail(PA_SOURCE_IS_LINKED(data->source->state), -PA_ERR_BADSTATE);
     pa_return_val_if_fail(!data->direct_on_input || data->direct_on_input->sink == data->source->monitor_of, -PA_ERR_INVALID);
 
     /* Routing is done. We have a source and a format. */
@@ -390,7 +390,7 @@ int pa_source_output_new(
         return r;
 
     if ((data->flags & PA_SOURCE_OUTPUT_NO_CREATE_ON_SUSPEND) &&
-        pa_source_get_state(data->source) == PA_SOURCE_SUSPENDED) {
+        data->source->state == PA_SOURCE_SUSPENDED) {
         pa_log("Failed to create source output: source is suspended.");
         return -PA_ERR_BADSTATE;
     }
@@ -612,7 +612,7 @@ void pa_source_output_unlink(pa_source_output*o) {
     reset_callbacks(o);
 
     if (o->source) {
-        if (PA_SOURCE_IS_LINKED(pa_source_get_state(o->source)))
+        if (PA_SOURCE_IS_LINKED(o->source->state))
             pa_source_update_status(o->source);
 
         o->source = NULL;
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index 6d4319632..b5017336f 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -842,7 +842,7 @@ int pa_source_sync_suspend(pa_source *s) {
     pa_assert(PA_SOURCE_IS_LINKED(s->state));
     pa_assert(s->monitor_of);
 
-    state = pa_sink_get_state(s->monitor_of);
+    state = s->monitor_of->state;
     suspend_cause = s->monitor_of->suspend_cause;
 
     /* The monitor source usually has the same state and suspend cause as the
diff --git a/src/pulsecore/source.h b/src/pulsecore/source.h
index f89a0c875..f4b69fe93 100644
--- a/src/pulsecore/source.h
+++ b/src/pulsecore/source.h
@@ -425,8 +425,6 @@ unsigned pa_source_used_by(pa_source *s); /* Number of connected streams that ar
  * "ignore" is non-NULL, that stream is not included in the count. */
 unsigned pa_source_check_suspend(pa_source *s, pa_source_output *ignore);
 
-#define pa_source_get_state(s) ((pa_source_state_t) (s)->state)
-
 const char *pa_source_state_to_string(pa_source_state_t state);
 
 /* Moves all inputs away, and stores them in pa_queue */
-- 
2.17.0



More information about the pulseaudio-discuss mailing list