| OLD | NEW |
| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 #endif // !defined(NDEBUG) | 92 #endif // !defined(NDEBUG) |
| 93 | 93 |
| 94 AudioDeviceIOS::AudioDeviceIOS() | 94 AudioDeviceIOS::AudioDeviceIOS() |
| 95 : audio_device_buffer_(nullptr), | 95 : audio_device_buffer_(nullptr), |
| 96 audio_unit_(nullptr), | 96 audio_unit_(nullptr), |
| 97 recording_(0), | 97 recording_(0), |
| 98 playing_(0), | 98 playing_(0), |
| 99 initialized_(false), | 99 initialized_(false), |
| 100 rec_is_initialized_(false), | 100 audio_is_initialized_(false), |
| 101 play_is_initialized_(false), | |
| 102 is_interrupted_(false), | 101 is_interrupted_(false), |
| 103 has_configured_session_(false) { | 102 has_configured_session_(false) { |
| 104 LOGI() << "ctor" << ios::GetCurrentThreadDescription(); | 103 LOGI() << "ctor" << ios::GetCurrentThreadDescription(); |
| 105 thread_ = rtc::Thread::Current(); | 104 thread_ = rtc::Thread::Current(); |
| 106 audio_session_observer_ = | 105 audio_session_observer_ = |
| 107 [[RTCAudioSessionDelegateAdapter alloc] initWithObserver:this]; | 106 [[RTCAudioSessionDelegateAdapter alloc] initWithObserver:this]; |
| 108 } | 107 } |
| 109 | 108 |
| 110 AudioDeviceIOS::~AudioDeviceIOS() { | 109 AudioDeviceIOS::~AudioDeviceIOS() { |
| 111 LOGI() << "~dtor" << ios::GetCurrentThreadDescription(); | 110 LOGI() << "~dtor" << ios::GetCurrentThreadDescription(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 StopPlayout(); | 157 StopPlayout(); |
| 159 StopRecording(); | 158 StopRecording(); |
| 160 initialized_ = false; | 159 initialized_ = false; |
| 161 return 0; | 160 return 0; |
| 162 } | 161 } |
| 163 | 162 |
| 164 int32_t AudioDeviceIOS::InitPlayout() { | 163 int32_t AudioDeviceIOS::InitPlayout() { |
| 165 LOGI() << "InitPlayout"; | 164 LOGI() << "InitPlayout"; |
| 166 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 165 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 167 RTC_DCHECK(initialized_); | 166 RTC_DCHECK(initialized_); |
| 168 RTC_DCHECK(!play_is_initialized_); | 167 RTC_DCHECK(!audio_is_initialized_); |
| 169 RTC_DCHECK(!playing_); | 168 RTC_DCHECK(!playing_); |
| 170 if (!rec_is_initialized_) { | 169 if (!audio_is_initialized_) { |
| 171 if (!InitPlayOrRecord()) { | 170 if (!InitPlayOrRecord()) { |
| 172 LOG_F(LS_ERROR) << "InitPlayOrRecord failed for InitPlayout!"; | 171 LOG_F(LS_ERROR) << "InitPlayOrRecord failed for InitPlayout!"; |
| 173 return -1; | 172 return -1; |
| 174 } | 173 } |
| 175 } | 174 } |
| 176 play_is_initialized_ = true; | 175 audio_is_initialized_ = true; |
| 177 return 0; | 176 return 0; |
| 178 } | 177 } |
| 179 | 178 |
| 180 int32_t AudioDeviceIOS::InitRecording() { | 179 int32_t AudioDeviceIOS::InitRecording() { |
| 181 LOGI() << "InitRecording"; | 180 LOGI() << "InitRecording"; |
| 182 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 181 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 183 RTC_DCHECK(initialized_); | 182 RTC_DCHECK(initialized_); |
| 184 RTC_DCHECK(!rec_is_initialized_); | 183 RTC_DCHECK(!audio_is_initialized_); |
| 185 RTC_DCHECK(!recording_); | 184 RTC_DCHECK(!recording_); |
| 186 if (!play_is_initialized_) { | 185 if (!audio_is_initialized_) { |
| 187 if (!InitPlayOrRecord()) { | 186 if (!InitPlayOrRecord()) { |
| 188 LOG_F(LS_ERROR) << "InitPlayOrRecord failed for InitRecording!"; | 187 LOG_F(LS_ERROR) << "InitPlayOrRecord failed for InitRecording!"; |
| 189 return -1; | 188 return -1; |
| 190 } | 189 } |
| 191 } | 190 } |
| 192 rec_is_initialized_ = true; | 191 audio_is_initialized_ = true; |
| 193 return 0; | 192 return 0; |
| 194 } | 193 } |
| 195 | 194 |
| 196 int32_t AudioDeviceIOS::StartPlayout() { | 195 int32_t AudioDeviceIOS::StartPlayout() { |
| 197 LOGI() << "StartPlayout"; | 196 LOGI() << "StartPlayout"; |
| 198 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 197 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 199 RTC_DCHECK(play_is_initialized_); | 198 RTC_DCHECK(audio_is_initialized_); |
| 200 RTC_DCHECK(!playing_); | 199 RTC_DCHECK(!playing_); |
| 201 RTC_DCHECK(audio_unit_); | 200 RTC_DCHECK(audio_unit_); |
| 202 if (fine_audio_buffer_) { | 201 if (fine_audio_buffer_) { |
| 203 fine_audio_buffer_->ResetPlayout(); | 202 fine_audio_buffer_->ResetPlayout(); |
| 204 } | 203 } |
| 205 if (!recording_ && | 204 if (!recording_ && |
| 206 audio_unit_->GetState() == VoiceProcessingAudioUnit::kInitialized) { | 205 audio_unit_->GetState() == VoiceProcessingAudioUnit::kInitialized) { |
| 207 if (!audio_unit_->Start()) { | 206 if (!audio_unit_->Start()) { |
| 208 RTCLogError(@"StartPlayout failed to start audio unit."); | 207 RTCLogError(@"StartPlayout failed to start audio unit."); |
| 209 return -1; | 208 return -1; |
| 210 } | 209 } |
| 211 LOG(LS_INFO) << "Voice-Processing I/O audio unit is now started"; | 210 LOG(LS_INFO) << "Voice-Processing I/O audio unit is now started"; |
| 212 } | 211 } |
| 213 rtc::AtomicOps::ReleaseStore(&playing_, 1); | 212 rtc::AtomicOps::ReleaseStore(&playing_, 1); |
| 214 return 0; | 213 return 0; |
| 215 } | 214 } |
| 216 | 215 |
| 217 int32_t AudioDeviceIOS::StopPlayout() { | 216 int32_t AudioDeviceIOS::StopPlayout() { |
| 218 LOGI() << "StopPlayout"; | 217 LOGI() << "StopPlayout"; |
| 219 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 218 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 220 if (!play_is_initialized_) { | 219 if (!audio_is_initialized_ || !playing_) { |
| 221 return 0; | |
| 222 } | |
| 223 if (!playing_) { | |
| 224 play_is_initialized_ = false; | |
| 225 return 0; | 220 return 0; |
| 226 } | 221 } |
| 227 if (!recording_) { | 222 if (!recording_) { |
| 228 ShutdownPlayOrRecord(); | 223 ShutdownPlayOrRecord(); |
| 224 audio_is_initialized_ = false; |
| 229 } | 225 } |
| 230 play_is_initialized_ = false; | |
| 231 rtc::AtomicOps::ReleaseStore(&playing_, 0); | 226 rtc::AtomicOps::ReleaseStore(&playing_, 0); |
| 232 return 0; | 227 return 0; |
| 233 } | 228 } |
| 234 | 229 |
| 235 int32_t AudioDeviceIOS::StartRecording() { | 230 int32_t AudioDeviceIOS::StartRecording() { |
| 236 LOGI() << "StartRecording"; | 231 LOGI() << "StartRecording"; |
| 237 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 232 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 238 RTC_DCHECK(rec_is_initialized_); | 233 RTC_DCHECK(audio_is_initialized_); |
| 239 RTC_DCHECK(!recording_); | 234 RTC_DCHECK(!recording_); |
| 240 RTC_DCHECK(audio_unit_); | 235 RTC_DCHECK(audio_unit_); |
| 241 if (fine_audio_buffer_) { | 236 if (fine_audio_buffer_) { |
| 242 fine_audio_buffer_->ResetRecord(); | 237 fine_audio_buffer_->ResetRecord(); |
| 243 } | 238 } |
| 244 if (!playing_ && | 239 if (!playing_ && |
| 245 audio_unit_->GetState() == VoiceProcessingAudioUnit::kInitialized) { | 240 audio_unit_->GetState() == VoiceProcessingAudioUnit::kInitialized) { |
| 246 if (!audio_unit_->Start()) { | 241 if (!audio_unit_->Start()) { |
| 247 RTCLogError(@"StartRecording failed to start audio unit."); | 242 RTCLogError(@"StartRecording failed to start audio unit."); |
| 248 return -1; | 243 return -1; |
| 249 } | 244 } |
| 250 LOG(LS_INFO) << "Voice-Processing I/O audio unit is now started"; | 245 LOG(LS_INFO) << "Voice-Processing I/O audio unit is now started"; |
| 251 } | 246 } |
| 252 rtc::AtomicOps::ReleaseStore(&recording_, 1); | 247 rtc::AtomicOps::ReleaseStore(&recording_, 1); |
| 253 return 0; | 248 return 0; |
| 254 } | 249 } |
| 255 | 250 |
| 256 int32_t AudioDeviceIOS::StopRecording() { | 251 int32_t AudioDeviceIOS::StopRecording() { |
| 257 LOGI() << "StopRecording"; | 252 LOGI() << "StopRecording"; |
| 258 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 253 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 259 if (!rec_is_initialized_) { | 254 if (!audio_is_initialized_ || !recording_) { |
| 260 return 0; | |
| 261 } | |
| 262 if (!recording_) { | |
| 263 rec_is_initialized_ = false; | |
| 264 return 0; | 255 return 0; |
| 265 } | 256 } |
| 266 if (!playing_) { | 257 if (!playing_) { |
| 267 ShutdownPlayOrRecord(); | 258 ShutdownPlayOrRecord(); |
| 259 audio_is_initialized_ = false; |
| 268 } | 260 } |
| 269 rec_is_initialized_ = false; | |
| 270 rtc::AtomicOps::ReleaseStore(&recording_, 0); | 261 rtc::AtomicOps::ReleaseStore(&recording_, 0); |
| 271 return 0; | 262 return 0; |
| 272 } | 263 } |
| 273 | 264 |
| 274 // Change the default receiver playout route to speaker. | 265 // Change the default receiver playout route to speaker. |
| 275 int32_t AudioDeviceIOS::SetLoudspeakerStatus(bool enable) { | 266 int32_t AudioDeviceIOS::SetLoudspeakerStatus(bool enable) { |
| 276 LOGI() << "SetLoudspeakerStatus(" << enable << ")"; | 267 LOGI() << "SetLoudspeakerStatus(" << enable << ")"; |
| 277 | 268 |
| 278 RTCAudioSession* session = [RTCAudioSession sharedInstance]; | 269 RTCAudioSession* session = [RTCAudioSession sharedInstance]; |
| 279 [session lockForConfiguration]; | 270 [session lockForConfiguration]; |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 RTCLog(@"Updating audio unit state. CanPlayOrRecord=%d IsInterrupted=%d", | 673 RTCLog(@"Updating audio unit state. CanPlayOrRecord=%d IsInterrupted=%d", |
| 683 can_play_or_record, is_interrupted_); | 674 can_play_or_record, is_interrupted_); |
| 684 | 675 |
| 685 if (is_interrupted_) { | 676 if (is_interrupted_) { |
| 686 RTCLog(@"Ignoring audio unit update due to interruption."); | 677 RTCLog(@"Ignoring audio unit update due to interruption."); |
| 687 return; | 678 return; |
| 688 } | 679 } |
| 689 | 680 |
| 690 // If we're not initialized we don't need to do anything. Audio unit will | 681 // If we're not initialized we don't need to do anything. Audio unit will |
| 691 // be initialized on initialization. | 682 // be initialized on initialization. |
| 692 if (!rec_is_initialized_ && !play_is_initialized_) | 683 if (!audio_is_initialized_) |
| 693 return; | 684 return; |
| 694 | 685 |
| 695 // If we're initialized, we must have an audio unit. | 686 // If we're initialized, we must have an audio unit. |
| 696 RTC_DCHECK(audio_unit_); | 687 RTC_DCHECK(audio_unit_); |
| 697 | 688 |
| 698 bool should_initialize_audio_unit = false; | 689 bool should_initialize_audio_unit = false; |
| 699 bool should_uninitialize_audio_unit = false; | 690 bool should_uninitialize_audio_unit = false; |
| 700 bool should_start_audio_unit = false; | 691 bool should_start_audio_unit = false; |
| 701 bool should_stop_audio_unit = false; | 692 bool should_stop_audio_unit = false; |
| 702 | 693 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 | 832 |
| 842 // All I/O should be stopped or paused prior to deactivating the audio | 833 // All I/O should be stopped or paused prior to deactivating the audio |
| 843 // session, hence we deactivate as last action. | 834 // session, hence we deactivate as last action. |
| 844 [session lockForConfiguration]; | 835 [session lockForConfiguration]; |
| 845 UnconfigureAudioSession(); | 836 UnconfigureAudioSession(); |
| 846 [session endWebRTCSession:nil]; | 837 [session endWebRTCSession:nil]; |
| 847 [session unlockForConfiguration]; | 838 [session unlockForConfiguration]; |
| 848 } | 839 } |
| 849 | 840 |
| 850 } // namespace webrtc | 841 } // namespace webrtc |
| OLD | NEW |