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. --- src/modules/alsa/alsa-mixer.c | 8 +++- src/modules/alsa/alsa-ucm.c | 9 +++- src/modules/bluetooth/module-bluetooth-device.c | 26 ++++++++---- src/pulsecore/device-port.c | 56 +++++++++++++++++++++---- src/pulsecore/device-port.h | 17 +++++++- 5 files changed, 97 insertions(+), 19 deletions(-) diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c index 2814add..cb81579 100644 --- a/src/modules/alsa/alsa-mixer.c +++ b/src/modules/alsa/alsa-mixer.c @@ -4459,8 +4459,14 @@ static pa_device_port* device_port_alsa_init(pa_hashmap *ports, if (!p) { pa_alsa_port_data *data; + pa_device_port_new_data port_data; - p = pa_device_port_new(core, name, description, sizeof(pa_alsa_port_data)); + 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); + + 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 f69ee89..437aa4d 100644 --- a/src/modules/alsa/alsa-ucm.c +++ b/src/modules/alsa/alsa-ucm.c @@ -688,7 +688,14 @@ static void ucm_add_port_combination( port = pa_hashmap_get(ports, name); if (!port) { - port = pa_device_port_new(core, pa_strna(name), desc, 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); + + 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 c877df2..aba9ac2 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 output_port_data, input_port_data; + const char *name_prefix = NULL; const char *input_description = NULL; const char *output_description = NULL; @@ -2140,17 +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, 0)); + pa_device_port_new_data_init(&output_port_data); + pa_device_port_new_data_set_name(&output_port_data, u->output_port_name); + pa_device_port_new_data_set_description(&output_port_data, output_description); + pa_device_port_new_data_set_direction(&output_port_data, PA_DIRECTION_OUTPUT); + pa_device_port_new_data_set_availability(&output_port_data, get_port_availability(u, PA_DIRECTION_OUTPUT)); + pa_assert_se(port = pa_device_port_new(u->core, &output_port_data, 0)); pa_assert_se(pa_hashmap_put(ports, port->name, port) >= 0); - port->is_output = 1; - port->is_input = 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, 0)); + pa_device_port_new_data_done(&output_port_data); + + pa_device_port_new_data_init(&input_port_data); + pa_device_port_new_data_set_name(&input_port_data, u->input_port_name); + pa_device_port_new_data_set_description(&input_port_data, output_description); + pa_device_port_new_data_set_direction(&input_port_data, PA_DIRECTION_INPUT); + pa_device_port_new_data_set_availability(&input_port_data, get_port_availability(u, PA_DIRECTION_INPUT)); + pa_assert_se(port = pa_device_port_new(u->core, &input_port_data, 0)); pa_assert_se(pa_hashmap_put(ports, port->name, port) >= 0); - port->is_output = 0; - port->is_input = 1; - port->available = get_port_availability(u, PA_DIRECTION_INPUT); + pa_device_port_new_data_done(&input_port_data); } /* Run from main thread */ diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c index f16de3a..7438dec 100644 --- a/src/pulsecore/device-port.c +++ b/src/pulsecore/device-port.c @@ -26,6 +26,46 @@ 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); + 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 *descritpion) { + pa_assert(data); + + pa_xfree(data->description); + data->description = pa_xstrdup(descritpion); +} + +void pa_device_port_new_data_set_availability(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); + + if (direction == PA_DIRECTION_OUTPUT) + data->is_output = true; + else if (direction == PA_DIRECTION_INPUT) + data->is_output = true; +} + +void pa_device_port_new_data_done(pa_device_port_new_data *data) { + pa_assert(data); +} + void pa_device_port_set_available(pa_device_port *p, pa_available_t status) { pa_core *core; @@ -66,23 +106,25 @@ static void device_port_free(pa_object *o) { } -pa_device_port *pa_device_port_new(pa_core *c, const char *name, const char *description, 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); 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->name = pa_xstrdup(name); - p->description = pa_xstrdup(description); + p->name = data->name; + p->description = data->description; 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->is_input = FALSE; - p->is_output = FALSE; + + p->is_input = data->is_input; + p->is_output = data->is_output; + p->latency_offset = 0; p->proplist = pa_proplist_new(); diff --git a/src/pulsecore/device-port.h b/src/pulsecore/device-port.h index c0c00cf..1599206 100644 --- a/src/pulsecore/device-port.h +++ b/src/pulsecore/device-port.h @@ -63,7 +63,22 @@ 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, size_t extra); +typedef struct pa_device_port_new_data { + char *name; + char *description; + pa_available_t available; + bool is_input; + bool is_output; +} 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_availability(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); -- 1.8.2