Skip to content

Commit 574c193

Browse files
authored
linux: improve conversation detect logging (#302)
media: correct AirPods conversational awareness state handling Fix incorrect detection of conversational awareness events. The previous implementation treated all non-0x01 packets as "disabled", which caused wrong behavior when the user manually enabled/disabled the feature or when voice-end events were received. Adds full decoding for packet types: - 0x01 → voice detected - 0x06/others → voice ended - 0x08 → feature disabled - 0x09 → feature enabled Signed-off-by: ozan956 <ozandurgut.2001@hotmail.com>
1 parent 10bf2fe commit 574c193

File tree

1 file changed

+43
-29
lines changed

1 file changed

+43
-29
lines changed

linux/media/mediacontroller.cpp

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -101,40 +101,54 @@ bool MediaController::isActiveOutputDeviceAirPods() {
101101
}
102102

103103
void MediaController::handleConversationalAwareness(const QByteArray &data) {
104-
LOG_DEBUG("Handling conversational awareness data: " << data.toHex());
105-
bool lowered = data[9] == 0x01;
106-
LOG_INFO("Conversational awareness: " << (lowered ? "enabled" : "disabled"));
107-
108-
if (lowered) {
109-
if (initialVolume == -1 && isActiveOutputDeviceAirPods()) {
110-
QString defaultSink = m_pulseAudio->getDefaultSink();
111-
initialVolume = m_pulseAudio->getSinkVolume(defaultSink);
112-
if (initialVolume == -1) {
113-
LOG_ERROR("Failed to get initial volume");
104+
if (data.size() < 10) {
105+
LOG_ERROR("Invalid conversational awareness packet");
114106
return;
115-
}
116-
LOG_DEBUG("Initial volume: " << initialVolume << "%");
117-
}
118-
QString defaultSink = m_pulseAudio->getDefaultSink();
119-
int targetVolume = initialVolume * 0.20;
120-
if (m_pulseAudio->setSinkVolume(defaultSink, targetVolume)) {
121-
LOG_INFO("Volume lowered to 0.20 of initial which is " << targetVolume << "%");
122-
} else {
123-
LOG_ERROR("Failed to lower volume");
124107
}
125-
} else {
126-
if (initialVolume != -1 && isActiveOutputDeviceAirPods()) {
127-
QString defaultSink = m_pulseAudio->getDefaultSink();
128-
if (m_pulseAudio->setSinkVolume(defaultSink, initialVolume)) {
129-
LOG_INFO("Volume restored to " << initialVolume << "%");
130-
} else {
131-
LOG_ERROR("Failed to restore volume");
132-
}
133-
initialVolume = -1;
108+
109+
uint8_t flag = (uint8_t)data[9];
110+
111+
switch (flag) {
112+
case 0x01:
113+
LOG_INFO("Conversational awareness event: voice detected");
114+
115+
if (initialVolume == -1 && isActiveOutputDeviceAirPods()) {
116+
QString sink = m_pulseAudio->getDefaultSink();
117+
initialVolume = m_pulseAudio->getSinkVolume(sink);
118+
LOG_DEBUG("Initial volume saved: " << initialVolume << "%");
119+
}
120+
121+
if (initialVolume != -1) {
122+
QString sink = m_pulseAudio->getDefaultSink();
123+
int target = initialVolume * 0.20;
124+
m_pulseAudio->setSinkVolume(sink, target);
125+
LOG_INFO("Volume lowered to " << target << "%");
126+
}
127+
break;
128+
129+
case 0x08:
130+
LOG_INFO("Conversational awareness disabled");
131+
initialVolume = -1;
132+
break;
133+
134+
case 0x09:
135+
LOG_INFO("Conversational awareness enabled");
136+
break;
137+
138+
default:
139+
LOG_INFO("Conversational awareness event: voice ended");
140+
141+
if (initialVolume != -1 && isActiveOutputDeviceAirPods()) {
142+
QString sink = m_pulseAudio->getDefaultSink();
143+
m_pulseAudio->setSinkVolume(sink, initialVolume);
144+
LOG_INFO("Volume restored to " << initialVolume << "%");
145+
initialVolume = -1;
146+
}
147+
break;
134148
}
135-
}
136149
}
137150

151+
138152
bool MediaController::isA2dpProfileAvailable() {
139153
if (m_deviceOutputName.isEmpty()) {
140154
return false;

0 commit comments

Comments
 (0)