[pulseaudio-commits] 5 commits - src/modules src/pulsecore
Tanu Kaskinen
tanuk at kemper.freedesktop.org
Fri Jun 29 04:48:07 PDT 2012
src/modules/alsa/alsa-mixer.c | 16 ++-
src/modules/alsa/alsa-mixer.h | 2
src/modules/alsa/alsa-sink.c | 2
src/modules/alsa/alsa-source.c | 2
src/modules/alsa/module-alsa-card.c | 1
src/modules/bluetooth/module-bluetooth-device.c | 11 --
src/modules/dbus/iface-card.c | 41 +---------
src/modules/dbus/iface-device.c | 32 ++-----
src/modules/module-card-restore.c | 2
src/modules/module-switch-on-port-available.c | 74 ++++++++----------
src/pulsecore/card.c | 10 +-
src/pulsecore/cli-command.c | 3
src/pulsecore/cli-text.c | 26 ++----
src/pulsecore/protocol-native.c | 97 ++++++++++--------------
src/pulsecore/sink.c | 7 -
src/pulsecore/source.c | 7 -
16 files changed, 140 insertions(+), 193 deletions(-)
New commits:
commit 8239fca09f4a500fbe333d215be899c5df34234e
Author: Tanu Kaskinen <tanuk at iki.fi>
Date: Fri Jun 8 21:49:12 2012 +0300
Assume that the ports hashmap of cards is always non-NULL.
The hashmap is created in pa_card_new_data_init().
diff --git a/src/modules/module-switch-on-port-available.c b/src/modules/module-switch-on-port-available.c
index 4c3d4af..1da612d 100644
--- a/src/modules/module-switch-on-port-available.c
+++ b/src/modules/module-switch-on-port-available.c
@@ -142,7 +142,7 @@ static pa_hook_result_t port_available_hook_callback(pa_core *c, pa_device_port
pa_log_debug("finding port %s", port->name);
PA_IDXSET_FOREACH(card, c->cards, state)
- if (card->ports && port == pa_hashmap_get(card->ports, port->name))
+ if (port == pa_hashmap_get(card->ports, port->name))
break;
if (!card) {
@@ -211,9 +211,6 @@ static void handle_all_unavailable(pa_core *core) {
pa_device_port *port;
void *state2;
- if (!card->ports)
- continue;
-
PA_HASHMAP_FOREACH(port, card->ports, state2) {
if (port->available == PA_PORT_AVAILABLE_NO)
port_available_hook_callback(core, port, NULL);
diff --git a/src/pulsecore/cli-text.c b/src/pulsecore/cli-text.c
index 8472b6c..e651919 100644
--- a/src/pulsecore/cli-text.c
+++ b/src/pulsecore/cli-text.c
@@ -120,7 +120,9 @@ static void append_port_list(pa_strbuf *s, pa_hashmap *ports)
pa_device_port *p;
void *state;
- if (!ports)
+ pa_assert(ports);
+
+ if (pa_hashmap_isempty(ports))
return;
pa_strbuf_puts(s, "\tports:\n");
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index bb61f75..3e9c911 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -3230,6 +3230,7 @@ static void client_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_c
static void card_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_card *card) {
void *state = NULL;
pa_card_profile *p;
+ pa_device_port *port;
pa_assert(t);
pa_assert(card);
@@ -3255,29 +3256,23 @@ static void card_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_car
if (c->version < 26)
return;
- if (card->ports) {
- pa_device_port* port;
+ pa_tagstruct_putu32(t, pa_hashmap_size(card->ports));
- pa_tagstruct_putu32(t, pa_hashmap_size(card->ports));
+ PA_HASHMAP_FOREACH(port, card->ports, state) {
+ void *state2;
- PA_HASHMAP_FOREACH(port, card->ports, state) {
- void *state2;
+ pa_tagstruct_puts(t, port->name);
+ pa_tagstruct_puts(t, port->description);
+ pa_tagstruct_putu32(t, port->priority);
+ pa_tagstruct_putu32(t, port->available);
+ pa_tagstruct_putu8(t, /* FIXME: port->direction */ (port->is_input ? PA_DIRECTION_INPUT : 0) | (port->is_output ? PA_DIRECTION_OUTPUT : 0));
+ pa_tagstruct_put_proplist(t, port->proplist);
- pa_tagstruct_puts(t, port->name);
- pa_tagstruct_puts(t, port->description);
- pa_tagstruct_putu32(t, port->priority);
- pa_tagstruct_putu32(t, port->available);
- pa_tagstruct_putu8(t, /* FIXME: port->direction */ (port->is_input ? PA_DIRECTION_INPUT : 0) | (port->is_output ? PA_DIRECTION_OUTPUT : 0));
- pa_tagstruct_put_proplist(t, port->proplist);
+ pa_tagstruct_putu32(t, pa_hashmap_size(port->profiles));
- pa_tagstruct_putu32(t, pa_hashmap_size(port->profiles));
-
- PA_HASHMAP_FOREACH(p, port->profiles, state2)
- pa_tagstruct_puts(t, p->name);
- }
-
- } else
- pa_tagstruct_putu32(t, 0);
+ PA_HASHMAP_FOREACH(p, port->profiles, state2)
+ pa_tagstruct_puts(t, p->name);
+ }
}
static void module_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_module *module) {
commit d184b54d7c93c18d7211cc4bf4b6a0bac0581e44
Author: Tanu Kaskinen <tanuk at iki.fi>
Date: Fri Jun 8 21:49:11 2012 +0300
Assume that the profiles hashmap of ports is always non-NULL.
It's a valid assumption nowadays, because the hashmap is
created in pa_device_port_new().
diff --git a/src/modules/module-switch-on-port-available.c b/src/modules/module-switch-on-port-available.c
index 5788825..4c3d4af 100644
--- a/src/modules/module-switch-on-port-available.c
+++ b/src/modules/module-switch-on-port-available.c
@@ -55,47 +55,47 @@ static pa_bool_t try_to_switch_profile(pa_card *card, pa_device_port *port) {
pa_log_debug("Finding best profile");
- if (port->profiles)
- PA_HASHMAP_FOREACH(profile, port->profiles, state) {
- if (best_profile && best_profile->priority >= profile->priority)
- continue;
+ PA_HASHMAP_FOREACH(profile, port->profiles, state) {
+ if (best_profile && best_profile->priority >= profile->priority)
+ continue;
+ /* We make a best effort to keep other direction unchanged */
+ if (!port->is_input) {
+ if (card->active_profile->n_sources != profile->n_sources)
+ continue;
- /* We make a best effort to keep other direction unchanged */
- if (!port->is_input) {
- if (card->active_profile->n_sources != profile->n_sources)
- continue;
+ if (card->active_profile->max_source_channels != profile->max_source_channels)
+ continue;
+ }
- if (card->active_profile->max_source_channels != profile->max_source_channels)
- continue;
- }
+ if (!port->is_output) {
+ if (card->active_profile->n_sinks != profile->n_sinks)
+ continue;
- if (!port->is_output) {
- if (card->active_profile->n_sinks != profile->n_sinks)
- continue;
+ if (card->active_profile->max_sink_channels != profile->max_sink_channels)
+ continue;
+ }
- if (card->active_profile->max_sink_channels != profile->max_sink_channels)
- continue;
- }
+ if (port->is_output) {
+ /* Try not to switch to HDMI sinks from analog when HDMI is becoming available */
+ uint32_t state2;
+ pa_sink *sink;
+ pa_bool_t found_active_port = FALSE;
- if (port->is_output) {
- /* Try not to switch to HDMI sinks from analog when HDMI is becoming available */
- uint32_t state2;
- pa_sink *sink;
- pa_bool_t found_active_port = FALSE;
- PA_IDXSET_FOREACH(sink, card->sinks, state2) {
- if (!sink->active_port)
- continue;
- if (sink->active_port->available != PA_PORT_AVAILABLE_NO)
- found_active_port = TRUE;
- }
- if (found_active_port)
+ PA_IDXSET_FOREACH(sink, card->sinks, state2) {
+ if (!sink->active_port)
continue;
+ if (sink->active_port->available != PA_PORT_AVAILABLE_NO)
+ found_active_port = TRUE;
}
- best_profile = profile;
+ if (found_active_port)
+ continue;
}
+ best_profile = profile;
+ }
+
if (!best_profile) {
pa_log_debug("No suitable profile found");
return FALSE;
@@ -152,8 +152,7 @@ static pa_hook_result_t port_available_hook_callback(pa_core *c, pa_device_port
find_sink_and_source(card, port, &sink, &source);
- is_active_profile = port->profiles &&
- card->active_profile == pa_hashmap_get(port->profiles, card->active_profile->name);
+ is_active_profile = card->active_profile == pa_hashmap_get(port->profiles, card->active_profile->name);
is_active_port = (sink && sink->active_port == port) || (source && source->active_port == port);
if (port->available == PA_PORT_AVAILABLE_NO && !is_active_port)
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index cb322cc..bb61f75 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -3261,6 +3261,8 @@ static void card_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_car
pa_tagstruct_putu32(t, pa_hashmap_size(card->ports));
PA_HASHMAP_FOREACH(port, card->ports, state) {
+ void *state2;
+
pa_tagstruct_puts(t, port->name);
pa_tagstruct_puts(t, port->description);
pa_tagstruct_putu32(t, port->priority);
@@ -3268,13 +3270,10 @@ static void card_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_car
pa_tagstruct_putu8(t, /* FIXME: port->direction */ (port->is_input ? PA_DIRECTION_INPUT : 0) | (port->is_output ? PA_DIRECTION_OUTPUT : 0));
pa_tagstruct_put_proplist(t, port->proplist);
- if (port->profiles) {
- void* state2;
- pa_tagstruct_putu32(t, pa_hashmap_size(port->profiles));
- PA_HASHMAP_FOREACH(p, port->profiles, state2)
- pa_tagstruct_puts(t, p->name);
- } else
- pa_tagstruct_putu32(t, 0);
+ pa_tagstruct_putu32(t, pa_hashmap_size(port->profiles));
+
+ PA_HASHMAP_FOREACH(p, port->profiles, state2)
+ pa_tagstruct_puts(t, p->name);
}
} else
commit 12af302ac7834f90231f727f00c20cad2c2cb5da
Author: Tanu Kaskinen <tanuk at iki.fi>
Date: Fri Jun 8 21:49:10 2012 +0300
card: Ensure that there's always at least one profile.
In practice there is always at least one profile, and I
don't think there will ever be cards without profiles.
Therefore, I added assertions to pa_card_new() stating that
the card new data must always contain at least one profile.
Now a lot of code can be simplified, because it's guaranteed
that the profiles hashmap and the active_profile field are
always non-NULL.
diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c
index b06394d..7e7e551 100644
--- a/src/modules/alsa/module-alsa-card.c
+++ b/src/modules/alsa/module-alsa-card.c
@@ -502,7 +502,6 @@ int pa__init(pa_module *m) {
if ((description = pa_proplist_gets(data.proplist, PA_PROP_DEVICE_DESCRIPTION)))
pa_reserve_wrapper_set_application_device_name(reserve, description);
- data.profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
add_profiles(u, data.profiles, data.ports);
if (pa_hashmap_isempty(data.profiles)) {
diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 84f0e72..06b4033 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -2852,8 +2852,6 @@ static int add_card(struct userdata *u, const pa_bluetooth_device *device) {
return -1;
}
- data.profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
-
/* we base hsp/a2dp availability on UUIDs.
Ideally, it would be based on "Connected" state, but
we can't afford to wait for this information when
diff --git a/src/modules/dbus/iface-card.c b/src/modules/dbus/iface-card.c
index d99c8b9..89e3988 100644
--- a/src/modules/dbus/iface-card.c
+++ b/src/modules/dbus/iface-card.c
@@ -309,16 +309,7 @@ static void handle_get_active_profile(DBusConnection *conn, DBusMessage *msg, vo
pa_assert(msg);
pa_assert(c);
- if (!c->active_profile) {
- pa_assert(pa_hashmap_isempty(c->profiles));
-
- pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY,
- "The card %s has no profiles, and therefore there's no active profile either.", c->card->name);
- return;
- }
-
active_profile = pa_dbusiface_card_profile_get_path(pa_hashmap_get(c->profiles, c->active_profile->name));
-
pa_dbus_send_basic_variant_reply(conn, msg, DBUS_TYPE_OBJECT_PATH, &active_profile);
}
@@ -333,15 +324,6 @@ static void handle_set_active_profile(DBusConnection *conn, DBusMessage *msg, DB
pa_assert(iter);
pa_assert(c);
- if (!c->active_profile) {
- pa_assert(pa_hashmap_isempty(c->profiles));
-
- pa_dbus_send_error(conn, msg, PA_DBUS_ERROR_NO_SUCH_PROPERTY,
- "The card %s has no profiles, and therefore there's no active profile either.",
- c->card->name);
- return;
- }
-
dbus_message_iter_get_basic(iter, &new_active_path);
if (!(new_active = pa_hashmap_get(c->profiles, new_active_path))) {
@@ -393,8 +375,7 @@ static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdat
sinks = get_sinks(c, &n_sinks);
sources = get_sources(c, &n_sources);
profiles = get_profiles(c, &n_profiles);
- if (c->active_profile)
- active_profile = pa_dbusiface_card_profile_get_path(pa_hashmap_get(c->profiles, c->active_profile->name));
+ active_profile = pa_dbusiface_card_profile_get_path(pa_hashmap_get(c->profiles, c->active_profile->name));
pa_assert_se((reply = dbus_message_new_method_return(msg)));
@@ -411,9 +392,7 @@ static void handle_get_all(DBusConnection *conn, DBusMessage *msg, void *userdat
pa_dbus_append_basic_array_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_SINKS].property_name, DBUS_TYPE_OBJECT_PATH, sinks, n_sinks);
pa_dbus_append_basic_array_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_SOURCES].property_name, DBUS_TYPE_OBJECT_PATH, sources, n_sources);
pa_dbus_append_basic_array_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_PROFILES].property_name, DBUS_TYPE_OBJECT_PATH, profiles, n_profiles);
-
- if (active_profile)
- pa_dbus_append_basic_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_ACTIVE_PROFILE].property_name, DBUS_TYPE_OBJECT_PATH, &active_profile);
+ pa_dbus_append_basic_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_ACTIVE_PROFILE].property_name, DBUS_TYPE_OBJECT_PATH, &active_profile);
pa_dbus_append_proplist_variant_dict_entry(&dict_iter, property_handlers[PROPERTY_HANDLER_PROPERTY_LIST].property_name, c->proplist);
@@ -501,6 +480,8 @@ static void subscription_cb(pa_core *core, pa_subscription_event_type_t t, uint3
pa_dbusiface_card *pa_dbusiface_card_new(pa_dbusiface_core *core, pa_card *card) {
pa_dbusiface_card *c = NULL;
+ pa_card_profile *profile;
+ void *state;
pa_assert(core);
pa_assert(card);
@@ -511,20 +492,14 @@ pa_dbusiface_card *pa_dbusiface_card_new(pa_dbusiface_core *core, pa_card *card)
c->path = pa_sprintf_malloc("%s/%s%u", PA_DBUS_CORE_OBJECT_PATH, OBJECT_NAME, card->index);
c->profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
c->next_profile_index = 0;
- c->active_profile = NULL;
+ c->active_profile = card->active_profile;
c->proplist = pa_proplist_copy(card->proplist);
c->dbus_protocol = pa_dbus_protocol_get(card->core);
c->subscription = pa_subscription_new(card->core, PA_SUBSCRIPTION_MASK_CARD, subscription_cb, c);
- if (card->profiles) {
- pa_card_profile *profile;
- void *state = NULL;
-
- PA_HASHMAP_FOREACH(profile, card->profiles, state) {
- pa_dbusiface_card_profile *p = pa_dbusiface_card_profile_new(c, card->core, profile, c->next_profile_index++);
- pa_hashmap_put(c->profiles, pa_dbusiface_card_profile_get_name(p), p);
- }
- pa_assert_se(c->active_profile = card->active_profile);
+ PA_HASHMAP_FOREACH(profile, card->profiles, state) {
+ pa_dbusiface_card_profile *p = pa_dbusiface_card_profile_new(c, card->core, profile, c->next_profile_index++);
+ pa_hashmap_put(c->profiles, pa_dbusiface_card_profile_get_name(p), p);
}
pa_assert_se(pa_dbus_protocol_add_interface(c->dbus_protocol, c->path, &card_interface_info, c) >= 0);
diff --git a/src/modules/module-card-restore.c b/src/modules/module-card-restore.c
index e90e610..1079a72 100644
--- a/src/modules/module-card-restore.c
+++ b/src/modules/module-card-restore.c
@@ -253,7 +253,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
return;
entry = entry_new();
- entry->profile = pa_xstrdup(card->active_profile ? card->active_profile->name : "");
+ entry->profile = pa_xstrdup(card->active_profile->name);
if ((old = entry_read(u, card->name))) {
diff --git a/src/modules/module-switch-on-port-available.c b/src/modules/module-switch-on-port-available.c
index f60d11e..5788825 100644
--- a/src/modules/module-switch-on-port-available.c
+++ b/src/modules/module-switch-on-port-available.c
@@ -60,10 +60,6 @@ static pa_bool_t try_to_switch_profile(pa_card *card, pa_device_port *port) {
if (best_profile && best_profile->priority >= profile->priority)
continue;
- if (!card->active_profile) {
- best_profile = profile;
- continue;
- }
/* We make a best effort to keep other direction unchanged */
if (!port->is_input) {
@@ -156,7 +152,7 @@ static pa_hook_result_t port_available_hook_callback(pa_core *c, pa_device_port
find_sink_and_source(card, port, &sink, &source);
- is_active_profile = port->profiles && card->active_profile &&
+ is_active_profile = port->profiles &&
card->active_profile == pa_hashmap_get(port->profiles, card->active_profile->name);
is_active_port = (sink && sink->active_port == port) || (source && source->active_port == port);
diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c
index d1f0de8..492c051 100644
--- a/src/pulsecore/card.c
+++ b/src/pulsecore/card.c
@@ -67,6 +67,7 @@ pa_card_new_data* pa_card_new_data_init(pa_card_new_data *data) {
memset(data, 0, sizeof(*data));
data->proplist = pa_proplist_new();
+ data->profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
data->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
return data;
}
@@ -114,6 +115,8 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
pa_core_assert_ref(core);
pa_assert(data);
pa_assert(data->name);
+ pa_assert(data->profiles);
+ pa_assert(!pa_hashmap_isempty(data->profiles));
c = pa_xnew(pa_card, 1);
@@ -149,11 +152,11 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
c->active_profile = NULL;
c->save_profile = FALSE;
- if (data->active_profile && c->profiles)
+ if (data->active_profile)
if ((c->active_profile = pa_hashmap_get(c->profiles, data->active_profile)))
c->save_profile = data->save_profile;
- if (!c->active_profile && c->profiles) {
+ if (!c->active_profile) {
void *state;
pa_card_profile *p;
@@ -221,6 +224,7 @@ void pa_card_free(pa_card *c) {
int pa_card_set_profile(pa_card *c, const char *name, pa_bool_t save) {
pa_card_profile *profile;
int r;
+
pa_assert(c);
if (!c->set_profile) {
@@ -228,7 +232,7 @@ int pa_card_set_profile(pa_card *c, const char *name, pa_bool_t save) {
return -PA_ERR_NOTIMPLEMENTED;
}
- if (!c->profiles || !name)
+ if (!name)
return -PA_ERR_NOENTITY;
if (!(profile = pa_hashmap_get(c->profiles, name)))
diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c
index a772e1e..130185a 100644
--- a/src/pulsecore/cli-command.c
+++ b/src/pulsecore/cli-command.c
@@ -1840,8 +1840,7 @@ static int pa_cli_command_dump(pa_core *c, pa_tokenizer *t, pa_strbuf *buf, pa_b
nl = TRUE;
}
- if (card->active_profile)
- pa_strbuf_printf(buf, "set-card-profile %s %s\n", card->name, card->active_profile->name);
+ pa_strbuf_printf(buf, "set-card-profile %s %s\n", card->name, card->active_profile->name);
}
nl = FALSE;
diff --git a/src/pulsecore/cli-text.c b/src/pulsecore/cli-text.c
index f322172..8472b6c 100644
--- a/src/pulsecore/cli-text.c
+++ b/src/pulsecore/cli-text.c
@@ -149,6 +149,8 @@ char *pa_card_list_to_string(pa_core *c) {
pa_sink *sink;
pa_source *source;
uint32_t sidx;
+ pa_card_profile *profile;
+ void *state;
pa_strbuf_printf(
s,
@@ -166,20 +168,14 @@ char *pa_card_list_to_string(pa_core *c) {
pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
pa_xfree(t);
- if (card->profiles) {
- pa_card_profile *p;
- void *state;
+ pa_strbuf_puts(s, "\tprofiles:\n");
+ PA_HASHMAP_FOREACH(profile, card->profiles, state)
+ pa_strbuf_printf(s, "\t\t%s: %s (priority %u)\n", profile->name, profile->description, profile->priority);
- pa_strbuf_puts(s, "\tprofiles:\n");
- PA_HASHMAP_FOREACH(p, card->profiles, state)
- pa_strbuf_printf(s, "\t\t%s: %s (priority %u)\n", p->name, p->description, p->priority);
- }
-
- if (card->active_profile)
- pa_strbuf_printf(
- s,
- "\tactive profile: <%s>\n",
- card->active_profile->name);
+ pa_strbuf_printf(
+ s,
+ "\tactive profile: <%s>\n",
+ card->active_profile->name);
if (!pa_idxset_isempty(card->sinks)) {
pa_strbuf_puts(s, "\tsinks:\n");
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index 25b9e75..cb322cc 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -3239,19 +3239,17 @@ static void card_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_car
pa_tagstruct_putu32(t, card->module ? card->module->index : PA_INVALID_INDEX);
pa_tagstruct_puts(t, card->driver);
- pa_tagstruct_putu32(t, card->profiles ? pa_hashmap_size(card->profiles) : 0);
+ pa_tagstruct_putu32(t, pa_hashmap_size(card->profiles));
- if (card->profiles) {
- while ((p = pa_hashmap_iterate(card->profiles, &state, NULL))) {
- pa_tagstruct_puts(t, p->name);
- pa_tagstruct_puts(t, p->description);
- pa_tagstruct_putu32(t, p->n_sinks);
- pa_tagstruct_putu32(t, p->n_sources);
- pa_tagstruct_putu32(t, p->priority);
- }
+ PA_HASHMAP_FOREACH(p, card->profiles, state) {
+ pa_tagstruct_puts(t, p->name);
+ pa_tagstruct_puts(t, p->description);
+ pa_tagstruct_putu32(t, p->n_sinks);
+ pa_tagstruct_putu32(t, p->n_sources);
+ pa_tagstruct_putu32(t, p->priority);
}
- pa_tagstruct_puts(t, card->active_profile ? card->active_profile->name : NULL);
+ pa_tagstruct_puts(t, card->active_profile->name);
pa_tagstruct_put_proplist(t, card->proplist);
if (c->version < 26)
commit 1a6da64b16ae6aacb1af195275883b88c596a960
Author: Tanu Kaskinen <tanuk at iki.fi>
Date: Fri Jun 8 21:49:09 2012 +0300
sink, source: Always create a hashmap for ports.
Having the hashmap sometimes NULL requires a lot of checking
here and there, so ensuring that the hashmap is always
non-NULL simplifies the code.
diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index 63370da..ee59dea 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -4462,17 +4462,21 @@ void pa_alsa_path_set_add_ports(
}
}
-void pa_alsa_add_ports(pa_hashmap **p, pa_alsa_path_set *ps, pa_card *card) {
+void pa_alsa_add_ports(void *sink_or_source_new_data, pa_alsa_path_set *ps, pa_card *card) {
+ pa_hashmap *ports;
- pa_assert(p);
- pa_assert(!*p);
+ pa_assert(sink_or_source_new_data);
pa_assert(ps);
+ if (ps->direction == PA_ALSA_DIRECTION_OUTPUT)
+ ports = ((pa_sink_new_data *) sink_or_source_new_data)->ports;
+ else
+ ports = ((pa_source_new_data *) sink_or_source_new_data)->ports;
+
if (ps->paths && pa_hashmap_size(ps->paths) > 0) {
pa_assert(card);
- *p = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
- pa_alsa_path_set_add_ports(ps, NULL, card->ports, *p, card->core);
+ pa_alsa_path_set_add_ports(ps, NULL, card->ports, ports, card->core);
}
- pa_log_debug("Added %u ports", *p ? pa_hashmap_size(*p) : 0);
+ pa_log_debug("Added %u ports", pa_hashmap_size(ports));
}
diff --git a/src/modules/alsa/alsa-mixer.h b/src/modules/alsa/alsa-mixer.h
index 6b12a7f..111dfaa 100644
--- a/src/modules/alsa/alsa-mixer.h
+++ b/src/modules/alsa/alsa-mixer.h
@@ -340,7 +340,7 @@ struct pa_alsa_port_data {
pa_alsa_setting *setting;
};
-void pa_alsa_add_ports(pa_hashmap **p, pa_alsa_path_set *ps, pa_card *card);
+void pa_alsa_add_ports(void *sink_or_source_new_data, pa_alsa_path_set *ps, pa_card *card);
void pa_alsa_path_set_add_ports(pa_alsa_path_set *ps, pa_card_profile *cp, pa_hashmap *ports, pa_hashmap *extra, pa_core *core);
#endif
diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index 1bee8f3..472d66a 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -2226,7 +2226,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
}
if (u->mixer_path_set)
- pa_alsa_add_ports(&data.ports, u->mixer_path_set, card);
+ pa_alsa_add_ports(&data, u->mixer_path_set, card);
u->sink = pa_sink_new(m->core, &data, PA_SINK_HARDWARE | PA_SINK_LATENCY | (u->use_tsched ? PA_SINK_DYNAMIC_LATENCY : 0) |
(set_formats ? PA_SINK_SET_FORMATS : 0));
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index dfad817..c27bbc2 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -1952,7 +1952,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
}
if (u->mixer_path_set)
- pa_alsa_add_ports(&data.ports, u->mixer_path_set, card);
+ pa_alsa_add_ports(&data, u->mixer_path_set, card);
u->source = pa_source_new(m->core, &data, PA_SOURCE_HARDWARE|PA_SOURCE_LATENCY|(u->use_tsched ? PA_SOURCE_DYNAMIC_LATENCY : 0));
pa_source_new_data_done(&data);
diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index d62cf06..84f0e72 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -2073,13 +2073,10 @@ static void connect_ports(struct userdata *u, void *sink_or_source_new_data, pa_
} data;
pa_device_port *port;
- if (direction == PA_DIRECTION_OUTPUT) {
+ if (direction == PA_DIRECTION_OUTPUT)
data.sink_new_data = sink_or_source_new_data;
- data.sink_new_data->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
- } else {
+ else
data.source_new_data = sink_or_source_new_data;
- data.source_new_data->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
- }
switch (u->profile) {
case PROFILE_A2DP:
@@ -2118,7 +2115,7 @@ static void connect_ports(struct userdata *u, void *sink_or_source_new_data, pa_
default:
pa_assert_not_reached();
- }
+ }
}
/* Run from main thread */
diff --git a/src/modules/dbus/iface-device.c b/src/modules/dbus/iface-device.c
index a5af730..316aba5 100644
--- a/src/modules/dbus/iface-device.c
+++ b/src/modules/dbus/iface-device.c
@@ -1189,6 +1189,8 @@ static void subscription_cb(pa_core *c, pa_subscription_event_type_t t, uint32_t
pa_dbusiface_device *pa_dbusiface_device_new_sink(pa_dbusiface_core *core, pa_sink *sink) {
pa_dbusiface_device *d = NULL;
+ pa_device_port *port;
+ void *state;
pa_assert(core);
pa_assert(sink);
@@ -1203,20 +1205,14 @@ pa_dbusiface_device *pa_dbusiface_device_new_sink(pa_dbusiface_core *core, pa_si
d->sink_state = pa_sink_get_state(sink);
d->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
d->next_port_index = 0;
- d->active_port = NULL;
+ d->active_port = sink->active_port;
d->proplist = pa_proplist_copy(sink->proplist);
d->dbus_protocol = pa_dbus_protocol_get(sink->core);
d->subscription = pa_subscription_new(sink->core, PA_SUBSCRIPTION_MASK_SINK, subscription_cb, d);
- if (sink->ports) {
- pa_device_port *port;
- void *state = NULL;
-
- PA_HASHMAP_FOREACH(port, sink->ports, state) {
- pa_dbusiface_device_port *p = pa_dbusiface_device_port_new(d, sink->core, port, d->next_port_index++);
- pa_hashmap_put(d->ports, pa_dbusiface_device_port_get_name(p), p);
- }
- pa_assert_se(d->active_port = sink->active_port);
+ PA_HASHMAP_FOREACH(port, sink->ports, state) {
+ pa_dbusiface_device_port *p = pa_dbusiface_device_port_new(d, sink->core, port, d->next_port_index++);
+ pa_hashmap_put(d->ports, pa_dbusiface_device_port_get_name(p), p);
}
pa_assert_se(pa_dbus_protocol_add_interface(d->dbus_protocol, d->path, &device_interface_info, d) >= 0);
@@ -1227,6 +1223,8 @@ pa_dbusiface_device *pa_dbusiface_device_new_sink(pa_dbusiface_core *core, pa_si
pa_dbusiface_device *pa_dbusiface_device_new_source(pa_dbusiface_core *core, pa_source *source) {
pa_dbusiface_device *d = NULL;
+ pa_device_port *port;
+ void *state;
pa_assert(core);
pa_assert(source);
@@ -1241,20 +1239,14 @@ pa_dbusiface_device *pa_dbusiface_device_new_source(pa_dbusiface_core *core, pa_
d->source_state = pa_source_get_state(source);
d->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
d->next_port_index = 0;
- d->active_port = NULL;
+ d->active_port = source->active_port;
d->proplist = pa_proplist_copy(source->proplist);
d->dbus_protocol = pa_dbus_protocol_get(source->core);
d->subscription = pa_subscription_new(source->core, PA_SUBSCRIPTION_MASK_SOURCE, subscription_cb, d);
- if (source->ports) {
- pa_device_port *port;
- void *state = NULL;
-
- PA_HASHMAP_FOREACH(port, source->ports, state) {
- pa_dbusiface_device_port *p = pa_dbusiface_device_port_new(d, source->core, port, d->next_port_index++);
- pa_hashmap_put(d->ports, pa_dbusiface_device_port_get_name(p), p);
- }
- pa_assert_se(d->active_port = source->active_port);
+ PA_HASHMAP_FOREACH(port, source->ports, state) {
+ pa_dbusiface_device_port *p = pa_dbusiface_device_port_new(d, source->core, port, d->next_port_index++);
+ pa_hashmap_put(d->ports, pa_dbusiface_device_port_get_name(p), p);
}
pa_assert_se(pa_dbus_protocol_add_interface(d->dbus_protocol, d->path, &device_interface_info, d) >= 0);
diff --git a/src/modules/module-switch-on-port-available.c b/src/modules/module-switch-on-port-available.c
index f198e44..f60d11e 100644
--- a/src/modules/module-switch-on-port-available.c
+++ b/src/modules/module-switch-on-port-available.c
@@ -121,12 +121,12 @@ static void find_sink_and_source(pa_card *card, pa_device_port *port, pa_sink **
if (port->is_output)
PA_IDXSET_FOREACH(sink, card->sinks, state)
- if (sink->ports && port == pa_hashmap_get(sink->ports, port->name))
+ if (port == pa_hashmap_get(sink->ports, port->name))
break;
if (port->is_input)
PA_IDXSET_FOREACH(source, card->sources, state)
- if (source->ports && port == pa_hashmap_get(source->ports, port->name))
+ if (port == pa_hashmap_get(source->ports, port->name))
break;
*si = sink;
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index e59bf7e..25b9e75 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -3114,19 +3114,17 @@ static void sink_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_sin
}
if (c->version >= 16) {
- pa_tagstruct_putu32(t, sink->ports ? pa_hashmap_size(sink->ports) : 0);
-
- if (sink->ports) {
- void *state;
- pa_device_port *p;
-
- PA_HASHMAP_FOREACH(p, sink->ports, state) {
- pa_tagstruct_puts(t, p->name);
- pa_tagstruct_puts(t, p->description);
- pa_tagstruct_putu32(t, p->priority);
- if (c->version >= 24)
- pa_tagstruct_putu32(t, p->available);
- }
+ void *state;
+ pa_device_port *p;
+
+ pa_tagstruct_putu32(t, pa_hashmap_size(sink->ports));
+
+ PA_HASHMAP_FOREACH(p, sink->ports, state) {
+ pa_tagstruct_puts(t, p->name);
+ pa_tagstruct_puts(t, p->description);
+ pa_tagstruct_putu32(t, p->priority);
+ if (c->version >= 24)
+ pa_tagstruct_putu32(t, p->available);
}
pa_tagstruct_puts(t, sink->active_port ? sink->active_port->name : NULL);
@@ -3186,20 +3184,17 @@ static void source_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_s
}
if (c->version >= 16) {
+ void *state;
+ pa_device_port *p;
- pa_tagstruct_putu32(t, source->ports ? pa_hashmap_size(source->ports) : 0);
+ pa_tagstruct_putu32(t, pa_hashmap_size(source->ports));
- if (source->ports) {
- void *state;
- pa_device_port *p;
-
- PA_HASHMAP_FOREACH(p, source->ports, state) {
- pa_tagstruct_puts(t, p->name);
- pa_tagstruct_puts(t, p->description);
- pa_tagstruct_putu32(t, p->priority);
- if (c->version >= 24)
- pa_tagstruct_putu32(t, p->available);
- }
+ PA_HASHMAP_FOREACH(p, source->ports, state) {
+ pa_tagstruct_puts(t, p->name);
+ pa_tagstruct_puts(t, p->description);
+ pa_tagstruct_putu32(t, p->priority);
+ if (c->version >= 24)
+ pa_tagstruct_putu32(t, p->available);
}
pa_tagstruct_puts(t, source->active_port ? source->active_port->name : NULL);
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 6186204..3d72f55 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -81,6 +81,7 @@ pa_sink_new_data* pa_sink_new_data_init(pa_sink_new_data *data) {
pa_zero(*data);
data->proplist = pa_proplist_new();
+ data->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
return data;
}
@@ -295,11 +296,11 @@ pa_sink* pa_sink_new(
s->active_port = NULL;
s->save_port = FALSE;
- if (data->active_port && s->ports)
+ if (data->active_port)
if ((s->active_port = pa_hashmap_get(s->ports, data->active_port)))
s->save_port = data->save_port;
- if (!s->active_port && s->ports) {
+ if (!s->active_port) {
void *state;
pa_device_port *p;
@@ -3300,7 +3301,7 @@ int pa_sink_set_port(pa_sink *s, const char *name, pa_bool_t save) {
return -PA_ERR_NOTIMPLEMENTED;
}
- if (!s->ports || !name)
+ if (!name)
return -PA_ERR_NOENTITY;
if (!(port = pa_hashmap_get(s->ports, name)))
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index f59abea..cefddae 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -73,6 +73,7 @@ pa_source_new_data* pa_source_new_data_init(pa_source_new_data *data) {
pa_zero(*data);
data->proplist = pa_proplist_new();
+ data->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
return data;
}
@@ -283,11 +284,11 @@ pa_source* pa_source_new(
s->active_port = NULL;
s->save_port = FALSE;
- if (data->active_port && s->ports)
+ if (data->active_port)
if ((s->active_port = pa_hashmap_get(s->ports, data->active_port)))
s->save_port = data->save_port;
- if (!s->active_port && s->ports) {
+ if (!s->active_port) {
void *state;
pa_device_port *p;
@@ -2570,7 +2571,7 @@ int pa_source_set_port(pa_source *s, const char *name, pa_bool_t save) {
return -PA_ERR_NOTIMPLEMENTED;
}
- if (!s->ports || !name)
+ if (!name)
return -PA_ERR_NOENTITY;
if (!(port = pa_hashmap_get(s->ports, name)))
commit 21c6c704383d38125c8208711f292427ac4544ca
Author: Tanu Kaskinen <tanuk at iki.fi>
Date: Fri Jun 8 19:36:45 2012 +0300
card: Don't crash if someone gives NULL name to pa_card_set_profile().
In my opinion, pa_card_set_profile() should assert that name
is not NULL, and it would be the job of the client interface
to filter out NULLs from the client input, but this is done
this way also when setting sink and source ports, so for
consistency I'll do this this way for now.
diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c
index 1d0a9ea..d1f0de8 100644
--- a/src/pulsecore/card.c
+++ b/src/pulsecore/card.c
@@ -228,7 +228,7 @@ int pa_card_set_profile(pa_card *c, const char *name, pa_bool_t save) {
return -PA_ERR_NOTIMPLEMENTED;
}
- if (!c->profiles)
+ if (!c->profiles || !name)
return -PA_ERR_NOENTITY;
if (!(profile = pa_hashmap_get(c->profiles, name)))
More information about the pulseaudio-commits
mailing list