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 |
Max Morin WebRTC
2016/06/30 11:22:58
Added missing logging header
| |
11 #include "webrtc/base/arraysize.h" | 11 #include "webrtc/base/arraysize.h" |
12 #include "webrtc/base/checks.h" | 12 #include "webrtc/base/checks.h" |
13 #include "webrtc/base/platform_thread.h" | 13 #include "webrtc/base/platform_thread.h" |
14 #include "webrtc/modules/audio_device/audio_device_config.h" | 14 #include "webrtc/modules/audio_device/audio_device_config.h" |
15 #include "webrtc/modules/audio_device/mac/audio_device_mac.h" | 15 #include "webrtc/modules/audio_device/mac/audio_device_mac.h" |
16 #include "webrtc/modules/audio_device/mac/portaudio/pa_ringbuffer.h" | 16 #include "webrtc/modules/audio_device/mac/portaudio/pa_ringbuffer.h" |
17 #include "webrtc/system_wrappers/include/event_wrapper.h" | 17 #include "webrtc/system_wrappers/include/event_wrapper.h" |
18 #include "webrtc/system_wrappers/include/trace.h" | 18 #include "webrtc/system_wrappers/include/trace.h" |
19 | 19 |
20 #include <ApplicationServices/ApplicationServices.h> | 20 #include <ApplicationServices/ApplicationServices.h> |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 _ptrAudioBuffer->SetRecordingChannels(N_REC_CHANNELS); | 214 _ptrAudioBuffer->SetRecordingChannels(N_REC_CHANNELS); |
215 _ptrAudioBuffer->SetPlayoutChannels(N_PLAY_CHANNELS); | 215 _ptrAudioBuffer->SetPlayoutChannels(N_PLAY_CHANNELS); |
216 } | 216 } |
217 | 217 |
218 int32_t AudioDeviceMac::ActiveAudioLayer( | 218 int32_t AudioDeviceMac::ActiveAudioLayer( |
219 AudioDeviceModule::AudioLayer& audioLayer) const { | 219 AudioDeviceModule::AudioLayer& audioLayer) const { |
220 audioLayer = AudioDeviceModule::kPlatformDefaultAudio; | 220 audioLayer = AudioDeviceModule::kPlatformDefaultAudio; |
221 return 0; | 221 return 0; |
222 } | 222 } |
223 | 223 |
224 int32_t AudioDeviceMac::Init() { | 224 AudioDeviceGeneric::InitStatus AudioDeviceMac::Init() { |
225 CriticalSectionScoped lock(&_critSect); | 225 CriticalSectionScoped lock(&_critSect); |
226 | 226 |
227 if (_initialized) { | 227 if (_initialized) { |
228 return 0; | 228 return InitStatus::OK; |
229 } | 229 } |
230 | 230 |
231 OSStatus err = noErr; | 231 OSStatus err = noErr; |
232 | 232 |
233 _isShutDown = false; | 233 _isShutDown = false; |
234 | 234 |
235 // PortAudio ring buffers require an elementCount which is a power of two. | 235 // PortAudio ring buffers require an elementCount which is a power of two. |
236 if (_renderBufData == NULL) { | 236 if (_renderBufData == NULL) { |
237 UInt32 powerOfTwo = 1; | 237 UInt32 powerOfTwo = 1; |
238 while (powerOfTwo < PLAY_BUF_SIZE_IN_SAMPLES) { | 238 while (powerOfTwo < PLAY_BUF_SIZE_IN_SAMPLES) { |
239 powerOfTwo <<= 1; | 239 powerOfTwo <<= 1; |
240 } | 240 } |
241 _renderBufSizeSamples = powerOfTwo; | 241 _renderBufSizeSamples = powerOfTwo; |
242 _renderBufData = new SInt16[_renderBufSizeSamples]; | 242 _renderBufData = new SInt16[_renderBufSizeSamples]; |
243 } | 243 } |
244 | 244 |
245 if (_paRenderBuffer == NULL) { | 245 if (_paRenderBuffer == NULL) { |
246 _paRenderBuffer = new PaUtilRingBuffer; | 246 _paRenderBuffer = new PaUtilRingBuffer; |
247 PaRingBufferSize bufSize = -1; | 247 PaRingBufferSize bufSize = -1; |
248 bufSize = PaUtil_InitializeRingBuffer( | 248 bufSize = PaUtil_InitializeRingBuffer( |
249 _paRenderBuffer, sizeof(SInt16), _renderBufSizeSamples, _renderBufData); | 249 _paRenderBuffer, sizeof(SInt16), _renderBufSizeSamples, _renderBufData); |
250 if (bufSize == -1) { | 250 if (bufSize == -1) { |
251 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, | 251 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, |
252 " PaUtil_InitializeRingBuffer() error"); | 252 " PaUtil_InitializeRingBuffer() error"); |
253 return -1; | 253 return InitStatus::PLAYOUT_ERROR; |
254 } | 254 } |
255 } | 255 } |
256 | 256 |
257 if (_captureBufData == NULL) { | 257 if (_captureBufData == NULL) { |
258 UInt32 powerOfTwo = 1; | 258 UInt32 powerOfTwo = 1; |
259 while (powerOfTwo < REC_BUF_SIZE_IN_SAMPLES) { | 259 while (powerOfTwo < REC_BUF_SIZE_IN_SAMPLES) { |
260 powerOfTwo <<= 1; | 260 powerOfTwo <<= 1; |
261 } | 261 } |
262 _captureBufSizeSamples = powerOfTwo; | 262 _captureBufSizeSamples = powerOfTwo; |
263 _captureBufData = new Float32[_captureBufSizeSamples]; | 263 _captureBufData = new Float32[_captureBufSizeSamples]; |
264 } | 264 } |
265 | 265 |
266 if (_paCaptureBuffer == NULL) { | 266 if (_paCaptureBuffer == NULL) { |
267 _paCaptureBuffer = new PaUtilRingBuffer; | 267 _paCaptureBuffer = new PaUtilRingBuffer; |
268 PaRingBufferSize bufSize = -1; | 268 PaRingBufferSize bufSize = -1; |
269 bufSize = | 269 bufSize = |
270 PaUtil_InitializeRingBuffer(_paCaptureBuffer, sizeof(Float32), | 270 PaUtil_InitializeRingBuffer(_paCaptureBuffer, sizeof(Float32), |
271 _captureBufSizeSamples, _captureBufData); | 271 _captureBufSizeSamples, _captureBufData); |
272 if (bufSize == -1) { | 272 if (bufSize == -1) { |
273 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, | 273 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, |
274 " PaUtil_InitializeRingBuffer() error"); | 274 " PaUtil_InitializeRingBuffer() error"); |
275 return -1; | 275 return InitStatus::RECORDING_ERROR; |
276 } | 276 } |
277 } | 277 } |
278 | 278 |
279 kern_return_t kernErr = KERN_SUCCESS; | 279 kern_return_t kernErr = KERN_SUCCESS; |
280 kernErr = semaphore_create(mach_task_self(), &_renderSemaphore, | 280 kernErr = semaphore_create(mach_task_self(), &_renderSemaphore, |
281 SYNC_POLICY_FIFO, 0); | 281 SYNC_POLICY_FIFO, 0); |
282 if (kernErr != KERN_SUCCESS) { | 282 if (kernErr != KERN_SUCCESS) { |
283 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, | 283 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, |
284 " semaphore_create() error: %d", kernErr); | 284 " semaphore_create() error: %d", kernErr); |
285 return -1; | 285 return InitStatus::OTHER_ERROR; |
286 } | 286 } |
287 | 287 |
288 kernErr = semaphore_create(mach_task_self(), &_captureSemaphore, | 288 kernErr = semaphore_create(mach_task_self(), &_captureSemaphore, |
289 SYNC_POLICY_FIFO, 0); | 289 SYNC_POLICY_FIFO, 0); |
290 if (kernErr != KERN_SUCCESS) { | 290 if (kernErr != KERN_SUCCESS) { |
291 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, | 291 WEBRTC_TRACE(kTraceCritical, kTraceAudioDevice, _id, |
292 " semaphore_create() error: %d", kernErr); | 292 " semaphore_create() error: %d", kernErr); |
293 return -1; | 293 return InitStatus::OTHER_ERROR; |
294 } | 294 } |
295 | 295 |
296 // Setting RunLoop to NULL here instructs HAL to manage its own thread for | 296 // Setting RunLoop to NULL here instructs HAL to manage its own thread for |
297 // notifications. This was the default behaviour on OS X 10.5 and earlier, | 297 // notifications. This was the default behaviour on OS X 10.5 and earlier, |
298 // but now must be explicitly specified. HAL would otherwise try to use the | 298 // but now must be explicitly specified. HAL would otherwise try to use the |
299 // main thread to issue notifications. | 299 // main thread to issue notifications. |
300 AudioObjectPropertyAddress propertyAddress = { | 300 AudioObjectPropertyAddress propertyAddress = { |
301 kAudioHardwarePropertyRunLoop, kAudioObjectPropertyScopeGlobal, | 301 kAudioHardwarePropertyRunLoop, kAudioObjectPropertyScopeGlobal, |
302 kAudioObjectPropertyElementMaster}; | 302 kAudioObjectPropertyElementMaster}; |
303 CFRunLoopRef runLoop = NULL; | 303 CFRunLoopRef runLoop = NULL; |
304 UInt32 size = sizeof(CFRunLoopRef); | 304 UInt32 size = sizeof(CFRunLoopRef); |
305 WEBRTC_CA_RETURN_ON_ERR(AudioObjectSetPropertyData( | 305 int aoerr = AudioObjectSetPropertyData( |
306 kAudioObjectSystemObject, &propertyAddress, 0, NULL, size, &runLoop)); | 306 kAudioObjectSystemObject, &propertyAddress, 0, NULL, size, &runLoop); |
307 if (aoerr != noErr) { | |
308 LOG(LS_ERROR) << "Error in AudioObjectSetPropertyData: " | |
309 << (const char*)&aoerr; | |
310 return InitStatus::OTHER_ERROR; | |
311 } | |
307 | 312 |
308 // Listen for any device changes. | 313 // Listen for any device changes. |
309 propertyAddress.mSelector = kAudioHardwarePropertyDevices; | 314 propertyAddress.mSelector = kAudioHardwarePropertyDevices; |
310 WEBRTC_CA_LOG_ERR(AudioObjectAddPropertyListener( | 315 WEBRTC_CA_LOG_ERR(AudioObjectAddPropertyListener( |
311 kAudioObjectSystemObject, &propertyAddress, &objectListenerProc, this)); | 316 kAudioObjectSystemObject, &propertyAddress, &objectListenerProc, this)); |
312 | 317 |
313 // Determine if this is a MacBook Pro | 318 // Determine if this is a MacBook Pro |
314 _macBookPro = false; | 319 _macBookPro = false; |
315 _macBookProPanRight = false; | 320 _macBookProPanRight = false; |
316 char buf[128]; | 321 char buf[128]; |
(...skipping 14 matching lines...) Expand all Loading... | |
331 | 336 |
332 _playWarning = 0; | 337 _playWarning = 0; |
333 _playError = 0; | 338 _playError = 0; |
334 _recWarning = 0; | 339 _recWarning = 0; |
335 _recError = 0; | 340 _recError = 0; |
336 | 341 |
337 get_mic_volume_counter_ms_ = 0; | 342 get_mic_volume_counter_ms_ = 0; |
338 | 343 |
339 _initialized = true; | 344 _initialized = true; |
340 | 345 |
341 return 0; | 346 return InitStatus::OK; |
342 } | 347 } |
343 | 348 |
344 int32_t AudioDeviceMac::Terminate() { | 349 int32_t AudioDeviceMac::Terminate() { |
345 if (!_initialized) { | 350 if (!_initialized) { |
346 return 0; | 351 return 0; |
347 } | 352 } |
348 | 353 |
349 if (_recording) { | 354 if (_recording) { |
350 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, | 355 WEBRTC_TRACE(kTraceError, kTraceAudioDevice, _id, |
351 " Recording must be stopped"); | 356 " Recording must be stopped"); |
(...skipping 2411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2763 bool keyState = | 2768 bool keyState = |
2764 CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, key_index); | 2769 CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, key_index); |
2765 // A false -> true change in keymap means a key is pressed. | 2770 // A false -> true change in keymap means a key is pressed. |
2766 key_down |= (keyState && !prev_key_state_[key_index]); | 2771 key_down |= (keyState && !prev_key_state_[key_index]); |
2767 // Save current state. | 2772 // Save current state. |
2768 prev_key_state_[key_index] = keyState; | 2773 prev_key_state_[key_index] = keyState; |
2769 } | 2774 } |
2770 return key_down; | 2775 return key_down; |
2771 } | 2776 } |
2772 } // namespace webrtc | 2777 } // namespace webrtc |
OLD | NEW |