forked from Blendman974/faceclaw
Fix some microphone-related bugs, add a debug panel
This commit is contained in:
1 parent
e8d2f5ade9
commit
7d0becfaa7
8 files changed
+650
-37
No files matched your search
+16
@@ -488,6 +488,22 @@ internal fun GlassesSessionCore.emitMicStatus(body: ByteArray, address: String)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun GlassesSessionCore.emitAudioMonitorPacket(data: ByteArray, arm: String, arrivalMs: Long) {
|
||||
if (audioMonitorListeners.isEmpty()) {
|
||||
return
|
||||
}
|
||||
val copy = data.copyOf()
|
||||
host.postToMain {
|
||||
for (monitorListener in audioMonitorListeners) {
|
||||
try {
|
||||
monitorListener.onAudioPacket(copy, arm, arrivalMs)
|
||||
} catch (t: Throwable) {
|
||||
logWarn("audio monitor listener failed", t)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun GlassesSessionCore.emitRingEvent(event: G2Event, frameId: Int) {
|
||||
val current = listener
|
||||
if (current == null) {
|
||||
|
||||
+21
-1
@@ -124,6 +124,7 @@ class GlassesSessionCore(
|
||||
internal val compassSubscriptions = CopyOnWriteList<CompassSubscription>(platform)
|
||||
internal val ambientLightListeners = CopyOnWriteList<FaceclawAmbientLightListener>(platform)
|
||||
internal val micStatusListeners = CopyOnWriteList<FaceclawMicStatusListener>(platform)
|
||||
internal val audioMonitorListeners = CopyOnWriteList<FaceclawAudioPacketListener>(platform)
|
||||
@Volatile internal var running = false
|
||||
@Volatile internal var userDisconnectRequested = false
|
||||
// Set when a connect attempt failed while an arm's OS bond is gone:
|
||||
@@ -834,6 +835,24 @@ class GlassesSessionCore(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Observe every packet on the audio (render) characteristic, on the main
|
||||
* thread, whether or not any capture is active. Purely passive: sends
|
||||
* nothing to the glasses and does not affect the capture listener, so it
|
||||
* shows what another app's mic activation actually produces.
|
||||
*/
|
||||
fun addAudioMonitorListener(listener: FaceclawAudioPacketListener?) {
|
||||
if (listener != null) {
|
||||
audioMonitorListeners.add(listener)
|
||||
}
|
||||
}
|
||||
|
||||
fun removeAudioMonitorListener(listener: FaceclawAudioPacketListener?) {
|
||||
if (listener != null) {
|
||||
audioMonitorListeners.remove(listener)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue a CFW mic_control record (['M','C',ver,op,...]) as a settings
|
||||
* field-103 write to both temples, or to a single one. Fire-and-forget:
|
||||
@@ -1593,10 +1612,11 @@ class GlassesSessionCore(
|
||||
lastIncomingAtMs = arrivalMs
|
||||
listenerToCall = if (audioCaptureActive) audioPacketListener else null
|
||||
}
|
||||
val arm = if (address.equals(leftAddress, ignoreCase = true)) "L" else if (address.equals(rightAddress, ignoreCase = true)) "R" else "?"
|
||||
emitAudioMonitorPacket(data, arm, arrivalMs)
|
||||
if (listenerToCall == null) {
|
||||
return
|
||||
}
|
||||
val arm = if (address.equals(leftAddress, ignoreCase = true)) "L" else if (address.equals(rightAddress, ignoreCase = true)) "R" else "?"
|
||||
try {
|
||||
listenerToCall.onAudioPacket(data.copyOf(), arm, arrivalMs)
|
||||
} catch (t: Throwable) {
|
||||
|
||||
Reference in new issue
Block a user