From 5895ea1573329c4190acee31247b6f26700eb246 Mon Sep 17 00:00:00 2001 From: "punyabrata@webrtc.org" Date: Mon, 22 Aug 2011 22:46:38 +0000 Subject: [PATCH] Fixes volume problem controls, happening with some Logitech headsets. Originally submitted as gips p4 depot CL 38122. Review URL: http://webrtc-codereview.appspot.com/116008 git-svn-id: http://webrtc.googlecode.com/svn/trunk@418 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../source/win/audio_mixer_manager_win.cc | 68 ++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/src/modules/audio_device/main/source/win/audio_mixer_manager_win.cc b/src/modules/audio_device/main/source/win/audio_mixer_manager_win.cc index 465f94c091..91afdec19c 100644 --- a/src/modules/audio_device/main/source/win/audio_mixer_manager_win.cc +++ b/src/modules/audio_device/main/source/win/audio_mixer_manager_win.cc @@ -303,7 +303,73 @@ WebRtc_Word32 AudioMixerManager::EnumerateMicrophones() _microphoneState[mixId].microphoneIsValid = true; // retrieve all controls for the identified wave-in destination - GetAllLineControls(mixId, destLine, controlArray); + if (!GetAllLineControls(mixId, destLine, controlArray)) + { + // This destination has no controls. We must try to control + // one of its sources instead. + // This is a rare state but has been found for some + // Logitech USB headsets. + + WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, + "this destination has no controls => must control source"); + for (DWORD sourceId = 0; sourceId < destLine.cConnections; sourceId++) + { + GetSourceLineInfo(mixId, destId, sourceId, sourceLine, false); + if (sourceLine.dwComponentType == + MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE) + { + WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, + "found microphone source ( name: %s, ID: %u)", + WideToUTF8(sourceLine.szName), sourceId); + GetAllLineControls(mixId, sourceLine, controlArray, false); + // scan the controls for this source and search for volume, + // mute and on/off (<=> boost) controls + for (UINT sc = 0; sc < sourceLine.cControls; sc++) + { + if (controlArray[sc].dwControlType == + MIXERCONTROL_CONTROLTYPE_VOLUME) + { + // store this volume control + _microphoneState[mixId].dwVolumeControlID = + controlArray[sc].dwControlID; + _microphoneState[mixId].volumeControlIsValid = true; + WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, + "found volume control (name: %s, ID: %u)", + WideToUTF8(controlArray[sc].szName), + controlArray[sc].dwControlID); + } + else if (controlArray[sc].dwControlType == + MIXERCONTROL_CONTROLTYPE_MUTE) + { + // store this mute control + _microphoneState[mixId].dwMuteControlID = + controlArray[sc].dwControlID; + _microphoneState[mixId].muteControlIsValid = true; + WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, + "found mute control (name: %s, ID: %u)", + WideToUTF8(controlArray[sc].szName), + controlArray[sc].dwControlID); + } + else if (controlArray[sc].dwControlType == + MIXERCONTROL_CONTROLTYPE_ONOFF || + controlArray[sc].dwControlType == + MIXERCONTROL_CONTROLTYPE_LOUDNESS) + { + // store this on/off control (most likely a Boost control) + _microphoneState[mixId].dwOnOffControlID = + controlArray[sc].dwControlID; + _microphoneState[mixId].onOffControlIsValid = true; + WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, + "found on/off control (name: %s, ID: %u)", + WideToUTF8(controlArray[sc].szName), + controlArray[sc].dwControlID); + } + } + } + } + + break; + } // It seems like there are three different configurations we can find in this state: //