mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
bluetooth: Use enum to represent form factors
Avoid using strings only to represent form factors in the bluetooth-util API and instead use a new dedicated enum type: pa_bt_form_factor_t.
This commit is contained in:
parent
278ceb453f
commit
11d7a2d197
3 changed files with 57 additions and 17 deletions
|
|
@ -1800,26 +1800,26 @@ pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *y, pa_bluetooth_hoo
|
|||
return &y->hooks[hook];
|
||||
}
|
||||
|
||||
const char*pa_bluetooth_get_form_factor(uint32_t class) {
|
||||
pa_bt_form_factor_t pa_bluetooth_get_form_factor(uint32_t class) {
|
||||
unsigned i;
|
||||
const char *r;
|
||||
pa_bt_form_factor_t r;
|
||||
|
||||
static const char * const table[] = {
|
||||
[1] = "headset",
|
||||
[2] = "hands-free",
|
||||
[4] = "microphone",
|
||||
[5] = "speaker",
|
||||
[6] = "headphone",
|
||||
[7] = "portable",
|
||||
[8] = "car",
|
||||
[10] = "hifi"
|
||||
static const pa_bt_form_factor_t table[] = {
|
||||
[1] = PA_BT_FORM_FACTOR_HEADSET,
|
||||
[2] = PA_BT_FORM_FACTOR_HANDSFREE,
|
||||
[4] = PA_BT_FORM_FACTOR_MICROPHONE,
|
||||
[5] = PA_BT_FORM_FACTOR_SPEAKER,
|
||||
[6] = PA_BT_FORM_FACTOR_HEADPHONE,
|
||||
[7] = PA_BT_FORM_FACTOR_PORTABLE,
|
||||
[8] = PA_BT_FORM_FACTOR_CAR,
|
||||
[10] = PA_BT_FORM_FACTOR_HIFI
|
||||
};
|
||||
|
||||
if (((class >> 8) & 31) != 4)
|
||||
return NULL;
|
||||
return PA_BT_FORM_FACTOR_UNKNOWN;
|
||||
|
||||
if ((i = (class >> 2) & 63) >= PA_ELEMENTSOF(table))
|
||||
r = NULL;
|
||||
r = PA_BT_FORM_FACTOR_UNKNOWN;
|
||||
else
|
||||
r = table[i];
|
||||
|
||||
|
|
@ -1829,6 +1829,31 @@ const char*pa_bluetooth_get_form_factor(uint32_t class) {
|
|||
return r;
|
||||
}
|
||||
|
||||
const char *pa_bt_form_factor_to_string(pa_bt_form_factor_t ff) {
|
||||
switch (ff) {
|
||||
case PA_BT_FORM_FACTOR_UNKNOWN:
|
||||
return "unknown";
|
||||
case PA_BT_FORM_FACTOR_HEADSET:
|
||||
return "headset";
|
||||
case PA_BT_FORM_FACTOR_HANDSFREE:
|
||||
return "hands-free";
|
||||
case PA_BT_FORM_FACTOR_MICROPHONE:
|
||||
return "microphone";
|
||||
case PA_BT_FORM_FACTOR_SPEAKER:
|
||||
return "speaker";
|
||||
case PA_BT_FORM_FACTOR_HEADPHONE:
|
||||
return "headphone";
|
||||
case PA_BT_FORM_FACTOR_PORTABLE:
|
||||
return "portable";
|
||||
case PA_BT_FORM_FACTOR_CAR:
|
||||
return "car";
|
||||
case PA_BT_FORM_FACTOR_HIFI:
|
||||
return "hifi";
|
||||
}
|
||||
|
||||
pa_assert_not_reached();
|
||||
}
|
||||
|
||||
char *pa_bluetooth_cleanup_name(const char *name) {
|
||||
char *t, *s, *d;
|
||||
bool space = false;
|
||||
|
|
|
|||
|
|
@ -154,7 +154,20 @@ void pa_bluetooth_transport_set_speaker_gain(pa_bluetooth_transport *t, uint16_t
|
|||
|
||||
pa_hook* pa_bluetooth_discovery_hook(pa_bluetooth_discovery *y, pa_bluetooth_hook_t hook);
|
||||
|
||||
const char* pa_bluetooth_get_form_factor(uint32_t class);
|
||||
typedef enum pa_bt_form_factor {
|
||||
PA_BT_FORM_FACTOR_UNKNOWN,
|
||||
PA_BT_FORM_FACTOR_HEADSET,
|
||||
PA_BT_FORM_FACTOR_HANDSFREE,
|
||||
PA_BT_FORM_FACTOR_MICROPHONE,
|
||||
PA_BT_FORM_FACTOR_SPEAKER,
|
||||
PA_BT_FORM_FACTOR_HEADPHONE,
|
||||
PA_BT_FORM_FACTOR_PORTABLE,
|
||||
PA_BT_FORM_FACTOR_CAR,
|
||||
PA_BT_FORM_FACTOR_HIFI,
|
||||
} pa_bt_form_factor_t;
|
||||
|
||||
pa_bt_form_factor_t pa_bluetooth_get_form_factor(uint32_t class);
|
||||
const char *pa_bt_form_factor_to_string(pa_bt_form_factor_t ff);
|
||||
|
||||
char *pa_bluetooth_cleanup_name(const char *name);
|
||||
|
||||
|
|
|
|||
|
|
@ -2147,7 +2147,7 @@ static int add_card(struct userdata *u) {
|
|||
bool b;
|
||||
pa_card_profile *p;
|
||||
enum profile *d;
|
||||
const char *ff;
|
||||
pa_bt_form_factor_t ff;
|
||||
char *n;
|
||||
const char *default_profile;
|
||||
const pa_bluetooth_device *device = u->device;
|
||||
|
|
@ -2167,8 +2167,10 @@ static int add_card(struct userdata *u) {
|
|||
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_API, "bluez");
|
||||
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_CLASS, "sound");
|
||||
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_BUS, "bluetooth");
|
||||
if ((ff = pa_bluetooth_get_form_factor(device->class)))
|
||||
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_FORM_FACTOR, ff);
|
||||
|
||||
if ((ff = pa_bluetooth_get_form_factor(device->class)) != PA_BT_FORM_FACTOR_UNKNOWN)
|
||||
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_FORM_FACTOR, pa_bt_form_factor_to_string(ff));
|
||||
|
||||
pa_proplist_sets(data.proplist, "bluez.path", device->path);
|
||||
pa_proplist_setf(data.proplist, "bluez.class", "0x%06x", (unsigned) device->class);
|
||||
pa_proplist_sets(data.proplist, "bluez.name", device->name);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue