blob: 8925b042b5603a0a1641237a87e0dbf7659a7ce0 [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"
Stefan Holmer80e12072016-02-23 13:30:42 +010022#include "webrtc/modules/congestion_controller/include/congestion_controller.h"
Stefan Holmerb86d4e42015-12-07 10:26:18 +010023#include "webrtc/modules/pacing/paced_sender.h"
24#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
solenberg13725082015-11-25 08:16:52 -080025#include "webrtc/voice_engine/channel_proxy.h"
solenberg85a04962015-10-27 03:35:21 -070026#include "webrtc/voice_engine/include/voe_audio_processing.h"
27#include "webrtc/voice_engine/include/voe_codec.h"
28#include "webrtc/voice_engine/include/voe_rtp_rtcp.h"
29#include "webrtc/voice_engine/include/voe_volume_control.h"
solenberg13725082015-11-25 08:16:52 -080030#include "webrtc/voice_engine/voice_engine_impl.h"
solenbergc7a8b082015-10-16 14:35:07 -070031
32namespace webrtc {
minyue7a973442016-10-20 03:27:12 -070033
34namespace {
35
36constexpr char kOpusCodecName[] = "opus";
37
38// TODO(minyue): Remove |LOG_RTCERR2|.
39#define LOG_RTCERR2(func, a1, a2, err) \
40 LOG(LS_WARNING) << "" << #func << "(" << a1 << ", " << a2 \
41 << ") failed, err=" << err
42
43// TODO(minyue): Remove |LOG_RTCERR3|.
44#define LOG_RTCERR3(func, a1, a2, a3, err) \
45 LOG(LS_WARNING) << "" << #func << "(" << a1 << ", " << a2 << ", " << a3 \
46 << ") failed, err=" << err
47
48std::string ToString(const webrtc::CodecInst& codec) {
49 std::stringstream ss;
50 ss << codec.plname << "/" << codec.plfreq << "/" << codec.channels << " ("
51 << codec.pltype << ")";
52 return ss.str();
53}
54
55bool IsCodec(const webrtc::CodecInst& codec, const char* ref_name) {
56 return (_stricmp(codec.plname, ref_name) == 0);
57}
58
59} // namespace
60
solenbergc7a8b082015-10-16 14:35:07 -070061std::string AudioSendStream::Config::Rtp::ToString() const {
62 std::stringstream ss;
63 ss << "{ssrc: " << ssrc;
64 ss << ", extensions: [";
65 for (size_t i = 0; i < extensions.size(); ++i) {
66 ss << extensions[i].ToString();
solenberg85a04962015-10-27 03:35:21 -070067 if (i != extensions.size() - 1) {
solenbergc7a8b082015-10-16 14:35:07 -070068 ss << ", ";
solenberg85a04962015-10-27 03:35:21 -070069 }
solenbergc7a8b082015-10-16 14:35:07 -070070 }
71 ss << ']';
solenberg971cab02016-06-14 10:02:41 -070072 ss << ", nack: " << nack.ToString();
solenberg3a941542015-11-16 07:34:50 -080073 ss << ", c_name: " << c_name;
solenbergc7a8b082015-10-16 14:35:07 -070074 ss << '}';
75 return ss.str();
76}
77
78std::string AudioSendStream::Config::ToString() const {
79 std::stringstream ss;
80 ss << "{rtp: " << rtp.ToString();
81 ss << ", voe_channel_id: " << voe_channel_id;
82 // TODO(solenberg): Encoder config.
minyue7a973442016-10-20 03:27:12 -070083 ss << ", cng_payload_type: " << send_codec_spec.cng_payload_type;
solenbergc7a8b082015-10-16 14:35:07 -070084 ss << '}';
85 return ss.str();
86}
87
88namespace internal {
solenberg566ef242015-11-06 15:34:49 -080089AudioSendStream::AudioSendStream(
90 const webrtc::AudioSendStream::Config& config,
Stefan Holmerb86d4e42015-12-07 10:26:18 +010091 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
perkj26091b12016-09-01 01:17:40 -070092 rtc::TaskQueue* worker_queue,
mflodman86cc6ff2016-07-26 04:44:06 -070093 CongestionController* congestion_controller,
tereliuse035e2d2016-09-21 06:51:47 -070094 BitrateAllocator* bitrate_allocator,
sprang982bf892016-10-13 06:23:11 -070095 RtcEventLog* event_log)
perkj26091b12016-09-01 01:17:40 -070096 : worker_queue_(worker_queue),
97 config_(config),
mflodman86cc6ff2016-07-26 04:44:06 -070098 audio_state_(audio_state),
99 bitrate_allocator_(bitrate_allocator) {
solenbergc7a8b082015-10-16 14:35:07 -0700100 LOG(LS_INFO) << "AudioSendStream: " << config_.ToString();
solenberg566ef242015-11-06 15:34:49 -0800101 RTC_DCHECK_NE(config_.voe_channel_id, -1);
102 RTC_DCHECK(audio_state_.get());
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100103 RTC_DCHECK(congestion_controller);
solenberg3a941542015-11-16 07:34:50 -0800104
solenberg13725082015-11-25 08:16:52 -0800105 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine());
kwibergfffa42b2016-02-23 10:46:32 -0800106 channel_proxy_ = voe_impl->GetChannelProxy(config_.voe_channel_id);
tereliuse035e2d2016-09-21 06:51:47 -0700107 channel_proxy_->SetRtcEventLog(event_log);
stefanbba9dec2016-02-01 04:39:55 -0800108 channel_proxy_->RegisterSenderCongestionControlObjects(
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100109 congestion_controller->pacer(),
110 congestion_controller->GetTransportFeedbackObserver(),
111 congestion_controller->packet_router());
solenberg13725082015-11-25 08:16:52 -0800112 channel_proxy_->SetRTCPStatus(true);
113 channel_proxy_->SetLocalSSRC(config.rtp.ssrc);
114 channel_proxy_->SetRTCP_CNAME(config.rtp.c_name);
solenberg971cab02016-06-14 10:02:41 -0700115 // TODO(solenberg): Config NACK history window (which is a packet count),
116 // using the actual packet size for the configured codec.
117 channel_proxy_->SetNACKStatus(config_.rtp.nack.rtp_history_ms != 0,
118 config_.rtp.nack.rtp_history_ms / 20);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100119
mflodman3d7db262016-04-29 00:57:13 -0700120 channel_proxy_->RegisterExternalTransport(config.send_transport);
121
solenberg3a941542015-11-16 07:34:50 -0800122 for (const auto& extension : config.rtp.extensions) {
isheriff6f8d6862016-05-26 11:24:55 -0700123 if (extension.uri == RtpExtension::kAbsSendTimeUri) {
solenberg358057b2015-11-27 10:46:42 -0800124 channel_proxy_->SetSendAbsoluteSenderTimeStatus(true, extension.id);
isheriff6f8d6862016-05-26 11:24:55 -0700125 } else if (extension.uri == RtpExtension::kAudioLevelUri) {
solenberg358057b2015-11-27 10:46:42 -0800126 channel_proxy_->SetSendAudioLevelIndicationStatus(true, extension.id);
isheriff6f8d6862016-05-26 11:24:55 -0700127 } else if (extension.uri == RtpExtension::kTransportSequenceNumberUri) {
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100128 channel_proxy_->EnableSendTransportSequenceNumber(extension.id);
solenberg3a941542015-11-16 07:34:50 -0800129 } else {
130 RTC_NOTREACHED() << "Registering unsupported RTP extension.";
131 }
132 }
minyue7a973442016-10-20 03:27:12 -0700133 if (!SetupSendCodec()) {
134 LOG(LS_ERROR) << "Failed to set up send codec state.";
135 }
solenbergc7a8b082015-10-16 14:35:07 -0700136}
137
138AudioSendStream::~AudioSendStream() {
solenberg85a04962015-10-27 03:35:21 -0700139 RTC_DCHECK(thread_checker_.CalledOnValidThread());
solenbergc7a8b082015-10-16 14:35:07 -0700140 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString();
mflodman3d7db262016-04-29 00:57:13 -0700141 channel_proxy_->DeRegisterExternalTransport();
stefanbba9dec2016-02-01 04:39:55 -0800142 channel_proxy_->ResetCongestionControlObjects();
tereliuse035e2d2016-09-21 06:51:47 -0700143 channel_proxy_->SetRtcEventLog(nullptr);
solenbergc7a8b082015-10-16 14:35:07 -0700144}
145
solenberg3a941542015-11-16 07:34:50 -0800146void AudioSendStream::Start() {
147 RTC_DCHECK(thread_checker_.CalledOnValidThread());
mflodman86cc6ff2016-07-26 04:44:06 -0700148 if (config_.min_bitrate_kbps != -1 && config_.max_bitrate_kbps != -1) {
149 RTC_DCHECK_GE(config_.max_bitrate_kbps, config_.min_bitrate_kbps);
perkj26091b12016-09-01 01:17:40 -0700150 rtc::Event thread_sync_event(false /* manual_reset */, false);
151 worker_queue_->PostTask([this, &thread_sync_event] {
152 bitrate_allocator_->AddObserver(this, config_.min_bitrate_kbps * 1000,
153 config_.max_bitrate_kbps * 1000, 0, true);
154 thread_sync_event.Set();
155 });
156 thread_sync_event.Wait(rtc::Event::kForever);
mflodman86cc6ff2016-07-26 04:44:06 -0700157 }
158
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800159 ScopedVoEInterface<VoEBase> base(voice_engine());
160 int error = base->StartSend(config_.voe_channel_id);
161 if (error != 0) {
162 LOG(LS_ERROR) << "AudioSendStream::Start failed with error: " << error;
163 }
solenberg3a941542015-11-16 07:34:50 -0800164}
165
166void AudioSendStream::Stop() {
167 RTC_DCHECK(thread_checker_.CalledOnValidThread());
perkj26091b12016-09-01 01:17:40 -0700168 rtc::Event thread_sync_event(false /* manual_reset */, false);
169 worker_queue_->PostTask([this, &thread_sync_event] {
170 bitrate_allocator_->RemoveObserver(this);
171 thread_sync_event.Set();
172 });
173 thread_sync_event.Wait(rtc::Event::kForever);
174
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800175 ScopedVoEInterface<VoEBase> base(voice_engine());
176 int error = base->StopSend(config_.voe_channel_id);
177 if (error != 0) {
178 LOG(LS_ERROR) << "AudioSendStream::Stop failed with error: " << error;
179 }
solenberg3a941542015-11-16 07:34:50 -0800180}
181
solenberg8842c3e2016-03-11 03:06:41 -0800182bool AudioSendStream::SendTelephoneEvent(int payload_type, int event,
183 int duration_ms) {
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100184 RTC_DCHECK(thread_checker_.CalledOnValidThread());
185 return channel_proxy_->SetSendTelephoneEventPayloadType(payload_type) &&
186 channel_proxy_->SendTelephoneEventOutband(event, duration_ms);
187}
188
solenberg94218532016-06-16 10:53:22 -0700189void AudioSendStream::SetMuted(bool muted) {
190 RTC_DCHECK(thread_checker_.CalledOnValidThread());
191 channel_proxy_->SetInputMute(muted);
192}
193
solenbergc7a8b082015-10-16 14:35:07 -0700194webrtc::AudioSendStream::Stats AudioSendStream::GetStats() const {
solenberg85a04962015-10-27 03:35:21 -0700195 RTC_DCHECK(thread_checker_.CalledOnValidThread());
196 webrtc::AudioSendStream::Stats stats;
197 stats.local_ssrc = config_.rtp.ssrc;
solenberg3a941542015-11-16 07:34:50 -0800198 ScopedVoEInterface<VoEAudioProcessing> processing(voice_engine());
199 ScopedVoEInterface<VoECodec> codec(voice_engine());
solenberg3a941542015-11-16 07:34:50 -0800200 ScopedVoEInterface<VoEVolumeControl> volume(voice_engine());
solenberg85a04962015-10-27 03:35:21 -0700201
solenberg358057b2015-11-27 10:46:42 -0800202 webrtc::CallStatistics call_stats = channel_proxy_->GetRTCPStatistics();
solenberg85a04962015-10-27 03:35:21 -0700203 stats.bytes_sent = call_stats.bytesSent;
204 stats.packets_sent = call_stats.packetsSent;
solenberg8b85de22015-11-16 09:48:04 -0800205 // RTT isn't known until a RTCP report is received. Until then, VoiceEngine
206 // returns 0 to indicate an error value.
207 if (call_stats.rttMs > 0) {
208 stats.rtt_ms = call_stats.rttMs;
209 }
210 // TODO(solenberg): [was ajm]: Re-enable this metric once we have a reliable
211 // implementation.
212 stats.aec_quality_min = -1;
solenberg85a04962015-10-27 03:35:21 -0700213
214 webrtc::CodecInst codec_inst = {0};
215 if (codec->GetSendCodec(config_.voe_channel_id, codec_inst) != -1) {
216 RTC_DCHECK_NE(codec_inst.pltype, -1);
217 stats.codec_name = codec_inst.plname;
218
219 // Get data from the last remote RTCP report.
solenberg358057b2015-11-27 10:46:42 -0800220 for (const auto& block : channel_proxy_->GetRemoteRTCPReportBlocks()) {
solenberg8b85de22015-11-16 09:48:04 -0800221 // Lookup report for send ssrc only.
222 if (block.source_SSRC == stats.local_ssrc) {
223 stats.packets_lost = block.cumulative_num_packets_lost;
224 stats.fraction_lost = Q8ToFloat(block.fraction_lost);
225 stats.ext_seqnum = block.extended_highest_sequence_number;
226 // Convert samples to milliseconds.
227 if (codec_inst.plfreq / 1000 > 0) {
228 stats.jitter_ms =
229 block.interarrival_jitter / (codec_inst.plfreq / 1000);
solenberg85a04962015-10-27 03:35:21 -0700230 }
solenberg8b85de22015-11-16 09:48:04 -0800231 break;
solenberg85a04962015-10-27 03:35:21 -0700232 }
233 }
234 }
235
solenberg85a04962015-10-27 03:35:21 -0700236 // Local speech level.
237 {
238 unsigned int level = 0;
solenberg358057b2015-11-27 10:46:42 -0800239 int error = volume->GetSpeechInputLevelFullRange(level);
solenberg8b85de22015-11-16 09:48:04 -0800240 RTC_DCHECK_EQ(0, error);
241 stats.audio_level = static_cast<int32_t>(level);
solenberg85a04962015-10-27 03:35:21 -0700242 }
243
solenberg85a04962015-10-27 03:35:21 -0700244 bool echo_metrics_on = false;
solenberg358057b2015-11-27 10:46:42 -0800245 int error = processing->GetEcMetricsStatus(echo_metrics_on);
solenberg8b85de22015-11-16 09:48:04 -0800246 RTC_DCHECK_EQ(0, error);
247 if (echo_metrics_on) {
solenberg85a04962015-10-27 03:35:21 -0700248 // These can also be negative, but in practice -1 is only used to signal
249 // insufficient data, since the resolution is limited to multiples of 4 ms.
250 int median = -1;
251 int std = -1;
252 float dummy = 0.0f;
solenberg8b85de22015-11-16 09:48:04 -0800253 error = processing->GetEcDelayMetrics(median, std, dummy);
254 RTC_DCHECK_EQ(0, error);
255 stats.echo_delay_median_ms = median;
256 stats.echo_delay_std_ms = std;
solenberg85a04962015-10-27 03:35:21 -0700257
258 // These can take on valid negative values, so use the lowest possible level
259 // as default rather than -1.
260 int erl = -100;
261 int erle = -100;
262 int dummy1 = 0;
263 int dummy2 = 0;
solenberg8b85de22015-11-16 09:48:04 -0800264 error = processing->GetEchoMetrics(erl, erle, dummy1, dummy2);
265 RTC_DCHECK_EQ(0, error);
266 stats.echo_return_loss = erl;
267 stats.echo_return_loss_enhancement = erle;
solenberg85a04962015-10-27 03:35:21 -0700268 }
269
ivoc8c63a822016-10-21 04:10:03 -0700270 // TODO(ivoc): Hook this up to the residual echo detector.
271 stats.residual_echo_likelihood = 0.0f;
272
solenberg3a941542015-11-16 07:34:50 -0800273 internal::AudioState* audio_state =
274 static_cast<internal::AudioState*>(audio_state_.get());
solenberg566ef242015-11-06 15:34:49 -0800275 stats.typing_noise_detected = audio_state->typing_noise_detected();
solenberg85a04962015-10-27 03:35:21 -0700276
277 return stats;
278}
279
pbos1ba8d392016-05-01 20:18:34 -0700280void AudioSendStream::SignalNetworkState(NetworkState state) {
281 RTC_DCHECK(thread_checker_.CalledOnValidThread());
282}
283
284bool AudioSendStream::DeliverRtcp(const uint8_t* packet, size_t length) {
285 // TODO(solenberg): Tests call this function on a network thread, libjingle
286 // calls on the worker thread. We should move towards always using a network
287 // thread. Then this check can be enabled.
288 // RTC_DCHECK(!thread_checker_.CalledOnValidThread());
289 return channel_proxy_->ReceivedRTCPPacket(packet, length);
290}
291
mflodman86cc6ff2016-07-26 04:44:06 -0700292uint32_t AudioSendStream::OnBitrateUpdated(uint32_t bitrate_bps,
293 uint8_t fraction_loss,
294 int64_t rtt) {
295 RTC_DCHECK_GE(bitrate_bps,
296 static_cast<uint32_t>(config_.min_bitrate_kbps * 1000));
297 // The bitrate allocator might allocate an higher than max configured bitrate
298 // if there is room, to allow for, as example, extra FEC. Ignore that for now.
299 const uint32_t max_bitrate_bps = config_.max_bitrate_kbps * 1000;
300 if (bitrate_bps > max_bitrate_bps)
301 bitrate_bps = max_bitrate_bps;
302
303 channel_proxy_->SetBitrate(bitrate_bps);
304
305 // The amount of audio protection is not exposed by the encoder, hence
306 // always returning 0.
307 return 0;
308}
309
solenberg85a04962015-10-27 03:35:21 -0700310const webrtc::AudioSendStream::Config& AudioSendStream::config() const {
311 RTC_DCHECK(thread_checker_.CalledOnValidThread());
312 return config_;
solenbergc7a8b082015-10-16 14:35:07 -0700313}
314
solenberg3a941542015-11-16 07:34:50 -0800315VoiceEngine* AudioSendStream::voice_engine() const {
316 internal::AudioState* audio_state =
317 static_cast<internal::AudioState*>(audio_state_.get());
318 VoiceEngine* voice_engine = audio_state->voice_engine();
319 RTC_DCHECK(voice_engine);
320 return voice_engine;
solenbergc7a8b082015-10-16 14:35:07 -0700321}
minyue7a973442016-10-20 03:27:12 -0700322
323// Apply current codec settings to a single voe::Channel used for sending.
324bool AudioSendStream::SetupSendCodec() {
325 ScopedVoEInterface<VoEBase> base(voice_engine());
326 ScopedVoEInterface<VoECodec> codec(voice_engine());
327
328 const int channel = config_.voe_channel_id;
329
330 // Disable VAD and FEC unless we know the other side wants them.
331 codec->SetVADStatus(channel, false);
332 codec->SetFECStatus(channel, false);
333
334 const auto& send_codec_spec = config_.send_codec_spec;
335
336 // Set the codec immediately, since SetVADStatus() depends on whether
337 // the current codec is mono or stereo.
338 LOG(LS_INFO) << "Send channel " << channel << " selected voice codec "
339 << ToString(send_codec_spec.codec_inst)
340 << ", bitrate=" << send_codec_spec.codec_inst.rate;
341
342 // If codec is already configured, we do not it again.
343 // TODO(minyue): check if this check is really needed, or can we move it into
344 // |codec->SetSendCodec|.
345 webrtc::CodecInst current_codec = {0};
346 if (codec->GetSendCodec(channel, current_codec) != 0 ||
347 (send_codec_spec.codec_inst != current_codec)) {
348 if (codec->SetSendCodec(channel, send_codec_spec.codec_inst) == -1) {
349 LOG_RTCERR2(SetSendCodec, channel, ToString(send_codec_spec.codec_inst),
350 base->LastError());
351 return false;
352 }
353 }
354
355 // FEC should be enabled after SetSendCodec.
356 if (send_codec_spec.enable_codec_fec) {
357 LOG(LS_INFO) << "Attempt to enable codec internal FEC on channel "
358 << channel;
359 if (codec->SetFECStatus(channel, true) == -1) {
360 // Enable codec internal FEC. Treat any failure as fatal internal error.
361 LOG_RTCERR2(SetFECStatus, channel, true, base->LastError());
362 return false;
363 }
364 }
365
366 if (IsCodec(send_codec_spec.codec_inst, kOpusCodecName)) {
367 // DTX and maxplaybackrate should be set after SetSendCodec. Because current
368 // send codec has to be Opus.
369
370 // Set Opus internal DTX.
371 LOG(LS_INFO) << "Attempt to "
372 << (send_codec_spec.enable_opus_dtx ? "enable" : "disable")
373 << " Opus DTX on channel " << channel;
374 if (codec->SetOpusDtx(channel, send_codec_spec.enable_opus_dtx)) {
375 LOG_RTCERR2(SetOpusDtx, channel, send_codec_spec.enable_opus_dtx,
376 base->LastError());
377 return false;
378 }
379
380 // If opus_max_playback_rate <= 0, the default maximum playback rate
381 // (48 kHz) will be used.
382 if (send_codec_spec.opus_max_playback_rate > 0) {
383 LOG(LS_INFO) << "Attempt to set maximum playback rate to "
384 << send_codec_spec.opus_max_playback_rate
385 << " Hz on channel " << channel;
386 if (codec->SetOpusMaxPlaybackRate(
387 channel, send_codec_spec.opus_max_playback_rate) == -1) {
388 LOG_RTCERR2(SetOpusMaxPlaybackRate, channel,
389 send_codec_spec.opus_max_playback_rate, base->LastError());
390 return false;
391 }
392 }
393 }
394
395 // Set the CN payloadtype and the VAD status.
396 if (send_codec_spec.cng_payload_type != -1) {
397 // The CN payload type for 8000 Hz clockrate is fixed at 13.
398 if (send_codec_spec.cng_plfreq != 8000) {
399 webrtc::PayloadFrequencies cn_freq;
400 switch (send_codec_spec.cng_plfreq) {
401 case 16000:
402 cn_freq = webrtc::kFreq16000Hz;
403 break;
404 case 32000:
405 cn_freq = webrtc::kFreq32000Hz;
406 break;
407 default:
408 RTC_NOTREACHED();
409 return false;
410 }
411 if (codec->SetSendCNPayloadType(channel, send_codec_spec.cng_payload_type,
412 cn_freq) == -1) {
413 LOG_RTCERR3(SetSendCNPayloadType, channel,
414 send_codec_spec.cng_payload_type, cn_freq,
415 base->LastError());
416
417 // TODO(ajm): This failure condition will be removed from VoE.
418 // Restore the return here when we update to a new enough webrtc.
419 //
420 // Not returning false because the SetSendCNPayloadType will fail if
421 // the channel is already sending.
422 // This can happen if the remote description is applied twice, for
423 // example in the case of ROAP on top of JSEP, where both side will
424 // send the offer.
425 }
426 }
427
428 // Only turn on VAD if we have a CN payload type that matches the
429 // clockrate for the codec we are going to use.
430 if (send_codec_spec.cng_plfreq == send_codec_spec.codec_inst.plfreq &&
431 send_codec_spec.codec_inst.channels == 1) {
432 // TODO(minyue): If CN frequency == 48000 Hz is allowed, consider the
433 // interaction between VAD and Opus FEC.
434 LOG(LS_INFO) << "Enabling VAD";
435 if (codec->SetVADStatus(channel, true) == -1) {
436 LOG_RTCERR2(SetVADStatus, channel, true, base->LastError());
437 return false;
438 }
439 }
440 }
441 return true;
442}
443
solenbergc7a8b082015-10-16 14:35:07 -0700444} // namespace internal
445} // namespace webrtc