summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpoljar (Damir Jelić) <poljarinho@gmail.com>2013-03-28 12:05:11 +0100
committerTanu Kaskinen <tanuk@iki.fi>2013-03-28 13:37:03 +0200
commita6c27a1fe523f35edc618a1b0bcfc52f594ea3c2 (patch)
tree9ca35d772d3f57159a13af31eb00bc589dede424
parent7de9b7e01bdeebf437a5976d8b0d4a31dabd3194 (diff)
device-port: Introduce pa_device_port_new_data
Port creation is now slightly different. It is now similar to how other objects are created (e.g. sinks/sources/cards). This should become more useful in the future when we move more stuff to the ports. Functionally nothing has changed.
-rw-r--r--src/modules/alsa/alsa-mixer.c10
-rw-r--r--src/modules/alsa/alsa-ucm.c10
-rw-r--r--src/modules/bluetooth/module-bluetooth-device.c22
-rw-r--r--src/pulsecore/device-port.c59
-rw-r--r--src/pulsecore/device-port.h16
5 files changed, 100 insertions, 17 deletions
diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index a6f3980d..4ebce39b 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -4496,11 +4496,15 @@ static pa_device_port* device_port_alsa_init(pa_hashmap *ports, /* card ports */
if (!p) {
pa_alsa_port_data *data;
- pa_direction_t direction;
+ pa_device_port_new_data port_data;
- direction = path->direction == PA_ALSA_DIRECTION_OUTPUT ? PA_DIRECTION_OUTPUT : PA_DIRECTION_INPUT;
+ pa_device_port_new_data_init(&port_data);
+ pa_device_port_new_data_set_name(&port_data, name);
+ pa_device_port_new_data_set_description(&port_data, description);
+ pa_device_port_new_data_set_direction(&port_data, path->direction == PA_ALSA_DIRECTION_OUTPUT ? PA_DIRECTION_OUTPUT : PA_DIRECTION_INPUT);
- p = pa_device_port_new(core, name, description, direction, sizeof(pa_alsa_port_data));
+ p = pa_device_port_new(core, &port_data, sizeof(pa_alsa_port_data));
+ pa_device_port_new_data_done(&port_data);
pa_assert(p);
pa_hashmap_put(ports, p->name, p);
pa_proplist_update(p->proplist, PA_UPDATE_REPLACE, path->proplist);
diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c
index a6de7aa6..d8ff6217 100644
--- a/src/modules/alsa/alsa-ucm.c
+++ b/src/modules/alsa/alsa-ucm.c
@@ -688,7 +688,15 @@ static void ucm_add_port_combination(
port = pa_hashmap_get(ports, name);
if (!port) {
- port = pa_device_port_new(core, pa_strna(name), desc, is_sink ? PA_DIRECTION_OUTPUT : PA_DIRECTION_INPUT, 0);
+ pa_device_port_new_data port_data;
+
+ pa_device_port_new_data_init(&port_data);
+ pa_device_port_new_data_set_name(&port_data, pa_strna(name));
+ pa_device_port_new_data_set_description(&port_data, desc);
+ pa_device_port_new_data_set_direction(&port_data, is_sink ? PA_DIRECTION_OUTPUT : PA_DIRECTION_INPUT);
+
+ port = pa_device_port_new(core, &port_data, 0);
+ pa_device_port_new_data_done(&port_data);
pa_assert(port);
pa_hashmap_put(ports, port->name, port);
diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index 2e21221f..cd0a515c 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -2070,6 +2070,8 @@ off:
/* Run from main thread */
static void create_card_ports(struct userdata *u, pa_hashmap *ports) {
pa_device_port *port;
+ pa_device_port_new_data port_data;
+
const char *name_prefix = NULL;
const char *input_description = NULL;
const char *output_description = NULL;
@@ -2140,13 +2142,23 @@ static void create_card_ports(struct userdata *u, pa_hashmap *ports) {
u->output_port_name = pa_sprintf_malloc("%s-output", name_prefix);
u->input_port_name = pa_sprintf_malloc("%s-input", name_prefix);
- pa_assert_se(port = pa_device_port_new(u->core, u->output_port_name, output_description, PA_DIRECTION_OUTPUT, 0));
+ pa_device_port_new_data_init(&port_data);
+ pa_device_port_new_data_set_name(&port_data, u->output_port_name);
+ pa_device_port_new_data_set_description(&port_data, output_description);
+ pa_device_port_new_data_set_direction(&port_data, PA_DIRECTION_OUTPUT);
+ pa_device_port_new_data_set_available(&port_data, get_port_availability(u, PA_DIRECTION_OUTPUT));
+ pa_assert_se(port = pa_device_port_new(u->core, &port_data, 0));
pa_assert_se(pa_hashmap_put(ports, port->name, port) >= 0);
- port->available = get_port_availability(u, PA_DIRECTION_OUTPUT);
-
- pa_assert_se(port = pa_device_port_new(u->core, u->input_port_name, input_description, PA_DIRECTION_OUTPUT, 0));
+ pa_device_port_new_data_done(&port_data);
+
+ pa_device_port_new_data_init(&port_data);
+ pa_device_port_new_data_set_name(&port_data, u->input_port_name);
+ pa_device_port_new_data_set_description(&port_data, output_description);
+ pa_device_port_new_data_set_direction(&port_data, PA_DIRECTION_INPUT);
+ pa_device_port_new_data_set_available(&port_data, get_port_availability(u, PA_DIRECTION_INPUT));
+ pa_assert_se(port = pa_device_port_new(u->core, &port_data, 0));
pa_assert_se(pa_hashmap_put(ports, port->name, port) >= 0);
- port->available = get_port_availability(u, PA_DIRECTION_INPUT);
+ pa_device_port_new_data_done(&port_data);
}
/* Run from main thread */
diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index acfc44df..96607027 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -26,6 +26,47 @@
PA_DEFINE_PUBLIC_CLASS(pa_device_port, pa_object);
+pa_device_port_new_data *pa_device_port_new_data_init(pa_device_port_new_data *data) {
+ pa_assert(data);
+
+ pa_zero(*data);
+ data->available = PA_AVAILABLE_UNKNOWN;
+ return data;
+}
+
+void pa_device_port_new_data_set_name(pa_device_port_new_data *data, const char *name) {
+ pa_assert(data);
+
+ pa_xfree(data->name);
+ data->name = pa_xstrdup(name);
+}
+
+void pa_device_port_new_data_set_description(pa_device_port_new_data *data, const char *description) {
+ pa_assert(data);
+
+ pa_xfree(data->description);
+ data->description = pa_xstrdup(description);
+}
+
+void pa_device_port_new_data_set_available(pa_device_port_new_data *data, pa_available_t available) {
+ pa_assert(data);
+
+ data->available = available;
+}
+
+void pa_device_port_new_data_set_direction(pa_device_port_new_data *data, pa_direction_t direction) {
+ pa_assert(data);
+
+ data->direction = direction;
+}
+
+void pa_device_port_new_data_done(pa_device_port_new_data *data) {
+ pa_assert(data);
+
+ pa_xfree(data->name);
+ pa_xfree(data->description);
+}
+
void pa_device_port_set_available(pa_device_port *p, pa_available_t status)
{
pa_core *core;
@@ -66,23 +107,27 @@ static void device_port_free(pa_object *o) {
}
-pa_device_port *pa_device_port_new(pa_core *c, const char *name, const char *description, pa_direction_t direction, size_t extra) {
+pa_device_port *pa_device_port_new(pa_core *c, pa_device_port_new_data *data, size_t extra) {
pa_device_port *p;
- pa_assert(name);
+ pa_assert(data);
+ pa_assert(data->name);
+ pa_assert(data->direction == PA_DIRECTION_OUTPUT || data->direction == PA_DIRECTION_INPUT);
p = PA_DEVICE_PORT(pa_object_new_internal(PA_ALIGN(sizeof(pa_device_port)) + extra, pa_device_port_type_id, pa_device_port_check_type));
p->parent.free = device_port_free;
- p->core = c;
- p->name = pa_xstrdup(name);
- p->description = pa_xstrdup(description);
+ p->name = data->name;
+ data->name = NULL;
+ p->description = data->description;
+ data->description = NULL;
p->core = c;
p->card = NULL;
p->priority = 0;
- p->available = PA_AVAILABLE_UNKNOWN;
+ p->available = data->available;
p->profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
- p->direction = direction;
+ p->direction = data->direction;
+
p->latency_offset = 0;
p->proplist = pa_proplist_new();
diff --git a/src/pulsecore/device-port.h b/src/pulsecore/device-port.h
index 7f210724..b10d5549 100644
--- a/src/pulsecore/device-port.h
+++ b/src/pulsecore/device-port.h
@@ -62,7 +62,21 @@ PA_DECLARE_PUBLIC_CLASS(pa_device_port);
#define PA_DEVICE_PORT_DATA(d) ((void*) ((uint8_t*) d + PA_ALIGN(sizeof(pa_device_port))))
-pa_device_port *pa_device_port_new(pa_core *c, const char *name, const char *description, pa_direction_t direction, size_t extra);
+typedef struct pa_device_port_new_data {
+ char *name;
+ char *description;
+ pa_available_t available;
+ pa_direction_t direction;
+} pa_device_port_new_data;
+
+pa_device_port_new_data *pa_device_port_new_data_init(pa_device_port_new_data *data);
+void pa_device_port_new_data_set_name(pa_device_port_new_data *data, const char *name);
+void pa_device_port_new_data_set_description(pa_device_port_new_data *data, const char *description);
+void pa_device_port_new_data_set_available(pa_device_port_new_data *data, pa_available_t available);
+void pa_device_port_new_data_set_direction(pa_device_port_new_data *data, pa_direction_t direction);
+void pa_device_port_new_data_done(pa_device_port_new_data *data);
+
+pa_device_port *pa_device_port_new(pa_core *c, pa_device_port_new_data *data, size_t extra);
/* The port's available status has changed */
void pa_device_port_set_available(pa_device_port *p, pa_available_t available);