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 #include <assert.h> | 11 #include <assert.h> |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
14 | 14 #include "webrtc/base/logging.h" |
15 #include "webrtc/modules/audio_device/audio_device_config.h" | 15 #include "webrtc/modules/audio_device/audio_device_config.h" |
16 #include "webrtc/modules/audio_device/linux/audio_device_pulse_linux.h" | 16 #include "webrtc/modules/audio_device/linux/audio_device_pulse_linux.h" |
17 | |
18 #include "webrtc/system_wrappers/include/event_wrapper.h" | 17 #include "webrtc/system_wrappers/include/event_wrapper.h" |
19 #include "webrtc/system_wrappers/include/trace.h" | 18 #include "webrtc/system_wrappers/include/trace.h" |
20 | 19 |
21 webrtc_adm_linux_pulse::PulseAudioSymbolTable PaSymbolTable; | 20 webrtc_adm_linux_pulse::PulseAudioSymbolTable PaSymbolTable; |
22 | 21 |
23 // Accesses Pulse functions through our late-binding symbol table instead of | 22 // Accesses Pulse functions through our late-binding symbol table instead of |
24 // directly. This way we don't have to link to libpulse, which means our binary | 23 // directly. This way we don't have to link to libpulse, which means our binary |
25 // will work on systems that don't have it. | 24 // will work on systems that don't have it. |
26 #define LATE(sym) \ | 25 #define LATE(sym) \ |
27 LATESYM_GET(webrtc_adm_linux_pulse::PulseAudioSymbolTable, &PaSymbolTable, sym
) | 26 LATESYM_GET(webrtc_adm_linux_pulse::PulseAudioSymbolTable, &PaSymbolTable, sym
) |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 // ActiveAudioLayer | 155 // ActiveAudioLayer |
157 // ---------------------------------------------------------------------------- | 156 // ---------------------------------------------------------------------------- |
158 | 157 |
159 int32_t AudioDeviceLinuxPulse::ActiveAudioLayer( | 158 int32_t AudioDeviceLinuxPulse::ActiveAudioLayer( |
160 AudioDeviceModule::AudioLayer& audioLayer) const | 159 AudioDeviceModule::AudioLayer& audioLayer) const |
161 { | 160 { |
162 audioLayer = AudioDeviceModule::kLinuxPulseAudio; | 161 audioLayer = AudioDeviceModule::kLinuxPulseAudio; |
163 return 0; | 162 return 0; |
164 } | 163 } |
165 | 164 |
166 int32_t AudioDeviceLinuxPulse::Init() | 165 AudioDeviceGeneric::InitStatus AudioDeviceLinuxPulse::Init() { |
167 { | 166 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
168 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 167 if (_initialized) { |
169 if (_initialized) | 168 return InitStatus::OK; |
170 { | 169 } |
171 return 0; | 170 |
| 171 // Initialize PulseAudio |
| 172 if (InitPulseAudio() < 0) { |
| 173 LOG(LS_ERROR) << "failed to initialize PulseAudio"; |
| 174 if (TerminatePulseAudio() < 0) { |
| 175 LOG(LS_ERROR) << "failed to terminate PulseAudio"; |
172 } | 176 } |
| 177 return InitStatus::OTHER_ERROR; |
| 178 } |
173 | 179 |
174 // Initialize PulseAudio | 180 _playWarning = 0; |
175 if (InitPulseAudio() < 0) | 181 _playError = 0; |
176 { | 182 _recWarning = 0; |
177 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 183 _recError = 0; |
178 " failed to initialize PulseAudio"); | |
179 | 184 |
180 if (TerminatePulseAudio() < 0) | 185 // Get X display handle for typing detection |
181 { | 186 _XDisplay = XOpenDisplay(NULL); |
182 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 187 if (!_XDisplay) { |
183 " failed to terminate PulseAudio"); | 188 LOG(LS_WARNING) |
184 } | 189 << "failed to open X display, typing detection will not work"; |
| 190 } |
185 | 191 |
186 return -1; | 192 // RECORDING |
187 } | 193 _ptrThreadRec.reset(new rtc::PlatformThread( |
| 194 RecThreadFunc, this, "webrtc_audio_module_rec_thread")); |
188 | 195 |
189 _playWarning = 0; | 196 _ptrThreadRec->Start(); |
190 _playError = 0; | 197 _ptrThreadRec->SetPriority(rtc::kRealtimePriority); |
191 _recWarning = 0; | |
192 _recError = 0; | |
193 | 198 |
194 //Get X display handle for typing detection | 199 // PLAYOUT |
195 _XDisplay = XOpenDisplay(NULL); | 200 _ptrThreadPlay.reset(new rtc::PlatformThread( |
196 if (!_XDisplay) | 201 PlayThreadFunc, this, "webrtc_audio_module_play_thread")); |
197 { | 202 _ptrThreadPlay->Start(); |
198 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 203 _ptrThreadPlay->SetPriority(rtc::kRealtimePriority); |
199 " failed to open X display, typing detection will not work"); | |
200 } | |
201 | 204 |
202 // RECORDING | 205 _initialized = true; |
203 _ptrThreadRec.reset(new rtc::PlatformThread( | |
204 RecThreadFunc, this, "webrtc_audio_module_rec_thread")); | |
205 | 206 |
206 _ptrThreadRec->Start(); | 207 return InitStatus::OK; |
207 _ptrThreadRec->SetPriority(rtc::kRealtimePriority); | |
208 | |
209 // PLAYOUT | |
210 _ptrThreadPlay.reset(new rtc::PlatformThread( | |
211 PlayThreadFunc, this, "webrtc_audio_module_play_thread")); | |
212 _ptrThreadPlay->Start(); | |
213 _ptrThreadPlay->SetPriority(rtc::kRealtimePriority); | |
214 | |
215 _initialized = true; | |
216 | |
217 return 0; | |
218 } | 208 } |
219 | 209 |
220 int32_t AudioDeviceLinuxPulse::Terminate() | 210 int32_t AudioDeviceLinuxPulse::Terminate() |
221 { | 211 { |
222 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 212 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
223 if (!_initialized) | 213 if (!_initialized) |
224 { | 214 { |
225 return 0; | 215 return 0; |
226 } | 216 } |
227 | 217 |
(...skipping 2769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2997 | 2987 |
2998 // A bit change in keymap means a key is pressed | 2988 // A bit change in keymap means a key is pressed |
2999 for (i = 0; i < sizeof(szKey); i++) | 2989 for (i = 0; i < sizeof(szKey); i++) |
3000 state |= (szKey[i] ^ _oldKeyState[i]) & szKey[i]; | 2990 state |= (szKey[i] ^ _oldKeyState[i]) & szKey[i]; |
3001 | 2991 |
3002 // Save old state | 2992 // Save old state |
3003 memcpy((char*)_oldKeyState, (char*)szKey, sizeof(_oldKeyState)); | 2993 memcpy((char*)_oldKeyState, (char*)szKey, sizeof(_oldKeyState)); |
3004 return (state != 0); | 2994 return (state != 0); |
3005 } | 2995 } |
3006 } | 2996 } |
OLD | NEW |