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

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

Powered by Google App Engine
This is Rietveld 408576698