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

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

Issue 1435293003: Improved error handling in iOS ADM to avoid race during init (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Feedback from pbos@ Created 5 years, 1 month 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 <AudioUnit/AudioUnit.h> 14 #include <AudioUnit/AudioUnit.h>
15 15
16 #include "webrtc/base/criticalsection.h"
pbos-webrtc 2015/11/18 18:51:48 Move to .cc file
henrika_webrtc 2015/11/19 12:04:19 Done.
16 #include "webrtc/base/scoped_ptr.h" 17 #include "webrtc/base/scoped_ptr.h"
18 #include "webrtc/base/thread_annotations.h"
pbos-webrtc 2015/11/18 18:51:48 Move to .cc file
henrika_webrtc 2015/11/19 12:04:19 Done.
17 #include "webrtc/base/thread_checker.h" 19 #include "webrtc/base/thread_checker.h"
18 #include "webrtc/modules/audio_device/audio_device_generic.h" 20 #include "webrtc/modules/audio_device/audio_device_generic.h"
19 21
20 namespace webrtc { 22 namespace webrtc {
21 23
22 class FineAudioBuffer; 24 class FineAudioBuffer;
23 25
24 // Implements full duplex 16-bit mono PCM audio support for iOS using a 26 // Implements full duplex 16-bit mono PCM audio support for iOS using a
25 // Voice-Processing (VP) I/O audio unit in Core Audio. The VP I/O audio unit 27 // Voice-Processing (VP) I/O audio unit in Core Audio. The VP I/O audio unit
26 // supports audio echo cancellation. It also adds automatic gain control, 28 // supports audio echo cancellation. It also adds automatic gain control,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 void ClearPlayoutWarning() override {} 150 void ClearPlayoutWarning() override {}
149 void ClearPlayoutError() override {} 151 void ClearPlayoutError() override {}
150 void ClearRecordingWarning() override {} 152 void ClearRecordingWarning() override {}
151 void ClearRecordingError() override {} 153 void ClearRecordingError() override {}
152 154
153 private: 155 private:
154 // Uses current |playout_parameters_| and |record_parameters_| to inform the 156 // Uses current |playout_parameters_| and |record_parameters_| to inform the
155 // audio device buffer (ADB) about our internal audio parameters. 157 // audio device buffer (ADB) about our internal audio parameters.
156 void UpdateAudioDeviceBuffer(); 158 void UpdateAudioDeviceBuffer();
157 159
160 bool ActivateAudioSession();
161 bool DeactivateAudioSession();
162
158 // Registers observers for the AVAudioSessionRouteChangeNotification and 163 // Registers observers for the AVAudioSessionRouteChangeNotification and
159 // AVAudioSessionInterruptionNotification notifications. 164 // AVAudioSessionInterruptionNotification notifications.
160 void RegisterNotificationObservers(); 165 void RegisterNotificationObservers();
161 void UnregisterNotificationObservers(); 166 void UnregisterNotificationObservers();
162 167
163 // Since the preferred audio parameters are only hints to the OS, the actual 168 // Since the preferred audio parameters are only hints to the OS, the actual
164 // values may be different once the AVAudioSession has been activated. 169 // values may be different once the AVAudioSession has been activated.
165 // This method asks for the current hardware parameters and takes actions 170 // This method asks for the current hardware parameters and takes actions
166 // if they should differ from what we have asked for initially. It also 171 // if they should differ from what we have asked for initially. It also
167 // defines |playout_parameters_| and |record_parameters_|. 172 // defines |playout_parameters_| and |record_parameters_|.
168 void SetupAudioBuffersForActiveAudioSession(); 173 void SetupAudioBuffersForActiveAudioSession();
169 174
170 // Creates a Voice-Processing I/O unit and configures it for full-duplex 175 // Creates a Voice-Processing I/O unit and configures it for full-duplex
171 // audio. The selected stream format is selected to avoid internal resampling 176 // audio. The selected stream format is selected to avoid internal resampling
172 // and to match the 10ms callback rate for WebRTC as well as possible. 177 // and to match the 10ms callback rate for WebRTC as well as possible.
173 // This method also initializes the created audio unit. 178 // This method also initializes the created audio unit.
174 bool SetupAndInitializeVoiceProcessingAudioUnit(); 179 bool SetupAndInitializeVoiceProcessingAudioUnit();
175 180
176 // Restarts active audio streams using a new sample rate. Required when e.g. 181 // Restarts active audio streams using a new sample rate. Required when e.g.
177 // a BT headset is enabled or disabled. 182 // a BT headset is enabled or disabled.
178 bool RestartAudioUnitWithNewFormat(float sample_rate); 183 bool RestartAudioUnitWithNewFormat(float sample_rate);
179 184
180 // Activates our audio session, creates and initializes the voice-processing 185 // Activates our audio session, creates and initializes the voice-processing
181 // audio unit and verifies that we got the preferred native audio parameters. 186 // audio unit and verifies that we got the preferred native audio parameters.
182 bool InitPlayOrRecord(); 187 bool InitPlayOrRecord();
183 188
184 // Closes and deletes the voice-processing I/O unit. 189 // Closes and deletes the voice-processing I/O unit.
185 bool ShutdownPlayOrRecord(); 190 void ShutdownPlayOrRecord();
191
192 // Helper method for destroying the existing audio unit.
193 void DisposeAudioUnit();
186 194
187 // Callback function called on a real-time priority I/O thread from the audio 195 // Callback function called on a real-time priority I/O thread from the audio
188 // unit. This method is used to signal that recorded audio is available. 196 // unit. This method is used to signal that recorded audio is available.
189 static OSStatus RecordedDataIsAvailable( 197 static OSStatus RecordedDataIsAvailable(
190 void* in_ref_con, 198 void* in_ref_con,
191 AudioUnitRenderActionFlags* io_action_flags, 199 AudioUnitRenderActionFlags* io_action_flags,
192 const AudioTimeStamp* time_stamp, 200 const AudioTimeStamp* time_stamp,
193 UInt32 in_bus_number, 201 UInt32 in_bus_number,
194 UInt32 in_number_frames, 202 UInt32 in_number_frames,
195 AudioBufferList* io_data); 203 AudioBufferList* io_data);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 void* audio_interruption_observer_; 294 void* audio_interruption_observer_;
287 void* route_change_observer_; 295 void* route_change_observer_;
288 296
289 // Contains the audio data format specification for a stream of audio. 297 // Contains the audio data format specification for a stream of audio.
290 AudioStreamBasicDescription application_format_; 298 AudioStreamBasicDescription application_format_;
291 }; 299 };
292 300
293 } // namespace webrtc 301 } // namespace webrtc
294 302
295 #endif // WEBRTC_MODULES_AUDIO_DEVICE_IOS_AUDIO_DEVICE_IOS_H_ 303 #endif // WEBRTC_MODULES_AUDIO_DEVICE_IOS_AUDIO_DEVICE_IOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698