niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
xians@webrtc.org | 79af734 | 2012-01-31 12:22:14 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "voice_engine/voe_base_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #include "common_audio/signal_processing/include/signal_processing_library.h" |
| 14 | #include "modules/audio_coding/include/audio_coding_module.h" |
| 15 | #include "modules/audio_device/audio_device_impl.h" |
| 16 | #include "modules/audio_processing/include/audio_processing.h" |
| 17 | #include "rtc_base/format_macros.h" |
| 18 | #include "rtc_base/location.h" |
| 19 | #include "rtc_base/logging.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "voice_engine/channel.h" |
| 21 | #include "voice_engine/include/voe_errors.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "voice_engine/transmit_mixer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "voice_engine/voice_engine_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 25 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 27 | VoEBase* VoEBase::GetInterface(VoiceEngine* voiceEngine) { |
| 28 | if (nullptr == voiceEngine) { |
| 29 | return nullptr; |
| 30 | } |
| 31 | VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); |
| 32 | s->AddRef(); |
| 33 | return s; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 36 | VoEBaseImpl::VoEBaseImpl(voe::SharedData* shared) |
solenberg | fc3a2e3 | 2017-09-26 09:35:01 -0700 | [diff] [blame] | 37 | : shared_(shared) {} |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 38 | |
| 39 | VoEBaseImpl::~VoEBaseImpl() { |
| 40 | TerminateInternal(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | } |
| 42 | |
henrika | ec6fbd2 | 2017-03-31 05:43:36 -0700 | [diff] [blame] | 43 | int32_t VoEBaseImpl::RecordedDataIsAvailable( |
| 44 | const void* audio_data, |
| 45 | const size_t number_of_frames, |
| 46 | const size_t bytes_per_sample, |
| 47 | const size_t number_of_channels, |
| 48 | const uint32_t sample_rate, |
| 49 | const uint32_t audio_delay_milliseconds, |
| 50 | const int32_t clock_drift, |
| 51 | const uint32_t volume, |
| 52 | const bool key_pressed, |
| 53 | uint32_t& new_mic_volume) { |
| 54 | RTC_DCHECK_EQ(2 * number_of_channels, bytes_per_sample); |
| 55 | RTC_DCHECK(shared_->transmit_mixer() != nullptr); |
| 56 | RTC_DCHECK(shared_->audio_device() != nullptr); |
| 57 | |
| 58 | uint32_t max_volume = 0; |
| 59 | uint16_t voe_mic_level = 0; |
| 60 | // Check for zero to skip this calculation; the consumer may use this to |
| 61 | // indicate no volume is available. |
| 62 | if (volume != 0) { |
| 63 | // Scale from ADM to VoE level range |
| 64 | if (shared_->audio_device()->MaxMicrophoneVolume(&max_volume) == 0) { |
| 65 | if (max_volume) { |
| 66 | voe_mic_level = static_cast<uint16_t>( |
| 67 | (volume * kMaxVolumeLevel + static_cast<int>(max_volume / 2)) / |
| 68 | max_volume); |
| 69 | } |
| 70 | } |
| 71 | // We learned that on certain systems (e.g Linux) the voe_mic_level |
| 72 | // can be greater than the maxVolumeLevel therefore |
| 73 | // we are going to cap the voe_mic_level to the maxVolumeLevel |
| 74 | // and change the maxVolume to volume if it turns out that |
| 75 | // the voe_mic_level is indeed greater than the maxVolumeLevel. |
| 76 | if (voe_mic_level > kMaxVolumeLevel) { |
| 77 | voe_mic_level = kMaxVolumeLevel; |
| 78 | max_volume = volume; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // Perform channel-independent operations |
| 83 | // (APM, mix with file, record to file, mute, etc.) |
| 84 | shared_->transmit_mixer()->PrepareDemux( |
| 85 | audio_data, number_of_frames, number_of_channels, sample_rate, |
| 86 | static_cast<uint16_t>(audio_delay_milliseconds), clock_drift, |
| 87 | voe_mic_level, key_pressed); |
| 88 | |
| 89 | // Copy the audio frame to each sending channel and perform |
| 90 | // channel-dependent operations (file mixing, mute, etc.), encode and |
| 91 | // packetize+transmit the RTP packet. |
| 92 | shared_->transmit_mixer()->ProcessAndEncodeAudio(); |
| 93 | |
| 94 | // Scale from VoE to ADM level range. |
| 95 | uint32_t new_voe_mic_level = shared_->transmit_mixer()->CaptureLevel(); |
| 96 | if (new_voe_mic_level != voe_mic_level) { |
| 97 | // Return the new volume if AGC has changed the volume. |
| 98 | return static_cast<int>((new_voe_mic_level * max_volume + |
| 99 | static_cast<int>(kMaxVolumeLevel / 2)) / |
| 100 | kMaxVolumeLevel); |
| 101 | } |
| 102 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 103 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | } |
| 105 | |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 106 | int32_t VoEBaseImpl::NeedMorePlayData(const size_t nSamples, |
| 107 | const size_t nBytesPerSample, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 108 | const size_t nChannels, |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 109 | const uint32_t samplesPerSec, |
| 110 | void* audioSamples, |
| 111 | size_t& nSamplesOut, |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 112 | int64_t* elapsed_time_ms, |
| 113 | int64_t* ntp_time_ms) { |
solenberg | 2397b9a | 2017-09-22 06:48:10 -0700 | [diff] [blame] | 114 | RTC_NOTREACHED(); |
xians@webrtc.org | 5692531 | 2014-04-14 10:50:37 +0000 | [diff] [blame] | 115 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | } |
| 117 | |
xians@webrtc.org | 5692531 | 2014-04-14 10:50:37 +0000 | [diff] [blame] | 118 | void VoEBaseImpl::PushCaptureData(int voe_channel, const void* audio_data, |
| 119 | int bits_per_sample, int sample_rate, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 120 | size_t number_of_channels, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 121 | size_t number_of_frames) { |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 122 | voe::ChannelOwner ch = shared_->channel_manager().GetChannel(voe_channel); |
henrika | ec6fbd2 | 2017-03-31 05:43:36 -0700 | [diff] [blame] | 123 | voe::Channel* channel = ch.channel(); |
| 124 | if (!channel) |
| 125 | return; |
| 126 | if (channel->Sending()) { |
| 127 | // Send the audio to each channel directly without using the APM in the |
| 128 | // transmit mixer. |
| 129 | channel->ProcessAndEncodeAudio(static_cast<const int16_t*>(audio_data), |
| 130 | sample_rate, number_of_frames, |
| 131 | number_of_channels); |
xians@webrtc.org | 07e5196 | 2014-01-29 13:54:02 +0000 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 135 | void VoEBaseImpl::PullRenderData(int bits_per_sample, |
| 136 | int sample_rate, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 137 | size_t number_of_channels, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 138 | size_t number_of_frames, |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 139 | void* audio_data, int64_t* elapsed_time_ms, |
wu@webrtc.org | cb711f7 | 2014-05-19 17:39:11 +0000 | [diff] [blame] | 140 | int64_t* ntp_time_ms) { |
solenberg | 2397b9a | 2017-09-22 06:48:10 -0700 | [diff] [blame] | 141 | RTC_NOTREACHED(); |
xians@webrtc.org | 5692531 | 2014-04-14 10:50:37 +0000 | [diff] [blame] | 142 | } |
| 143 | |
ossu | 5f7cfa5 | 2016-05-30 08:11:28 -0700 | [diff] [blame] | 144 | int VoEBaseImpl::Init( |
| 145 | AudioDeviceModule* external_adm, |
peah | e67bedb | 2017-07-07 04:25:11 -0700 | [diff] [blame] | 146 | AudioProcessing* audio_processing, |
ossu | 5f7cfa5 | 2016-05-30 08:11:28 -0700 | [diff] [blame] | 147 | const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) { |
peah | e67bedb | 2017-07-07 04:25:11 -0700 | [diff] [blame] | 148 | RTC_DCHECK(audio_processing); |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 149 | rtc::CritScope cs(shared_->crit_sec()); |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 150 | WebRtcSpl_Init(); |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 151 | if (shared_->process_thread()) { |
| 152 | shared_->process_thread()->Start(); |
| 153 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 154 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 155 | // Create an internal ADM if the user has not added an external |
| 156 | // ADM implementation as input to Init(). |
| 157 | if (external_adm == nullptr) { |
Tommi | 931e658 | 2015-05-20 09:44:38 +0200 | [diff] [blame] | 158 | #if !defined(WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE) |
| 159 | return -1; |
| 160 | #else |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 161 | // Create the internal ADM implementation. |
Peter Boström | 4adbbcf | 2016-05-03 15:51:26 -0400 | [diff] [blame] | 162 | shared_->set_audio_device(AudioDeviceModule::Create( |
solenberg | 5b3e49a | 2017-03-15 08:08:07 -0700 | [diff] [blame] | 163 | VoEId(shared_->instance_id(), -1), |
| 164 | AudioDeviceModule::kPlatformDefaultAudio)); |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 165 | if (shared_->audio_device() == nullptr) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 166 | LOG(LS_ERROR) << "Init() failed to create the ADM"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 167 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 168 | } |
Tommi | 931e658 | 2015-05-20 09:44:38 +0200 | [diff] [blame] | 169 | #endif // WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 170 | } else { |
| 171 | // Use the already existing external ADM implementation. |
| 172 | shared_->set_audio_device(external_adm); |
| 173 | LOG_F(LS_INFO) |
| 174 | << "An external ADM implementation will be used in VoiceEngine"; |
| 175 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 176 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 177 | bool available = false; |
andrew@webrtc.org | f458916 | 2011-10-03 15:22:28 +0000 | [diff] [blame] | 178 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 179 | // -------------------- |
| 180 | // Reinitialize the ADM |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 181 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 182 | // Register the AudioTransport implementation |
| 183 | if (shared_->audio_device()->RegisterAudioCallback(this) != 0) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 184 | LOG(LS_ERROR) << "Init() failed to register audio callback for the ADM"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 185 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 186 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 187 | // ADM initialization |
| 188 | if (shared_->audio_device()->Init() != 0) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 189 | LOG(LS_ERROR) << "Init() failed to initialize the ADM"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 190 | return -1; |
| 191 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 192 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 193 | // Initialize the default speaker |
| 194 | if (shared_->audio_device()->SetPlayoutDevice( |
| 195 | WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE) != 0) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 196 | LOG(LS_ERROR) << "Init() failed to set the default output device"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 197 | } |
| 198 | if (shared_->audio_device()->InitSpeaker() != 0) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 199 | LOG(LS_ERROR) << "Init() failed to initialize the speaker"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 200 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 201 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 202 | // Initialize the default microphone |
| 203 | if (shared_->audio_device()->SetRecordingDevice( |
| 204 | WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE) != 0) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 205 | LOG(LS_ERROR) << "Init() failed to set the default input device"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 206 | } |
| 207 | if (shared_->audio_device()->InitMicrophone() != 0) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 208 | LOG(LS_ERROR) << "Init() failed to initialize the microphone"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 209 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 210 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 211 | // Set number of channels |
| 212 | if (shared_->audio_device()->StereoPlayoutIsAvailable(&available) != 0) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 213 | LOG(LS_ERROR) << "Init() failed to query stereo playout mode"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 214 | } |
| 215 | if (shared_->audio_device()->SetStereoPlayout(available) != 0) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 216 | LOG(LS_ERROR) << "Init() failed to set mono/stereo playout mode"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 217 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 218 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 219 | // TODO(andrew): These functions don't tell us whether stereo recording |
| 220 | // is truly available. We simply set the AudioProcessing input to stereo |
| 221 | // here, because we have to wait until receiving the first frame to |
| 222 | // determine the actual number of channels anyway. |
| 223 | // |
| 224 | // These functions may be changed; tracked here: |
| 225 | // http://code.google.com/p/webrtc/issues/detail?id=204 |
| 226 | shared_->audio_device()->StereoRecordingIsAvailable(&available); |
| 227 | if (shared_->audio_device()->SetStereoRecording(available) != 0) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 228 | LOG(LS_ERROR) << "Init() failed to set mono/stereo recording mode"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 229 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 230 | |
peah | e67bedb | 2017-07-07 04:25:11 -0700 | [diff] [blame] | 231 | shared_->set_audio_processing(audio_processing); |
niklas.enbom@webrtc.org | e33a102 | 2011-11-16 10:33:53 +0000 | [diff] [blame] | 232 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 233 | // Configure AudioProcessing components. |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 234 | // TODO(peah): Move this initialization to webrtcvoiceengine.cc. |
peah | e67bedb | 2017-07-07 04:25:11 -0700 | [diff] [blame] | 235 | if (audio_processing->high_pass_filter()->Enable(true) != 0) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 236 | LOG_F(LS_ERROR) << "Failed to enable high pass filter."; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 237 | return -1; |
| 238 | } |
peah | e67bedb | 2017-07-07 04:25:11 -0700 | [diff] [blame] | 239 | if (audio_processing->echo_cancellation()->enable_drift_compensation(false) != |
| 240 | 0) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 241 | LOG_F(LS_ERROR) << "Failed to disable drift compensation."; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 242 | return -1; |
| 243 | } |
peah | e67bedb | 2017-07-07 04:25:11 -0700 | [diff] [blame] | 244 | if (audio_processing->noise_suppression()->set_level(kDefaultNsMode) != 0) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 245 | LOG_F(LS_ERROR) << "Failed to set noise suppression level: " |
| 246 | << kDefaultNsMode; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 247 | return -1; |
| 248 | } |
peah | e67bedb | 2017-07-07 04:25:11 -0700 | [diff] [blame] | 249 | GainControl* agc = audio_processing->gain_control(); |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 250 | if (agc->set_analog_level_limits(kMinVolumeLevel, kMaxVolumeLevel) != 0) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 251 | LOG_F(LS_ERROR) << "Failed to set analog level limits with minimum: " |
| 252 | << kMinVolumeLevel << " and maximum: " << kMaxVolumeLevel; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 253 | return -1; |
| 254 | } |
| 255 | if (agc->set_mode(kDefaultAgcMode) != 0) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 256 | LOG_F(LS_ERROR) << "Failed to set mode: " << kDefaultAgcMode; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 257 | return -1; |
| 258 | } |
| 259 | if (agc->Enable(kDefaultAgcState) != 0) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 260 | LOG_F(LS_ERROR) << "Failed to set agc state: " << kDefaultAgcState; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 261 | return -1; |
| 262 | } |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 263 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 264 | #ifdef WEBRTC_VOICE_ENGINE_AGC |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 265 | bool agc_enabled = |
| 266 | agc->mode() == GainControl::kAdaptiveAnalog && agc->is_enabled(); |
| 267 | if (shared_->audio_device()->SetAGC(agc_enabled) != 0) { |
Jelena Marusic | f353dd5 | 2015-05-06 15:04:22 +0200 | [diff] [blame] | 268 | LOG_F(LS_ERROR) << "Failed to set agc to enabled: " << agc_enabled; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 269 | // TODO(ajm): No error return here due to |
| 270 | // https://code.google.com/p/webrtc/issues/detail?id=1464 |
| 271 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 272 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 273 | |
Karl Wiberg | f3850f6 | 2017-11-02 13:04:41 +0100 | [diff] [blame^] | 274 | RTC_DCHECK(decoder_factory); |
| 275 | decoder_factory_ = decoder_factory; |
ossu | 5f7cfa5 | 2016-05-30 08:11:28 -0700 | [diff] [blame] | 276 | |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 277 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 280 | int VoEBaseImpl::Terminate() { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 281 | rtc::CritScope cs(shared_->crit_sec()); |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 282 | return TerminateInternal(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 283 | } |
| 284 | |
turaj@webrtc.org | 03f3370 | 2013-11-13 00:02:48 +0000 | [diff] [blame] | 285 | int VoEBaseImpl::CreateChannel() { |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 286 | return CreateChannel(ChannelConfig()); |
turaj@webrtc.org | 03f3370 | 2013-11-13 00:02:48 +0000 | [diff] [blame] | 287 | } |
| 288 | |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 289 | int VoEBaseImpl::CreateChannel(const ChannelConfig& config) { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 290 | rtc::CritScope cs(shared_->crit_sec()); |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 291 | ChannelConfig config_copy(config); |
| 292 | config_copy.acm_config.decoder_factory = decoder_factory_; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 293 | voe::ChannelOwner channel_owner = |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 294 | shared_->channel_manager().CreateChannel(config_copy); |
turaj@webrtc.org | 03f3370 | 2013-11-13 00:02:48 +0000 | [diff] [blame] | 295 | return InitializeChannel(&channel_owner); |
| 296 | } |
| 297 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 298 | int VoEBaseImpl::InitializeChannel(voe::ChannelOwner* channel_owner) { |
| 299 | if (channel_owner->channel()->SetEngineInformation( |
solenberg | 796b8f9 | 2017-03-01 17:02:23 -0800 | [diff] [blame] | 300 | *shared_->process_thread(), *shared_->audio_device(), |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 301 | shared_->encoder_queue()) != 0) { |
| 302 | LOG(LS_ERROR) << "CreateChannel() failed to associate engine and channel." |
| 303 | " Destroying channel."; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 304 | shared_->channel_manager().DestroyChannel( |
| 305 | channel_owner->channel()->ChannelId()); |
| 306 | return -1; |
| 307 | } else if (channel_owner->channel()->Init() != 0) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 308 | LOG(LS_ERROR) << "CreateChannel() failed to initialize channel. Destroying" |
| 309 | " channel."; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 310 | shared_->channel_manager().DestroyChannel( |
| 311 | channel_owner->channel()->ChannelId()); |
| 312 | return -1; |
| 313 | } |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 314 | return channel_owner->channel()->ChannelId(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 317 | int VoEBaseImpl::DeleteChannel(int channel) { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 318 | rtc::CritScope cs(shared_->crit_sec()); |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 319 | { |
| 320 | voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); |
| 321 | voe::Channel* channelPtr = ch.channel(); |
| 322 | if (channelPtr == nullptr) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 323 | LOG(LS_ERROR) << "DeleteChannel() failed to locate channel"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 324 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 325 | } |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 326 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 327 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 328 | shared_->channel_manager().DestroyChannel(channel); |
| 329 | if (StopSend() != 0) { |
| 330 | return -1; |
| 331 | } |
| 332 | if (StopPlayout() != 0) { |
| 333 | return -1; |
| 334 | } |
| 335 | return 0; |
| 336 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 337 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 338 | int VoEBaseImpl::StartPlayout(int channel) { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 339 | rtc::CritScope cs(shared_->crit_sec()); |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 340 | voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); |
| 341 | voe::Channel* channelPtr = ch.channel(); |
| 342 | if (channelPtr == nullptr) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 343 | LOG(LS_ERROR) << "StartPlayout() failed to locate channel"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 344 | return -1; |
| 345 | } |
| 346 | if (channelPtr->Playing()) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 347 | return 0; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 348 | } |
| 349 | if (StartPlayout() != 0) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 350 | LOG(LS_ERROR) << "StartPlayout() failed to start playout"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 351 | return -1; |
| 352 | } |
| 353 | return channelPtr->StartPlayout(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 356 | int VoEBaseImpl::StopPlayout(int channel) { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 357 | rtc::CritScope cs(shared_->crit_sec()); |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 358 | voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); |
| 359 | voe::Channel* channelPtr = ch.channel(); |
| 360 | if (channelPtr == nullptr) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 361 | LOG(LS_ERROR) << "StopPlayout() failed to locate channel"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 362 | return -1; |
| 363 | } |
| 364 | if (channelPtr->StopPlayout() != 0) { |
| 365 | LOG_F(LS_WARNING) << "StopPlayout() failed to stop playout for channel " |
| 366 | << channel; |
| 367 | } |
| 368 | return StopPlayout(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 371 | int VoEBaseImpl::StartSend(int channel) { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 372 | rtc::CritScope cs(shared_->crit_sec()); |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 373 | voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); |
| 374 | voe::Channel* channelPtr = ch.channel(); |
| 375 | if (channelPtr == nullptr) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 376 | LOG(LS_ERROR) << "StartSend() failed to locate channel"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 377 | return -1; |
| 378 | } |
| 379 | if (channelPtr->Sending()) { |
| 380 | return 0; |
| 381 | } |
| 382 | if (StartSend() != 0) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 383 | LOG(LS_ERROR) << "StartSend() failed to start recording"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 384 | return -1; |
| 385 | } |
| 386 | return channelPtr->StartSend(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 389 | int VoEBaseImpl::StopSend(int channel) { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 390 | rtc::CritScope cs(shared_->crit_sec()); |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 391 | voe::ChannelOwner ch = shared_->channel_manager().GetChannel(channel); |
| 392 | voe::Channel* channelPtr = ch.channel(); |
| 393 | if (channelPtr == nullptr) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 394 | LOG(LS_ERROR) << "StopSend() failed to locate channel"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 395 | return -1; |
| 396 | } |
henrika | ec6fbd2 | 2017-03-31 05:43:36 -0700 | [diff] [blame] | 397 | channelPtr->StopSend(); |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 398 | return StopSend(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 401 | int32_t VoEBaseImpl::StartPlayout() { |
solenberg | e313e02 | 2015-09-08 02:16:04 -0700 | [diff] [blame] | 402 | if (!shared_->audio_device()->Playing()) { |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 403 | if (shared_->audio_device()->InitPlayout() != 0) { |
| 404 | LOG_F(LS_ERROR) << "Failed to initialize playout"; |
| 405 | return -1; |
| 406 | } |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 407 | if (playout_enabled_ && shared_->audio_device()->StartPlayout() != 0) { |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 408 | LOG_F(LS_ERROR) << "Failed to start playout"; |
| 409 | return -1; |
| 410 | } |
| 411 | } |
| 412 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 413 | } |
| 414 | |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 415 | int32_t VoEBaseImpl::StopPlayout() { |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 416 | if (!playout_enabled_) { |
| 417 | return 0; |
| 418 | } |
| 419 | // Stop audio-device playing if no channel is playing out. |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 420 | if (shared_->NumOfPlayingChannels() == 0) { |
| 421 | if (shared_->audio_device()->StopPlayout() != 0) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 422 | LOG(LS_ERROR) << "StopPlayout() failed to stop playout"; |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 423 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 424 | } |
pbos@webrtc.org | 676ff1e | 2013-08-07 17:57:36 +0000 | [diff] [blame] | 425 | } |
| 426 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 427 | } |
| 428 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 429 | int32_t VoEBaseImpl::StartSend() { |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 430 | if (!shared_->audio_device()->Recording()) { |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 431 | if (shared_->audio_device()->InitRecording() != 0) { |
| 432 | LOG_F(LS_ERROR) << "Failed to initialize recording"; |
| 433 | return -1; |
| 434 | } |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 435 | if (recording_enabled_ && shared_->audio_device()->StartRecording() != 0) { |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 436 | LOG_F(LS_ERROR) << "Failed to start recording"; |
| 437 | return -1; |
| 438 | } |
| 439 | } |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 440 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 443 | int32_t VoEBaseImpl::StopSend() { |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 444 | if (!recording_enabled_) { |
| 445 | return 0; |
| 446 | } |
| 447 | // Stop audio-device recording if no channel is recording. |
solenberg | b63310a | 2017-09-18 03:04:12 -0700 | [diff] [blame] | 448 | if (shared_->NumOfSendingChannels() == 0) { |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 449 | if (shared_->audio_device()->StopRecording() != 0) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 450 | LOG(LS_ERROR) << "StopSend() failed to stop recording"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 451 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 452 | } |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 453 | shared_->transmit_mixer()->StopSend(); |
| 454 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 455 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 456 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 457 | } |
| 458 | |
henrika | 5f6bf24 | 2017-11-01 11:06:56 +0100 | [diff] [blame] | 459 | int32_t VoEBaseImpl::SetPlayout(bool enabled) { |
| 460 | LOG(INFO) << "SetPlayout(" << enabled << ")"; |
| 461 | if (playout_enabled_ == enabled) { |
| 462 | return 0; |
| 463 | } |
| 464 | playout_enabled_ = enabled; |
| 465 | if (shared_->NumOfPlayingChannels() == 0) { |
| 466 | // If there are no channels attempting to play out yet, there's nothing to |
| 467 | // be done; we should be in a "not playing out" state either way. |
| 468 | return 0; |
| 469 | } |
| 470 | int32_t ret; |
| 471 | if (enabled) { |
| 472 | ret = shared_->audio_device()->StartPlayout(); |
| 473 | if (ret != 0) { |
| 474 | LOG(LS_ERROR) << "SetPlayout(true) failed to start playout"; |
| 475 | } |
| 476 | } else { |
| 477 | ret = shared_->audio_device()->StopPlayout(); |
| 478 | if (ret != 0) { |
| 479 | LOG(LS_ERROR) << "SetPlayout(false) failed to stop playout"; |
| 480 | } |
| 481 | } |
| 482 | return ret; |
| 483 | } |
| 484 | |
| 485 | int32_t VoEBaseImpl::SetRecording(bool enabled) { |
| 486 | LOG(INFO) << "SetRecording(" << enabled << ")"; |
| 487 | if (recording_enabled_ == enabled) { |
| 488 | return 0; |
| 489 | } |
| 490 | recording_enabled_ = enabled; |
| 491 | if (shared_->NumOfSendingChannels() == 0) { |
| 492 | // If there are no channels attempting to record out yet, there's nothing to |
| 493 | // be done; we should be in a "not recording" state either way. |
| 494 | return 0; |
| 495 | } |
| 496 | int32_t ret; |
| 497 | if (enabled) { |
| 498 | ret = shared_->audio_device()->StartRecording(); |
| 499 | if (ret != 0) { |
| 500 | LOG(LS_ERROR) << "SetRecording(true) failed to start recording"; |
| 501 | } |
| 502 | } else { |
| 503 | ret = shared_->audio_device()->StopRecording(); |
| 504 | if (ret != 0) { |
| 505 | LOG(LS_ERROR) << "SetRecording(false) failed to stop recording"; |
| 506 | } |
| 507 | } |
| 508 | return ret; |
| 509 | } |
| 510 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 511 | int32_t VoEBaseImpl::TerminateInternal() { |
| 512 | // Delete any remaining channel objects |
| 513 | shared_->channel_manager().DestroyAllChannels(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 514 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 515 | if (shared_->process_thread()) { |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 516 | shared_->process_thread()->Stop(); |
| 517 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 518 | |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 519 | if (shared_->audio_device()) { |
| 520 | if (shared_->audio_device()->StopPlayout() != 0) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 521 | LOG(LS_ERROR) << "TerminateInternal() failed to stop playout"; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 522 | } |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 523 | if (shared_->audio_device()->StopRecording() != 0) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 524 | LOG(LS_ERROR) << "TerminateInternal() failed to stop recording"; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 525 | } |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 526 | if (shared_->audio_device()->RegisterAudioCallback(nullptr) != 0) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 527 | LOG(LS_ERROR) << "TerminateInternal() failed to de-register audio " |
| 528 | "callback for the ADM"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 529 | } |
| 530 | if (shared_->audio_device()->Terminate() != 0) { |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 531 | LOG(LS_ERROR) << "TerminateInternal() failed to terminate the ADM"; |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 532 | } |
| 533 | shared_->set_audio_device(nullptr); |
| 534 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 535 | |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 536 | shared_->set_audio_processing(nullptr); |
Jelena Marusic | 2dd6a27 | 2015-04-14 09:47:00 +0200 | [diff] [blame] | 537 | |
solenberg | 1c239d4 | 2017-09-29 06:00:28 -0700 | [diff] [blame] | 538 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 539 | } |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 540 | } // namespace webrtc |