1 /* 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_WIN_H 12 #define WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_WIN_H 13 14 #include "webrtc/typedefs.h" 15 #include "webrtc/modules/audio_device/include/audio_device.h" 16 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 17 #include <Windows.h> 18 #include <mmsystem.h> 19 20 namespace webrtc { 21 22 class AudioMixerManager 23 { 24 public: 25 enum { MAX_NUMBER_MIXER_DEVICES = 40 }; 26 enum { MAX_NUMBER_OF_LINE_CONTROLS = 20 }; 27 enum { MAX_NUMBER_OF_MULTIPLE_ITEMS = 20 }; 28 struct SpeakerLineInfo 29 { 30 DWORD dwLineID; 31 bool speakerIsValid; 32 DWORD dwVolumeControlID; 33 bool volumeControlIsValid; 34 DWORD dwMuteControlID; 35 bool muteControlIsValid; 36 }; 37 struct MicrophoneLineInfo 38 { 39 DWORD dwLineID; 40 bool microphoneIsValid; 41 DWORD dwVolumeControlID; 42 bool volumeControlIsValid; 43 DWORD dwMuteControlID; 44 bool muteControlIsValid; 45 DWORD dwOnOffControlID; 46 bool onOffControlIsValid; 47 }; 48 public: 49 int32_t EnumerateAll(); 50 int32_t EnumerateSpeakers(); 51 int32_t EnumerateMicrophones(); 52 int32_t OpenSpeaker(AudioDeviceModule::WindowsDeviceType device); 53 int32_t OpenSpeaker(uint16_t index); 54 int32_t OpenMicrophone(AudioDeviceModule::WindowsDeviceType device); 55 int32_t OpenMicrophone(uint16_t index); 56 int32_t SetSpeakerVolume(uint32_t volume); 57 int32_t SpeakerVolume(uint32_t& volume) const; 58 int32_t MaxSpeakerVolume(uint32_t& maxVolume) const; 59 int32_t MinSpeakerVolume(uint32_t& minVolume) const; 60 int32_t SpeakerVolumeStepSize(uint16_t& stepSize) const; 61 int32_t SpeakerVolumeIsAvailable(bool& available); 62 int32_t SpeakerMuteIsAvailable(bool& available); 63 int32_t SetSpeakerMute(bool enable); 64 int32_t SpeakerMute(bool& enabled) const; 65 int32_t MicrophoneMuteIsAvailable(bool& available); 66 int32_t SetMicrophoneMute(bool enable); 67 int32_t MicrophoneMute(bool& enabled) const; 68 int32_t MicrophoneBoostIsAvailable(bool& available); 69 int32_t SetMicrophoneBoost(bool enable); 70 int32_t MicrophoneBoost(bool& enabled) const; 71 int32_t MicrophoneVolumeIsAvailable(bool& available); 72 int32_t SetMicrophoneVolume(uint32_t volume); 73 int32_t MicrophoneVolume(uint32_t& volume) const; 74 int32_t MaxMicrophoneVolume(uint32_t& maxVolume) const; 75 int32_t MinMicrophoneVolume(uint32_t& minVolume) const; 76 int32_t MicrophoneVolumeStepSize(uint16_t& stepSize) const; 77 int32_t Close(); 78 int32_t CloseSpeaker(); 79 int32_t CloseMicrophone(); 80 bool SpeakerIsInitialized() const; 81 bool MicrophoneIsInitialized() const; 82 UINT Devices() const; 83 84 private: 85 UINT DestinationLines(UINT mixId) const; 86 UINT SourceLines(UINT mixId, DWORD destId) const; 87 bool GetCapabilities(UINT mixId, MIXERCAPS& caps, bool trace = false) const; 88 bool GetDestinationLineInfo(UINT mixId, DWORD destId, MIXERLINE& line, bool trace = false) const; 89 bool GetSourceLineInfo(UINT mixId, DWORD destId, DWORD srcId, MIXERLINE& line, bool trace = false) const; 90 91 bool GetAllLineControls(UINT mixId, const MIXERLINE& line, MIXERCONTROL* controlArray, bool trace = false) const; 92 bool GetLineControl(UINT mixId, DWORD dwControlID, MIXERCONTROL& control) const; 93 bool GetControlDetails(UINT mixId, MIXERCONTROL& controlArray, bool trace = false) const; 94 bool GetUnsignedControlValue(UINT mixId, DWORD dwControlID, DWORD& dwValue) const; 95 bool SetUnsignedControlValue(UINT mixId, DWORD dwControlID, DWORD dwValue) const; 96 bool SetBooleanControlValue(UINT mixId, DWORD dwControlID, bool value) const; 97 bool GetBooleanControlValue(UINT mixId, DWORD dwControlID, bool& value) const; 98 bool GetSelectedMuxSource(UINT mixId, DWORD dwControlID, DWORD cMultipleItems, UINT& index) const; 99 100 private: 101 void ClearSpeakerState(); 102 void ClearSpeakerState(UINT idx); 103 void ClearMicrophoneState(); 104 void ClearMicrophoneState(UINT idx); 105 bool SpeakerIsValid(UINT idx) const; 106 UINT ValidSpeakers() const; 107 bool MicrophoneIsValid(UINT idx) const; 108 UINT ValidMicrophones() const; 109 110 void TraceStatusAndSupportFlags(DWORD fdwLine) const; 111 void TraceTargetType(DWORD dwType) const; 112 void TraceComponentType(DWORD dwComponentType) const; 113 void TraceControlType(DWORD dwControlType) const; 114 void TraceControlStatusAndSupportFlags(DWORD fdwControl) const; 115 void TraceWaveInError(MMRESULT error) const; 116 void TraceWaveOutError(MMRESULT error) const; 117 // Converts from wide-char to UTF-8 if UNICODE is defined. 118 // Does nothing if UNICODE is undefined. 119 char* WideToUTF8(const TCHAR* src) const; 120 121 public: 122 AudioMixerManager(const int32_t id); 123 ~AudioMixerManager(); 124 125 private: 126 CriticalSectionWrapper& _critSect; 127 int32_t _id; 128 HMIXER _outputMixerHandle; 129 UINT _outputMixerID; 130 HMIXER _inputMixerHandle; 131 UINT _inputMixerID; 132 SpeakerLineInfo _speakerState[MAX_NUMBER_MIXER_DEVICES]; 133 MicrophoneLineInfo _microphoneState[MAX_NUMBER_MIXER_DEVICES]; 134 mutable char _str[MAXERRORLENGTH]; 135 }; 136 137 } // namespace webrtc 138 139 #endif // WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_H 140