summaryrefslogtreecommitdiff
path: root/chromium/third_party/webrtc/modules/audio_device/win/audio_mixer_manager_win.h
blob: 1e0ab47ad4da256d4fa31c10faba20f475a60079 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_WIN_H
#define WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_WIN_H

#include "webrtc/typedefs.h"
#include "webrtc/modules/audio_device/include/audio_device.h"
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
#include <Windows.h>
#include <mmsystem.h>

namespace webrtc {

class AudioMixerManager
{
public:
    enum { MAX_NUMBER_MIXER_DEVICES = 40 };
    enum { MAX_NUMBER_OF_LINE_CONTROLS = 20 };
    enum { MAX_NUMBER_OF_MULTIPLE_ITEMS = 20 };
    struct SpeakerLineInfo
    {
        DWORD dwLineID;
        bool  speakerIsValid;
        DWORD dwVolumeControlID;
        bool  volumeControlIsValid;
        DWORD dwMuteControlID;
        bool  muteControlIsValid;
    };
    struct MicrophoneLineInfo
    {
        DWORD dwLineID;
        bool  microphoneIsValid;
        DWORD dwVolumeControlID;
        bool  volumeControlIsValid;
        DWORD dwMuteControlID;
        bool  muteControlIsValid;
        DWORD dwOnOffControlID;
        bool  onOffControlIsValid;
    };
public:
    int32_t EnumerateAll();
    int32_t EnumerateSpeakers();
    int32_t EnumerateMicrophones();
    int32_t OpenSpeaker(AudioDeviceModule::WindowsDeviceType device);
    int32_t OpenSpeaker(uint16_t index);
    int32_t OpenMicrophone(AudioDeviceModule::WindowsDeviceType device);
    int32_t OpenMicrophone(uint16_t index);
    int32_t SetSpeakerVolume(uint32_t volume);
    int32_t SpeakerVolume(uint32_t& volume) const;
    int32_t MaxSpeakerVolume(uint32_t& maxVolume) const;
    int32_t MinSpeakerVolume(uint32_t& minVolume) const;
    int32_t SpeakerVolumeStepSize(uint16_t& stepSize) const;
    int32_t SpeakerVolumeIsAvailable(bool& available);
    int32_t SpeakerMuteIsAvailable(bool& available);
    int32_t SetSpeakerMute(bool enable);
    int32_t SpeakerMute(bool& enabled) const;
    int32_t MicrophoneMuteIsAvailable(bool& available);
    int32_t SetMicrophoneMute(bool enable);
    int32_t MicrophoneMute(bool& enabled) const;
    int32_t MicrophoneBoostIsAvailable(bool& available);
    int32_t SetMicrophoneBoost(bool enable);
    int32_t MicrophoneBoost(bool& enabled) const;
    int32_t MicrophoneVolumeIsAvailable(bool& available);
    int32_t SetMicrophoneVolume(uint32_t volume);
    int32_t MicrophoneVolume(uint32_t& volume) const;
    int32_t MaxMicrophoneVolume(uint32_t& maxVolume) const;
    int32_t MinMicrophoneVolume(uint32_t& minVolume) const;
    int32_t MicrophoneVolumeStepSize(uint16_t& stepSize) const;
    int32_t Close();
    int32_t CloseSpeaker();
    int32_t CloseMicrophone();
    bool SpeakerIsInitialized() const;
    bool MicrophoneIsInitialized() const;
    UINT Devices() const;

private:
    UINT DestinationLines(UINT mixId) const;
    UINT SourceLines(UINT mixId, DWORD destId) const;
    bool GetCapabilities(UINT mixId, MIXERCAPS& caps, bool trace = false) const;
    bool GetDestinationLineInfo(UINT mixId, DWORD destId, MIXERLINE& line, bool trace = false) const;
    bool GetSourceLineInfo(UINT mixId, DWORD destId, DWORD srcId, MIXERLINE& line, bool trace = false) const;

    bool GetAllLineControls(UINT mixId, const MIXERLINE& line, MIXERCONTROL* controlArray, bool trace = false) const;
    bool GetLineControl(UINT mixId, DWORD dwControlID, MIXERCONTROL& control) const;
    bool GetControlDetails(UINT mixId, MIXERCONTROL& controlArray, bool trace = false) const;
    bool GetUnsignedControlValue(UINT mixId, DWORD dwControlID, DWORD& dwValue) const;
    bool SetUnsignedControlValue(UINT mixId, DWORD dwControlID, DWORD dwValue) const;
    bool SetBooleanControlValue(UINT mixId, DWORD dwControlID, bool value) const;
    bool GetBooleanControlValue(UINT mixId, DWORD dwControlID, bool& value) const;
    bool GetSelectedMuxSource(UINT mixId, DWORD dwControlID, DWORD cMultipleItems, UINT& index) const;

private:
    void ClearSpeakerState();
    void ClearSpeakerState(UINT idx);
    void ClearMicrophoneState();
    void ClearMicrophoneState(UINT idx);
    bool SpeakerIsValid(UINT idx) const;
    UINT ValidSpeakers() const;
    bool MicrophoneIsValid(UINT idx) const;
    UINT ValidMicrophones() const;

    void TraceStatusAndSupportFlags(DWORD fdwLine) const;
    void TraceTargetType(DWORD dwType) const;
    void TraceComponentType(DWORD dwComponentType) const;
    void TraceControlType(DWORD dwControlType) const;
    void TraceControlStatusAndSupportFlags(DWORD fdwControl) const;
    void TraceWaveInError(MMRESULT error) const;
    void TraceWaveOutError(MMRESULT error) const;
    // Converts from wide-char to UTF-8 if UNICODE is defined.
    // Does nothing if UNICODE is undefined.
    char* WideToUTF8(const TCHAR* src) const;

public:
    AudioMixerManager(const int32_t id);
    ~AudioMixerManager();

private:
    CriticalSectionWrapper& _critSect;
    int32_t                 _id;
    HMIXER                  _outputMixerHandle;
    UINT                    _outputMixerID;
    HMIXER                  _inputMixerHandle;
    UINT                    _inputMixerID;
    SpeakerLineInfo         _speakerState[MAX_NUMBER_MIXER_DEVICES];
    MicrophoneLineInfo      _microphoneState[MAX_NUMBER_MIXER_DEVICES];
    mutable char            _str[MAXERRORLENGTH];
};

}  // namespace webrtc

#endif  // WEBRTC_AUDIO_DEVICE_AUDIO_MIXER_MANAGER_H