blob: fbed0f12af09281f57adc8620a3de708d1bb5a63 [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
solenberg3a941542015-11-16 07:34:50 -0800270 internal::AudioState* audio_state =
271 static_cast<internal::AudioState*>(audio_state_.get());
solenberg566ef242015-11-06 15:34:49 -0800272 stats.typing_noise_detected = audio_state->typing_noise_detected();
solenberg85a04962015-10-27 03:35:21 -0700273
274 return stats;
275}
276
pbos1ba8d392016-05-01 20:18:34 -0700277void AudioSendStream::SignalNetworkState(NetworkState state) {
278 RTC_DCHECK(thread_checker_.CalledOnValidThread());
279}
280
281bool AudioSendStream::DeliverRtcp(const uint8_t* packet, size_t length) {
282 // TODO(solenberg): Tests call this function on a network thread, libjingle
283 // calls on the worker thread. We should move towards always using a network
284 // thread. Then this check can be enabled.
285 // RTC_DCHECK(!thread_checker_.CalledOnValidThread());
286 return channel_proxy_->ReceivedRTCPPacket(packet, length);
287}
288
mflodman86cc6ff2016-07-26 04:44:06 -0700289uint32_t AudioSendStream::OnBitrateUpdated(uint32_t bitrate_bps,
290 uint8_t fraction_loss,
291 int64_t rtt) {
292 RTC_DCHECK_GE(bitrate_bps,
293 static_cast<uint32_t>(config_.min_bitrate_kbps * 1000));
294 // The bitrate allocator might allocate an higher than max configured bitrate
295 // if there is room, to allow for, as example, extra FEC. Ignore that for now.
296 const uint32_t max_bitrate_bps = config_.max_bitrate_kbps * 1000;
297 if (bitrate_bps > max_bitrate_bps)
298 bitrate_bps = max_bitrate_bps;
299
300 channel_proxy_->SetBitrate(bitrate_bps);
301
302 // The amount of audio protection is not exposed by the encoder, hence
303 // always returning 0.
304 return 0;
305}
306
solenberg85a04962015-10-27 03:35:21 -0700307const webrtc::AudioSendStream::Config& AudioSendStream::config() const {
308 RTC_DCHECK(thread_checker_.CalledOnValidThread());
309 return config_;
solenbergc7a8b082015-10-16 14:35:07 -0700310}
311
solenberg3a941542015-11-16 07:34:50 -0800312VoiceEngine* AudioSendStream::voice_engine() const {
313 internal::AudioState* audio_state =
314 static_cast<internal::AudioState*>(audio_state_.get());
315 VoiceEngine* voice_engine = audio_state->voice_engine();
316 RTC_DCHECK(voice_engine);
317 return voice_engine;
solenbergc7a8b082015-10-16 14:35:07 -0700318}
minyue7a973442016-10-20 03:27:12 -0700319
320// Apply current codec settings to a single voe::Channel used for sending.
321bool AudioSendStream::SetupSendCodec() {
322 ScopedVoEInterface<VoEBase> base(voice_engine());
323 ScopedVoEInterface<VoECodec> codec(voice_engine());
324
325 const int channel = config_.voe_channel_id;
326
327 // Disable VAD and FEC unless we know the other side wants them.
328 codec->SetVADStatus(channel, false);
329 codec->SetFECStatus(channel, false);
330
331 const auto& send_codec_spec = config_.send_codec_spec;
332
333 // Set the codec immediately, since SetVADStatus() depends on whether
334 // the current codec is mono or stereo.
335 LOG(LS_INFO) << "Send channel " << channel << " selected voice codec "
336 << ToString(send_codec_spec.codec_inst)
337 << ", bitrate=" << send_codec_spec.codec_inst.rate;
338
339 // If codec is already configured, we do not it again.
340 // TODO(minyue): check if this check is really needed, or can we move it into
341 // |codec->SetSendCodec|.
342 webrtc::CodecInst current_codec = {0};
343 if (codec->GetSendCodec(channel, current_codec) != 0 ||
344 (send_codec_spec.codec_inst != current_codec)) {
345 if (codec->SetSendCodec(channel, send_codec_spec.codec_inst) == -1) {
346 LOG_RTCERR2(SetSendCodec, channel, ToString(send_codec_spec.codec_inst),
347 base->LastError());
348 return false;
349 }
350 }
351
352 // FEC should be enabled after SetSendCodec.
353 if (send_codec_spec.enable_codec_fec) {
354 LOG(LS_INFO) << "Attempt to enable codec internal FEC on channel "
355 << channel;
356 if (codec->SetFECStatus(channel, true) == -1) {
357 // Enable codec internal FEC. Treat any failure as fatal internal error.
358 LOG_RTCERR2(SetFECStatus, channel, true, base->LastError());
359 return false;
360 }
361 }
362
363 if (IsCodec(send_codec_spec.codec_inst, kOpusCodecName)) {
364 // DTX and maxplaybackrate should be set after SetSendCodec. Because current
365 // send codec has to be Opus.
366
367 // Set Opus internal DTX.
368 LOG(LS_INFO) << "Attempt to "
369 << (send_codec_spec.enable_opus_dtx ? "enable" : "disable")
370 << " Opus DTX on channel " << channel;
371 if (codec->SetOpusDtx(channel, send_codec_spec.enable_opus_dtx)) {
372 LOG_RTCERR2(SetOpusDtx, channel, send_codec_spec.enable_opus_dtx,
373 base->LastError());
374 return false;
375 }
376
377 // If opus_max_playback_rate <= 0, the default maximum playback rate
378 // (48 kHz) will be used.
379 if (send_codec_spec.opus_max_playback_rate > 0) {
380 LOG(LS_INFO) << "Attempt to set maximum playback rate to "
381 << send_codec_spec.opus_max_playback_rate
382 << " Hz on channel " << channel;
383 if (codec->SetOpusMaxPlaybackRate(
384 channel, send_codec_spec.opus_max_playback_rate) == -1) {
385 LOG_RTCERR2(SetOpusMaxPlaybackRate, channel,
386 send_codec_spec.opus_max_playback_rate, base->LastError());
387 return false;
388 }
389 }
390 }
391
392 // Set the CN payloadtype and the VAD status.
393 if (send_codec_spec.cng_payload_type != -1) {
394 // The CN payload type for 8000 Hz clockrate is fixed at 13.
395 if (send_codec_spec.cng_plfreq != 8000) {
396 webrtc::PayloadFrequencies cn_freq;
397 switch (send_codec_spec.cng_plfreq) {
398 case 16000:
399 cn_freq = webrtc::kFreq16000Hz;
400 break;
401 case 32000:
402 cn_freq = webrtc::kFreq32000Hz;
403 break;
404 default:
405 RTC_NOTREACHED();
406 return false;
407 }
408 if (codec->SetSendCNPayloadType(channel, send_codec_spec.cng_payload_type,
409 cn_freq) == -1) {
410 LOG_RTCERR3(SetSendCNPayloadType, channel,
411 send_codec_spec.cng_payload_type, cn_freq,
412 base->LastError());
413
414 // TODO(ajm): This failure condition will be removed from VoE.
415 // Restore the return here when we update to a new enough webrtc.
416 //
417 // Not returning false because the SetSendCNPayloadType will fail if
418 // the channel is already sending.
419 // This can happen if the remote description is applied twice, for
420 // example in the case of ROAP on top of JSEP, where both side will
421 // send the offer.
422 }
423 }
424
425 // Only turn on VAD if we have a CN payload type that matches the
426 // clockrate for the codec we are going to use.
427 if (send_codec_spec.cng_plfreq == send_codec_spec.codec_inst.plfreq &&
428 send_codec_spec.codec_inst.channels == 1) {
429 // TODO(minyue): If CN frequency == 48000 Hz is allowed, consider the
430 // interaction between VAD and Opus FEC.
431 LOG(LS_INFO) << "Enabling VAD";
432 if (codec->SetVADStatus(channel, true) == -1) {
433 LOG_RTCERR2(SetVADStatus, channel, true, base->LastError());
434 return false;
435 }
436 }
437 }
438 return true;
439}
440
solenbergc7a8b082015-10-16 14:35:07 -0700441} // namespace internal
442} // namespace webrtc