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