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

Side by Side Diff: webrtc/modules/audio_device/ios/objc/RTCAudioSession.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
« no previous file with comments | « webrtc/modules/audio_device/ios/audio_device_ios.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2016 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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 // TODO(tkchin): Figure out if this is really necessary. 629 // TODO(tkchin): Figure out if this is really necessary.
630 if (!self.inputAvailable) { 630 if (!self.inputAvailable) {
631 RTCLogError(@"No audio input path is available!"); 631 RTCLogError(@"No audio input path is available!");
632 [self unconfigureWebRTCSession:nil]; 632 [self unconfigureWebRTCSession:nil];
633 if (outError) { 633 if (outError) {
634 *outError = [self configurationErrorWithDescription:@"No input path."]; 634 *outError = [self configurationErrorWithDescription:@"No input path."];
635 } 635 }
636 return NO; 636 return NO;
637 } 637 }
638 638
639 // It can happen (e.g. in combination with BT devices) that the attempt to set
tkchin_webrtc 2016/06/14 19:13:28 It seems like we should do this on route changes,
henrika_webrtc 2016/06/15 13:46:58 But the problem is that it does not work since we
640 // the preferred sample rate for WebRTC (48kHz) fails. If so, disable the
641 // current session and make a new configuration attempt using the sample rate
642 // that worked. A typical case is that only 8 or 16kHz can be set, e.g. in
643 // combination with BT headsets. Using this "trick" seems to avoid a state
644 // where Core Audio asks for a different number of audio frames than what the
645 // session's I/O buffer duration corresponds to.
646 // TODO(henrika): this fix resolves b/29185303 but it has only been tested on
tkchin_webrtc 2016/06/14 19:13:28 Don't reference buganizer in webrtc. File a corres
henrika_webrtc 2016/06/15 13:46:58 Done.
647 // a limited set of iOS devices and BT devices.
648 double session_sample_rate = self.sampleRate;
649 double preferred_sample_rate = webRTCConfig.sampleRate;
650 if (session_sample_rate != preferred_sample_rate) {
651 RTCLogWarning(
652 @"Current sample rate (%.2f) is not the preferred rate (%.2f)",
653 session_sample_rate, preferred_sample_rate);
654 // Perform a second configuration attempt but use a sample rate that is
655 // known to work this time instead (e.g. 8 or 16kHz in combination with BT
656 // headsets).
657 RTCLog(@"Configuring audio session for WebRTC using new sample rate.");
658 [self unconfigureWebRTCSession:nil];
tkchin_webrtc 2016/06/14 19:13:28 this won't work if there are multiple activations
henrika_webrtc 2016/06/15 13:46:58 Missed that. I actually started out by making the
659 webRTCConfig.sampleRate = session_sample_rate;
660 [RTCAudioSessionConfiguration setWebRTCConfiguration:webRTCConfig];
tkchin_webrtc 2016/06/14 19:13:28 I don't think we should set the default because we
henrika_webrtc 2016/06/15 13:46:58 Agree that it is not a clean solution. Will rethin
661 if (![self setConfiguration:webRTCConfig active:YES error:&error]) {
662 RTCLogError(@"Failed to set WebRTC audio configuration: %@",
663 error.localizedDescription);
664 [self unconfigureWebRTCSession:nil];
665 if (outError) {
666 *outError = error;
667 }
668 return NO;
669 }
670 // Restore original WebRTC configuration parameters.
671 webRTCConfig.sampleRate = preferred_sample_rate;
672 [RTCAudioSessionConfiguration setWebRTCConfiguration:webRTCConfig];
673 }
674
639 return YES; 675 return YES;
640 } 676 }
641 677
642 - (BOOL)unconfigureWebRTCSession:(NSError **)outError { 678 - (BOOL)unconfigureWebRTCSession:(NSError **)outError {
643 if (outError) { 679 if (outError) {
644 *outError = nil; 680 *outError = nil;
645 } 681 }
646 if (![self checkLock:outError]) { 682 if (![self checkLock:outError]) {
647 return NO; 683 return NO;
648 } 684 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 - (void)notifyDidStopPlayOrRecord { 799 - (void)notifyDidStopPlayOrRecord {
764 for (auto delegate : self.delegates) { 800 for (auto delegate : self.delegates) {
765 SEL sel = @selector(audioSessionDidStopPlayOrRecord:); 801 SEL sel = @selector(audioSessionDidStopPlayOrRecord:);
766 if ([delegate respondsToSelector:sel]) { 802 if ([delegate respondsToSelector:sel]) {
767 [delegate audioSessionDidStopPlayOrRecord:self]; 803 [delegate audioSessionDidStopPlayOrRecord:self];
768 } 804 }
769 } 805 }
770 } 806 }
771 807
772 @end 808 @end
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/ios/audio_device_ios.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698