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 |
11 #include "voice_engine/voe_base_impl.h" | 11 #include "voice_engine/voe_base_impl.h" |
12 | 12 |
13 #include "api/audio_codecs/builtin_audio_decoder_factory.h" | 13 #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
14 #include "common_audio/signal_processing/include/signal_processing_library.h" | 14 #include "common_audio/signal_processing/include/signal_processing_library.h" |
15 #include "modules/audio_coding/include/audio_coding_module.h" | 15 #include "modules/audio_coding/include/audio_coding_module.h" |
16 #include "modules/audio_device/audio_device_impl.h" | 16 #include "modules/audio_device/audio_device_impl.h" |
17 #include "modules/audio_processing/include/audio_processing.h" | 17 #include "modules/audio_processing/include/audio_processing.h" |
18 #include "rtc_base/format_macros.h" | 18 #include "rtc_base/format_macros.h" |
19 #include "rtc_base/location.h" | 19 #include "rtc_base/location.h" |
20 #include "rtc_base/logging.h" | 20 #include "rtc_base/logging.h" |
21 #include "system_wrappers/include/file_wrapper.h" | |
22 #include "voice_engine/channel.h" | 21 #include "voice_engine/channel.h" |
23 #include "voice_engine/include/voe_errors.h" | 22 #include "voice_engine/include/voe_errors.h" |
24 #include "voice_engine/output_mixer.h" | |
25 #include "voice_engine/transmit_mixer.h" | 23 #include "voice_engine/transmit_mixer.h" |
26 #include "voice_engine/utility.h" | |
27 #include "voice_engine/voice_engine_impl.h" | 24 #include "voice_engine/voice_engine_impl.h" |
28 | 25 |
29 namespace webrtc { | 26 namespace webrtc { |
30 | 27 |
31 VoEBase* VoEBase::GetInterface(VoiceEngine* voiceEngine) { | 28 VoEBase* VoEBase::GetInterface(VoiceEngine* voiceEngine) { |
32 if (nullptr == voiceEngine) { | 29 if (nullptr == voiceEngine) { |
33 return nullptr; | 30 return nullptr; |
34 } | 31 } |
35 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); | 32 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); |
36 s->AddRef(); | 33 s->AddRef(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 if (new_voe_mic_level != voe_mic_level) { | 130 if (new_voe_mic_level != voe_mic_level) { |
134 // Return the new volume if AGC has changed the volume. | 131 // Return the new volume if AGC has changed the volume. |
135 return static_cast<int>((new_voe_mic_level * max_volume + | 132 return static_cast<int>((new_voe_mic_level * max_volume + |
136 static_cast<int>(kMaxVolumeLevel / 2)) / | 133 static_cast<int>(kMaxVolumeLevel / 2)) / |
137 kMaxVolumeLevel); | 134 kMaxVolumeLevel); |
138 } | 135 } |
139 | 136 |
140 return 0; | 137 return 0; |
141 } | 138 } |
142 | 139 |
143 int32_t VoEBaseImpl::NeedMorePlayData(const size_t nSamples, | 140 int32_t VoEBaseImpl::NeedMorePlayData(const size_t nSamples, |
hlundin-webrtc
2017/09/22 09:17:44
Mark as deprecated?
the sun
2017/09/22 10:49:00
Done.
| |
144 const size_t nBytesPerSample, | 141 const size_t nBytesPerSample, |
145 const size_t nChannels, | 142 const size_t nChannels, |
146 const uint32_t samplesPerSec, | 143 const uint32_t samplesPerSec, |
147 void* audioSamples, | 144 void* audioSamples, |
148 size_t& nSamplesOut, | 145 size_t& nSamplesOut, |
149 int64_t* elapsed_time_ms, | 146 int64_t* elapsed_time_ms, |
150 int64_t* ntp_time_ms) { | 147 int64_t* ntp_time_ms) { |
151 GetPlayoutData(static_cast<int>(samplesPerSec), nChannels, nSamples, true, | 148 RTC_NOTREACHED(); |
152 audioSamples, elapsed_time_ms, ntp_time_ms); | |
153 nSamplesOut = audioFrame_.samples_per_channel_; | |
154 return 0; | 149 return 0; |
155 } | 150 } |
156 | 151 |
157 void VoEBaseImpl::PushCaptureData(int voe_channel, const void* audio_data, | 152 void VoEBaseImpl::PushCaptureData(int voe_channel, const void* audio_data, |
158 int bits_per_sample, int sample_rate, | 153 int bits_per_sample, int sample_rate, |
159 size_t number_of_channels, | 154 size_t number_of_channels, |
160 size_t number_of_frames) { | 155 size_t number_of_frames) { |
161 voe::ChannelOwner ch = shared_->channel_manager().GetChannel(voe_channel); | 156 voe::ChannelOwner ch = shared_->channel_manager().GetChannel(voe_channel); |
162 voe::Channel* channel = ch.channel(); | 157 voe::Channel* channel = ch.channel(); |
163 if (!channel) | 158 if (!channel) |
164 return; | 159 return; |
165 if (channel->Sending()) { | 160 if (channel->Sending()) { |
166 // Send the audio to each channel directly without using the APM in the | 161 // Send the audio to each channel directly without using the APM in the |
167 // transmit mixer. | 162 // transmit mixer. |
168 channel->ProcessAndEncodeAudio(static_cast<const int16_t*>(audio_data), | 163 channel->ProcessAndEncodeAudio(static_cast<const int16_t*>(audio_data), |
169 sample_rate, number_of_frames, | 164 sample_rate, number_of_frames, |
170 number_of_channels); | 165 number_of_channels); |
171 } | 166 } |
172 } | 167 } |
173 | 168 |
174 void VoEBaseImpl::PullRenderData(int bits_per_sample, | 169 void VoEBaseImpl::PullRenderData(int bits_per_sample, |
hlundin-webrtc
2017/09/22 09:17:45
Mark as deprecated?
the sun
2017/09/22 10:49:00
Done.
| |
175 int sample_rate, | 170 int sample_rate, |
176 size_t number_of_channels, | 171 size_t number_of_channels, |
177 size_t number_of_frames, | 172 size_t number_of_frames, |
178 void* audio_data, int64_t* elapsed_time_ms, | 173 void* audio_data, int64_t* elapsed_time_ms, |
179 int64_t* ntp_time_ms) { | 174 int64_t* ntp_time_ms) { |
180 assert(bits_per_sample == 16); | 175 RTC_NOTREACHED(); |
181 assert(number_of_frames == static_cast<size_t>(sample_rate / 100)); | |
182 | |
183 GetPlayoutData(sample_rate, number_of_channels, number_of_frames, false, | |
184 audio_data, elapsed_time_ms, ntp_time_ms); | |
185 } | 176 } |
186 | 177 |
187 int VoEBaseImpl::RegisterVoiceEngineObserver(VoiceEngineObserver& observer) { | 178 int VoEBaseImpl::RegisterVoiceEngineObserver(VoiceEngineObserver& observer) { |
188 rtc::CritScope cs(&callbackCritSect_); | 179 rtc::CritScope cs(&callbackCritSect_); |
189 if (voiceEngineObserverPtr_) { | 180 if (voiceEngineObserverPtr_) { |
190 shared_->SetLastError( | 181 shared_->SetLastError( |
191 VE_INVALID_OPERATION, kTraceError, | 182 VE_INVALID_OPERATION, kTraceError, |
192 "RegisterVoiceEngineObserver() observer already enabled"); | 183 "RegisterVoiceEngineObserver() observer already enabled"); |
193 return -1; | 184 return -1; |
194 } | 185 } |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 | 402 |
412 ChannelConfig config_copy(config); | 403 ChannelConfig config_copy(config); |
413 config_copy.acm_config.decoder_factory = decoder_factory_; | 404 config_copy.acm_config.decoder_factory = decoder_factory_; |
414 voe::ChannelOwner channel_owner = | 405 voe::ChannelOwner channel_owner = |
415 shared_->channel_manager().CreateChannel(config_copy); | 406 shared_->channel_manager().CreateChannel(config_copy); |
416 return InitializeChannel(&channel_owner); | 407 return InitializeChannel(&channel_owner); |
417 } | 408 } |
418 | 409 |
419 int VoEBaseImpl::InitializeChannel(voe::ChannelOwner* channel_owner) { | 410 int VoEBaseImpl::InitializeChannel(voe::ChannelOwner* channel_owner) { |
420 if (channel_owner->channel()->SetEngineInformation( | 411 if (channel_owner->channel()->SetEngineInformation( |
421 shared_->statistics(), *shared_->output_mixer(), | 412 shared_->statistics(), |
422 *shared_->process_thread(), *shared_->audio_device(), | 413 *shared_->process_thread(), *shared_->audio_device(), |
423 voiceEngineObserverPtr_, &callbackCritSect_, | 414 voiceEngineObserverPtr_, &callbackCritSect_, |
424 shared_->encoder_queue()) != 0) { | 415 shared_->encoder_queue()) != 0) { |
425 shared_->SetLastError( | 416 shared_->SetLastError( |
426 VE_CHANNEL_NOT_CREATED, kTraceError, | 417 VE_CHANNEL_NOT_CREATED, kTraceError, |
427 "CreateChannel() failed to associate engine and channel." | 418 "CreateChannel() failed to associate engine and channel." |
428 " Destroying channel."); | 419 " Destroying channel."); |
429 shared_->channel_manager().DestroyChannel( | 420 shared_->channel_manager().DestroyChannel( |
430 channel_owner->channel()->ChannelId()); | 421 channel_owner->channel()->ChannelId()); |
431 return -1; | 422 return -1; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
646 shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, | 637 shared_->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError, |
647 "TerminateInternal() failed to terminate the ADM"); | 638 "TerminateInternal() failed to terminate the ADM"); |
648 } | 639 } |
649 shared_->set_audio_device(nullptr); | 640 shared_->set_audio_device(nullptr); |
650 } | 641 } |
651 | 642 |
652 shared_->set_audio_processing(nullptr); | 643 shared_->set_audio_processing(nullptr); |
653 | 644 |
654 return shared_->statistics().SetUnInitialized(); | 645 return shared_->statistics().SetUnInitialized(); |
655 } | 646 } |
656 | |
657 void VoEBaseImpl::GetPlayoutData(int sample_rate, size_t number_of_channels, | |
658 size_t number_of_frames, bool feed_data_to_apm, | |
659 void* audio_data, int64_t* elapsed_time_ms, | |
660 int64_t* ntp_time_ms) { | |
661 assert(shared_->output_mixer() != nullptr); | |
662 | |
663 // TODO(andrew): if the device is running in mono, we should tell the mixer | |
664 // here so that it will only request mono from AudioCodingModule. | |
665 // Perform mixing of all active participants (channel-based mixing) | |
666 shared_->output_mixer()->MixActiveChannels(); | |
667 | |
668 // Additional operations on the combined signal | |
669 shared_->output_mixer()->DoOperationsOnCombinedSignal(feed_data_to_apm); | |
670 | |
671 // Retrieve the final output mix (resampled to match the ADM) | |
672 shared_->output_mixer()->GetMixedAudio(sample_rate, number_of_channels, | |
673 &audioFrame_); | |
674 | |
675 assert(number_of_frames == audioFrame_.samples_per_channel_); | |
676 assert(sample_rate == audioFrame_.sample_rate_hz_); | |
677 | |
678 // Deliver audio (PCM) samples to the ADM | |
679 memcpy(audio_data, audioFrame_.data(), | |
680 sizeof(int16_t) * number_of_frames * number_of_channels); | |
681 | |
682 *elapsed_time_ms = audioFrame_.elapsed_time_ms_; | |
683 *ntp_time_ms = audioFrame_.ntp_time_ms_; | |
684 } | |
685 | |
686 } // namespace webrtc | 647 } // namespace webrtc |
OLD | NEW |