| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_ALSA_LINUX_H | 11 #ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_ALSA_LINUX_H |
| 12 #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_ALSA_LINUX_H | 12 #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_ALSA_LINUX_H |
| 13 | 13 |
| 14 #include <memory> | 14 #include <memory> |
| 15 | 15 |
| 16 #include "webrtc/base/criticalsection.h" |
| 16 #include "webrtc/base/platform_thread.h" | 17 #include "webrtc/base/platform_thread.h" |
| 17 #include "webrtc/modules/audio_device/audio_device_generic.h" | 18 #include "webrtc/modules/audio_device/audio_device_generic.h" |
| 18 #include "webrtc/modules/audio_device/linux/audio_mixer_manager_alsa_linux.h" | 19 #include "webrtc/modules/audio_device/linux/audio_mixer_manager_alsa_linux.h" |
| 19 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | |
| 20 | 20 |
| 21 #if defined(USE_X11) | 21 #if defined(USE_X11) |
| 22 #include <X11/Xlib.h> | 22 #include <X11/Xlib.h> |
| 23 #endif | 23 #endif |
| 24 #include <alsa/asoundlib.h> | 24 #include <alsa/asoundlib.h> |
| 25 #include <sys/ioctl.h> | 25 #include <sys/ioctl.h> |
| 26 #include <sys/soundcard.h> | 26 #include <sys/soundcard.h> |
| 27 | 27 |
| 28 | 28 |
| 29 namespace webrtc | 29 namespace webrtc |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 int32_t SetPlayoutBuffer(const AudioDeviceModule::BufferType type, | 138 int32_t SetPlayoutBuffer(const AudioDeviceModule::BufferType type, |
| 139 uint16_t sizeMS) override; | 139 uint16_t sizeMS) override; |
| 140 int32_t PlayoutBuffer(AudioDeviceModule::BufferType& type, | 140 int32_t PlayoutBuffer(AudioDeviceModule::BufferType& type, |
| 141 uint16_t& sizeMS) const override; | 141 uint16_t& sizeMS) const override; |
| 142 int32_t PlayoutDelay(uint16_t& delayMS) const override; | 142 int32_t PlayoutDelay(uint16_t& delayMS) const override; |
| 143 int32_t RecordingDelay(uint16_t& delayMS) const override; | 143 int32_t RecordingDelay(uint16_t& delayMS) const override; |
| 144 | 144 |
| 145 // CPU load | 145 // CPU load |
| 146 int32_t CPULoad(uint16_t& load) const override; | 146 int32_t CPULoad(uint16_t& load) const override; |
| 147 | 147 |
| 148 public: | |
| 149 bool PlayoutWarning() const override; | 148 bool PlayoutWarning() const override; |
| 150 bool PlayoutError() const override; | 149 bool PlayoutError() const override; |
| 151 bool RecordingWarning() const override; | 150 bool RecordingWarning() const override; |
| 152 bool RecordingError() const override; | 151 bool RecordingError() const override; |
| 153 void ClearPlayoutWarning() override; | 152 void ClearPlayoutWarning() override; |
| 154 void ClearPlayoutError() override; | 153 void ClearPlayoutError() override; |
| 155 void ClearRecordingWarning() override; | 154 void ClearRecordingWarning() override; |
| 156 void ClearRecordingError() override; | 155 void ClearRecordingError() override; |
| 157 | 156 |
| 158 public: | |
| 159 void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) override; | 157 void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) override; |
| 160 | 158 |
| 161 private: | 159 private: |
| 162 int32_t GetDevicesInfo(const int32_t function, | 160 int32_t GetDevicesInfo(const int32_t function, |
| 163 const bool playback, | 161 const bool playback, |
| 164 const int32_t enumDeviceNo = 0, | 162 const int32_t enumDeviceNo = 0, |
| 165 char* enumDeviceName = NULL, | 163 char* enumDeviceName = NULL, |
| 166 const int32_t ednLen = 0) const; | 164 const int32_t ednLen = 0) const; |
| 167 int32_t ErrorRecovery(int32_t error, snd_pcm_t* deviceHandle); | 165 int32_t ErrorRecovery(int32_t error, snd_pcm_t* deviceHandle); |
| 168 | 166 |
| 169 private: | |
| 170 bool KeyPressed() const; | 167 bool KeyPressed() const; |
| 171 | 168 |
| 172 private: | |
| 173 void Lock() EXCLUSIVE_LOCK_FUNCTION(_critSect) { _critSect.Enter(); }; | 169 void Lock() EXCLUSIVE_LOCK_FUNCTION(_critSect) { _critSect.Enter(); }; |
| 174 void UnLock() UNLOCK_FUNCTION(_critSect) { _critSect.Leave(); }; | 170 void UnLock() UNLOCK_FUNCTION(_critSect) { _critSect.Leave(); }; |
| 175 private: | 171 |
| 176 inline int32_t InputSanityCheckAfterUnlockedPeriod() const; | 172 inline int32_t InputSanityCheckAfterUnlockedPeriod() const; |
| 177 inline int32_t OutputSanityCheckAfterUnlockedPeriod() const; | 173 inline int32_t OutputSanityCheckAfterUnlockedPeriod() const; |
| 178 | 174 |
| 179 private: | |
| 180 static bool RecThreadFunc(void*); | 175 static bool RecThreadFunc(void*); |
| 181 static bool PlayThreadFunc(void*); | 176 static bool PlayThreadFunc(void*); |
| 182 bool RecThreadProcess(); | 177 bool RecThreadProcess(); |
| 183 bool PlayThreadProcess(); | 178 bool PlayThreadProcess(); |
| 184 | 179 |
| 185 private: | |
| 186 AudioDeviceBuffer* _ptrAudioBuffer; | 180 AudioDeviceBuffer* _ptrAudioBuffer; |
| 187 | 181 |
| 188 CriticalSectionWrapper& _critSect; | 182 rtc::CriticalSection _critSect; |
| 189 | 183 |
| 190 // TODO(pbos): Make plain members and start/stop instead of resetting these | 184 // TODO(pbos): Make plain members and start/stop instead of resetting these |
| 191 // pointers. A thread can be reused. | 185 // pointers. A thread can be reused. |
| 192 std::unique_ptr<rtc::PlatformThread> _ptrThreadRec; | 186 std::unique_ptr<rtc::PlatformThread> _ptrThreadRec; |
| 193 std::unique_ptr<rtc::PlatformThread> _ptrThreadPlay; | 187 std::unique_ptr<rtc::PlatformThread> _ptrThreadPlay; |
| 194 | 188 |
| 195 int32_t _id; | 189 int32_t _id; |
| 196 | 190 |
| 197 AudioMixerManagerLinuxALSA _mixerManager; | 191 AudioMixerManagerLinuxALSA _mixerManager; |
| 198 | 192 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 219 uint8_t _recChannels; | 213 uint8_t _recChannels; |
| 220 uint8_t _playChannels; | 214 uint8_t _playChannels; |
| 221 | 215 |
| 222 int8_t* _recordingBuffer; // in byte | 216 int8_t* _recordingBuffer; // in byte |
| 223 int8_t* _playoutBuffer; // in byte | 217 int8_t* _playoutBuffer; // in byte |
| 224 uint32_t _recordingFramesLeft; | 218 uint32_t _recordingFramesLeft; |
| 225 uint32_t _playoutFramesLeft; | 219 uint32_t _playoutFramesLeft; |
| 226 | 220 |
| 227 AudioDeviceModule::BufferType _playBufType; | 221 AudioDeviceModule::BufferType _playBufType; |
| 228 | 222 |
| 229 private: | |
| 230 bool _initialized; | 223 bool _initialized; |
| 231 bool _recording; | 224 bool _recording; |
| 232 bool _playing; | 225 bool _playing; |
| 233 bool _recIsInitialized; | 226 bool _recIsInitialized; |
| 234 bool _playIsInitialized; | 227 bool _playIsInitialized; |
| 235 bool _AGC; | 228 bool _AGC; |
| 236 | 229 |
| 237 snd_pcm_sframes_t _recordingDelay; | 230 snd_pcm_sframes_t _recordingDelay; |
| 238 snd_pcm_sframes_t _playoutDelay; | 231 snd_pcm_sframes_t _playoutDelay; |
| 239 | 232 |
| 240 uint16_t _playWarning; | 233 uint16_t _playWarning; |
| 241 uint16_t _playError; | 234 uint16_t _playError; |
| 242 uint16_t _recWarning; | 235 uint16_t _recWarning; |
| 243 uint16_t _recError; | 236 uint16_t _recError; |
| 244 | 237 |
| 245 uint16_t _playBufDelay; // playback delay | 238 uint16_t _playBufDelay; // playback delay |
| 246 uint16_t _playBufDelayFixed; // fixed playback delay | 239 uint16_t _playBufDelayFixed; // fixed playback delay |
| 247 | 240 |
| 248 char _oldKeyState[32]; | 241 char _oldKeyState[32]; |
| 249 #if defined(USE_X11) | 242 #if defined(USE_X11) |
| 250 Display* _XDisplay; | 243 Display* _XDisplay; |
| 251 #endif | 244 #endif |
| 252 }; | 245 }; |
| 253 | 246 |
| 254 } | 247 } |
| 255 | 248 |
| 256 #endif // MODULES_AUDIO_DEVICE_MAIN_SOURCE_LINUX_AUDIO_DEVICE_ALSA_LINUX_H_ | 249 #endif // MODULES_AUDIO_DEVICE_MAIN_SOURCE_LINUX_AUDIO_DEVICE_ALSA_LINUX_H_ |
| OLD | NEW |