xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 1 | /* |
leozwang@webrtc.org | 28f3913 | 2012-03-01 18:01:48 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef AUDIO_DEVICE_AUDIO_DEVICE_MAC_H_ |
| 12 | #define AUDIO_DEVICE_AUDIO_DEVICE_MAC_H_ |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 13 | |
kwiberg | f01633e | 2016-02-24 05:00:36 -0800 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "modules/audio_device/audio_device_generic.h" |
| 17 | #include "modules/audio_device/mac/audio_mixer_manager_mac.h" |
| 18 | #include "rtc_base/criticalsection.h" |
| 19 | #include "rtc_base/logging.h" |
| 20 | #include "rtc_base/thread_annotations.h" |
| 21 | #include "system_wrappers/include/event_wrapper.h" |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 22 | |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 23 | #include <AudioToolbox/AudioConverter.h> |
pbos@webrtc.org | 811269d | 2013-07-11 13:24:38 +0000 | [diff] [blame] | 24 | #include <CoreAudio/CoreAudio.h> |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 25 | #include <mach/semaphore.h> |
| 26 | |
| 27 | struct PaUtilRingBuffer; |
| 28 | |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 29 | namespace rtc { |
| 30 | class PlatformThread; |
| 31 | } // namespace rtc |
| 32 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 33 | namespace webrtc { |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 34 | class EventWrapper; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 35 | |
andrew@webrtc.org | 569fdef | 2013-06-08 00:43:25 +0000 | [diff] [blame] | 36 | const uint32_t N_REC_SAMPLES_PER_SEC = 48000; |
| 37 | const uint32_t N_PLAY_SAMPLES_PER_SEC = 48000; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 38 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 39 | const uint32_t N_REC_CHANNELS = 1; // default is mono recording |
| 40 | const uint32_t N_PLAY_CHANNELS = 2; // default is stereo playout |
andrew@webrtc.org | 569fdef | 2013-06-08 00:43:25 +0000 | [diff] [blame] | 41 | const uint32_t N_DEVICE_CHANNELS = 64; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 42 | |
andrew | ec80f03 | 2016-01-08 01:16:17 -0800 | [diff] [blame] | 43 | const int kBufferSizeMs = 10; |
| 44 | |
| 45 | const uint32_t ENGINE_REC_BUF_SIZE_IN_SAMPLES = |
| 46 | N_REC_SAMPLES_PER_SEC * kBufferSizeMs / 1000; |
| 47 | const uint32_t ENGINE_PLAY_BUF_SIZE_IN_SAMPLES = |
| 48 | N_PLAY_SAMPLES_PER_SEC * kBufferSizeMs / 1000; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 49 | |
andrew@webrtc.org | 6f69eb7 | 2013-06-07 17:56:50 +0000 | [diff] [blame] | 50 | const int N_BLOCKS_IO = 2; |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 51 | const int N_BUFFERS_IN = 2; // Must be at least N_BLOCKS_IO. |
andrew@webrtc.org | 6f69eb7 | 2013-06-07 17:56:50 +0000 | [diff] [blame] | 52 | const int N_BUFFERS_OUT = 3; // Must be at least N_BLOCKS_IO. |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 53 | |
andrew | ec80f03 | 2016-01-08 01:16:17 -0800 | [diff] [blame] | 54 | const uint32_t TIMER_PERIOD_MS = 2 * 10 * N_BLOCKS_IO * 1000000; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 55 | |
andrew@webrtc.org | 569fdef | 2013-06-08 00:43:25 +0000 | [diff] [blame] | 56 | const uint32_t REC_BUF_SIZE_IN_SAMPLES = |
andrew@webrtc.org | 6f69eb7 | 2013-06-07 17:56:50 +0000 | [diff] [blame] | 57 | ENGINE_REC_BUF_SIZE_IN_SAMPLES * N_DEVICE_CHANNELS * N_BUFFERS_IN; |
andrew@webrtc.org | 569fdef | 2013-06-08 00:43:25 +0000 | [diff] [blame] | 58 | const uint32_t PLAY_BUF_SIZE_IN_SAMPLES = |
andrew@webrtc.org | 6f69eb7 | 2013-06-07 17:56:50 +0000 | [diff] [blame] | 59 | ENGINE_PLAY_BUF_SIZE_IN_SAMPLES * N_PLAY_CHANNELS * N_BUFFERS_OUT; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 60 | |
andrew | ec80f03 | 2016-01-08 01:16:17 -0800 | [diff] [blame] | 61 | const int kGetMicVolumeIntervalMs = 1000; |
| 62 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 63 | class AudioDeviceMac : public AudioDeviceGeneric { |
| 64 | public: |
saza | b4aa4eb | 2017-07-19 01:12:36 -0700 | [diff] [blame] | 65 | AudioDeviceMac(); |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 66 | ~AudioDeviceMac(); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 67 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 68 | // Retrieve the currently utilized audio layer |
| 69 | virtual int32_t ActiveAudioLayer( |
| 70 | AudioDeviceModule::AudioLayer& audioLayer) const; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 71 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 72 | // Main initializaton and termination |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 73 | virtual InitStatus Init(); |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 74 | virtual int32_t Terminate(); |
| 75 | virtual bool Initialized() const; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 76 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 77 | // Device enumeration |
| 78 | virtual int16_t PlayoutDevices(); |
| 79 | virtual int16_t RecordingDevices(); |
| 80 | virtual int32_t PlayoutDeviceName(uint16_t index, |
| 81 | char name[kAdmMaxDeviceNameSize], |
| 82 | char guid[kAdmMaxGuidSize]); |
| 83 | virtual int32_t RecordingDeviceName(uint16_t index, |
| 84 | char name[kAdmMaxDeviceNameSize], |
| 85 | char guid[kAdmMaxGuidSize]); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 86 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 87 | // Device selection |
| 88 | virtual int32_t SetPlayoutDevice(uint16_t index); |
| 89 | virtual int32_t SetPlayoutDevice(AudioDeviceModule::WindowsDeviceType device); |
| 90 | virtual int32_t SetRecordingDevice(uint16_t index); |
| 91 | virtual int32_t SetRecordingDevice( |
| 92 | AudioDeviceModule::WindowsDeviceType device); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 93 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 94 | // Audio transport initialization |
| 95 | virtual int32_t PlayoutIsAvailable(bool& available); |
| 96 | virtual int32_t InitPlayout(); |
| 97 | virtual bool PlayoutIsInitialized() const; |
| 98 | virtual int32_t RecordingIsAvailable(bool& available); |
| 99 | virtual int32_t InitRecording(); |
| 100 | virtual bool RecordingIsInitialized() const; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 101 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 102 | // Audio transport control |
| 103 | virtual int32_t StartPlayout(); |
| 104 | virtual int32_t StopPlayout(); |
| 105 | virtual bool Playing() const; |
| 106 | virtual int32_t StartRecording(); |
| 107 | virtual int32_t StopRecording(); |
| 108 | virtual bool Recording() const; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 109 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 110 | // Microphone Automatic Gain Control (AGC) |
| 111 | virtual int32_t SetAGC(bool enable); |
| 112 | virtual bool AGC() const; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 113 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 114 | // Audio mixer initialization |
| 115 | virtual int32_t InitSpeaker(); |
| 116 | virtual bool SpeakerIsInitialized() const; |
| 117 | virtual int32_t InitMicrophone(); |
| 118 | virtual bool MicrophoneIsInitialized() const; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 119 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 120 | // Speaker volume controls |
| 121 | virtual int32_t SpeakerVolumeIsAvailable(bool& available); |
| 122 | virtual int32_t SetSpeakerVolume(uint32_t volume); |
| 123 | virtual int32_t SpeakerVolume(uint32_t& volume) const; |
| 124 | virtual int32_t MaxSpeakerVolume(uint32_t& maxVolume) const; |
| 125 | virtual int32_t MinSpeakerVolume(uint32_t& minVolume) const; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 126 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 127 | // Microphone volume controls |
| 128 | virtual int32_t MicrophoneVolumeIsAvailable(bool& available); |
| 129 | virtual int32_t SetMicrophoneVolume(uint32_t volume); |
| 130 | virtual int32_t MicrophoneVolume(uint32_t& volume) const; |
| 131 | virtual int32_t MaxMicrophoneVolume(uint32_t& maxVolume) const; |
| 132 | virtual int32_t MinMicrophoneVolume(uint32_t& minVolume) const; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 133 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 134 | // Microphone mute control |
| 135 | virtual int32_t MicrophoneMuteIsAvailable(bool& available); |
| 136 | virtual int32_t SetMicrophoneMute(bool enable); |
| 137 | virtual int32_t MicrophoneMute(bool& enabled) const; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 138 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 139 | // Speaker mute control |
| 140 | virtual int32_t SpeakerMuteIsAvailable(bool& available); |
| 141 | virtual int32_t SetSpeakerMute(bool enable); |
| 142 | virtual int32_t SpeakerMute(bool& enabled) const; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 143 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 144 | // Stereo support |
| 145 | virtual int32_t StereoPlayoutIsAvailable(bool& available); |
| 146 | virtual int32_t SetStereoPlayout(bool enable); |
| 147 | virtual int32_t StereoPlayout(bool& enabled) const; |
| 148 | virtual int32_t StereoRecordingIsAvailable(bool& available); |
| 149 | virtual int32_t SetStereoRecording(bool enable); |
| 150 | virtual int32_t StereoRecording(bool& enabled) const; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 151 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 152 | // Delay information and control |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 153 | virtual int32_t PlayoutDelay(uint16_t& delayMS) const; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 154 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 155 | virtual void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 156 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 157 | private: |
| 158 | virtual int32_t MicrophoneIsAvailable(bool& available); |
| 159 | virtual int32_t SpeakerIsAvailable(bool& available); |
andrew@webrtc.org | c7c432a | 2014-04-02 16:49:26 +0000 | [diff] [blame] | 160 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 161 | static void AtomicSet32(int32_t* theValue, int32_t newValue); |
| 162 | static int32_t AtomicGet32(int32_t* theValue); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 163 | |
saza | b4aa4eb | 2017-07-19 01:12:36 -0700 | [diff] [blame] | 164 | static void logCAMsg(const rtc::LoggingSeverity sev, |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 165 | const char* msg, |
| 166 | const char* err); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 167 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 168 | int32_t GetNumberDevices(const AudioObjectPropertyScope scope, |
| 169 | AudioDeviceID scopedDeviceIds[], |
| 170 | const uint32_t deviceListLength); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 171 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 172 | int32_t GetDeviceName(const AudioObjectPropertyScope scope, |
| 173 | const uint16_t index, |
| 174 | char* name); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 175 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 176 | int32_t InitDevice(uint16_t userDeviceIndex, |
| 177 | AudioDeviceID& deviceId, |
| 178 | bool isInput); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 179 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 180 | // Always work with our preferred playout format inside VoE. |
| 181 | // Then convert the output to the OS setting using an AudioConverter. |
| 182 | OSStatus SetDesiredPlayoutFormat(); |
braveyao@webrtc.org | 346a64b | 2015-03-21 01:05:56 +0000 | [diff] [blame] | 183 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 184 | static OSStatus objectListenerProc( |
| 185 | AudioObjectID objectId, |
| 186 | UInt32 numberAddresses, |
| 187 | const AudioObjectPropertyAddress addresses[], |
| 188 | void* clientData); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 189 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 190 | OSStatus implObjectListenerProc(AudioObjectID objectId, |
| 191 | UInt32 numberAddresses, |
| 192 | const AudioObjectPropertyAddress addresses[]); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 193 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 194 | int32_t HandleDeviceChange(); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 195 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 196 | int32_t HandleStreamFormatChange(AudioObjectID objectId, |
| 197 | AudioObjectPropertyAddress propertyAddress); |
| 198 | |
| 199 | int32_t HandleDataSourceChange(AudioObjectID objectId, |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 200 | AudioObjectPropertyAddress propertyAddress); |
| 201 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 202 | int32_t HandleProcessorOverload(AudioObjectPropertyAddress propertyAddress); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 203 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 204 | static OSStatus deviceIOProc(AudioDeviceID device, |
| 205 | const AudioTimeStamp* now, |
| 206 | const AudioBufferList* inputData, |
| 207 | const AudioTimeStamp* inputTime, |
| 208 | AudioBufferList* outputData, |
| 209 | const AudioTimeStamp* outputTime, |
| 210 | void* clientData); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 211 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 212 | static OSStatus outConverterProc( |
| 213 | AudioConverterRef audioConverter, |
| 214 | UInt32* numberDataPackets, |
| 215 | AudioBufferList* data, |
| 216 | AudioStreamPacketDescription** dataPacketDescription, |
| 217 | void* userData); |
| 218 | |
| 219 | static OSStatus inDeviceIOProc(AudioDeviceID device, |
| 220 | const AudioTimeStamp* now, |
| 221 | const AudioBufferList* inputData, |
| 222 | const AudioTimeStamp* inputTime, |
| 223 | AudioBufferList* outputData, |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 224 | const AudioTimeStamp* outputTime, |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 225 | void* clientData); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 226 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 227 | static OSStatus inConverterProc( |
| 228 | AudioConverterRef audioConverter, |
| 229 | UInt32* numberDataPackets, |
| 230 | AudioBufferList* data, |
| 231 | AudioStreamPacketDescription** dataPacketDescription, |
| 232 | void* inUserData); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 233 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 234 | OSStatus implDeviceIOProc(const AudioBufferList* inputData, |
| 235 | const AudioTimeStamp* inputTime, |
| 236 | AudioBufferList* outputData, |
| 237 | const AudioTimeStamp* outputTime); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 238 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 239 | OSStatus implOutConverterProc(UInt32* numberDataPackets, |
| 240 | AudioBufferList* data); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 241 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 242 | OSStatus implInDeviceIOProc(const AudioBufferList* inputData, |
| 243 | const AudioTimeStamp* inputTime); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 244 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 245 | OSStatus implInConverterProc(UInt32* numberDataPackets, |
| 246 | AudioBufferList* data); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 247 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 248 | static bool RunCapture(void*); |
| 249 | static bool RunRender(void*); |
| 250 | bool CaptureWorkerThread(); |
| 251 | bool RenderWorkerThread(); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 252 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 253 | bool KeyPressed(); |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 254 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 255 | AudioDeviceBuffer* _ptrAudioBuffer; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 256 | |
kthelgason | ff046c7 | 2017-03-31 02:03:55 -0700 | [diff] [blame] | 257 | rtc::CriticalSection _critSect; |
niklas.enbom@webrtc.org | 3be565b | 2013-05-07 21:04:24 +0000 | [diff] [blame] | 258 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 259 | EventWrapper& _stopEventRec; |
| 260 | EventWrapper& _stopEvent; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 261 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 262 | // TODO(pbos): Replace with direct members, just start/stop, no need to |
| 263 | // recreate the thread. |
| 264 | // Only valid/running between calls to StartRecording and StopRecording. |
kwiberg | f01633e | 2016-02-24 05:00:36 -0800 | [diff] [blame] | 265 | std::unique_ptr<rtc::PlatformThread> capture_worker_thread_; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 266 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 267 | // Only valid/running between calls to StartPlayout and StopPlayout. |
kwiberg | f01633e | 2016-02-24 05:00:36 -0800 | [diff] [blame] | 268 | std::unique_ptr<rtc::PlatformThread> render_worker_thread_; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 269 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 270 | AudioMixerManagerMac _mixerManager; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 271 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 272 | uint16_t _inputDeviceIndex; |
| 273 | uint16_t _outputDeviceIndex; |
| 274 | AudioDeviceID _inputDeviceID; |
| 275 | AudioDeviceID _outputDeviceID; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 276 | #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 277 | AudioDeviceIOProcID _inDeviceIOProcID; |
| 278 | AudioDeviceIOProcID _deviceIOProcID; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 279 | #endif |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 280 | bool _inputDeviceIsSpecified; |
| 281 | bool _outputDeviceIsSpecified; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 282 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 283 | uint8_t _recChannels; |
| 284 | uint8_t _playChannels; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 285 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 286 | Float32* _captureBufData; |
| 287 | SInt16* _renderBufData; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 288 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 289 | SInt16 _renderConvertData[PLAY_BUF_SIZE_IN_SAMPLES]; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 290 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 291 | bool _initialized; |
| 292 | bool _isShutDown; |
| 293 | bool _recording; |
| 294 | bool _playing; |
| 295 | bool _recIsInitialized; |
| 296 | bool _playIsInitialized; |
| 297 | bool _AGC; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 298 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 299 | // Atomically set varaibles |
| 300 | int32_t _renderDeviceIsAlive; |
| 301 | int32_t _captureDeviceIsAlive; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 302 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 303 | bool _twoDevices; |
| 304 | bool _doStop; // For play if not shared device or play+rec if shared device |
| 305 | bool _doStopRec; // For rec if not shared device |
| 306 | bool _macBookPro; |
| 307 | bool _macBookProPanRight; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 308 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 309 | AudioConverterRef _captureConverter; |
| 310 | AudioConverterRef _renderConverter; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 311 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 312 | AudioStreamBasicDescription _outStreamFormat; |
| 313 | AudioStreamBasicDescription _outDesiredFormat; |
| 314 | AudioStreamBasicDescription _inStreamFormat; |
| 315 | AudioStreamBasicDescription _inDesiredFormat; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 316 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 317 | uint32_t _captureLatencyUs; |
| 318 | uint32_t _renderLatencyUs; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 319 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 320 | // Atomically set variables |
| 321 | mutable int32_t _captureDelayUs; |
| 322 | mutable int32_t _renderDelayUs; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 323 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 324 | int32_t _renderDelayOffsetSamples; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 325 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 326 | PaUtilRingBuffer* _paCaptureBuffer; |
| 327 | PaUtilRingBuffer* _paRenderBuffer; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 328 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 329 | semaphore_t _renderSemaphore; |
| 330 | semaphore_t _captureSemaphore; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 331 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 332 | int _captureBufSizeSamples; |
| 333 | int _renderBufSizeSamples; |
niklas.enbom@webrtc.org | cc9238e | 2013-08-15 14:19:12 +0000 | [diff] [blame] | 334 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 335 | // Typing detection |
| 336 | // 0x5c is key "9", after that comes function keys. |
| 337 | bool prev_key_state_[0x5d]; |
andrew | ec80f03 | 2016-01-08 01:16:17 -0800 | [diff] [blame] | 338 | |
andrew | 2bc63a1 | 2016-01-11 15:59:17 -0800 | [diff] [blame] | 339 | int get_mic_volume_counter_ms_; |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 340 | }; |
| 341 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 342 | } // namespace webrtc |
xians@google.com | 68efa21 | 2011-08-11 12:41:56 +0000 | [diff] [blame] | 343 | |
| 344 | #endif // MODULES_AUDIO_DEVICE_MAIN_SOURCE_MAC_AUDIO_DEVICE_MAC_H_ |