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

Side by Side Diff: webrtc/modules/audio_device/ios/audio_device_ios.h

Issue 1796983004: Use RTCAudioSessionDelegate in AudioDeviceIOS. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Some nits. Created 4 years, 9 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
11 #ifndef WEBRTC_MODULES_AUDIO_DEVICE_IOS_AUDIO_DEVICE_IOS_H_ 11 #ifndef WEBRTC_MODULES_AUDIO_DEVICE_IOS_AUDIO_DEVICE_IOS_H_
12 #define WEBRTC_MODULES_AUDIO_DEVICE_IOS_AUDIO_DEVICE_IOS_H_ 12 #define WEBRTC_MODULES_AUDIO_DEVICE_IOS_AUDIO_DEVICE_IOS_H_
13 13
14 #include <memory> 14 #include <memory>
15 15
16 #include <AudioUnit/AudioUnit.h> 16 #include <AudioUnit/AudioUnit.h>
17 17
18 #include "webrtc/base/asyncinvoker.h"
19 #include "webrtc/base/objc/RTCMacros.h"
20 #include "webrtc/base/thread.h"
18 #include "webrtc/base/thread_checker.h" 21 #include "webrtc/base/thread_checker.h"
19 #include "webrtc/modules/audio_device/audio_device_generic.h" 22 #include "webrtc/modules/audio_device/audio_device_generic.h"
23 #include "webrtc/modules/audio_device/ios/audio_session_observer.h"
24
25 RTC_FWD_DECL_OBJC_CLASS(RTCAudioSessionDelegateAdapter);
20 26
21 namespace webrtc { 27 namespace webrtc {
22 28
23 class FineAudioBuffer; 29 class FineAudioBuffer;
24 30
25 // Implements full duplex 16-bit mono PCM audio support for iOS using a 31 // Implements full duplex 16-bit mono PCM audio support for iOS using a
26 // Voice-Processing (VP) I/O audio unit in Core Audio. The VP I/O audio unit 32 // Voice-Processing (VP) I/O audio unit in Core Audio. The VP I/O audio unit
27 // supports audio echo cancellation. It also adds automatic gain control, 33 // supports audio echo cancellation. It also adds automatic gain control,
28 // adjustment of voice-processing quality and muting. 34 // adjustment of voice-processing quality and muting.
29 // 35 //
30 // An instance must be created and destroyed on one and the same thread. 36 // An instance must be created and destroyed on one and the same thread.
31 // All supported public methods must also be called on the same thread. 37 // All supported public methods must also be called on the same thread.
32 // A thread checker will RTC_DCHECK if any supported method is called on an 38 // A thread checker will RTC_DCHECK if any supported method is called on an
33 // invalid thread. 39 // invalid thread.
34 // 40 //
35 // Recorded audio will be delivered on a real-time internal I/O thread in the 41 // Recorded audio will be delivered on a real-time internal I/O thread in the
36 // audio unit. The audio unit will also ask for audio data to play out on this 42 // audio unit. The audio unit will also ask for audio data to play out on this
37 // same thread. 43 // same thread.
38 class AudioDeviceIOS : public AudioDeviceGeneric { 44 class AudioDeviceIOS : public AudioDeviceGeneric,
45 public AudioSessionObserver {
39 public: 46 public:
40 AudioDeviceIOS(); 47 AudioDeviceIOS();
41 ~AudioDeviceIOS(); 48 ~AudioDeviceIOS();
42 49
43 void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) override; 50 void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) override;
44 51
45 int32_t Init() override; 52 int32_t Init() override;
46 int32_t Terminate() override; 53 int32_t Terminate() override;
47 bool Initialized() const override { return initialized_; } 54 bool Initialized() const override { return initialized_; }
48 55
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 int32_t CPULoad(uint16_t& load) const override; 151 int32_t CPULoad(uint16_t& load) const override;
145 bool PlayoutWarning() const override; 152 bool PlayoutWarning() const override;
146 bool PlayoutError() const override; 153 bool PlayoutError() const override;
147 bool RecordingWarning() const override; 154 bool RecordingWarning() const override;
148 bool RecordingError() const override; 155 bool RecordingError() const override;
149 void ClearPlayoutWarning() override {} 156 void ClearPlayoutWarning() override {}
150 void ClearPlayoutError() override {} 157 void ClearPlayoutError() override {}
151 void ClearRecordingWarning() override {} 158 void ClearRecordingWarning() override {}
152 void ClearRecordingError() override {} 159 void ClearRecordingError() override {}
153 160
161 // AudioSessionObserver methods. May be called from any thread.
162 void OnInterruptionBegin() override;
163 void OnInterruptionEnd() override;
164 void OnValidRouteChange() override;
165
154 private: 166 private:
167 // Called by the relevant AudioSessionObserver methods on |thread_|.
168 void HandleInterruptionBegin();
169 void HandleInterruptionEnd();
170 void HandleValidRouteChange();
171
155 // Uses current |playout_parameters_| and |record_parameters_| to inform the 172 // Uses current |playout_parameters_| and |record_parameters_| to inform the
156 // audio device buffer (ADB) about our internal audio parameters. 173 // audio device buffer (ADB) about our internal audio parameters.
157 void UpdateAudioDeviceBuffer(); 174 void UpdateAudioDeviceBuffer();
158 175
159 // Registers observers for the AVAudioSessionRouteChangeNotification and
160 // AVAudioSessionInterruptionNotification notifications.
161 void RegisterNotificationObservers();
162 void UnregisterNotificationObservers();
163
164 // Since the preferred audio parameters are only hints to the OS, the actual 176 // Since the preferred audio parameters are only hints to the OS, the actual
165 // values may be different once the AVAudioSession has been activated. 177 // values may be different once the AVAudioSession has been activated.
166 // This method asks for the current hardware parameters and takes actions 178 // This method asks for the current hardware parameters and takes actions
167 // if they should differ from what we have asked for initially. It also 179 // if they should differ from what we have asked for initially. It also
168 // defines |playout_parameters_| and |record_parameters_|. 180 // defines |playout_parameters_| and |record_parameters_|.
169 void SetupAudioBuffersForActiveAudioSession(); 181 void SetupAudioBuffersForActiveAudioSession();
170 182
171 // Creates a Voice-Processing I/O unit and configures it for full-duplex 183 // Creates a Voice-Processing I/O unit and configures it for full-duplex
172 // audio. The selected stream format is selected to avoid internal resampling 184 // audio. The selected stream format is selected to avoid internal resampling
173 // and to match the 10ms callback rate for WebRTC as well as possible. 185 // and to match the 10ms callback rate for WebRTC as well as possible.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 UInt32 in_bus_number, 223 UInt32 in_bus_number,
212 UInt32 in_number_frames, 224 UInt32 in_number_frames,
213 AudioBufferList* io_data); 225 AudioBufferList* io_data);
214 OSStatus OnGetPlayoutData(AudioUnitRenderActionFlags* io_action_flags, 226 OSStatus OnGetPlayoutData(AudioUnitRenderActionFlags* io_action_flags,
215 UInt32 in_number_frames, 227 UInt32 in_number_frames,
216 AudioBufferList* io_data); 228 AudioBufferList* io_data);
217 229
218 // Ensures that methods are called from the same thread as this object is 230 // Ensures that methods are called from the same thread as this object is
219 // created on. 231 // created on.
220 rtc::ThreadChecker thread_checker_; 232 rtc::ThreadChecker thread_checker_;
233 // Thread that this object is created on.
234 rtc::Thread* thread_;
235 // Invoker used to execute methods on thread_.
236 std::unique_ptr<rtc::AsyncInvoker> async_invoker_;
221 237
222 // Raw pointer handle provided to us in AttachAudioBuffer(). Owned by the 238 // Raw pointer handle provided to us in AttachAudioBuffer(). Owned by the
223 // AudioDeviceModuleImpl class and called by AudioDeviceModuleImpl::Create(). 239 // AudioDeviceModuleImpl class and called by AudioDeviceModuleImpl::Create().
224 // The AudioDeviceBuffer is a member of the AudioDeviceModuleImpl instance 240 // The AudioDeviceBuffer is a member of the AudioDeviceModuleImpl instance
225 // and therefore outlives this object. 241 // and therefore outlives this object.
226 AudioDeviceBuffer* audio_device_buffer_; 242 AudioDeviceBuffer* audio_device_buffer_;
227 243
228 // Contains audio parameters (sample rate, #channels, buffer size etc.) for 244 // Contains audio parameters (sample rate, #channels, buffer size etc.) for
229 // the playout and recording sides. These structure is set in two steps: 245 // the playout and recording sides. These structure is set in two steps:
230 // first, native sample rate and #channels are defined in Init(). Next, the 246 // first, native sample rate and #channels are defined in Init(). Next, the
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 295
280 // Set to true after successful call to Init(), false otherwise. 296 // Set to true after successful call to Init(), false otherwise.
281 bool initialized_; 297 bool initialized_;
282 298
283 // Set to true after successful call to InitRecording(), false otherwise. 299 // Set to true after successful call to InitRecording(), false otherwise.
284 bool rec_is_initialized_; 300 bool rec_is_initialized_;
285 301
286 // Set to true after successful call to InitPlayout(), false otherwise. 302 // Set to true after successful call to InitPlayout(), false otherwise.
287 bool play_is_initialized_; 303 bool play_is_initialized_;
288 304
305 // Set to true if audio session is interrupted, false otherwise.
306 bool is_interrupted_;
307
289 // Audio interruption observer instance. 308 // Audio interruption observer instance.
290 void* audio_interruption_observer_; 309 RTCAudioSessionDelegateAdapter* audio_session_observer_;
291 void* route_change_observer_;
292 310
293 // Contains the audio data format specification for a stream of audio. 311 // Contains the audio data format specification for a stream of audio.
294 AudioStreamBasicDescription application_format_; 312 AudioStreamBasicDescription application_format_;
295 }; 313 };
296 314
297 } // namespace webrtc 315 } // namespace webrtc
298 316
299 #endif // WEBRTC_MODULES_AUDIO_DEVICE_IOS_AUDIO_DEVICE_IOS_H_ 317 #endif // WEBRTC_MODULES_AUDIO_DEVICE_IOS_AUDIO_DEVICE_IOS_H_
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/audio_device.gypi ('k') | webrtc/modules/audio_device/ios/audio_device_ios.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698