sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_DEVICE_IOS_AUDIO_DEVICE_IOS_H_ |
| 12 | #define MODULES_AUDIO_DEVICE_IOS_AUDIO_DEVICE_IOS_H_ |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +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/ios/audio_session_observer.h" |
| 18 | #include "modules/audio_device/ios/voice_processing_audio_unit.h" |
| 19 | #include "rtc_base/buffer.h" |
| 20 | #include "rtc_base/gtest_prod_util.h" |
| 21 | #include "rtc_base/thread.h" |
| 22 | #include "rtc_base/thread_annotations.h" |
| 23 | #include "rtc_base/thread_checker.h" |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 24 | #include "sdk/objc/Framework/Headers/WebRTC/RTCMacros.h" |
tkchin | e54467f | 2016-03-15 16:54:03 -0700 | [diff] [blame] | 25 | |
| 26 | RTC_FWD_DECL_OBJC_CLASS(RTCAudioSessionDelegateAdapter); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 27 | |
| 28 | namespace webrtc { |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 29 | |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 30 | class FineAudioBuffer; |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 31 | |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 32 | // Implements full duplex 16-bit mono PCM audio support for iOS using a |
| 33 | // Voice-Processing (VP) I/O audio unit in Core Audio. The VP I/O audio unit |
| 34 | // supports audio echo cancellation. It also adds automatic gain control, |
| 35 | // adjustment of voice-processing quality and muting. |
| 36 | // |
| 37 | // An instance must be created and destroyed on one and the same thread. |
| 38 | // All supported public methods must also be called on the same thread. |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 39 | // A thread checker will RTC_DCHECK if any supported method is called on an |
| 40 | // invalid thread. |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 41 | // |
| 42 | // Recorded audio will be delivered on a real-time internal I/O thread in the |
| 43 | // audio unit. The audio unit will also ask for audio data to play out on this |
| 44 | // same thread. |
tkchin | e54467f | 2016-03-15 16:54:03 -0700 | [diff] [blame] | 45 | class AudioDeviceIOS : public AudioDeviceGeneric, |
Zeke Chin | 1300caa | 2016-03-18 14:39:11 -0700 | [diff] [blame] | 46 | public AudioSessionObserver, |
tkchin | d251196 | 2016-05-06 18:54:15 -0700 | [diff] [blame] | 47 | public VoiceProcessingAudioUnitObserver, |
| 48 | public rtc::MessageHandler { |
tkchin@webrtc.org | 122caa5 | 2014-07-15 20:20:47 +0000 | [diff] [blame] | 49 | public: |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 50 | AudioDeviceIOS(); |
tkchin@webrtc.org | 122caa5 | 2014-07-15 20:20:47 +0000 | [diff] [blame] | 51 | ~AudioDeviceIOS(); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 52 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 53 | void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) override; |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 54 | |
Max Morin | 84cab20 | 2016-07-01 13:35:19 +0200 | [diff] [blame] | 55 | InitStatus Init() override; |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 56 | int32_t Terminate() override; |
henrika | af35f83 | 2017-06-16 13:22:13 +0200 | [diff] [blame] | 57 | bool Initialized() const override; |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 58 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 59 | int32_t InitPlayout() override; |
henrika | af35f83 | 2017-06-16 13:22:13 +0200 | [diff] [blame] | 60 | bool PlayoutIsInitialized() const override; |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 61 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 62 | int32_t InitRecording() override; |
henrika | af35f83 | 2017-06-16 13:22:13 +0200 | [diff] [blame] | 63 | bool RecordingIsInitialized() const override; |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 64 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 65 | int32_t StartPlayout() override; |
| 66 | int32_t StopPlayout() override; |
pbos | 46ad542 | 2015-12-07 14:29:14 -0800 | [diff] [blame] | 67 | bool Playing() const override { return playing_; } |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 68 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 69 | int32_t StartRecording() override; |
| 70 | int32_t StopRecording() override; |
pbos | 46ad542 | 2015-12-07 14:29:14 -0800 | [diff] [blame] | 71 | bool Recording() const override { return recording_; } |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 72 | |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 73 | // These methods returns hard-coded delay values and not dynamic delay |
| 74 | // estimates. The reason is that iOS supports a built-in AEC and the WebRTC |
| 75 | // AEC will always be disabled in the Libjingle layer to avoid running two |
| 76 | // AEC implementations at the same time. And, it saves resources to avoid |
| 77 | // updating these delay values continuously. |
| 78 | // TODO(henrika): it would be possible to mark these two methods as not |
| 79 | // implemented since they are only called for A/V-sync purposes today and |
| 80 | // A/V-sync is not supported on iOS. However, we avoid adding error messages |
| 81 | // the log by using these dummy implementations instead. |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 82 | int32_t PlayoutDelay(uint16_t& delayMS) const override; |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 83 | |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 84 | // Native audio parameters stored during construction. |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 85 | // These methods are unique for the iOS implementation. |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 86 | int GetPlayoutAudioParameters(AudioParameters* params) const override; |
| 87 | int GetRecordAudioParameters(AudioParameters* params) const override; |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 88 | |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 89 | // These methods are currently not fully implemented on iOS: |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 90 | |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 91 | // See audio_device_not_implemented.cc for trivial implementations. |
kjellander | 080a1e3 | 2016-05-25 11:37:11 -0700 | [diff] [blame] | 92 | int32_t ActiveAudioLayer( |
| 93 | AudioDeviceModule::AudioLayer& audioLayer) const override; |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 94 | int32_t PlayoutIsAvailable(bool& available) override; |
| 95 | int32_t RecordingIsAvailable(bool& available) override; |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 96 | int16_t PlayoutDevices() override; |
| 97 | int16_t RecordingDevices() override; |
| 98 | int32_t PlayoutDeviceName(uint16_t index, |
| 99 | char name[kAdmMaxDeviceNameSize], |
| 100 | char guid[kAdmMaxGuidSize]) override; |
| 101 | int32_t RecordingDeviceName(uint16_t index, |
| 102 | char name[kAdmMaxDeviceNameSize], |
| 103 | char guid[kAdmMaxGuidSize]) override; |
| 104 | int32_t SetPlayoutDevice(uint16_t index) override; |
| 105 | int32_t SetPlayoutDevice( |
| 106 | AudioDeviceModule::WindowsDeviceType device) override; |
| 107 | int32_t SetRecordingDevice(uint16_t index) override; |
| 108 | int32_t SetRecordingDevice( |
| 109 | AudioDeviceModule::WindowsDeviceType device) override; |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 110 | int32_t InitSpeaker() override; |
| 111 | bool SpeakerIsInitialized() const override; |
| 112 | int32_t InitMicrophone() override; |
| 113 | bool MicrophoneIsInitialized() const override; |
| 114 | int32_t SpeakerVolumeIsAvailable(bool& available) override; |
| 115 | int32_t SetSpeakerVolume(uint32_t volume) override; |
| 116 | int32_t SpeakerVolume(uint32_t& volume) const override; |
| 117 | int32_t MaxSpeakerVolume(uint32_t& maxVolume) const override; |
| 118 | int32_t MinSpeakerVolume(uint32_t& minVolume) const override; |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 119 | int32_t MicrophoneVolumeIsAvailable(bool& available) override; |
| 120 | int32_t SetMicrophoneVolume(uint32_t volume) override; |
| 121 | int32_t MicrophoneVolume(uint32_t& volume) const override; |
| 122 | int32_t MaxMicrophoneVolume(uint32_t& maxVolume) const override; |
| 123 | int32_t MinMicrophoneVolume(uint32_t& minVolume) const override; |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 124 | int32_t MicrophoneMuteIsAvailable(bool& available) override; |
| 125 | int32_t SetMicrophoneMute(bool enable) override; |
| 126 | int32_t MicrophoneMute(bool& enabled) const override; |
| 127 | int32_t SpeakerMuteIsAvailable(bool& available) override; |
| 128 | int32_t SetSpeakerMute(bool enable) override; |
| 129 | int32_t SpeakerMute(bool& enabled) const override; |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 130 | int32_t StereoPlayoutIsAvailable(bool& available) override; |
| 131 | int32_t SetStereoPlayout(bool enable) override; |
| 132 | int32_t StereoPlayout(bool& enabled) const override; |
| 133 | int32_t StereoRecordingIsAvailable(bool& available) override; |
| 134 | int32_t SetStereoRecording(bool enable) override; |
| 135 | int32_t StereoRecording(bool& enabled) const override; |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 136 | |
tkchin | e54467f | 2016-03-15 16:54:03 -0700 | [diff] [blame] | 137 | // AudioSessionObserver methods. May be called from any thread. |
| 138 | void OnInterruptionBegin() override; |
| 139 | void OnInterruptionEnd() override; |
| 140 | void OnValidRouteChange() override; |
tkchin | d251196 | 2016-05-06 18:54:15 -0700 | [diff] [blame] | 141 | void OnCanPlayOrRecordChange(bool can_play_or_record) override; |
henrika | af35f83 | 2017-06-16 13:22:13 +0200 | [diff] [blame] | 142 | void OnChangedOutputVolume() override; |
tkchin | e54467f | 2016-03-15 16:54:03 -0700 | [diff] [blame] | 143 | |
Zeke Chin | 1300caa | 2016-03-18 14:39:11 -0700 | [diff] [blame] | 144 | // VoiceProcessingAudioUnitObserver methods. |
| 145 | OSStatus OnDeliverRecordedData(AudioUnitRenderActionFlags* flags, |
| 146 | const AudioTimeStamp* time_stamp, |
| 147 | UInt32 bus_number, |
| 148 | UInt32 num_frames, |
| 149 | AudioBufferList* io_data) override; |
| 150 | OSStatus OnGetPlayoutData(AudioUnitRenderActionFlags* flags, |
| 151 | const AudioTimeStamp* time_stamp, |
| 152 | UInt32 bus_number, |
| 153 | UInt32 num_frames, |
| 154 | AudioBufferList* io_data) override; |
| 155 | |
tkchin | d251196 | 2016-05-06 18:54:15 -0700 | [diff] [blame] | 156 | // Handles messages from posts. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 157 | void OnMessage(rtc::Message* msg) override; |
tkchin | d251196 | 2016-05-06 18:54:15 -0700 | [diff] [blame] | 158 | |
tkchin@webrtc.org | 122caa5 | 2014-07-15 20:20:47 +0000 | [diff] [blame] | 159 | private: |
tkchin | e54467f | 2016-03-15 16:54:03 -0700 | [diff] [blame] | 160 | // Called by the relevant AudioSessionObserver methods on |thread_|. |
| 161 | void HandleInterruptionBegin(); |
| 162 | void HandleInterruptionEnd(); |
| 163 | void HandleValidRouteChange(); |
tkchin | d251196 | 2016-05-06 18:54:15 -0700 | [diff] [blame] | 164 | void HandleCanPlayOrRecordChange(bool can_play_or_record); |
| 165 | void HandleSampleRateChange(float sample_rate); |
henrika | 7be7883 | 2017-06-13 17:34:16 +0200 | [diff] [blame] | 166 | void HandlePlayoutGlitchDetected(); |
henrika | af35f83 | 2017-06-16 13:22:13 +0200 | [diff] [blame] | 167 | void HandleOutputVolumeChange(); |
tkchin | e54467f | 2016-03-15 16:54:03 -0700 | [diff] [blame] | 168 | |
henrika | 8c471e7 | 2015-10-01 07:36:45 -0700 | [diff] [blame] | 169 | // Uses current |playout_parameters_| and |record_parameters_| to inform the |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 170 | // audio device buffer (ADB) about our internal audio parameters. |
| 171 | void UpdateAudioDeviceBuffer(); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 172 | |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 173 | // Since the preferred audio parameters are only hints to the OS, the actual |
| 174 | // values may be different once the AVAudioSession has been activated. |
| 175 | // This method asks for the current hardware parameters and takes actions |
| 176 | // if they should differ from what we have asked for initially. It also |
henrika | 8c471e7 | 2015-10-01 07:36:45 -0700 | [diff] [blame] | 177 | // defines |playout_parameters_| and |record_parameters_|. |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 178 | void SetupAudioBuffersForActiveAudioSession(); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 179 | |
Zeke Chin | 1300caa | 2016-03-18 14:39:11 -0700 | [diff] [blame] | 180 | // Creates the audio unit. |
| 181 | bool CreateAudioUnit(); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 182 | |
tkchin | d251196 | 2016-05-06 18:54:15 -0700 | [diff] [blame] | 183 | // Updates the audio unit state based on current state. |
| 184 | void UpdateAudioUnit(bool can_play_or_record); |
| 185 | |
| 186 | // Configures the audio session for WebRTC. |
jtteh | f84c1d6 | 2017-04-21 13:56:39 -0700 | [diff] [blame] | 187 | bool ConfigureAudioSession(); |
tkchin | d251196 | 2016-05-06 18:54:15 -0700 | [diff] [blame] | 188 | // Unconfigures the audio session. |
| 189 | void UnconfigureAudioSession(); |
henrika | 45c136b | 2015-10-21 04:11:53 -0700 | [diff] [blame] | 190 | |
henrika | 8c471e7 | 2015-10-01 07:36:45 -0700 | [diff] [blame] | 191 | // Activates our audio session, creates and initializes the voice-processing |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 192 | // audio unit and verifies that we got the preferred native audio parameters. |
| 193 | bool InitPlayOrRecord(); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 194 | |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 195 | // Closes and deletes the voice-processing I/O unit. |
henrika | 34911ad | 2015-11-20 15:47:09 +0100 | [diff] [blame] | 196 | void ShutdownPlayOrRecord(); |
| 197 | |
henrika | 79445ea | 2018-05-29 16:04:16 +0200 | [diff] [blame] | 198 | // Resets thread-checkers before a call is restarted. |
| 199 | void PrepareForNewStart(); |
| 200 | |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 201 | // Ensures that methods are called from the same thread as this object is |
| 202 | // created on. |
henrika | 8c471e7 | 2015-10-01 07:36:45 -0700 | [diff] [blame] | 203 | rtc::ThreadChecker thread_checker_; |
henrika | af35f83 | 2017-06-16 13:22:13 +0200 | [diff] [blame] | 204 | |
| 205 | // Native I/O audio thread checker. |
| 206 | rtc::ThreadChecker io_thread_checker_; |
| 207 | |
tkchin | e54467f | 2016-03-15 16:54:03 -0700 | [diff] [blame] | 208 | // Thread that this object is created on. |
| 209 | rtc::Thread* thread_; |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 210 | |
| 211 | // Raw pointer handle provided to us in AttachAudioBuffer(). Owned by the |
Peter Boström | 4adbbcf | 2016-05-03 15:51:26 -0400 | [diff] [blame] | 212 | // AudioDeviceModuleImpl class and called by AudioDeviceModule::Create(). |
henrika | ba35d05 | 2015-07-14 17:04:08 +0200 | [diff] [blame] | 213 | // The AudioDeviceBuffer is a member of the AudioDeviceModuleImpl instance |
| 214 | // and therefore outlives this object. |
henrika | 8c471e7 | 2015-10-01 07:36:45 -0700 | [diff] [blame] | 215 | AudioDeviceBuffer* audio_device_buffer_; |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 216 | |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 217 | // Contains audio parameters (sample rate, #channels, buffer size etc.) for |
| 218 | // the playout and recording sides. These structure is set in two steps: |
| 219 | // first, native sample rate and #channels are defined in Init(). Next, the |
| 220 | // audio session is activated and we verify that the preferred parameters |
| 221 | // were granted by the OS. At this stage it is also possible to add a third |
| 222 | // component to the parameters; the native I/O buffer duration. |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 223 | // A RTC_CHECK will be hit if we for some reason fail to open an audio session |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 224 | // using the specified parameters. |
henrika | 8c471e7 | 2015-10-01 07:36:45 -0700 | [diff] [blame] | 225 | AudioParameters playout_parameters_; |
| 226 | AudioParameters record_parameters_; |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 227 | |
Zeke Chin | 1300caa | 2016-03-18 14:39:11 -0700 | [diff] [blame] | 228 | // The AudioUnit used to play and record audio. |
| 229 | std::unique_ptr<VoiceProcessingAudioUnit> audio_unit_; |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 230 | |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 231 | // FineAudioBuffer takes an AudioDeviceBuffer which delivers audio data |
| 232 | // in chunks of 10ms. It then allows for this data to be pulled in |
| 233 | // a finer or coarser granularity. I.e. interacting with this class instead |
| 234 | // of directly with the AudioDeviceBuffer one can ask for any number of |
| 235 | // audio data samples. Is also supports a similar scheme for the recording |
| 236 | // side. |
| 237 | // Example: native buffer size can be 128 audio frames at 16kHz sample rate. |
| 238 | // WebRTC will provide 480 audio frames per 10ms but iOS asks for 128 |
| 239 | // in each callback (one every 8ms). This class can then ask for 128 and the |
| 240 | // FineAudioBuffer will ask WebRTC for new data only when needed and also |
| 241 | // cache non-utilized audio between callbacks. On the recording side, iOS |
| 242 | // can provide audio data frames of size 128 and these are accumulated until |
| 243 | // enough data to supply one 10ms call exists. This 10ms chunk is then sent |
| 244 | // to WebRTC and the remaining part is stored. |
kwiberg | f01633e | 2016-02-24 05:00:36 -0800 | [diff] [blame] | 245 | std::unique_ptr<FineAudioBuffer> fine_audio_buffer_; |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 246 | |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 247 | // Temporary storage for recorded data. AudioUnitRender() renders into this |
| 248 | // array as soon as a frame of the desired buffer size has been recorded. |
henrika | bc9ffad | 2017-06-01 14:25:45 +0200 | [diff] [blame] | 249 | // On real iOS devices, the size will be fixed and set once. For iOS |
| 250 | // simulators, the size can vary from callback to callback and the size |
| 251 | // will be changed dynamically to account for this behavior. |
henrika | 8d7393b | 2018-04-19 13:40:15 +0200 | [diff] [blame] | 252 | rtc::BufferT<int16_t> record_audio_buffer_; |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 253 | |
| 254 | // Set to 1 when recording is active and 0 otherwise. |
pbos | 46ad542 | 2015-12-07 14:29:14 -0800 | [diff] [blame] | 255 | volatile int recording_; |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 256 | |
| 257 | // Set to 1 when playout is active and 0 otherwise. |
pbos | 46ad542 | 2015-12-07 14:29:14 -0800 | [diff] [blame] | 258 | volatile int playing_; |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 259 | |
| 260 | // Set to true after successful call to Init(), false otherwise. |
Niels Möller | 1e06289 | 2018-02-07 10:18:32 +0100 | [diff] [blame] | 261 | bool initialized_ RTC_GUARDED_BY(thread_checker_); |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 262 | |
henrika | 17802ae | 2016-09-21 04:55:04 -0700 | [diff] [blame] | 263 | // Set to true after successful call to InitRecording() or InitPlayout(), |
| 264 | // false otherwise. |
| 265 | bool audio_is_initialized_; |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 266 | |
tkchin | e54467f | 2016-03-15 16:54:03 -0700 | [diff] [blame] | 267 | // Set to true if audio session is interrupted, false otherwise. |
| 268 | bool is_interrupted_; |
| 269 | |
henrika | 86d907c | 2015-09-07 16:09:50 +0200 | [diff] [blame] | 270 | // Audio interruption observer instance. |
henrika | af35f83 | 2017-06-16 13:22:13 +0200 | [diff] [blame] | 271 | RTCAudioSessionDelegateAdapter* audio_session_observer_ |
Niels Möller | 1e06289 | 2018-02-07 10:18:32 +0100 | [diff] [blame] | 272 | RTC_GUARDED_BY(thread_checker_); |
tkchin | d251196 | 2016-05-06 18:54:15 -0700 | [diff] [blame] | 273 | |
| 274 | // Set to true if we've activated the audio session. |
Niels Möller | 1e06289 | 2018-02-07 10:18:32 +0100 | [diff] [blame] | 275 | bool has_configured_session_ RTC_GUARDED_BY(thread_checker_); |
jtteh | 5171a7f | 2017-05-09 15:09:37 -0700 | [diff] [blame] | 276 | |
henrika | 7be7883 | 2017-06-13 17:34:16 +0200 | [diff] [blame] | 277 | // Counts number of detected audio glitches on the playout side. |
Niels Möller | 1e06289 | 2018-02-07 10:18:32 +0100 | [diff] [blame] | 278 | int64_t num_detected_playout_glitches_ RTC_GUARDED_BY(thread_checker_); |
| 279 | int64_t last_playout_time_ RTC_GUARDED_BY(io_thread_checker_); |
henrika | 7be7883 | 2017-06-13 17:34:16 +0200 | [diff] [blame] | 280 | |
| 281 | // Counts number of playout callbacks per call. |
henrika | af35f83 | 2017-06-16 13:22:13 +0200 | [diff] [blame] | 282 | // The value isupdated on the native I/O thread and later read on the |
| 283 | // creating thread (see thread_checker_) but at this stage no audio is |
| 284 | // active. Hence, it is a "thread safe" design and no lock is needed. |
henrika | 7be7883 | 2017-06-13 17:34:16 +0200 | [diff] [blame] | 285 | int64_t num_playout_callbacks_; |
| 286 | |
henrika | af35f83 | 2017-06-16 13:22:13 +0200 | [diff] [blame] | 287 | // Contains the time for when the last output volume change was detected. |
Niels Möller | 1e06289 | 2018-02-07 10:18:32 +0100 | [diff] [blame] | 288 | int64_t last_output_volume_change_time_ RTC_GUARDED_BY(thread_checker_); |
henrika | af35f83 | 2017-06-16 13:22:13 +0200 | [diff] [blame] | 289 | |
jtteh | 5171a7f | 2017-05-09 15:09:37 -0700 | [diff] [blame] | 290 | // Exposes private members for testing purposes only. |
| 291 | FRIEND_TEST_ALL_PREFIXES(AudioDeviceTest, testInterruptedAudioSession); |
sjlee@webrtc.org | 4b42508 | 2012-09-10 17:58:21 +0000 | [diff] [blame] | 292 | }; |
| 293 | |
| 294 | } // namespace webrtc |
| 295 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 296 | #endif // MODULES_AUDIO_DEVICE_IOS_AUDIO_DEVICE_IOS_H_ |