andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 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 | |
| 11 | #ifndef WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_MAC_H |
| 12 | #define WEBRTC_AUDIO_DEVICE_AUDIO_DEVICE_MAC_H |
| 13 | |
kwiberg | c0677bd | 2016-02-24 13:00:36 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
pbos@webrtc.org | bc669ac | 2013-07-11 13:24:38 | [diff] [blame] | 16 | #include "webrtc/modules/audio_device/audio_device_generic.h" |
| 17 | #include "webrtc/modules/audio_device/mac/audio_mixer_manager_mac.h" |
Edward Lemur | 76de83e | 2017-07-06 17:44:34 | [diff] [blame] | 18 | #include "webrtc/rtc_base/criticalsection.h" |
saza | f7e08b2 | 2017-07-19 08:12:36 | [diff] [blame] | 19 | #include "webrtc/rtc_base/logging.h" |
Edward Lemur | 76de83e | 2017-07-06 17:44:34 | [diff] [blame] | 20 | #include "webrtc/rtc_base/thread_annotations.h" |
kthelgason | 912e1cf | 2017-03-31 09:03:55 | [diff] [blame] | 21 | #include "webrtc/system_wrappers/include/event_wrapper.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 22 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 23 | #include <AudioToolbox/AudioConverter.h> |
pbos@webrtc.org | bc669ac | 2013-07-11 13:24:38 | [diff] [blame] | 24 | #include <CoreAudio/CoreAudio.h> |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 25 | #include <mach/semaphore.h> |
| 26 | |
| 27 | struct PaUtilRingBuffer; |
| 28 | |
Peter Boström | daf1aa4 | 2015-11-26 16:45:47 | [diff] [blame] | 29 | namespace rtc { |
| 30 | class PlatformThread; |
| 31 | } // namespace rtc |
| 32 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 33 | namespace webrtc { |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 34 | class EventWrapper; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 35 | |
andrew@webrtc.org | 1125d89 | 2013-06-08 00:43:25 | [diff] [blame] | 36 | const uint32_t N_REC_SAMPLES_PER_SEC = 48000; |
| 37 | const uint32_t N_PLAY_SAMPLES_PER_SEC = 48000; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 38 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [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 | 1125d89 | 2013-06-08 00:43:25 | [diff] [blame] | 41 | const uint32_t N_DEVICE_CHANNELS = 64; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 42 | |
andrew | ebe7b60 | 2016-01-08 09:16:17 | [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; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 49 | |
andrew@webrtc.org | 64e2651 | 2013-06-07 17:56:50 | [diff] [blame] | 50 | const int N_BLOCKS_IO = 2; |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 51 | const int N_BUFFERS_IN = 2; // Must be at least N_BLOCKS_IO. |
andrew@webrtc.org | 64e2651 | 2013-06-07 17:56:50 | [diff] [blame] | 52 | const int N_BUFFERS_OUT = 3; // Must be at least N_BLOCKS_IO. |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 53 | |
andrew | ebe7b60 | 2016-01-08 09:16:17 | [diff] [blame] | 54 | const uint32_t TIMER_PERIOD_MS = 2 * 10 * N_BLOCKS_IO * 1000000; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 55 | |
andrew@webrtc.org | 1125d89 | 2013-06-08 00:43:25 | [diff] [blame] | 56 | const uint32_t REC_BUF_SIZE_IN_SAMPLES = |
andrew@webrtc.org | 64e2651 | 2013-06-07 17:56:50 | [diff] [blame] | 57 | ENGINE_REC_BUF_SIZE_IN_SAMPLES * N_DEVICE_CHANNELS * N_BUFFERS_IN; |
andrew@webrtc.org | 1125d89 | 2013-06-08 00:43:25 | [diff] [blame] | 58 | const uint32_t PLAY_BUF_SIZE_IN_SAMPLES = |
andrew@webrtc.org | 64e2651 | 2013-06-07 17:56:50 | [diff] [blame] | 59 | ENGINE_PLAY_BUF_SIZE_IN_SAMPLES * N_PLAY_CHANNELS * N_BUFFERS_OUT; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 60 | |
andrew | ebe7b60 | 2016-01-08 09:16:17 | [diff] [blame] | 61 | const int kGetMicVolumeIntervalMs = 1000; |
| 62 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 63 | class AudioDeviceMac : public AudioDeviceGeneric { |
| 64 | public: |
saza | f7e08b2 | 2017-07-19 08:12:36 | [diff] [blame] | 65 | AudioDeviceMac(); |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 66 | ~AudioDeviceMac(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 67 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 68 | // Retrieve the currently utilized audio layer |
| 69 | virtual int32_t ActiveAudioLayer( |
| 70 | AudioDeviceModule::AudioLayer& audioLayer) const; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 71 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 72 | // Main initializaton and termination |
Max Morin | 190023d | 2016-07-01 11:35:19 | [diff] [blame] | 73 | virtual InitStatus Init(); |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 74 | virtual int32_t Terminate(); |
| 75 | virtual bool Initialized() const; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 76 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [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]); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 86 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [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); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 93 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [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; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 101 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [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; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 109 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 110 | // Microphone Automatic Gain Control (AGC) |
| 111 | virtual int32_t SetAGC(bool enable); |
| 112 | virtual bool AGC() const; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 113 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [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; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 119 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [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; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 126 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [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; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 133 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [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; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 138 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [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; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 143 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [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; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 151 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 152 | // Delay information and control |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 153 | virtual int32_t PlayoutDelay(uint16_t& delayMS) const; |
| 154 | virtual int32_t RecordingDelay(uint16_t& delayMS) const; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 155 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 156 | virtual bool PlayoutWarning() const; |
| 157 | virtual bool PlayoutError() const; |
| 158 | virtual bool RecordingWarning() const; |
| 159 | virtual bool RecordingError() const; |
| 160 | virtual void ClearPlayoutWarning(); |
| 161 | virtual void ClearPlayoutError(); |
| 162 | virtual void ClearRecordingWarning(); |
| 163 | virtual void ClearRecordingError(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 164 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 165 | virtual void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 166 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 167 | private: |
| 168 | virtual int32_t MicrophoneIsAvailable(bool& available); |
| 169 | virtual int32_t SpeakerIsAvailable(bool& available); |
andrew@webrtc.org | cceb392 | 2014-04-02 16:49:26 | [diff] [blame] | 170 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 171 | static void AtomicSet32(int32_t* theValue, int32_t newValue); |
| 172 | static int32_t AtomicGet32(int32_t* theValue); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 173 | |
saza | f7e08b2 | 2017-07-19 08:12:36 | [diff] [blame] | 174 | static void logCAMsg(const rtc::LoggingSeverity sev, |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 175 | const char* msg, |
| 176 | const char* err); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 177 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 178 | int32_t GetNumberDevices(const AudioObjectPropertyScope scope, |
| 179 | AudioDeviceID scopedDeviceIds[], |
| 180 | const uint32_t deviceListLength); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 181 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 182 | int32_t GetDeviceName(const AudioObjectPropertyScope scope, |
| 183 | const uint16_t index, |
| 184 | char* name); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 185 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 186 | int32_t InitDevice(uint16_t userDeviceIndex, |
| 187 | AudioDeviceID& deviceId, |
| 188 | bool isInput); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 189 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 190 | // Always work with our preferred playout format inside VoE. |
| 191 | // Then convert the output to the OS setting using an AudioConverter. |
| 192 | OSStatus SetDesiredPlayoutFormat(); |
braveyao@webrtc.org | 462472f | 2015-03-21 01:05:56 | [diff] [blame] | 193 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 194 | static OSStatus objectListenerProc( |
| 195 | AudioObjectID objectId, |
| 196 | UInt32 numberAddresses, |
| 197 | const AudioObjectPropertyAddress addresses[], |
| 198 | void* clientData); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 199 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 200 | OSStatus implObjectListenerProc(AudioObjectID objectId, |
| 201 | UInt32 numberAddresses, |
| 202 | const AudioObjectPropertyAddress addresses[]); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 203 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 204 | int32_t HandleDeviceChange(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 205 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 206 | int32_t HandleStreamFormatChange(AudioObjectID objectId, |
| 207 | AudioObjectPropertyAddress propertyAddress); |
| 208 | |
| 209 | int32_t HandleDataSourceChange(AudioObjectID objectId, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 210 | AudioObjectPropertyAddress propertyAddress); |
| 211 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 212 | int32_t HandleProcessorOverload(AudioObjectPropertyAddress propertyAddress); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 213 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 214 | static OSStatus deviceIOProc(AudioDeviceID device, |
| 215 | const AudioTimeStamp* now, |
| 216 | const AudioBufferList* inputData, |
| 217 | const AudioTimeStamp* inputTime, |
| 218 | AudioBufferList* outputData, |
| 219 | const AudioTimeStamp* outputTime, |
| 220 | void* clientData); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 221 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 222 | static OSStatus outConverterProc( |
| 223 | AudioConverterRef audioConverter, |
| 224 | UInt32* numberDataPackets, |
| 225 | AudioBufferList* data, |
| 226 | AudioStreamPacketDescription** dataPacketDescription, |
| 227 | void* userData); |
| 228 | |
| 229 | static OSStatus inDeviceIOProc(AudioDeviceID device, |
| 230 | const AudioTimeStamp* now, |
| 231 | const AudioBufferList* inputData, |
| 232 | const AudioTimeStamp* inputTime, |
| 233 | AudioBufferList* outputData, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 234 | const AudioTimeStamp* outputTime, |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 235 | void* clientData); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 236 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 237 | static OSStatus inConverterProc( |
| 238 | AudioConverterRef audioConverter, |
| 239 | UInt32* numberDataPackets, |
| 240 | AudioBufferList* data, |
| 241 | AudioStreamPacketDescription** dataPacketDescription, |
| 242 | void* inUserData); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 243 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 244 | OSStatus implDeviceIOProc(const AudioBufferList* inputData, |
| 245 | const AudioTimeStamp* inputTime, |
| 246 | AudioBufferList* outputData, |
| 247 | const AudioTimeStamp* outputTime); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 248 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 249 | OSStatus implOutConverterProc(UInt32* numberDataPackets, |
| 250 | AudioBufferList* data); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 251 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 252 | OSStatus implInDeviceIOProc(const AudioBufferList* inputData, |
| 253 | const AudioTimeStamp* inputTime); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 254 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 255 | OSStatus implInConverterProc(UInt32* numberDataPackets, |
| 256 | AudioBufferList* data); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 257 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 258 | static bool RunCapture(void*); |
| 259 | static bool RunRender(void*); |
| 260 | bool CaptureWorkerThread(); |
| 261 | bool RenderWorkerThread(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 262 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 263 | bool KeyPressed(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 264 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 265 | AudioDeviceBuffer* _ptrAudioBuffer; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 266 | |
kthelgason | 912e1cf | 2017-03-31 09:03:55 | [diff] [blame] | 267 | rtc::CriticalSection _critSect; |
niklas.enbom@webrtc.org | 28832e1 | 2013-05-07 21:04:24 | [diff] [blame] | 268 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 269 | EventWrapper& _stopEventRec; |
| 270 | EventWrapper& _stopEvent; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 271 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 272 | // TODO(pbos): Replace with direct members, just start/stop, no need to |
| 273 | // recreate the thread. |
| 274 | // Only valid/running between calls to StartRecording and StopRecording. |
kwiberg | c0677bd | 2016-02-24 13:00:36 | [diff] [blame] | 275 | std::unique_ptr<rtc::PlatformThread> capture_worker_thread_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 276 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 277 | // Only valid/running between calls to StartPlayout and StopPlayout. |
kwiberg | c0677bd | 2016-02-24 13:00:36 | [diff] [blame] | 278 | std::unique_ptr<rtc::PlatformThread> render_worker_thread_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 279 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 280 | AudioMixerManagerMac _mixerManager; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 281 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 282 | uint16_t _inputDeviceIndex; |
| 283 | uint16_t _outputDeviceIndex; |
| 284 | AudioDeviceID _inputDeviceID; |
| 285 | AudioDeviceID _outputDeviceID; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 286 | #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 287 | AudioDeviceIOProcID _inDeviceIOProcID; |
| 288 | AudioDeviceIOProcID _deviceIOProcID; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 289 | #endif |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 290 | bool _inputDeviceIsSpecified; |
| 291 | bool _outputDeviceIsSpecified; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 292 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 293 | uint8_t _recChannels; |
| 294 | uint8_t _playChannels; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 295 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 296 | Float32* _captureBufData; |
| 297 | SInt16* _renderBufData; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 298 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 299 | SInt16 _renderConvertData[PLAY_BUF_SIZE_IN_SAMPLES]; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 300 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 301 | bool _initialized; |
| 302 | bool _isShutDown; |
| 303 | bool _recording; |
| 304 | bool _playing; |
| 305 | bool _recIsInitialized; |
| 306 | bool _playIsInitialized; |
| 307 | bool _AGC; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 308 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 309 | // Atomically set varaibles |
| 310 | int32_t _renderDeviceIsAlive; |
| 311 | int32_t _captureDeviceIsAlive; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 312 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 313 | bool _twoDevices; |
| 314 | bool _doStop; // For play if not shared device or play+rec if shared device |
| 315 | bool _doStopRec; // For rec if not shared device |
| 316 | bool _macBookPro; |
| 317 | bool _macBookProPanRight; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 318 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 319 | AudioConverterRef _captureConverter; |
| 320 | AudioConverterRef _renderConverter; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 321 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 322 | AudioStreamBasicDescription _outStreamFormat; |
| 323 | AudioStreamBasicDescription _outDesiredFormat; |
| 324 | AudioStreamBasicDescription _inStreamFormat; |
| 325 | AudioStreamBasicDescription _inDesiredFormat; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 326 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 327 | uint32_t _captureLatencyUs; |
| 328 | uint32_t _renderLatencyUs; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 329 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 330 | // Atomically set variables |
| 331 | mutable int32_t _captureDelayUs; |
| 332 | mutable int32_t _renderDelayUs; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 333 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 334 | int32_t _renderDelayOffsetSamples; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 335 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 336 | uint16_t _playWarning; |
| 337 | uint16_t _playError; |
| 338 | uint16_t _recWarning; |
| 339 | uint16_t _recError; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 340 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 341 | PaUtilRingBuffer* _paCaptureBuffer; |
| 342 | PaUtilRingBuffer* _paRenderBuffer; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 343 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 344 | semaphore_t _renderSemaphore; |
| 345 | semaphore_t _captureSemaphore; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 346 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 347 | int _captureBufSizeSamples; |
| 348 | int _renderBufSizeSamples; |
niklas.enbom@webrtc.org | e807da9 | 2013-08-15 14:19:12 | [diff] [blame] | 349 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 350 | // Typing detection |
| 351 | // 0x5c is key "9", after that comes function keys. |
| 352 | bool prev_key_state_[0x5d]; |
andrew | ebe7b60 | 2016-01-08 09:16:17 | [diff] [blame] | 353 | |
andrew | 0cbc06b | 2016-01-11 23:59:17 | [diff] [blame] | 354 | int get_mic_volume_counter_ms_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 355 | }; |
| 356 | |
pbos@webrtc.org | 3b89e10 | 2013-07-03 15:12:26 | [diff] [blame] | 357 | } // namespace webrtc |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 | [diff] [blame] | 358 | |
| 359 | #endif // MODULES_AUDIO_DEVICE_MAIN_SOURCE_MAC_AUDIO_DEVICE_MAC_H_ |