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

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

Issue 2822233002: Don't call unconfigureWebRTCSession if setConfiguration fails. webrtc:7471 (Closed)
Patch Set: Handle configure failure in audio_device_ios.mm Created 3 years, 8 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 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 case VoiceProcessingAudioUnit::kStarted: 710 case VoiceProcessingAudioUnit::kStarted:
711 RTCLog(@"VPAU state: Started"); 711 RTCLog(@"VPAU state: Started");
712 RTC_DCHECK(playing_ || recording_); 712 RTC_DCHECK(playing_ || recording_);
713 should_stop_audio_unit = !can_play_or_record; 713 should_stop_audio_unit = !can_play_or_record;
714 should_uninitialize_audio_unit = should_stop_audio_unit; 714 should_uninitialize_audio_unit = should_stop_audio_unit;
715 break; 715 break;
716 } 716 }
717 717
718 if (should_initialize_audio_unit) { 718 if (should_initialize_audio_unit) {
719 RTCLog(@"Initializing audio unit for UpdateAudioUnit"); 719 RTCLog(@"Initializing audio unit for UpdateAudioUnit");
720 ConfigureAudioSession(); 720 if (ConfigureAudioSession()) {
721 SetupAudioBuffersForActiveAudioSession(); 721 SetupAudioBuffersForActiveAudioSession();
722 if (!audio_unit_->Initialize(playout_parameters_.sample_rate())) { 722 if (!audio_unit_->Initialize(playout_parameters_.sample_rate())) {
723 RTCLogError(@"Failed to initialize audio unit."); 723 RTCLogError(@"Failed to initialize audio unit.");
724 return;
725 }
726 } else {
727 RTCLogError(@"Failed to configure audio unit.");
tkchin_webrtc 2017/04/18 21:06:33 misleading - the audio unit is never configured he
jtt_webrtc 2017/04/18 21:28:05 Callers may assume that the audio session has been
tkchin_webrtc 2017/04/21 19:52:21 I'm worried that this will break existing situatio
jtt_webrtc 2017/04/21 20:12:15 I'll change it so that SetupAudioBuffersForActiveA
724 return; 728 return;
725 } 729 }
726 } 730 }
727 731
728 if (should_start_audio_unit) { 732 if (should_start_audio_unit) {
729 RTCLog(@"Starting audio unit for UpdateAudioUnit"); 733 RTCLog(@"Starting audio unit for UpdateAudioUnit");
730 // Log session settings before trying to start audio streaming. 734 // Log session settings before trying to start audio streaming.
731 RTCAudioSession* session = [RTCAudioSession sharedInstance]; 735 RTCAudioSession* session = [RTCAudioSession sharedInstance];
732 RTCLog(@"%@", session); 736 RTCLog(@"%@", session);
733 if (!audio_unit_->Start()) { 737 if (!audio_unit_->Start()) {
(...skipping 10 matching lines...) Expand all
744 } 748 }
745 } 749 }
746 750
747 if (should_uninitialize_audio_unit) { 751 if (should_uninitialize_audio_unit) {
748 RTCLog(@"Uninitializing audio unit for UpdateAudioUnit"); 752 RTCLog(@"Uninitializing audio unit for UpdateAudioUnit");
749 audio_unit_->Uninitialize(); 753 audio_unit_->Uninitialize();
750 UnconfigureAudioSession(); 754 UnconfigureAudioSession();
751 } 755 }
752 } 756 }
753 757
754 void AudioDeviceIOS::ConfigureAudioSession() { 758 bool AudioDeviceIOS::ConfigureAudioSession() {
755 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 759 RTC_DCHECK(thread_checker_.CalledOnValidThread());
756 RTCLog(@"Configuring audio session."); 760 RTCLog(@"Configuring audio session.");
757 if (has_configured_session_) { 761 if (has_configured_session_) {
758 RTCLogWarning(@"Audio session already configured."); 762 RTCLogWarning(@"Audio session already configured.");
759 return; 763 return false;
760 } 764 }
761 RTCAudioSession* session = [RTCAudioSession sharedInstance]; 765 RTCAudioSession* session = [RTCAudioSession sharedInstance];
762 [session lockForConfiguration]; 766 [session lockForConfiguration];
763 [session configureWebRTCSession:nil]; 767 has_configured_session_ = [session configureWebRTCSession:nil];
764 [session unlockForConfiguration]; 768 [session unlockForConfiguration];
765 has_configured_session_ = true;
766 RTCLog(@"Configured audio session."); 769 RTCLog(@"Configured audio session.");
tkchin_webrtc 2017/04/21 19:52:21 This isn't true if the session configuration faile
jtt_webrtc 2017/04/21 20:12:16 Done.
770 return has_configured_session_;
767 } 771 }
768 772
769 void AudioDeviceIOS::UnconfigureAudioSession() { 773 void AudioDeviceIOS::UnconfigureAudioSession() {
770 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 774 RTC_DCHECK(thread_checker_.CalledOnValidThread());
771 RTCLog(@"Unconfiguring audio session."); 775 RTCLog(@"Unconfiguring audio session.");
772 if (!has_configured_session_) { 776 if (!has_configured_session_) {
773 RTCLogWarning(@"Audio session already unconfigured."); 777 RTCLogWarning(@"Audio session already unconfigured.");
774 return; 778 return;
775 } 779 }
776 RTCAudioSession* session = [RTCAudioSession sharedInstance]; 780 RTCAudioSession* session = [RTCAudioSession sharedInstance];
(...skipping 21 matching lines...) Expand all
798 NSError* error = nil; 802 NSError* error = nil;
799 if (![session beginWebRTCSession:&error]) { 803 if (![session beginWebRTCSession:&error]) {
800 [session unlockForConfiguration]; 804 [session unlockForConfiguration];
801 RTCLogError(@"Failed to begin WebRTC session: %@", 805 RTCLogError(@"Failed to begin WebRTC session: %@",
802 error.localizedDescription); 806 error.localizedDescription);
803 return false; 807 return false;
804 } 808 }
805 809
806 // If we are ready to play or record, initialize the audio unit. 810 // If we are ready to play or record, initialize the audio unit.
807 if (session.canPlayOrRecord) { 811 if (session.canPlayOrRecord) {
808 ConfigureAudioSession(); 812 if (ConfigureAudioSession()) {
809 SetupAudioBuffersForActiveAudioSession(); 813 SetupAudioBuffersForActiveAudioSession();
810 audio_unit_->Initialize(playout_parameters_.sample_rate()); 814 audio_unit_->Initialize(playout_parameters_.sample_rate());
815 }
811 } 816 }
812 817
813 // Release the lock. 818 // Release the lock.
814 [session unlockForConfiguration]; 819 [session unlockForConfiguration];
815 820
816 return true; 821 return has_configured_session_;
817 } 822 }
818 823
819 void AudioDeviceIOS::ShutdownPlayOrRecord() { 824 void AudioDeviceIOS::ShutdownPlayOrRecord() {
820 LOGI() << "ShutdownPlayOrRecord"; 825 LOGI() << "ShutdownPlayOrRecord";
821 826
822 // Stop the audio unit to prevent any additional audio callbacks. 827 // Stop the audio unit to prevent any additional audio callbacks.
823 audio_unit_->Stop(); 828 audio_unit_->Stop();
824 829
825 // Close and delete the voice-processing I/O unit. 830 // Close and delete the voice-processing I/O unit.
826 audio_unit_.reset(); 831 audio_unit_.reset();
827 832
828 // Remove audio session notification observers. 833 // Remove audio session notification observers.
829 RTCAudioSession* session = [RTCAudioSession sharedInstance]; 834 RTCAudioSession* session = [RTCAudioSession sharedInstance];
830 [session removeDelegate:audio_session_observer_]; 835 [session removeDelegate:audio_session_observer_];
831 836
832 // All I/O should be stopped or paused prior to deactivating the audio 837 // All I/O should be stopped or paused prior to deactivating the audio
833 // session, hence we deactivate as last action. 838 // session, hence we deactivate as last action.
834 [session lockForConfiguration]; 839 [session lockForConfiguration];
835 UnconfigureAudioSession(); 840 UnconfigureAudioSession();
836 [session endWebRTCSession:nil]; 841 [session endWebRTCSession:nil];
837 [session unlockForConfiguration]; 842 [session unlockForConfiguration];
838 } 843 }
839 844
840 } // namespace webrtc 845 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/ios/audio_device_ios.h ('k') | webrtc/modules/audio_device/ios/objc/RTCAudioSession.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698