acp: use properties for port type and available group

This commit is contained in:
Wim Taymans 2020-10-28 11:48:24 +01:00
parent 893873b69e
commit 8116da41b9
3 changed files with 58 additions and 110 deletions

View file

@ -87,34 +87,26 @@ enum acp_available {
const char *acp_available_str(enum acp_available status);
/** Port type. New types can be added in the future, so applications should
* gracefully handle situations where a type identifier doesn't match any item
* in this enumeration. */
enum acp_port_type {
ACP_PORT_TYPE_UNKNOWN = 0,
ACP_PORT_TYPE_AUX = 1,
ACP_PORT_TYPE_SPEAKER = 2,
ACP_PORT_TYPE_HEADPHONES = 3,
ACP_PORT_TYPE_LINE = 4,
ACP_PORT_TYPE_MIC = 5,
ACP_PORT_TYPE_HEADSET = 6,
ACP_PORT_TYPE_HANDSET = 7,
ACP_PORT_TYPE_EARPIECE = 8,
ACP_PORT_TYPE_SPDIF = 9,
ACP_PORT_TYPE_HDMI = 10,
ACP_PORT_TYPE_TV = 11,
ACP_PORT_TYPE_RADIO = 12,
ACP_PORT_TYPE_VIDEO = 13,
ACP_PORT_TYPE_USB = 14,
ACP_PORT_TYPE_BLUETOOTH = 15,
ACP_PORT_TYPE_PORTABLE = 16,
ACP_PORT_TYPE_HANDSFREE = 17,
ACP_PORT_TYPE_CAR = 18,
ACP_PORT_TYPE_HIFI = 19,
ACP_PORT_TYPE_PHONE = 20,
ACP_PORT_TYPE_NETWORK = 21,
ACP_PORT_TYPE_ANALOG = 22,
};
#define ACP_KEY_PORT_TYPE "port.type" /**< a Port type, like "aux", "speaker", ... */
#define ACP_KEY_PORT_AVAILABLE_GROUP "port.available-group"
/**< An indentifier for the group of ports that share their availability status with
* each other. This is meant especially for handling cases where one 3.5 mm connector
* is used for headphones, headsets and microphones, and the hardware can only tell
* that something was plugged in but not what exactly. In this situation the ports for
* all those devices share their availability status, and ACP can't tell which
* one is actually plugged in, and some application may ask the user what was plugged
* in. Such applications should get a list of all card ports and compare their
* `available_group` fields. Ports that have the same group are those that need
* input from the user to determine which device was plugged in. The application should
* then activate the user-chosen port.
*
* May be NULL, in which case the port is not part of any availability group (which is
* the same as having a group with only one member).
*
* The group identifier must be treated as an opaque identifier. The string may look
* like an ALSA control name, but applications must not assume any such relationship.
* The group naming scheme can change without a warning.
*/
struct acp_device;
@ -154,31 +146,6 @@ struct acp_port {
uint32_t priority; /**< The higher this value is, the more useful this port is as a default. */
enum acp_direction direction;
enum acp_available available; /**< A flags (see #acp_port_available), indicating availability status of this port. */
const char *availability_group; /**< An indentifier for the group of ports that share their availability status with
* each other. This is meant especially for handling cases where one 3.5 mm connector
* is used for headphones, headsets and microphones, and the hardware can only tell
* that something was plugged in but not what exactly. In this situation the ports for
* all those devices share their availability status, and PulseAudio can't tell which
* one is actually plugged in, and some application may ask the user what was plugged
* in. Such applications should get a list of all card ports and compare their
* `available_group` fields. Ports that have the same group are those that need
* input from the user to determine which device was plugged in. The application should
* then activate the user-chosen port.
*
* May be NULL, in which case the port is not part of any availability group (which is
* the same as having a group with only one member).
*
* The group identifier must be treated as an opaque identifier. The string may look
* like an ALSA control name, but applications must not assume any such relationship.
* The group naming scheme can change without a warning.
*
* Since one group can include both input and output ports, the grouping should be done
* using pa_card_port_info instead of pa_sink_port_info, but this field is duplicated
* also in pa_sink_port_info (and pa_source_port_info) in case someone finds that
* convenient.
*/
enum acp_port_type type; /**< Port type, see #pa_device_port_type. */
struct acp_dict props; /**< extra port properties */
uint32_t n_profiles; /**< number of elements in profiles array */

View file

@ -22,6 +22,38 @@
#include "device-port.h"
#include "alsa-mixer.h"
static const char *port_types[] = {
[PA_DEVICE_PORT_TYPE_UNKNOWN] = "unknown",
[PA_DEVICE_PORT_TYPE_AUX] = "aux",
[PA_DEVICE_PORT_TYPE_SPEAKER] = "speaker",
[PA_DEVICE_PORT_TYPE_HEADPHONES] = "headphones",
[PA_DEVICE_PORT_TYPE_LINE] = "line",
[PA_DEVICE_PORT_TYPE_MIC] = "mic",
[PA_DEVICE_PORT_TYPE_HEADSET] = "headset",
[PA_DEVICE_PORT_TYPE_HANDSET] = "handset",
[PA_DEVICE_PORT_TYPE_EARPIECE] = "earpiece",
[PA_DEVICE_PORT_TYPE_SPDIF] = "spdif",
[PA_DEVICE_PORT_TYPE_HDMI] = "hdmi",
[PA_DEVICE_PORT_TYPE_TV] = "tv",
[PA_DEVICE_PORT_TYPE_RADIO] = "radio",
[PA_DEVICE_PORT_TYPE_VIDEO] = "video",
[PA_DEVICE_PORT_TYPE_USB] = "usb",
[PA_DEVICE_PORT_TYPE_BLUETOOTH] = "bluetooth",
[PA_DEVICE_PORT_TYPE_PORTABLE] = "portable",
[PA_DEVICE_PORT_TYPE_HANDSFREE] = "handsfree",
[PA_DEVICE_PORT_TYPE_CAR] = "car",
[PA_DEVICE_PORT_TYPE_HIFI] = "hifi",
[PA_DEVICE_PORT_TYPE_PHONE] = "phone",
[PA_DEVICE_PORT_TYPE_NETWORK] = "network",
[PA_DEVICE_PORT_TYPE_ANALOG] = "analog",
};
static const char *str_port_type(pa_device_port_type_t type)
{
int idx = (type >= 0 && type < PA_ELEMENTSOF(port_types)) ? type : 0;
return port_types[idx];
}
pa_device_port_new_data *pa_device_port_new_data_init(pa_device_port_new_data *data)
{
pa_assert(data);
@ -96,16 +128,19 @@ pa_device_port *pa_device_port_new(pa_core *c, pa_device_port_new_data *data, si
p->priority = p->port.priority = 0;
p->available = data->available;
p->port.available = (enum acp_available) data->available;
p->port.availability_group = p->availability_group = data->availability_group;
p->availability_group = data->availability_group;
data->availability_group = NULL;
p->profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
p->direction = data->direction;
p->port.direction = data->direction == PA_DIRECTION_OUTPUT ?
ACP_DIRECTION_PLAYBACK : ACP_DIRECTION_CAPTURE;
p->type = data->type;
p->port.type = (enum acp_port_type) data->type;
p->proplist = pa_proplist_new();
pa_proplist_sets(p->proplist, ACP_KEY_PORT_TYPE, str_port_type(data->type));
if (p->availability_group)
pa_proplist_sets(p->proplist, ACP_KEY_PORT_AVAILABLE_GROUP, p->availability_group);
p->user_data = (void*)((uint8_t*)p + sizeof(pa_device_port));
return p;