device-port: add type member

The clients might wanna to know for which purpose is the port.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2020-04-14 20:04:00 +02:00 committed by Tanu Kaskinen
parent 861836c5f7
commit feee531c2b
9 changed files with 77 additions and 10 deletions

View file

@ -1762,6 +1762,7 @@ static pa_available_t transport_state_to_availability(pa_bluetooth_transport_sta
static void create_card_ports(struct userdata *u, pa_hashmap *ports) {
pa_device_port *port;
pa_device_port_new_data port_data;
pa_device_port_type_t input_type, output_type;
const char *name_prefix, *input_description, *output_description;
pa_assert(u);
@ -1771,60 +1772,67 @@ static void create_card_ports(struct userdata *u, pa_hashmap *ports) {
name_prefix = "unknown";
input_description = _("Bluetooth Input");
output_description = _("Bluetooth Output");
input_type = output_type = PA_DEVICE_PORT_TYPE_BLUETOOTH;
switch (form_factor_from_class(u->device->class_of_device)) {
case PA_BLUETOOTH_FORM_FACTOR_HEADSET:
name_prefix = "headset";
input_description = output_description = _("Headset");
input_type = output_type = PA_DEVICE_PORT_TYPE_HEADSET;
break;
case PA_BLUETOOTH_FORM_FACTOR_HANDSFREE:
name_prefix = "handsfree";
input_description = output_description = _("Handsfree");
input_type = output_type = PA_DEVICE_PORT_TYPE_HANDSFREE;
break;
case PA_BLUETOOTH_FORM_FACTOR_MICROPHONE:
name_prefix = "microphone";
input_description = _("Microphone");
output_description = _("Bluetooth Output");
input_type = PA_DEVICE_PORT_TYPE_MIC;
break;
case PA_BLUETOOTH_FORM_FACTOR_SPEAKER:
name_prefix = "speaker";
input_description = _("Bluetooth Input");
output_description = _("Speaker");
output_type = PA_DEVICE_PORT_TYPE_SPEAKER;
break;
case PA_BLUETOOTH_FORM_FACTOR_HEADPHONE:
name_prefix = "headphone";
input_description = _("Bluetooth Input");
output_description = _("Headphone");
output_type = PA_DEVICE_PORT_TYPE_HEADPHONES;
break;
case PA_BLUETOOTH_FORM_FACTOR_PORTABLE:
name_prefix = "portable";
input_description = output_description = _("Portable");
input_type = output_type = PA_DEVICE_PORT_TYPE_PORTABLE;
break;
case PA_BLUETOOTH_FORM_FACTOR_CAR:
name_prefix = "car";
input_description = output_description = _("Car");
input_type = output_type = PA_DEVICE_PORT_TYPE_CAR;
break;
case PA_BLUETOOTH_FORM_FACTOR_HIFI:
name_prefix = "hifi";
input_description = output_description = _("HiFi");
input_type = output_type = PA_DEVICE_PORT_TYPE_HIFI;
break;
case PA_BLUETOOTH_FORM_FACTOR_PHONE:
name_prefix = "phone";
input_description = output_description = _("Phone");
input_type = output_type = PA_DEVICE_PORT_TYPE_PHONE;
break;
case PA_BLUETOOTH_FORM_FACTOR_UNKNOWN:
name_prefix = "unknown";
input_description = _("Bluetooth Input");
output_description = _("Bluetooth Output");
break;
}
@ -1833,6 +1841,7 @@ static void create_card_ports(struct userdata *u, pa_hashmap *ports) {
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_type(&port_data, output_type);
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);
@ -1843,6 +1852,7 @@ static void create_card_ports(struct userdata *u, pa_hashmap *ports) {
pa_device_port_new_data_set_name(&port_data, u->input_port_name);
pa_device_port_new_data_set_description(&port_data, input_description);
pa_device_port_new_data_set_direction(&port_data, PA_DIRECTION_INPUT);
pa_device_port_new_data_set_type(&port_data, input_type);
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);

View file

@ -1039,7 +1039,9 @@ static int read_ports(struct userdata *u, pa_tagstruct *t) {
pa_log("Parse failure");
return -PA_ERR_PROTOCOL;
}
if (u->version >= 34 && pa_tagstruct_gets(t, &s) < 0) { /* available_group */
if (u->version >= 34 &&
(pa_tagstruct_gets(t, &s) < 0 || /* available_group */
pa_tagstruct_getu32(t, &priority) < 0)) { /* device port type */
pa_log("Parse failure");
return -PA_ERR_PROTOCOL;
}

View file

@ -635,6 +635,7 @@ static pa_device_port *raop_create_port(struct userdata *u, const char *server)
pa_device_port_new_data_set_name(&data, "network-output");
pa_device_port_new_data_set_description(&data, server);
pa_device_port_new_data_set_direction(&data, PA_DIRECTION_OUTPUT);
pa_device_port_new_data_set_type(&data, PA_DEVICE_PORT_TYPE_NETWORK);
port = pa_device_port_new(u->core, &data, 0);