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

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

Issue 2063733002: Resolves issue with bad audio using BT headsets on iOS (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: improved comments Created 4 years, 6 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
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 RTC_CHECK_EQ(size_in_bytes / VoiceProcessingAudioUnit::kBytesPerSample, 424 RTC_CHECK_EQ(size_in_bytes / VoiceProcessingAudioUnit::kBytesPerSample,
425 num_frames); 425 num_frames);
426 int8_t* destination = reinterpret_cast<int8_t*>(audio_buffer->mData); 426 int8_t* destination = reinterpret_cast<int8_t*>(audio_buffer->mData);
427 // Produce silence and give audio unit a hint about it if playout is not 427 // Produce silence and give audio unit a hint about it if playout is not
428 // activated. 428 // activated.
429 if (!rtc::AtomicOps::AcquireLoad(&playing_)) { 429 if (!rtc::AtomicOps::AcquireLoad(&playing_)) {
430 *flags |= kAudioUnitRenderAction_OutputIsSilence; 430 *flags |= kAudioUnitRenderAction_OutputIsSilence;
431 memset(destination, 0, size_in_bytes); 431 memset(destination, 0, size_in_bytes);
432 return noErr; 432 return noErr;
433 } 433 }
434 // Produce silence and log a warning message for the case when Core Audio is
435 // asking for an invalid number of audio frames. I don't expect this to happen
436 // but it is done as a safety measure to avoid bad audio if such as case would
437 // ever be triggered e.g. in combination with BT devices.
438 const size_t frames_per_buffer = playout_parameters_.frames_per_buffer();
439 if (num_frames != frames_per_buffer) {
440 RTCLogWarning(@"Expected %u frames but got %u",
441 static_cast<unsigned int>(frames_per_buffer),
442 static_cast<unsigned int>(num_frames));
443 *flags |= kAudioUnitRenderAction_OutputIsSilence;
444 memset(destination, 0, size_in_bytes);
445 return noErr;
446 }
447
434 // Read decoded 16-bit PCM samples from WebRTC (using a size that matches 448 // Read decoded 16-bit PCM samples from WebRTC (using a size that matches
435 // the native I/O audio unit) to a preallocated intermediate buffer and 449 // the native I/O audio unit) to a preallocated intermediate buffer and
436 // copy the result to the audio buffer in the |io_data| destination. 450 // copy the result to the audio buffer in the |io_data| destination.
437 int8_t* source = playout_audio_buffer_.get(); 451 int8_t* source = playout_audio_buffer_.get();
438 fine_audio_buffer_->GetPlayoutData(source); 452 fine_audio_buffer_->GetPlayoutData(source);
439 memcpy(destination, source, size_in_bytes); 453 memcpy(destination, source, size_in_bytes);
440 return noErr; 454 return noErr;
441 } 455 }
442 456
443 void AudioDeviceIOS::OnMessage(rtc::Message *msg) { 457 void AudioDeviceIOS::OnMessage(rtc::Message *msg) {
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 831
818 // All I/O should be stopped or paused prior to deactivating the audio 832 // All I/O should be stopped or paused prior to deactivating the audio
819 // session, hence we deactivate as last action. 833 // session, hence we deactivate as last action.
820 [session lockForConfiguration]; 834 [session lockForConfiguration];
821 UnconfigureAudioSession(); 835 UnconfigureAudioSession();
822 [session endWebRTCSession:nil]; 836 [session endWebRTCSession:nil];
823 [session unlockForConfiguration]; 837 [session unlockForConfiguration];
824 } 838 }
825 839
826 } // namespace webrtc 840 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698