blob: 8d4ad3221ffc6f96e91440190fdd8d226976222f [file] [log] [blame]
solenbergc7a8b082015-10-16 14:35:07 -07001/*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
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
11#include "webrtc/audio/audio_send_stream.h"
12
13#include <string>
14
solenberg566ef242015-11-06 15:34:49 -080015#include "webrtc/audio/audio_state.h"
solenberg85a04962015-10-27 03:35:21 -070016#include "webrtc/audio/conversion.h"
solenberg566ef242015-11-06 15:34:49 -080017#include "webrtc/audio/scoped_voe_interface.h"
solenbergc7a8b082015-10-16 14:35:07 -070018#include "webrtc/base/checks.h"
perkj26091b12016-09-01 01:17:40 -070019#include "webrtc/base/event.h"
solenbergc7a8b082015-10-16 14:35:07 -070020#include "webrtc/base/logging.h"
perkj26091b12016-09-01 01:17:40 -070021#include "webrtc/base/task_queue.h"
stefan7de8d642017-02-07 07:14:08 -080022#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
Stefan Holmer80e12072016-02-23 13:30:42 +010023#include "webrtc/modules/congestion_controller/include/congestion_controller.h"
Stefan Holmerb86d4e42015-12-07 10:26:18 +010024#include "webrtc/modules/pacing/paced_sender.h"
25#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
solenberg13725082015-11-25 08:16:52 -080026#include "webrtc/voice_engine/channel_proxy.h"
solenbergbd9a77f2017-02-06 12:53:57 -080027#include "webrtc/voice_engine/include/voe_base.h"
solenberg85a04962015-10-27 03:35:21 -070028#include "webrtc/voice_engine/include/voe_volume_control.h"
solenberg13725082015-11-25 08:16:52 -080029#include "webrtc/voice_engine/voice_engine_impl.h"
solenbergc7a8b082015-10-16 14:35:07 -070030
31namespace webrtc {
minyue7a973442016-10-20 03:27:12 -070032
33namespace {
34
35constexpr char kOpusCodecName[] = "opus";
36
minyue7a973442016-10-20 03:27:12 -070037bool IsCodec(const webrtc::CodecInst& codec, const char* ref_name) {
38 return (_stricmp(codec.plname, ref_name) == 0);
39}
minyue7a973442016-10-20 03:27:12 -070040} // namespace
41
solenbergc7a8b082015-10-16 14:35:07 -070042namespace internal {
solenberg566ef242015-11-06 15:34:49 -080043AudioSendStream::AudioSendStream(
44 const webrtc::AudioSendStream::Config& config,
Stefan Holmerb86d4e42015-12-07 10:26:18 +010045 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
perkj26091b12016-09-01 01:17:40 -070046 rtc::TaskQueue* worker_queue,
nisse0245da02016-11-30 03:35:20 -080047 PacketRouter* packet_router,
mflodman86cc6ff2016-07-26 04:44:06 -070048 CongestionController* congestion_controller,
tereliuse035e2d2016-09-21 06:51:47 -070049 BitrateAllocator* bitrate_allocator,
michaelt9332b7d2016-11-30 07:51:13 -080050 RtcEventLog* event_log,
51 RtcpRttStats* rtcp_rtt_stats)
perkj26091b12016-09-01 01:17:40 -070052 : worker_queue_(worker_queue),
53 config_(config),
mflodman86cc6ff2016-07-26 04:44:06 -070054 audio_state_(audio_state),
michaeltf4caaab2017-01-16 23:55:07 -080055 bitrate_allocator_(bitrate_allocator),
56 congestion_controller_(congestion_controller) {
solenbergc7a8b082015-10-16 14:35:07 -070057 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString();
solenberg566ef242015-11-06 15:34:49 -080058 RTC_DCHECK_NE(config_.voe_channel_id, -1);
59 RTC_DCHECK(audio_state_.get());
Stefan Holmerb86d4e42015-12-07 10:26:18 +010060 RTC_DCHECK(congestion_controller);
solenberg3a941542015-11-16 07:34:50 -080061
solenberg13725082015-11-25 08:16:52 -080062 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine());
kwibergfffa42b2016-02-23 10:46:32 -080063 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id);
tereliuse035e2d2016-09-21 06:51:47 -070064 channel_proxy_->SetRtcEventLog(event_log);
michaelt9332b7d2016-11-30 07:51:13 -080065 channel_proxy_->SetRtcpRttStats(rtcp_rtt_stats);
solenberg13725082015-11-25 08:16:52 -080066 channel_proxy_->SetRTCPStatus(true);
67 channel_proxy_->SetLocalSSRC(config.rtp.ssrc);
68 channel_proxy_->SetRTCP_CNAME(config.rtp.c_name);
solenberg971cab02016-06-14 10:02:41 -070069 // TODO(solenberg): Config NACK history window (which is a packet count),
70 // using the actual packet size for the configured codec.
71 channel_proxy_->SetNACKStatus(config_.rtp.nack.rtp_history_ms != 0,
72 config_.rtp.nack.rtp_history_ms / 20);
Stefan Holmerb86d4e42015-12-07 10:26:18 +010073
mflodman3d7db262016-04-29 00:57:13 -070074 channel_proxy_->RegisterExternalTransport(config.send_transport);
75
solenberg3a941542015-11-16 07:34:50 -080076 for (const auto& extension : config.rtp.extensions) {
stefanb521aa72016-11-01 03:17:16 -070077 if (extension.uri == RtpExtension::kAudioLevelUri) {
solenberg358057b2015-11-27 10:46:42 -080078 channel_proxy_->SetSendAudioLevelIndicationStatus(true, extension.id);
isheriff6f8d6862016-05-26 11:24:55 -070079 } else if (extension.uri == RtpExtension::kTransportSequenceNumberUri) {
Stefan Holmerb86d4e42015-12-07 10:26:18 +010080 channel_proxy_->EnableSendTransportSequenceNumber(extension.id);
stefan55d1ebb2017-01-27 06:17:09 -080081 congestion_controller->EnablePeriodicAlrProbing(true);
stefan7de8d642017-02-07 07:14:08 -080082 bandwidth_observer_.reset(congestion_controller->GetBitrateController()
83 ->CreateRtcpBandwidthObserver());
solenberg3a941542015-11-16 07:34:50 -080084 } else {
85 RTC_NOTREACHED() << "Registering unsupported RTP extension.";
86 }
87 }
stefan7de8d642017-02-07 07:14:08 -080088 channel_proxy_->RegisterSenderCongestionControlObjects(
89 congestion_controller->pacer(),
90 congestion_controller->GetTransportFeedbackObserver(), packet_router,
91 bandwidth_observer_.get());
minyue7a973442016-10-20 03:27:12 -070092 if (!SetupSendCodec()) {
93 LOG(LS_ERROR) << "Failed to set up send codec state.";
94 }
solenbergc7a8b082015-10-16 14:35:07 -070095}
96
97AudioSendStream::~AudioSendStream() {
solenberg85a04962015-10-27 03:35:21 -070098 RTC_DCHECK(thread_checker_.CalledOnValidThread());
solenbergc7a8b082015-10-16 14:35:07 -070099 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString();
mflodman3d7db262016-04-29 00:57:13 -0700100 channel_proxy_->DeRegisterExternalTransport();
stefanbba9dec2016-02-01 04:39:55 -0800101 channel_proxy_->ResetCongestionControlObjects();
tereliuse035e2d2016-09-21 06:51:47 -0700102 channel_proxy_->SetRtcEventLog(nullptr);
michaelt9332b7d2016-11-30 07:51:13 -0800103 channel_proxy_->SetRtcpRttStats(nullptr);
solenbergc7a8b082015-10-16 14:35:07 -0700104}
105
solenberg3a941542015-11-16 07:34:50 -0800106void AudioSendStream::Start() {
107 RTC_DCHECK(thread_checker_.CalledOnValidThread());
minyue10cbb462016-11-07 09:29:22 -0800108 if (config_.min_bitrate_bps != -1 && config_.max_bitrate_bps != -1) {
109 RTC_DCHECK_GE(config_.max_bitrate_bps, config_.min_bitrate_bps);
perkj26091b12016-09-01 01:17:40 -0700110 rtc::Event thread_sync_event(false /* manual_reset */, false);
111 worker_queue_->PostTask([this, &thread_sync_event] {
minyue10cbb462016-11-07 09:29:22 -0800112 bitrate_allocator_->AddObserver(this, config_.min_bitrate_bps,
113 config_.max_bitrate_bps, 0, true);
perkj26091b12016-09-01 01:17:40 -0700114 thread_sync_event.Set();
115 });
116 thread_sync_event.Wait(rtc::Event::kForever);
mflodman86cc6ff2016-07-26 04:44:06 -0700117 }
118
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800119 ScopedVoEInterface<VoEBase> base(voice_engine());
120 int error = base->StartSend(config_.voe_channel_id);
121 if (error != 0) {
122 LOG(LS_ERROR) << "AudioSendStream::Start failed with error: " << error;
123 }
solenberg3a941542015-11-16 07:34:50 -0800124}
125
126void AudioSendStream::Stop() {
127 RTC_DCHECK(thread_checker_.CalledOnValidThread());
perkj26091b12016-09-01 01:17:40 -0700128 rtc::Event thread_sync_event(false /* manual_reset */, false);
129 worker_queue_->PostTask([this, &thread_sync_event] {
130 bitrate_allocator_->RemoveObserver(this);
131 thread_sync_event.Set();
132 });
133 thread_sync_event.Wait(rtc::Event::kForever);
134
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800135 ScopedVoEInterface<VoEBase> base(voice_engine());
136 int error = base->StopSend(config_.voe_channel_id);
137 if (error != 0) {
138 LOG(LS_ERROR) << "AudioSendStream::Stop failed with error: " << error;
139 }
solenberg3a941542015-11-16 07:34:50 -0800140}
141
solenbergffbbcac2016-11-17 05:25:37 -0800142bool AudioSendStream::SendTelephoneEvent(int payload_type,
143 int payload_frequency, int event,
solenberg8842c3e2016-03-11 03:06:41 -0800144 int duration_ms) {
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100145 RTC_DCHECK(thread_checker_.CalledOnValidThread());
solenbergffbbcac2016-11-17 05:25:37 -0800146 return channel_proxy_->SetSendTelephoneEventPayloadType(payload_type,
147 payload_frequency) &&
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100148 channel_proxy_->SendTelephoneEventOutband(event, duration_ms);
149}
150
solenberg94218532016-06-16 10:53:22 -0700151void AudioSendStream::SetMuted(bool muted) {
152 RTC_DCHECK(thread_checker_.CalledOnValidThread());
153 channel_proxy_->SetInputMute(muted);
154}
155
solenbergc7a8b082015-10-16 14:35:07 -0700156webrtc::AudioSendStream::Stats AudioSendStream::GetStats() const {
solenberg85a04962015-10-27 03:35:21 -0700157 RTC_DCHECK(thread_checker_.CalledOnValidThread());
158 webrtc::AudioSendStream::Stats stats;
159 stats.local_ssrc = config_.rtp.ssrc;
solenberg85a04962015-10-27 03:35:21 -0700160
solenberg358057b2015-11-27 10:46:42 -0800161 webrtc::CallStatistics call_stats = channel_proxy_->GetRTCPStatistics();
solenberg85a04962015-10-27 03:35:21 -0700162 stats.bytes_sent = call_stats.bytesSent;
163 stats.packets_sent = call_stats.packetsSent;
solenberg8b85de22015-11-16 09:48:04 -0800164 // RTT isn't known until a RTCP report is received. Until then, VoiceEngine
165 // returns 0 to indicate an error value.
166 if (call_stats.rttMs > 0) {
167 stats.rtt_ms = call_stats.rttMs;
168 }
169 // TODO(solenberg): [was ajm]: Re-enable this metric once we have a reliable
170 // implementation.
171 stats.aec_quality_min = -1;
solenberg85a04962015-10-27 03:35:21 -0700172
173 webrtc::CodecInst codec_inst = {0};
solenbergbd9a77f2017-02-06 12:53:57 -0800174 if (channel_proxy_->GetSendCodec(&codec_inst)) {
solenberg85a04962015-10-27 03:35:21 -0700175 RTC_DCHECK_NE(codec_inst.pltype, -1);
176 stats.codec_name = codec_inst.plname;
hbos1acfbd22016-11-17 23:43:29 -0800177 stats.codec_payload_type = rtc::Optional<int>(codec_inst.pltype);
solenberg85a04962015-10-27 03:35:21 -0700178
179 // Get data from the last remote RTCP report.
solenberg358057b2015-11-27 10:46:42 -0800180 for (const auto& block : channel_proxy_->GetRemoteRTCPReportBlocks()) {
solenberg8b85de22015-11-16 09:48:04 -0800181 // Lookup report for send ssrc only.
182 if (block.source_SSRC == stats.local_ssrc) {
183 stats.packets_lost = block.cumulative_num_packets_lost;
184 stats.fraction_lost = Q8ToFloat(block.fraction_lost);
185 stats.ext_seqnum = block.extended_highest_sequence_number;
186 // Convert samples to milliseconds.
187 if (codec_inst.plfreq / 1000 > 0) {
188 stats.jitter_ms =
189 block.interarrival_jitter / (codec_inst.plfreq / 1000);
solenberg85a04962015-10-27 03:35:21 -0700190 }
solenberg8b85de22015-11-16 09:48:04 -0800191 break;
solenberg85a04962015-10-27 03:35:21 -0700192 }
193 }
194 }
195
solenberg85a04962015-10-27 03:35:21 -0700196 // Local speech level.
197 {
solenbergbd9a77f2017-02-06 12:53:57 -0800198 ScopedVoEInterface<VoEVolumeControl> volume(voice_engine());
solenberg85a04962015-10-27 03:35:21 -0700199 unsigned int level = 0;
solenberg358057b2015-11-27 10:46:42 -0800200 int error = volume->GetSpeechInputLevelFullRange(level);
solenberg8b85de22015-11-16 09:48:04 -0800201 RTC_DCHECK_EQ(0, error);
202 stats.audio_level = static_cast<int32_t>(level);
solenberg85a04962015-10-27 03:35:21 -0700203 }
204
ivoc7aba0292016-11-14 04:52:06 -0800205 ScopedVoEInterface<VoEBase> base(voice_engine());
206 RTC_DCHECK(base->audio_processing());
207 auto audio_processing_stats = base->audio_processing()->GetStatistics();
208 stats.echo_delay_median_ms = audio_processing_stats.delay_median;
209 stats.echo_delay_std_ms = audio_processing_stats.delay_standard_deviation;
210 stats.echo_return_loss = audio_processing_stats.echo_return_loss.instant();
211 stats.echo_return_loss_enhancement =
212 audio_processing_stats.echo_return_loss_enhancement.instant();
213 stats.residual_echo_likelihood =
214 audio_processing_stats.residual_echo_likelihood;
ivoc4e477a12017-01-15 08:29:46 -0800215 stats.residual_echo_likelihood_recent_max =
216 audio_processing_stats.residual_echo_likelihood_recent_max;
ivoc8c63a822016-10-21 04:10:03 -0700217
solenberg3a941542015-11-16 07:34:50 -0800218 internal::AudioState* audio_state =
219 static_cast<internal::AudioState*>(audio_state_.get());
solenberg566ef242015-11-06 15:34:49 -0800220 stats.typing_noise_detected = audio_state->typing_noise_detected();
solenberg85a04962015-10-27 03:35:21 -0700221
222 return stats;
223}
224
pbos1ba8d392016-05-01 20:18:34 -0700225void AudioSendStream::SignalNetworkState(NetworkState state) {
226 RTC_DCHECK(thread_checker_.CalledOnValidThread());
227}
228
229bool AudioSendStream::DeliverRtcp(const uint8_t* packet, size_t length) {
230 // TODO(solenberg): Tests call this function on a network thread, libjingle
231 // calls on the worker thread. We should move towards always using a network
232 // thread. Then this check can be enabled.
233 // RTC_DCHECK(!thread_checker_.CalledOnValidThread());
234 return channel_proxy_->ReceivedRTCPPacket(packet, length);
235}
236
mflodman86cc6ff2016-07-26 04:44:06 -0700237uint32_t AudioSendStream::OnBitrateUpdated(uint32_t bitrate_bps,
238 uint8_t fraction_loss,
minyue78b4d562016-11-30 04:47:39 -0800239 int64_t rtt,
240 int64_t probing_interval_ms) {
mflodman86cc6ff2016-07-26 04:44:06 -0700241 RTC_DCHECK_GE(bitrate_bps,
minyue10cbb462016-11-07 09:29:22 -0800242 static_cast<uint32_t>(config_.min_bitrate_bps));
mflodman86cc6ff2016-07-26 04:44:06 -0700243 // The bitrate allocator might allocate an higher than max configured bitrate
244 // if there is room, to allow for, as example, extra FEC. Ignore that for now.
minyue10cbb462016-11-07 09:29:22 -0800245 const uint32_t max_bitrate_bps = config_.max_bitrate_bps;
mflodman86cc6ff2016-07-26 04:44:06 -0700246 if (bitrate_bps > max_bitrate_bps)
247 bitrate_bps = max_bitrate_bps;
248
minyue78b4d562016-11-30 04:47:39 -0800249 channel_proxy_->SetBitrate(bitrate_bps, probing_interval_ms);
mflodman86cc6ff2016-07-26 04:44:06 -0700250
251 // The amount of audio protection is not exposed by the encoder, hence
252 // always returning 0.
253 return 0;
254}
255
solenberg85a04962015-10-27 03:35:21 -0700256const webrtc::AudioSendStream::Config& AudioSendStream::config() const {
257 RTC_DCHECK(thread_checker_.CalledOnValidThread());
258 return config_;
solenbergc7a8b082015-10-16 14:35:07 -0700259}
260
michaelt79e05882016-11-08 02:50:09 -0800261void AudioSendStream::SetTransportOverhead(int transport_overhead_per_packet) {
262 RTC_DCHECK(thread_checker_.CalledOnValidThread());
michaeltf4caaab2017-01-16 23:55:07 -0800263 congestion_controller_->SetTransportOverhead(transport_overhead_per_packet);
michaelt79e05882016-11-08 02:50:09 -0800264 channel_proxy_->SetTransportOverhead(transport_overhead_per_packet);
265}
266
solenberg3a941542015-11-16 07:34:50 -0800267VoiceEngine* AudioSendStream::voice_engine() const {
268 internal::AudioState* audio_state =
269 static_cast<internal::AudioState*>(audio_state_.get());
270 VoiceEngine* voice_engine = audio_state->voice_engine();
271 RTC_DCHECK(voice_engine);
272 return voice_engine;
solenbergc7a8b082015-10-16 14:35:07 -0700273}
minyue7a973442016-10-20 03:27:12 -0700274
275// Apply current codec settings to a single voe::Channel used for sending.
276bool AudioSendStream::SetupSendCodec() {
minyue7a973442016-10-20 03:27:12 -0700277 // Disable VAD and FEC unless we know the other side wants them.
solenbergbd9a77f2017-02-06 12:53:57 -0800278 channel_proxy_->SetVADStatus(false);
279 channel_proxy_->SetCodecFECStatus(false);
minyue7a973442016-10-20 03:27:12 -0700280
minyue6f0b9fd2016-11-14 00:51:50 -0800281 // We disable audio network adaptor here. This will on one hand make sure that
282 // audio network adaptor is disabled by default, and on the other allow audio
283 // network adaptor to be reconfigured, since SetReceiverFrameLengthRange can
284 // be only called when audio network adaptor is disabled.
285 channel_proxy_->DisableAudioNetworkAdaptor();
286
minyue7a973442016-10-20 03:27:12 -0700287 const auto& send_codec_spec = config_.send_codec_spec;
288
solenberg940b6d62016-10-25 11:19:07 -0700289 // We set the codec first, since the below extra configuration is only applied
290 // to the "current" codec.
minyue7a973442016-10-20 03:27:12 -0700291
292 // If codec is already configured, we do not it again.
293 // TODO(minyue): check if this check is really needed, or can we move it into
294 // |codec->SetSendCodec|.
295 webrtc::CodecInst current_codec = {0};
solenbergbd9a77f2017-02-06 12:53:57 -0800296 if (!channel_proxy_->GetSendCodec(&current_codec) ||
minyue7a973442016-10-20 03:27:12 -0700297 (send_codec_spec.codec_inst != current_codec)) {
solenbergbd9a77f2017-02-06 12:53:57 -0800298 if (!channel_proxy_->SetSendCodec(send_codec_spec.codec_inst)) {
299 LOG(LS_WARNING) << "SetSendCodec() failed.";
minyue7a973442016-10-20 03:27:12 -0700300 return false;
301 }
302 }
303
solenberg940b6d62016-10-25 11:19:07 -0700304 // Codec internal FEC. Treat any failure as fatal internal error.
minyue7a973442016-10-20 03:27:12 -0700305 if (send_codec_spec.enable_codec_fec) {
solenbergbd9a77f2017-02-06 12:53:57 -0800306 if (!channel_proxy_->SetCodecFECStatus(true)) {
307 LOG(LS_WARNING) << "SetCodecFECStatus() failed.";
minyue7a973442016-10-20 03:27:12 -0700308 return false;
309 }
310 }
311
solenberg940b6d62016-10-25 11:19:07 -0700312 // DTX and maxplaybackrate are only set if current codec is Opus.
minyue7a973442016-10-20 03:27:12 -0700313 if (IsCodec(send_codec_spec.codec_inst, kOpusCodecName)) {
solenbergbd9a77f2017-02-06 12:53:57 -0800314 if (!channel_proxy_->SetOpusDtx(send_codec_spec.enable_opus_dtx)) {
315 LOG(LS_WARNING) << "SetOpusDtx() failed.";
minyue7a973442016-10-20 03:27:12 -0700316 return false;
317 }
318
319 // If opus_max_playback_rate <= 0, the default maximum playback rate
320 // (48 kHz) will be used.
321 if (send_codec_spec.opus_max_playback_rate > 0) {
solenbergbd9a77f2017-02-06 12:53:57 -0800322 if (!channel_proxy_->SetOpusMaxPlaybackRate(
323 send_codec_spec.opus_max_playback_rate)) {
324 LOG(LS_WARNING) << "SetOpusMaxPlaybackRate() failed.";
minyue7a973442016-10-20 03:27:12 -0700325 return false;
326 }
327 }
minyue6b825df2016-10-31 04:08:32 -0700328
329 if (config_.audio_network_adaptor_config) {
330 // Audio network adaptor is only allowed for Opus currently.
331 // |SetReceiverFrameLengthRange| needs to be called before
332 // |EnableAudioNetworkAdaptor|.
333 channel_proxy_->SetReceiverFrameLengthRange(send_codec_spec.min_ptime_ms,
334 send_codec_spec.max_ptime_ms);
335 channel_proxy_->EnableAudioNetworkAdaptor(
336 *config_.audio_network_adaptor_config);
337 LOG(LS_INFO) << "Audio network adaptor enabled on SSRC "
338 << config_.rtp.ssrc;
minyue6b825df2016-10-31 04:08:32 -0700339 }
minyue7a973442016-10-20 03:27:12 -0700340 }
341
342 // Set the CN payloadtype and the VAD status.
343 if (send_codec_spec.cng_payload_type != -1) {
344 // The CN payload type for 8000 Hz clockrate is fixed at 13.
345 if (send_codec_spec.cng_plfreq != 8000) {
346 webrtc::PayloadFrequencies cn_freq;
347 switch (send_codec_spec.cng_plfreq) {
348 case 16000:
349 cn_freq = webrtc::kFreq16000Hz;
350 break;
351 case 32000:
352 cn_freq = webrtc::kFreq32000Hz;
353 break;
354 default:
355 RTC_NOTREACHED();
356 return false;
357 }
solenbergbd9a77f2017-02-06 12:53:57 -0800358 if (!channel_proxy_->SetSendCNPayloadType(
359 send_codec_spec.cng_payload_type, cn_freq)) {
360 LOG(LS_WARNING) << "SetSendCNPayloadType() failed.";
minyue7a973442016-10-20 03:27:12 -0700361 // TODO(ajm): This failure condition will be removed from VoE.
362 // Restore the return here when we update to a new enough webrtc.
363 //
364 // Not returning false because the SetSendCNPayloadType will fail if
365 // the channel is already sending.
366 // This can happen if the remote description is applied twice, for
367 // example in the case of ROAP on top of JSEP, where both side will
368 // send the offer.
369 }
370 }
371
372 // Only turn on VAD if we have a CN payload type that matches the
373 // clockrate for the codec we are going to use.
374 if (send_codec_spec.cng_plfreq == send_codec_spec.codec_inst.plfreq &&
375 send_codec_spec.codec_inst.channels == 1) {
376 // TODO(minyue): If CN frequency == 48000 Hz is allowed, consider the
377 // interaction between VAD and Opus FEC.
solenbergbd9a77f2017-02-06 12:53:57 -0800378 if (!channel_proxy_->SetVADStatus(true)) {
379 LOG(LS_WARNING) << "SetVADStatus() failed.";
minyue7a973442016-10-20 03:27:12 -0700380 return false;
381 }
382 }
383 }
384 return true;
385}
386
solenbergc7a8b082015-10-16 14:35:07 -0700387} // namespace internal
388} // namespace webrtc