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

@ -42,59 +42,6 @@ struct data {
bool quit;
};
static const char *str_port_type(enum acp_port_type type)
{
switch (type) {
case ACP_PORT_TYPE_UNKNOWN:
return "unknown";
case ACP_PORT_TYPE_AUX:
return "aux";
case ACP_PORT_TYPE_SPEAKER:
return "speaker";
case ACP_PORT_TYPE_HEADPHONES:
return "headphones";
case ACP_PORT_TYPE_LINE:
return "line";
case ACP_PORT_TYPE_MIC:
return "mic";
case ACP_PORT_TYPE_HEADSET:
return "headset";
case ACP_PORT_TYPE_HANDSET:
return "handset";
case ACP_PORT_TYPE_EARPIECE:
return "earpiece";
case ACP_PORT_TYPE_SPDIF:
return "spdif";
case ACP_PORT_TYPE_HDMI:
return "hdmi";
case ACP_PORT_TYPE_TV:
return "tv";
case ACP_PORT_TYPE_RADIO:
return "radio";
case ACP_PORT_TYPE_VIDEO:
return "video";
case ACP_PORT_TYPE_USB:
return "usb";
case ACP_PORT_TYPE_BLUETOOTH:
return "bluetooth";
case ACP_PORT_TYPE_PORTABLE:
return "portable";
case ACP_PORT_TYPE_HANDSFREE:
return "handsfree";
case ACP_PORT_TYPE_CAR:
return "car";
case ACP_PORT_TYPE_HIFI:
return "hifi";
case ACP_PORT_TYPE_PHONE:
return "phone";
case ACP_PORT_TYPE_NETWORK:
return "network";
case ACP_PORT_TYPE_ANALOG:
return "analog";
}
return "error";
}
static void acp_debug_dict(struct acp_dict *dict, int indent)
{
const struct acp_dict_item *it;
@ -232,10 +179,9 @@ static void print_port(struct data *data, struct acp_port *p, int indent, int le
{
uint32_t i;
fprintf(stderr, "%*s %c port %u: name:\"%s\" direction:%s prio:%d group:%s type:%s (available: %s)\n",
fprintf(stderr, "%*s %c port %u: name:\"%s\" direction:%s prio:%d (available: %s)\n",
indent, "", p->flags & ACP_PORT_ACTIVE ? '*' : ' ', p->index,
p->name, acp_direction_str(p->direction), p->priority,
p->availability_group, str_port_type(p->type),
acp_available_str(p->available));
if (level > 0) {
acp_debug_dict(&p->props, indent + 8);

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;