Fix for presense detection of headset plugging which only reports presence/absense of the microphone part, relates to gemian/gemian#7

This commit is contained in:
Adam Boardman 2021-05-02 17:06:46 +01:00
parent 995913eaf3
commit 930e65658c

View file

@ -125,22 +125,30 @@ static const char *headset_ports[] = {
static void notify_ports(pa_droid_extevdev *u) { static void notify_ports(pa_droid_extevdev *u) {
unsigned int i; unsigned int i;
pa_log_debug("headphone: %d, microphone: %d, lineout: %d, yes: %d, no: %d", u->sw_headphone_insert,
u->sw_microphone_insert, u->sw_lineout_insert, PA_AVAILABLE_YES, PA_AVAILABLE_NO);
pa_available_t has_headphone = pa_available_t has_headphone =
((u->sw_headphone_insert || u->sw_lineout_insert) ((u->sw_headphone_insert || u->sw_lineout_insert)
&& !u->sw_microphone_insert) ? PA_AVAILABLE_YES : PA_AVAILABLE_NO; && !u->sw_microphone_insert) ? PA_AVAILABLE_YES : PA_AVAILABLE_NO;
pa_log_debug("has_headphone: %d", has_headphone);
for (i=0; i < N_ELEMENTS(headphone_ports); i++) { for (i=0; i < N_ELEMENTS(headphone_ports); i++) {
pa_device_port *p = pa_hashmap_get(u->card->ports, headphone_ports[i]); pa_device_port *p = pa_hashmap_get(u->card->ports, headphone_ports[i]);
pa_log_debug("headphone device port %d, %d", i, p);
if (p) if (p)
pa_device_port_set_available(p, has_headphone); pa_device_port_set_available(p, has_headphone);
} }
pa_available_t has_headset = pa_available_t has_headset =
((u->sw_headphone_insert || u->sw_lineout_insert) u->sw_microphone_insert ? PA_AVAILABLE_YES : PA_AVAILABLE_NO;
&& u->sw_microphone_insert) ? PA_AVAILABLE_YES : PA_AVAILABLE_NO;
pa_log_debug("has_headset: %d", has_headset);
for (i=0; i < N_ELEMENTS(headset_ports); i++) { for (i=0; i < N_ELEMENTS(headset_ports); i++) {
pa_device_port *p = pa_hashmap_get(u->card->ports, headset_ports[i]); pa_device_port *p = pa_hashmap_get(u->card->ports, headset_ports[i]);
pa_log_debug("headset device port %d, %d", i, p);
if (p) if (p)
pa_device_port_set_available(p, has_headset); pa_device_port_set_available(p, has_headset);
} }
@ -155,6 +163,8 @@ static void evdev_cb(pa_mainloop_api *a, pa_io_event *e, int fd,
int err; int err;
struct input_event ev; struct input_event ev;
pa_log_debug("EV callback start...");
while (1) { while (1) {
err = libevdev_next_event(u->evdev_dev, flags, &ev); err = libevdev_next_event(u->evdev_dev, flags, &ev);
@ -184,22 +194,30 @@ static void evdev_cb(pa_mainloop_api *a, pa_io_event *e, int fd,
if (ev.type == EV_SW) { if (ev.type == EV_SW) {
switch (ev.code) { switch (ev.code) {
case SW_HEADPHONE_INSERT: case SW_HEADPHONE_INSERT:
pa_log_debug("Headphone Insert %d", ev.value);
u->sw_headphone_insert = ev.value; u->sw_headphone_insert = ev.value;
break; break;
case SW_MICROPHONE_INSERT: case SW_MICROPHONE_INSERT:
pa_log_debug("Microphone Insert %d", ev.value);
u->sw_microphone_insert = ev.value; u->sw_microphone_insert = ev.value;
break; break;
case SW_LINEOUT_INSERT: case SW_LINEOUT_INSERT:
pa_log_debug("Lineout Insert %d", ev.value);
u->sw_lineout_insert = ev.value; u->sw_lineout_insert = ev.value;
break; break;
default: default:
pa_log_debug("Unknown switch %d", ev.code);
/* Ignore unknown switch. */ /* Ignore unknown switch. */
break; break;
} }
} else if (ev.type == EV_SYN && ev.code == SYN_REPORT) { } else if (ev.type == EV_SYN && ev.code == SYN_REPORT) {
pa_log_debug("SYN Report");
notify_ports(u); notify_ports(u);
} }
} }
pa_log_debug("EV callback end.");
} }
static void read_initial_switch_values(pa_droid_extevdev *u) { static void read_initial_switch_values(pa_droid_extevdev *u) {