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

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

Issue 1420043008: Create rtc::AtomicInt POD struct. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: intentional obliteration of the unintentional whitespace of doom 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
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 LOG(LS_INFO) << " system version: " << ios::GetSystemVersion(); 186 LOG(LS_INFO) << " system version: " << ios::GetSystemVersion();
187 LOG(LS_INFO) << " device type: " << ios::GetDeviceType(); 187 LOG(LS_INFO) << " device type: " << ios::GetDeviceType();
188 LOG(LS_INFO) << " device name: " << ios::GetDeviceName(); 188 LOG(LS_INFO) << " device name: " << ios::GetDeviceName();
189 } 189 }
190 } 190 }
191 #endif // !defined(NDEBUG) 191 #endif // !defined(NDEBUG)
192 192
193 AudioDeviceIOS::AudioDeviceIOS() 193 AudioDeviceIOS::AudioDeviceIOS()
194 : audio_device_buffer_(nullptr), 194 : audio_device_buffer_(nullptr),
195 vpio_unit_(nullptr), 195 vpio_unit_(nullptr),
196 recording_(0),
197 playing_(0),
198 initialized_(false), 196 initialized_(false),
199 rec_is_initialized_(false), 197 rec_is_initialized_(false),
200 play_is_initialized_(false), 198 play_is_initialized_(false),
201 audio_interruption_observer_(nullptr), 199 audio_interruption_observer_(nullptr),
202 route_change_observer_(nullptr) { 200 route_change_observer_(nullptr) {
203 LOGI() << "ctor" << ios::GetCurrentThreadDescription(); 201 LOGI() << "ctor" << ios::GetCurrentThreadDescription();
204 } 202 }
205 203
206 AudioDeviceIOS::~AudioDeviceIOS() { 204 AudioDeviceIOS::~AudioDeviceIOS() {
207 LOGI() << "~dtor"; 205 LOGI() << "~dtor";
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 ShutdownPlayOrRecord(); 247 ShutdownPlayOrRecord();
250 initialized_ = false; 248 initialized_ = false;
251 return 0; 249 return 0;
252 } 250 }
253 251
254 int32_t AudioDeviceIOS::InitPlayout() { 252 int32_t AudioDeviceIOS::InitPlayout() {
255 LOGI() << "InitPlayout"; 253 LOGI() << "InitPlayout";
256 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 254 RTC_DCHECK(thread_checker_.CalledOnValidThread());
257 RTC_DCHECK(initialized_); 255 RTC_DCHECK(initialized_);
258 RTC_DCHECK(!play_is_initialized_); 256 RTC_DCHECK(!play_is_initialized_);
259 RTC_DCHECK(!playing_); 257 RTC_DCHECK(!Playing());
260 if (!rec_is_initialized_) { 258 if (!rec_is_initialized_) {
261 if (!InitPlayOrRecord()) { 259 if (!InitPlayOrRecord()) {
262 LOG_F(LS_ERROR) << "InitPlayOrRecord failed!"; 260 LOG_F(LS_ERROR) << "InitPlayOrRecord failed!";
263 return -1; 261 return -1;
264 } 262 }
265 } 263 }
266 play_is_initialized_ = true; 264 play_is_initialized_ = true;
267 return 0; 265 return 0;
268 } 266 }
269 267
270 int32_t AudioDeviceIOS::InitRecording() { 268 int32_t AudioDeviceIOS::InitRecording() {
271 LOGI() << "InitRecording"; 269 LOGI() << "InitRecording";
272 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 270 RTC_DCHECK(thread_checker_.CalledOnValidThread());
273 RTC_DCHECK(initialized_); 271 RTC_DCHECK(initialized_);
274 RTC_DCHECK(!rec_is_initialized_); 272 RTC_DCHECK(!rec_is_initialized_);
275 RTC_DCHECK(!recording_); 273 RTC_DCHECK(!Recording());
276 if (!play_is_initialized_) { 274 if (!play_is_initialized_) {
277 if (!InitPlayOrRecord()) { 275 if (!InitPlayOrRecord()) {
278 LOG_F(LS_ERROR) << "InitPlayOrRecord failed!"; 276 LOG_F(LS_ERROR) << "InitPlayOrRecord failed!";
279 return -1; 277 return -1;
280 } 278 }
281 } 279 }
282 rec_is_initialized_ = true; 280 rec_is_initialized_ = true;
283 return 0; 281 return 0;
284 } 282 }
285 283
286 int32_t AudioDeviceIOS::StartPlayout() { 284 int32_t AudioDeviceIOS::StartPlayout() {
287 LOGI() << "StartPlayout"; 285 LOGI() << "StartPlayout";
288 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 286 RTC_DCHECK(thread_checker_.CalledOnValidThread());
289 RTC_DCHECK(play_is_initialized_); 287 RTC_DCHECK(play_is_initialized_);
290 RTC_DCHECK(!playing_); 288 RTC_DCHECK(!Playing());
291 fine_audio_buffer_->ResetPlayout(); 289 fine_audio_buffer_->ResetPlayout();
292 if (!recording_) { 290 if (!Recording()) {
293 OSStatus result = AudioOutputUnitStart(vpio_unit_); 291 OSStatus result = AudioOutputUnitStart(vpio_unit_);
294 if (result != noErr) { 292 if (result != noErr) {
295 LOG_F(LS_ERROR) << "AudioOutputUnitStart failed: " << result; 293 LOG_F(LS_ERROR) << "AudioOutputUnitStart failed: " << result;
296 return -1; 294 return -1;
297 } 295 }
298 } 296 }
299 rtc::AtomicOps::ReleaseStore(&playing_, 1); 297 rtc::AtomicInt::ReleaseStore(&playing_, 1);
300 return 0; 298 return 0;
301 } 299 }
302 300
303 int32_t AudioDeviceIOS::StopPlayout() { 301 int32_t AudioDeviceIOS::StopPlayout() {
304 LOGI() << "StopPlayout"; 302 LOGI() << "StopPlayout";
305 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 303 RTC_DCHECK(thread_checker_.CalledOnValidThread());
306 if (!play_is_initialized_ || !playing_) { 304 if (!play_is_initialized_ || !Playing()) {
307 return 0; 305 return 0;
308 } 306 }
309 if (!recording_) { 307 if (!Recording()) {
310 ShutdownPlayOrRecord(); 308 ShutdownPlayOrRecord();
311 } 309 }
312 play_is_initialized_ = false; 310 play_is_initialized_ = false;
313 rtc::AtomicOps::ReleaseStore(&playing_, 0); 311 rtc::AtomicInt::ReleaseStore(&playing_, 0);
314 return 0; 312 return 0;
315 } 313 }
316 314
317 int32_t AudioDeviceIOS::StartRecording() { 315 int32_t AudioDeviceIOS::StartRecording() {
318 LOGI() << "StartRecording"; 316 LOGI() << "StartRecording";
319 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 317 RTC_DCHECK(thread_checker_.CalledOnValidThread());
320 RTC_DCHECK(rec_is_initialized_); 318 RTC_DCHECK(rec_is_initialized_);
321 RTC_DCHECK(!recording_); 319 RTC_DCHECK(!Recording());
322 fine_audio_buffer_->ResetRecord(); 320 fine_audio_buffer_->ResetRecord();
323 if (!playing_) { 321 if (!Playing()) {
324 OSStatus result = AudioOutputUnitStart(vpio_unit_); 322 OSStatus result = AudioOutputUnitStart(vpio_unit_);
325 if (result != noErr) { 323 if (result != noErr) {
326 LOG_F(LS_ERROR) << "AudioOutputUnitStart failed: " << result; 324 LOG_F(LS_ERROR) << "AudioOutputUnitStart failed: " << result;
327 return -1; 325 return -1;
328 } 326 }
329 } 327 }
330 rtc::AtomicOps::ReleaseStore(&recording_, 1); 328 rtc::AtomicInt::ReleaseStore(&recording_, 1);
331 return 0; 329 return 0;
332 } 330 }
333 331
334 int32_t AudioDeviceIOS::StopRecording() { 332 int32_t AudioDeviceIOS::StopRecording() {
335 LOGI() << "StopRecording"; 333 LOGI() << "StopRecording";
336 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 334 RTC_DCHECK(thread_checker_.CalledOnValidThread());
337 if (!rec_is_initialized_ || !recording_) { 335 if (!rec_is_initialized_ || !Recording()) {
338 return 0; 336 return 0;
339 } 337 }
340 if (!playing_) { 338 if (!Playing()) {
341 ShutdownPlayOrRecord(); 339 ShutdownPlayOrRecord();
342 } 340 }
343 rec_is_initialized_ = false; 341 rec_is_initialized_ = false;
344 rtc::AtomicOps::ReleaseStore(&recording_, 0); 342 rtc::AtomicInt::ReleaseStore(&recording_, 0);
345 return 0; 343 return 0;
346 } 344 }
347 345
348 // Change the default receiver playout route to speaker. 346 // Change the default receiver playout route to speaker.
349 int32_t AudioDeviceIOS::SetLoudspeakerStatus(bool enable) { 347 int32_t AudioDeviceIOS::SetLoudspeakerStatus(bool enable) {
350 LOGI() << "SetLoudspeakerStatus(" << enable << ")"; 348 LOGI() << "SetLoudspeakerStatus(" << enable << ")";
351 349
352 AVAudioSession* session = [AVAudioSession sharedInstance]; 350 AVAudioSession* session = [AVAudioSession sharedInstance];
353 NSString* category = session.category; 351 NSString* category = session.category;
354 AVAudioSessionCategoryOptions options = session.categoryOptions; 352 AVAudioSessionCategoryOptions options = session.categoryOptions;
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 io_action_flags, in_time_stamp, in_bus_number, in_number_frames); 842 io_action_flags, in_time_stamp, in_bus_number, in_number_frames);
845 } 843 }
846 844
847 OSStatus AudioDeviceIOS::OnRecordedDataIsAvailable( 845 OSStatus AudioDeviceIOS::OnRecordedDataIsAvailable(
848 AudioUnitRenderActionFlags* io_action_flags, 846 AudioUnitRenderActionFlags* io_action_flags,
849 const AudioTimeStamp* in_time_stamp, 847 const AudioTimeStamp* in_time_stamp,
850 UInt32 in_bus_number, 848 UInt32 in_bus_number,
851 UInt32 in_number_frames) { 849 UInt32 in_number_frames) {
852 OSStatus result = noErr; 850 OSStatus result = noErr;
853 // Simply return if recording is not enabled. 851 // Simply return if recording is not enabled.
854 if (!rtc::AtomicOps::AcquireLoad(&recording_)) 852 if (!Recording())
855 return result; 853 return result;
856 if (in_number_frames != record_parameters_.frames_per_buffer()) { 854 if (in_number_frames != record_parameters_.frames_per_buffer()) {
857 // We have seen short bursts (1-2 frames) where |in_number_frames| changes. 855 // We have seen short bursts (1-2 frames) where |in_number_frames| changes.
858 // Add a log to keep track of longer sequences if that should ever happen. 856 // Add a log to keep track of longer sequences if that should ever happen.
859 LOG(LS_WARNING) << "in_number_frames (" << in_number_frames 857 LOG(LS_WARNING) << "in_number_frames (" << in_number_frames
860 << ") != " << record_parameters_.frames_per_buffer(); 858 << ") != " << record_parameters_.frames_per_buffer();
861 } 859 }
862 // Obtain the recorded audio samples by initiating a rendering cycle. 860 // Obtain the recorded audio samples by initiating a rendering cycle.
863 // Since it happens on the input bus, the |io_data| parameter is a reference 861 // Since it happens on the input bus, the |io_data| parameter is a reference
864 // to the preallocated audio buffer list that the audio unit renders into. 862 // to the preallocated audio buffer list that the audio unit renders into.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 // Verify 16-bit, noninterleaved mono PCM signal format. 901 // Verify 16-bit, noninterleaved mono PCM signal format.
904 RTC_DCHECK_EQ(1u, io_data->mNumberBuffers); 902 RTC_DCHECK_EQ(1u, io_data->mNumberBuffers);
905 RTC_DCHECK_EQ(1u, io_data->mBuffers[0].mNumberChannels); 903 RTC_DCHECK_EQ(1u, io_data->mBuffers[0].mNumberChannels);
906 // Get pointer to internal audio buffer to which new audio data shall be 904 // Get pointer to internal audio buffer to which new audio data shall be
907 // written. 905 // written.
908 const UInt32 dataSizeInBytes = io_data->mBuffers[0].mDataByteSize; 906 const UInt32 dataSizeInBytes = io_data->mBuffers[0].mDataByteSize;
909 RTC_CHECK_EQ(dataSizeInBytes / kBytesPerSample, in_number_frames); 907 RTC_CHECK_EQ(dataSizeInBytes / kBytesPerSample, in_number_frames);
910 SInt8* destination = static_cast<SInt8*>(io_data->mBuffers[0].mData); 908 SInt8* destination = static_cast<SInt8*>(io_data->mBuffers[0].mData);
911 // Produce silence and give audio unit a hint about it if playout is not 909 // Produce silence and give audio unit a hint about it if playout is not
912 // activated. 910 // activated.
913 if (!rtc::AtomicOps::AcquireLoad(&playing_)) { 911 if (!Playing()) {
914 *io_action_flags |= kAudioUnitRenderAction_OutputIsSilence; 912 *io_action_flags |= kAudioUnitRenderAction_OutputIsSilence;
915 memset(destination, 0, dataSizeInBytes); 913 memset(destination, 0, dataSizeInBytes);
916 return noErr; 914 return noErr;
917 } 915 }
918 // Read decoded 16-bit PCM samples from WebRTC (using a size that matches 916 // Read decoded 16-bit PCM samples from WebRTC (using a size that matches
919 // the native I/O audio unit) to a preallocated intermediate buffer and 917 // the native I/O audio unit) to a preallocated intermediate buffer and
920 // copy the result to the audio buffer in the |io_data| destination. 918 // copy the result to the audio buffer in the |io_data| destination.
921 SInt8* source = playout_audio_buffer_.get(); 919 SInt8* source = playout_audio_buffer_.get();
922 fine_audio_buffer_->GetPlayoutData(source); 920 fine_audio_buffer_->GetPlayoutData(source);
923 memcpy(destination, source, dataSizeInBytes); 921 memcpy(destination, source, dataSizeInBytes);
924 return noErr; 922 return noErr;
925 } 923 }
926 924
927 } // namespace webrtc 925 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/ios/audio_device_ios.h ('k') | webrtc/modules/pacing/packet_router.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698