| 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 "webrtc/modules/audio_device/mac/audio_mixer_manager_mac.h" | 11 #include "webrtc/modules/audio_device/mac/audio_mixer_manager_mac.h" |
| 12 #include "webrtc/system_wrappers/include/trace.h" | |
| 13 | 12 |
| 14 #include <unistd.h> // getpid() | 13 #include <unistd.h> // getpid() |
| 15 | 14 |
| 16 namespace webrtc { | 15 namespace webrtc { |
| 17 | 16 |
| 18 #define WEBRTC_CA_RETURN_ON_ERR(expr) \ | 17 #define WEBRTC_CA_RETURN_ON_ERR(expr) \ |
| 19 do { \ | 18 do { \ |
| 20 err = expr; \ | 19 err = expr; \ |
| 21 if (err != noErr) { \ | 20 if (err != noErr) { \ |
| 22 logCAMsg(kTraceError, kTraceAudioDevice, _id, "Error in " #expr, \ | 21 logCAMsg(kTraceError, kTraceAudioDevice, _id, "Error in " #expr, \ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 37 #define WEBRTC_CA_LOG_WARN(expr) \ | 36 #define WEBRTC_CA_LOG_WARN(expr) \ |
| 38 do { \ | 37 do { \ |
| 39 err = expr; \ | 38 err = expr; \ |
| 40 if (err != noErr) { \ | 39 if (err != noErr) { \ |
| 41 logCAMsg(kTraceWarning, kTraceAudioDevice, _id, "Error in " #expr, \ | 40 logCAMsg(kTraceWarning, kTraceAudioDevice, _id, "Error in " #expr, \ |
| 42 (const char*) & err); \ | 41 (const char*) & err); \ |
| 43 } \ | 42 } \ |
| 44 } while (0) | 43 } while (0) |
| 45 | 44 |
| 46 AudioMixerManagerMac::AudioMixerManagerMac(const int32_t id) | 45 AudioMixerManagerMac::AudioMixerManagerMac(const int32_t id) |
| 47 : _critSect(*CriticalSectionWrapper::CreateCriticalSection()), | 46 : _id(id), |
| 48 _id(id), | |
| 49 _inputDeviceID(kAudioObjectUnknown), | 47 _inputDeviceID(kAudioObjectUnknown), |
| 50 _outputDeviceID(kAudioObjectUnknown), | 48 _outputDeviceID(kAudioObjectUnknown), |
| 51 _noInputChannels(0), | 49 _noInputChannels(0), |
| 52 _noOutputChannels(0) { | 50 _noOutputChannels(0) { |
| 53 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s constructed", | 51 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s constructed", |
| 54 __FUNCTION__); | 52 __FUNCTION__); |
| 55 } | 53 } |
| 56 | 54 |
| 57 AudioMixerManagerMac::~AudioMixerManagerMac() { | 55 AudioMixerManagerMac::~AudioMixerManagerMac() { |
| 58 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destructed", | 56 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s destructed", |
| 59 __FUNCTION__); | 57 __FUNCTION__); |
| 60 | |
| 61 Close(); | 58 Close(); |
| 62 | |
| 63 delete &_critSect; | |
| 64 } | 59 } |
| 65 | 60 |
| 66 // ============================================================================ | 61 // ============================================================================ |
| 67 // PUBLIC METHODS | 62 // PUBLIC METHODS |
| 68 // ============================================================================ | 63 // ============================================================================ |
| 69 | 64 |
| 70 int32_t AudioMixerManagerMac::Close() { | 65 int32_t AudioMixerManagerMac::Close() { |
| 71 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__); | 66 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__); |
| 72 | 67 |
| 73 CriticalSectionScoped lock(&_critSect); | 68 rtc::CritScope lock(&_critSect); |
| 74 | 69 |
| 75 CloseSpeaker(); | 70 CloseSpeaker(); |
| 76 CloseMicrophone(); | 71 CloseMicrophone(); |
| 77 | 72 |
| 78 return 0; | 73 return 0; |
| 79 } | 74 } |
| 80 | 75 |
| 81 int32_t AudioMixerManagerMac::CloseSpeaker() { | 76 int32_t AudioMixerManagerMac::CloseSpeaker() { |
| 82 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__); | 77 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__); |
| 83 | 78 |
| 84 CriticalSectionScoped lock(&_critSect); | 79 rtc::CritScope lock(&_critSect); |
| 85 | 80 |
| 86 _outputDeviceID = kAudioObjectUnknown; | 81 _outputDeviceID = kAudioObjectUnknown; |
| 87 _noOutputChannels = 0; | 82 _noOutputChannels = 0; |
| 88 | 83 |
| 89 return 0; | 84 return 0; |
| 90 } | 85 } |
| 91 | 86 |
| 92 int32_t AudioMixerManagerMac::CloseMicrophone() { | 87 int32_t AudioMixerManagerMac::CloseMicrophone() { |
| 93 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__); | 88 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, "%s", __FUNCTION__); |
| 94 | 89 |
| 95 CriticalSectionScoped lock(&_critSect); | 90 rtc::CritScope lock(&_critSect); |
| 96 | 91 |
| 97 _inputDeviceID = kAudioObjectUnknown; | 92 _inputDeviceID = kAudioObjectUnknown; |
| 98 _noInputChannels = 0; | 93 _noInputChannels = 0; |
| 99 | 94 |
| 100 return 0; | 95 return 0; |
| 101 } | 96 } |
| 102 | 97 |
| 103 int32_t AudioMixerManagerMac::OpenSpeaker(AudioDeviceID deviceID) { | 98 int32_t AudioMixerManagerMac::OpenSpeaker(AudioDeviceID deviceID) { |
| 104 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 99 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 105 "AudioMixerManagerMac::OpenSpeaker(id=%d)", deviceID); | 100 "AudioMixerManagerMac::OpenSpeaker(id=%d)", deviceID); |
| 106 | 101 |
| 107 CriticalSectionScoped lock(&_critSect); | 102 rtc::CritScope lock(&_critSect); |
| 108 | 103 |
| 109 OSStatus err = noErr; | 104 OSStatus err = noErr; |
| 110 UInt32 size = 0; | 105 UInt32 size = 0; |
| 111 pid_t hogPid = -1; | 106 pid_t hogPid = -1; |
| 112 | 107 |
| 113 _outputDeviceID = deviceID; | 108 _outputDeviceID = deviceID; |
| 114 | 109 |
| 115 // Check which process, if any, has hogged the device. | 110 // Check which process, if any, has hogged the device. |
| 116 AudioObjectPropertyAddress propertyAddress = { | 111 AudioObjectPropertyAddress propertyAddress = { |
| 117 kAudioDevicePropertyHogMode, kAudioDevicePropertyScopeOutput, 0}; | 112 kAudioDevicePropertyHogMode, kAudioDevicePropertyScopeOutput, 0}; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 148 | 143 |
| 149 _noOutputChannels = streamFormat.mChannelsPerFrame; | 144 _noOutputChannels = streamFormat.mChannelsPerFrame; |
| 150 | 145 |
| 151 return 0; | 146 return 0; |
| 152 } | 147 } |
| 153 | 148 |
| 154 int32_t AudioMixerManagerMac::OpenMicrophone(AudioDeviceID deviceID) { | 149 int32_t AudioMixerManagerMac::OpenMicrophone(AudioDeviceID deviceID) { |
| 155 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 150 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 156 "AudioMixerManagerMac::OpenMicrophone(id=%d)", deviceID); | 151 "AudioMixerManagerMac::OpenMicrophone(id=%d)", deviceID); |
| 157 | 152 |
| 158 CriticalSectionScoped lock(&_critSect); | 153 rtc::CritScope lock(&_critSect); |
| 159 | 154 |
| 160 OSStatus err = noErr; | 155 OSStatus err = noErr; |
| 161 UInt32 size = 0; | 156 UInt32 size = 0; |
| 162 pid_t hogPid = -1; | 157 pid_t hogPid = -1; |
| 163 | 158 |
| 164 _inputDeviceID = deviceID; | 159 _inputDeviceID = deviceID; |
| 165 | 160 |
| 166 // Check which process, if any, has hogged the device. | 161 // Check which process, if any, has hogged the device. |
| 167 AudioObjectPropertyAddress propertyAddress = { | 162 AudioObjectPropertyAddress propertyAddress = { |
| 168 kAudioDevicePropertyHogMode, kAudioDevicePropertyScopeInput, 0}; | 163 kAudioDevicePropertyHogMode, kAudioDevicePropertyScopeInput, 0}; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 bool AudioMixerManagerMac::MicrophoneIsInitialized() const { | 204 bool AudioMixerManagerMac::MicrophoneIsInitialized() const { |
| 210 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__); | 205 WEBRTC_TRACE(kTraceMemory, kTraceAudioDevice, _id, "%s", __FUNCTION__); |
| 211 | 206 |
| 212 return (_inputDeviceID != kAudioObjectUnknown); | 207 return (_inputDeviceID != kAudioObjectUnknown); |
| 213 } | 208 } |
| 214 | 209 |
| 215 int32_t AudioMixerManagerMac::SetSpeakerVolume(uint32_t volume) { | 210 int32_t AudioMixerManagerMac::SetSpeakerVolume(uint32_t volume) { |
| 216 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 211 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 217 "AudioMixerManagerMac::SetSpeakerVolume(volume=%u)", volume); | 212 "AudioMixerManagerMac::SetSpeakerVolume(volume=%u)", volume); |
| 218 | 213 |
| 219 CriticalSectionScoped lock(&_critSect); | 214 rtc::CritScope lock(&_critSect); |
| 220 | 215 |
| 221 if (_outputDeviceID == kAudioObjectUnknown) { | 216 if (_outputDeviceID == kAudioObjectUnknown) { |
| 222 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 217 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 223 " device ID has not been set"); | 218 " device ID has not been set"); |
| 224 return -1; | 219 return -1; |
| 225 } | 220 } |
| 226 | 221 |
| 227 OSStatus err = noErr; | 222 OSStatus err = noErr; |
| 228 UInt32 size = 0; | 223 UInt32 size = 0; |
| 229 bool success = false; | 224 bool success = false; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 } | 444 } |
| 450 | 445 |
| 451 available = true; | 446 available = true; |
| 452 return 0; | 447 return 0; |
| 453 } | 448 } |
| 454 | 449 |
| 455 int32_t AudioMixerManagerMac::SetSpeakerMute(bool enable) { | 450 int32_t AudioMixerManagerMac::SetSpeakerMute(bool enable) { |
| 456 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 451 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 457 "AudioMixerManagerMac::SetSpeakerMute(enable=%u)", enable); | 452 "AudioMixerManagerMac::SetSpeakerMute(enable=%u)", enable); |
| 458 | 453 |
| 459 CriticalSectionScoped lock(&_critSect); | 454 rtc::CritScope lock(&_critSect); |
| 460 | 455 |
| 461 if (_outputDeviceID == kAudioObjectUnknown) { | 456 if (_outputDeviceID == kAudioObjectUnknown) { |
| 462 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 457 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 463 " device ID has not been set"); | 458 " device ID has not been set"); |
| 464 return -1; | 459 return -1; |
| 465 } | 460 } |
| 466 | 461 |
| 467 OSStatus err = noErr; | 462 OSStatus err = noErr; |
| 468 UInt32 size = 0; | 463 UInt32 size = 0; |
| 469 UInt32 mute = enable ? 1 : 0; | 464 UInt32 mute = enable ? 1 : 0; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 } | 620 } |
| 626 | 621 |
| 627 available = true; | 622 available = true; |
| 628 return 0; | 623 return 0; |
| 629 } | 624 } |
| 630 | 625 |
| 631 int32_t AudioMixerManagerMac::SetMicrophoneMute(bool enable) { | 626 int32_t AudioMixerManagerMac::SetMicrophoneMute(bool enable) { |
| 632 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 627 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 633 "AudioMixerManagerMac::SetMicrophoneMute(enable=%u)", enable); | 628 "AudioMixerManagerMac::SetMicrophoneMute(enable=%u)", enable); |
| 634 | 629 |
| 635 CriticalSectionScoped lock(&_critSect); | 630 rtc::CritScope lock(&_critSect); |
| 636 | 631 |
| 637 if (_inputDeviceID == kAudioObjectUnknown) { | 632 if (_inputDeviceID == kAudioObjectUnknown) { |
| 638 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 633 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 639 " device ID has not been set"); | 634 " device ID has not been set"); |
| 640 return -1; | 635 return -1; |
| 641 } | 636 } |
| 642 | 637 |
| 643 OSStatus err = noErr; | 638 OSStatus err = noErr; |
| 644 UInt32 size = 0; | 639 UInt32 size = 0; |
| 645 UInt32 mute = enable ? 1 : 0; | 640 UInt32 mute = enable ? 1 : 0; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 | 747 |
| 753 available = false; // No AudioObjectPropertySelector value for Mic Boost | 748 available = false; // No AudioObjectPropertySelector value for Mic Boost |
| 754 | 749 |
| 755 return 0; | 750 return 0; |
| 756 } | 751 } |
| 757 | 752 |
| 758 int32_t AudioMixerManagerMac::SetMicrophoneBoost(bool enable) { | 753 int32_t AudioMixerManagerMac::SetMicrophoneBoost(bool enable) { |
| 759 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 754 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 760 "AudioMixerManagerMac::SetMicrophoneBoost(enable=%u)", enable); | 755 "AudioMixerManagerMac::SetMicrophoneBoost(enable=%u)", enable); |
| 761 | 756 |
| 762 CriticalSectionScoped lock(&_critSect); | 757 rtc::CritScope lock(&_critSect); |
| 763 | 758 |
| 764 if (_inputDeviceID == kAudioObjectUnknown) { | 759 if (_inputDeviceID == kAudioObjectUnknown) { |
| 765 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 760 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 766 " device ID has not been set"); | 761 " device ID has not been set"); |
| 767 return -1; | 762 return -1; |
| 768 } | 763 } |
| 769 | 764 |
| 770 // Ensure that the selected microphone has a valid boost control. | 765 // Ensure that the selected microphone has a valid boost control. |
| 771 bool available(false); | 766 bool available(false); |
| 772 MicrophoneBoostIsAvailable(available); | 767 MicrophoneBoostIsAvailable(available); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 } | 825 } |
| 831 | 826 |
| 832 available = true; | 827 available = true; |
| 833 return 0; | 828 return 0; |
| 834 } | 829 } |
| 835 | 830 |
| 836 int32_t AudioMixerManagerMac::SetMicrophoneVolume(uint32_t volume) { | 831 int32_t AudioMixerManagerMac::SetMicrophoneVolume(uint32_t volume) { |
| 837 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, | 832 WEBRTC_TRACE(kTraceInfo, kTraceAudioDevice, _id, |
| 838 "AudioMixerManagerMac::SetMicrophoneVolume(volume=%u)", volume); | 833 "AudioMixerManagerMac::SetMicrophoneVolume(volume=%u)", volume); |
| 839 | 834 |
| 840 CriticalSectionScoped lock(&_critSect); | 835 rtc::CritScope lock(&_critSect); |
| 841 | 836 |
| 842 if (_inputDeviceID == kAudioObjectUnknown) { | 837 if (_inputDeviceID == kAudioObjectUnknown) { |
| 843 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, | 838 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, _id, |
| 844 " device ID has not been set"); | 839 " device ID has not been set"); |
| 845 return -1; | 840 return -1; |
| 846 } | 841 } |
| 847 | 842 |
| 848 OSStatus err = noErr; | 843 OSStatus err = noErr; |
| 849 UInt32 size = 0; | 844 UInt32 size = 0; |
| 850 bool success = false; | 845 bool success = false; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 WEBRTC_TRACE(level, module, id, "%s: %.4s", msg, err); | 1008 WEBRTC_TRACE(level, module, id, "%s: %.4s", msg, err); |
| 1014 #else | 1009 #else |
| 1015 // We need to flip the characters in this case. | 1010 // We need to flip the characters in this case. |
| 1016 WEBRTC_TRACE(level, module, id, "%s: %.1s%.1s%.1s%.1s", msg, err + 3, err + 2, | 1011 WEBRTC_TRACE(level, module, id, "%s: %.1s%.1s%.1s%.1s", msg, err + 3, err + 2, |
| 1017 err + 1, err); | 1012 err + 1, err); |
| 1018 #endif | 1013 #endif |
| 1019 } | 1014 } |
| 1020 | 1015 |
| 1021 } // namespace webrtc | 1016 } // namespace webrtc |
| 1022 // EOF | 1017 // EOF |
| OLD | NEW |