fix(sndDevices): handle device reconnection and filter capture events in OnDeviceStateChanged - #532
Conversation
… in OnDeviceStateChanged - Filter capture (eRender) device events in OnDeviceStateChanged via IMMEndpoint.GetDataFlow to prevent unnecessary playback reinit when input devices change state - Track reconnected device GUID when state transitions to ACTIVE - Add reconnection detection in sndDevicesImplementDeviceRules to auto-select reconnected playback devices (fixes BT headset reconnect after UNPLUGGED) - Clear reconnection state on reinit
|
@claude can you review this PR. |
|
Claude finished @bvijay74's task in 6m 31s —— View job Reviewing PR #532
|

Summary
Fixes multiple device management bugs in the sndDevices module that affect Bluetooth device reconnection and unnecessary reinitialization from capture device events.
Changes
OnDeviceStateChanged — Filter capture events
The callback now queries IMMEndpoint.GetDataFlow and returns S_OK early for non-render (capture/input) devices. Previously, any device state change — including microphone unplug/reconnect — would trigger a playback processing thread restart.
OnDeviceStateChanged — Track reconnections
When a device transitions to DEVICE_STATE_ACTIVE, its GUID is saved to
reconnectedDeviceGuidandhasReconnectedDeviceis set. This preserves the dedup guard (preventing callback storms on repeated same-state events) while allowing the reconnection to be detected.sndDevicesImplementDeviceRules — Reconnection handling
Added a new check after the count-based new-device detection: if
hasReconnectedDeviceis set, find that device in the current list and select it. This handles Bluetooth headsets that are already enumerated (in UNPLUGGED state) and then connect — their count doesn't change, so the existing count-based logic would miss them.sndDevicesReInit — Reconnection state cleared
Both fields are reset during reinit to prevent stale reconnection state.
Files Changed
audiopassthru/include/sndDevices.h— AddedreconnectedDeviceGuidandhasReconnectedDevicefieldsaudiopassthru/src/sndDevices/sndDevicesDeviceCallbacks.cpp— Capture filter + reconnection trackingaudiopassthru/src/sndDevices/sndDevicesImplementDeviceRules.cpp— Reconnection device selectionaudiopassthru/src/sndDevices/sndDevicesReInit.cpp— Clear reconnection stateRelated Issues