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 AUDIO_DEVICE_AUDIO_MIXER_MANAGER_ALSA_LINUX_H_
12 #define AUDIO_DEVICE_AUDIO_MIXER_MANAGER_ALSA_LINUX_H_
13 
14 #include "modules/audio_device/include/audio_device.h"
15 #include "modules/audio_device/linux/alsasymboltable_linux.h"
16 #include "rtc_base/criticalsection.h"
17 #include "typedefs.h"  // NOLINT(build/include)
18 
19 #include <alsa/asoundlib.h>
20 
21 namespace webrtc
22 {
23 
24 class AudioMixerManagerLinuxALSA
25 {
26 public:
27     int32_t OpenSpeaker(char* deviceName);
28     int32_t OpenMicrophone(char* deviceName);
29     int32_t SetSpeakerVolume(uint32_t volume);
30     int32_t SpeakerVolume(uint32_t& volume) const;
31     int32_t MaxSpeakerVolume(uint32_t& maxVolume) const;
32     int32_t MinSpeakerVolume(uint32_t& minVolume) const;
33     int32_t SpeakerVolumeIsAvailable(bool& available);
34     int32_t SpeakerMuteIsAvailable(bool& available);
35     int32_t SetSpeakerMute(bool enable);
36     int32_t SpeakerMute(bool& enabled) const;
37     int32_t MicrophoneMuteIsAvailable(bool& available);
38     int32_t SetMicrophoneMute(bool enable);
39     int32_t MicrophoneMute(bool& enabled) const;
40     int32_t MicrophoneVolumeIsAvailable(bool& available);
41     int32_t SetMicrophoneVolume(uint32_t volume);
42     int32_t MicrophoneVolume(uint32_t& volume) const;
43     int32_t MaxMicrophoneVolume(uint32_t& maxVolume) const;
44     int32_t MinMicrophoneVolume(uint32_t& minVolume) const;
45     int32_t Close();
46     int32_t CloseSpeaker();
47     int32_t CloseMicrophone();
48     bool SpeakerIsInitialized() const;
49     bool MicrophoneIsInitialized() const;
50 
51 public:
52     AudioMixerManagerLinuxALSA();
53     ~AudioMixerManagerLinuxALSA();
54 
55 private:
56     int32_t LoadMicMixerElement() const;
57     int32_t LoadSpeakerMixerElement() const;
58     void GetControlName(char *controlName, char* deviceName) const;
59 
60 private:
61     rtc::CriticalSection _critSect;
62     mutable snd_mixer_t* _outputMixerHandle;
63     char _outputMixerStr[kAdmMaxDeviceNameSize];
64     mutable snd_mixer_t* _inputMixerHandle;
65     char _inputMixerStr[kAdmMaxDeviceNameSize];
66     mutable snd_mixer_elem_t* _outputMixerElement;
67     mutable snd_mixer_elem_t* _inputMixerElement;
68 };
69 
70 }
71 
72 #endif  // MODULES_AUDIO_DEVICE_MAIN_SOURCE_LINUX_AUDIO_MIXER_MANAGER_ALSA_LINUX_H_
73