[pulseaudio-discuss] [PATCH 5/5] sink, source: New functions: pa_{sink, source}_new_data_add_port().
Tanu Kaskinen
tanuk at iki.fi
Fri Jun 8 11:49:13 PDT 2012
It's a bit confusing that when adding ports to a new sink or
source, the ports have to be reffed by the implementor, but
they will be unreffed when the sink or source is freed. It
may appear as if the sink or source implementation has a
bug, because it looks like there's no corresponding unref()
call for the ref() call. This patch tries to make things
less confusing by moving the ref() operation to sink.c and
source.c - the same files where the unref() calls are made.
Another benefit is that creating ports is now slightly more
convenient, because one call does two things: adds the new
port to the hashmap and refs the port.
---
src/modules/alsa/alsa-mixer.c | 21 +++++++++++++--------
src/modules/alsa/alsa-mixer.h | 2 +-
src/modules/bluetooth/module-bluetooth-device.c | 16 ++++++----------
src/pulsecore/sink.c | 8 ++++++++
src/pulsecore/sink.h | 1 +
src/pulsecore/source.c | 8 ++++++++
src/pulsecore/source.h | 1 +
7 files changed, 38 insertions(+), 19 deletions(-)
diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index 9a5a60d..3bea8a9 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -4499,7 +4499,7 @@ static pa_device_port* device_port_alsa_init(pa_hashmap *ports,
pa_alsa_path *path,
pa_alsa_setting *setting,
pa_card_profile *cp,
- pa_hashmap *extra,
+ void *sink_or_source_new_data,
pa_core *core) {
pa_device_port * p = pa_hashmap_get(ports, name);
@@ -4522,9 +4522,14 @@ static pa_device_port* device_port_alsa_init(pa_hashmap *ports,
if (cp)
pa_hashmap_put(p->profiles, cp->name, cp);
- if (extra) {
- pa_hashmap_put(extra, p->name, p);
- pa_device_port_ref(p);
+ if (sink_or_source_new_data) {
+ if (p->is_output) {
+ /* FIXME: This is not entirely safe as long as dual-direction ports
+ * are possible. */
+ pa_assert(!p->is_input);
+ pa_sink_new_data_add_port(sink_or_source_new_data, p);
+ } else
+ pa_source_new_data_add_port(sink_or_source_new_data, p);
}
return p;
@@ -4534,7 +4539,7 @@ void pa_alsa_path_set_add_ports(
pa_alsa_path_set *ps,
pa_card_profile *cp,
pa_hashmap *ports,
- pa_hashmap *extra,
+ void *sink_or_source_new_data,
pa_core *core) {
pa_alsa_path *path;
@@ -4550,7 +4555,7 @@ void pa_alsa_path_set_add_ports(
/* If there is no or just one setting we only need a
* single entry */
pa_device_port *port = device_port_alsa_init(ports, path->name,
- path->description, path, path->settings, cp, extra, core);
+ path->description, path, path->settings, cp, sink_or_source_new_data, core);
port->priority = path->priority * 100;
} else {
@@ -4566,7 +4571,7 @@ void pa_alsa_path_set_add_ports(
else
d = pa_xstrdup(path->description);
- port = device_port_alsa_init(ports, n, d, path, s, cp, extra, core);
+ port = device_port_alsa_init(ports, n, d, path, s, cp, sink_or_source_new_data, core);
port->priority = path->priority * 100 + s->priority;
pa_xfree(n);
@@ -4589,7 +4594,7 @@ void pa_alsa_add_ports(void *sink_or_source_new_data, pa_alsa_path_set *ps, pa_c
if (ps->paths && pa_hashmap_size(ps->paths) > 0) {
pa_assert(card);
- pa_alsa_path_set_add_ports(ps, NULL, card->ports, ports, card->core);
+ pa_alsa_path_set_add_ports(ps, NULL, card->ports, sink_or_source_new_data, card->core);
}
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 db0d25e..635564e 100644
--- a/src/modules/alsa/alsa-mixer.h
+++ b/src/modules/alsa/alsa-mixer.h
@@ -340,6 +340,6 @@ struct pa_alsa_port_data {
};
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);
+void pa_alsa_path_set_add_ports(pa_alsa_path_set *ps, pa_card_profile *cp, pa_hashmap *ports, void *sink_or_source_new_data, pa_core *core);
#endif
diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 4c0325a..cf84d04 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -2088,36 +2088,32 @@ static void connect_ports(struct userdata *u, void *sink_or_source_new_data, pa_
switch (u->profile) {
case PROFILE_A2DP:
pa_assert_se(port = pa_hashmap_get(u->card->ports, "a2dp-output"));
- pa_assert_se(pa_hashmap_put(data.sink_new_data->ports, port->name, port) >= 0);
- pa_device_port_ref(port);
+ pa_sink_new_data_add_port(data.sink_new_data, port);
break;
case PROFILE_A2DP_SOURCE:
pa_assert_se(port = pa_hashmap_get(u->card->ports, "a2dp-input"));
- pa_assert_se(pa_hashmap_put(data.source_new_data->ports, port->name, port) >= 0);
- pa_device_port_ref(port);
+ pa_source_new_data_add_port(data.source_new_data, port);
break;
case PROFILE_HSP:
if (direction == PA_DIRECTION_OUTPUT) {
pa_assert_se(port = pa_hashmap_get(u->card->ports, "hsp-output"));
- pa_assert_se(pa_hashmap_put(data.sink_new_data->ports, port->name, port) >= 0);
+ pa_sink_new_data_add_port(data.sink_new_data, port);
} else {
pa_assert_se(port = pa_hashmap_get(u->card->ports, "hsp-input"));
- pa_assert_se(pa_hashmap_put(data.source_new_data->ports, port->name, port) >= 0);
+ pa_source_new_data_add_port(data.source_new_data, port);
}
- pa_device_port_ref(port);
break;
case PROFILE_HFGW:
if (direction == PA_DIRECTION_OUTPUT) {
pa_assert_se(port = pa_hashmap_get(u->card->ports, "hfgw-output"));
- pa_assert_se(pa_hashmap_put(data.sink_new_data->ports, port->name, port) >= 0);
+ pa_sink_new_data_add_port(data.sink_new_data, port);
} else {
pa_assert_se(port = pa_hashmap_get(u->card->ports, "hfgw-input"));
- pa_assert_se(pa_hashmap_put(data.source_new_data->ports, port->name, port) >= 0);
+ pa_source_new_data_add_port(data.source_new_data, port);
}
- pa_device_port_ref(port);
break;
default:
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 50d4013..7ec1a21 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -128,6 +128,14 @@ void pa_sink_new_data_set_muted(pa_sink_new_data *data, pa_bool_t mute) {
data->muted = !!mute;
}
+void pa_sink_new_data_add_port(pa_sink_new_data *data, pa_device_port *port) {
+ pa_assert(data);
+ pa_assert(port);
+
+ pa_assert_se(pa_hashmap_put(data->ports, port->name, port) >= 0);
+ pa_device_port_ref(port);
+}
+
void pa_sink_new_data_set_port(pa_sink_new_data *data, const char *port) {
pa_assert(data);
diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h
index 0b5048a..942fb09 100644
--- a/src/pulsecore/sink.h
+++ b/src/pulsecore/sink.h
@@ -357,6 +357,7 @@ void pa_sink_new_data_set_channel_map(pa_sink_new_data *data, const pa_channel_m
void pa_sink_new_data_set_alternate_sample_rate(pa_sink_new_data *data, const uint32_t alternate_sample_rate);
void pa_sink_new_data_set_volume(pa_sink_new_data *data, const pa_cvolume *volume);
void pa_sink_new_data_set_muted(pa_sink_new_data *data, pa_bool_t mute);
+void pa_sink_new_data_add_port(pa_sink_new_data *data, pa_device_port *port);
void pa_sink_new_data_set_port(pa_sink_new_data *data, const char *port);
void pa_sink_new_data_done(pa_sink_new_data *data);
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index 63a0b89..7c14861 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -120,6 +120,14 @@ void pa_source_new_data_set_muted(pa_source_new_data *data, pa_bool_t mute) {
data->muted = !!mute;
}
+void pa_source_new_data_add_port(pa_source_new_data *data, pa_device_port *port) {
+ pa_assert(data);
+ pa_assert(port);
+
+ pa_assert_se(pa_hashmap_put(data->ports, port->name, port));
+ pa_device_port_ref(port);
+}
+
void pa_source_new_data_set_port(pa_source_new_data *data, const char *port) {
pa_assert(data);
diff --git a/src/pulsecore/source.h b/src/pulsecore/source.h
index 30c2037..7183e9c 100644
--- a/src/pulsecore/source.h
+++ b/src/pulsecore/source.h
@@ -294,6 +294,7 @@ void pa_source_new_data_set_channel_map(pa_source_new_data *data, const pa_chann
void pa_source_new_data_set_alternate_sample_rate(pa_source_new_data *data, const uint32_t alternate_sample_rate);
void pa_source_new_data_set_volume(pa_source_new_data *data, const pa_cvolume *volume);
void pa_source_new_data_set_muted(pa_source_new_data *data, pa_bool_t mute);
+void pa_source_new_data_add_port(pa_source_new_data *data, pa_device_port *port);
void pa_source_new_data_set_port(pa_source_new_data *data, const char *port);
void pa_source_new_data_done(pa_source_new_data *data);
--
1.7.10
More information about the pulseaudio-discuss
mailing list