Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(581)

Side by Side Diff: modules/audio_device/mac/audio_device_mac.cc

Issue 3020493002: Remove AudioDeviceObserver and make ADM not inherit from the Module interface.
Patch Set: linux build error Created 3 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 _twoDevices(true), 137 _twoDevices(true),
138 _doStop(false), 138 _doStop(false),
139 _doStopRec(false), 139 _doStopRec(false),
140 _macBookPro(false), 140 _macBookPro(false),
141 _macBookProPanRight(false), 141 _macBookProPanRight(false),
142 _captureLatencyUs(0), 142 _captureLatencyUs(0),
143 _renderLatencyUs(0), 143 _renderLatencyUs(0),
144 _captureDelayUs(0), 144 _captureDelayUs(0),
145 _renderDelayUs(0), 145 _renderDelayUs(0),
146 _renderDelayOffsetSamples(0), 146 _renderDelayOffsetSamples(0),
147 _playWarning(0),
148 _playError(0),
149 _recWarning(0),
150 _recError(0),
151 _paCaptureBuffer(NULL), 147 _paCaptureBuffer(NULL),
152 _paRenderBuffer(NULL), 148 _paRenderBuffer(NULL),
153 _captureBufSizeSamples(0), 149 _captureBufSizeSamples(0),
154 _renderBufSizeSamples(0), 150 _renderBufSizeSamples(0),
155 prev_key_state_(), 151 prev_key_state_(),
156 get_mic_volume_counter_ms_(0) { 152 get_mic_volume_counter_ms_(0) {
157 LOG(LS_INFO) << __FUNCTION__ << " created"; 153 LOG(LS_INFO) << __FUNCTION__ << " created";
158 154
159 RTC_DCHECK(&_stopEvent != NULL); 155 RTC_DCHECK(&_stopEvent != NULL);
160 RTC_DCHECK(&_stopEventRec != NULL); 156 RTC_DCHECK(&_stopEventRec != NULL);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 int intErr = sysctlbyname("hw.model", buf, &length, NULL, 0); 329 int intErr = sysctlbyname("hw.model", buf, &length, NULL, 0);
334 if (intErr != 0) { 330 if (intErr != 0) {
335 LOG(LS_ERROR) << "Error in sysctlbyname(): " << err; 331 LOG(LS_ERROR) << "Error in sysctlbyname(): " << err;
336 } else { 332 } else {
337 LOG(LS_VERBOSE) << "Hardware model: " << buf; 333 LOG(LS_VERBOSE) << "Hardware model: " << buf;
338 if (strncmp(buf, "MacBookPro", 10) == 0) { 334 if (strncmp(buf, "MacBookPro", 10) == 0) {
339 _macBookPro = true; 335 _macBookPro = true;
340 } 336 }
341 } 337 }
342 338
343 _playWarning = 0;
344 _playError = 0;
345 _recWarning = 0;
346 _recError = 0;
347
348 get_mic_volume_counter_ms_ = 0; 339 get_mic_volume_counter_ms_ = 0;
349 340
350 _initialized = true; 341 _initialized = true;
351 342
352 return InitStatus::OK; 343 return InitStatus::OK;
353 } 344 }
354 345
355 int32_t AudioDeviceMac::Terminate() { 346 int32_t AudioDeviceMac::Terminate() {
356 if (!_initialized) { 347 if (!_initialized) {
357 return 0; 348 return 0;
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 int32_t captureDelayUs = AtomicGet32(&_captureDelayUs); 1539 int32_t captureDelayUs = AtomicGet32(&_captureDelayUs);
1549 delayMS = 1540 delayMS =
1550 static_cast<uint16_t>(1e-3 * (captureDelayUs + _captureLatencyUs) + 0.5); 1541 static_cast<uint16_t>(1e-3 * (captureDelayUs + _captureLatencyUs) + 0.5);
1551 return 0; 1542 return 0;
1552 } 1543 }
1553 1544
1554 bool AudioDeviceMac::Playing() const { 1545 bool AudioDeviceMac::Playing() const {
1555 return (_playing); 1546 return (_playing);
1556 } 1547 }
1557 1548
1558 bool AudioDeviceMac::PlayoutWarning() const {
1559 return (_playWarning > 0);
1560 }
1561
1562 bool AudioDeviceMac::PlayoutError() const {
1563 return (_playError > 0);
1564 }
1565
1566 bool AudioDeviceMac::RecordingWarning() const {
1567 return (_recWarning > 0);
1568 }
1569
1570 bool AudioDeviceMac::RecordingError() const {
1571 return (_recError > 0);
1572 }
1573
1574 void AudioDeviceMac::ClearPlayoutWarning() {
1575 _playWarning = 0;
1576 }
1577
1578 void AudioDeviceMac::ClearPlayoutError() {
1579 _playError = 0;
1580 }
1581
1582 void AudioDeviceMac::ClearRecordingWarning() {
1583 _recWarning = 0;
1584 }
1585
1586 void AudioDeviceMac::ClearRecordingError() {
1587 _recError = 0;
1588 }
1589
1590 // ============================================================================ 1549 // ============================================================================
1591 // Private Methods 1550 // Private Methods
1592 // ============================================================================ 1551 // ============================================================================
1593 1552
1594 int32_t AudioDeviceMac::GetNumberDevices(const AudioObjectPropertyScope scope, 1553 int32_t AudioDeviceMac::GetNumberDevices(const AudioObjectPropertyScope scope,
1595 AudioDeviceID scopedDeviceIds[], 1554 AudioDeviceID scopedDeviceIds[],
1596 const uint32_t deviceListLength) { 1555 const uint32_t deviceListLength) {
1597 OSStatus err = noErr; 1556 OSStatus err = noErr;
1598 1557
1599 AudioObjectPropertyAddress propertyAddress = { 1558 AudioObjectPropertyAddress propertyAddress = {
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1992 kAudioDevicePropertyDeviceIsAlive, kAudioDevicePropertyScopeInput, 0}; 1951 kAudioDevicePropertyDeviceIsAlive, kAudioDevicePropertyScopeInput, 0};
1993 UInt32 deviceIsAlive = 1; 1952 UInt32 deviceIsAlive = 1;
1994 UInt32 size = sizeof(UInt32); 1953 UInt32 size = sizeof(UInt32);
1995 err = AudioObjectGetPropertyData(_inputDeviceID, &propertyAddress, 0, NULL, 1954 err = AudioObjectGetPropertyData(_inputDeviceID, &propertyAddress, 0, NULL,
1996 &size, &deviceIsAlive); 1955 &size, &deviceIsAlive);
1997 1956
1998 if (err == kAudioHardwareBadDeviceError || deviceIsAlive == 0) { 1957 if (err == kAudioHardwareBadDeviceError || deviceIsAlive == 0) {
1999 LOG(LS_WARNING) << "Capture device is not alive (probably removed)"; 1958 LOG(LS_WARNING) << "Capture device is not alive (probably removed)";
2000 AtomicSet32(&_captureDeviceIsAlive, 0); 1959 AtomicSet32(&_captureDeviceIsAlive, 0);
2001 _mixerManager.CloseMicrophone(); 1960 _mixerManager.CloseMicrophone();
2002 if (_recError == 1) {
2003 LOG(LS_WARNING) << "pending recording error exists";
2004 }
2005 _recError = 1; // triggers callback from module process thread
2006 } else if (err != noErr) { 1961 } else if (err != noErr) {
2007 logCAMsg(rtc::LS_ERROR, 1962 logCAMsg(rtc::LS_ERROR,
2008 "Error in AudioDeviceGetProperty()", (const char*)&err); 1963 "Error in AudioDeviceGetProperty()", (const char*)&err);
2009 return -1; 1964 return -1;
2010 } 1965 }
2011 } 1966 }
2012 1967
2013 if (SpeakerIsInitialized()) { 1968 if (SpeakerIsInitialized()) {
2014 AudioObjectPropertyAddress propertyAddress = { 1969 AudioObjectPropertyAddress propertyAddress = {
2015 kAudioDevicePropertyDeviceIsAlive, kAudioDevicePropertyScopeOutput, 0}; 1970 kAudioDevicePropertyDeviceIsAlive, kAudioDevicePropertyScopeOutput, 0};
2016 UInt32 deviceIsAlive = 1; 1971 UInt32 deviceIsAlive = 1;
2017 UInt32 size = sizeof(UInt32); 1972 UInt32 size = sizeof(UInt32);
2018 err = AudioObjectGetPropertyData(_outputDeviceID, &propertyAddress, 0, NULL, 1973 err = AudioObjectGetPropertyData(_outputDeviceID, &propertyAddress, 0, NULL,
2019 &size, &deviceIsAlive); 1974 &size, &deviceIsAlive);
2020 1975
2021 if (err == kAudioHardwareBadDeviceError || deviceIsAlive == 0) { 1976 if (err == kAudioHardwareBadDeviceError || deviceIsAlive == 0) {
2022 LOG(LS_WARNING) << "Render device is not alive (probably removed)"; 1977 LOG(LS_WARNING) << "Render device is not alive (probably removed)";
2023 AtomicSet32(&_renderDeviceIsAlive, 0); 1978 AtomicSet32(&_renderDeviceIsAlive, 0);
2024 _mixerManager.CloseSpeaker(); 1979 _mixerManager.CloseSpeaker();
2025 if (_playError == 1) {
2026 LOG(LS_WARNING) << "pending playout error exists";
2027 }
2028 _playError = 1; // triggers callback from module process thread
2029 } else if (err != noErr) { 1980 } else if (err != noErr) {
2030 logCAMsg(rtc::LS_ERROR, 1981 logCAMsg(rtc::LS_ERROR,
2031 "Error in AudioDeviceGetProperty()", (const char*)&err); 1982 "Error in AudioDeviceGetProperty()", (const char*)&err);
2032 return -1; 1983 return -1;
2033 } 1984 }
2034 } 1985 }
2035 1986
2036 return 0; 1987 return 0;
2037 } 1988 }
2038 1989
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
2602 bool keyState = 2553 bool keyState =
2603 CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, key_index); 2554 CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, key_index);
2604 // A false -> true change in keymap means a key is pressed. 2555 // A false -> true change in keymap means a key is pressed.
2605 key_down |= (keyState && !prev_key_state_[key_index]); 2556 key_down |= (keyState && !prev_key_state_[key_index]);
2606 // Save current state. 2557 // Save current state.
2607 prev_key_state_[key_index] = keyState; 2558 prev_key_state_[key_index] = keyState;
2608 } 2559 }
2609 return key_down; 2560 return key_down;
2610 } 2561 }
2611 } // namespace webrtc 2562 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698