blob: 3831b8d27a1997c008dee230bf056bce74922776 [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
minyue7a973442016-10-20 03:27:12 -070038bool IsCodec(const webrtc::CodecInst& codec, const char* ref_name) {
39 return (_stricmp(codec.plname, ref_name) == 0);
40}
minyue7a973442016-10-20 03:27:12 -070041} // namespace
42
solenbergc7a8b082015-10-16 14:35:07 -070043namespace internal {
solenberg566ef242015-11-06 15:34:49 -080044AudioSendStream::AudioSendStream(
45 const webrtc::AudioSendStream::Config& config,
Stefan Holmerb86d4e42015-12-07 10:26:18 +010046 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
perkj26091b12016-09-01 01:17:40 -070047 rtc::TaskQueue* worker_queue,
nisse0245da02016-11-30 03:35:20 -080048 PacketRouter* packet_router,
mflodman86cc6ff2016-07-26 04:44:06 -070049 CongestionController* congestion_controller,
tereliuse035e2d2016-09-21 06:51:47 -070050 BitrateAllocator* bitrate_allocator,
michaelt9332b7d2016-11-30 07:51:13 -080051 RtcEventLog* event_log,
52 RtcpRttStats* rtcp_rtt_stats)
perkj26091b12016-09-01 01:17:40 -070053 : worker_queue_(worker_queue),
54 config_(config),
mflodman86cc6ff2016-07-26 04:44:06 -070055 audio_state_(audio_state),
56 bitrate_allocator_(bitrate_allocator) {
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);
stefanbba9dec2016-02-01 04:39:55 -080066 channel_proxy_->RegisterSenderCongestionControlObjects(
Stefan Holmerb86d4e42015-12-07 10:26:18 +010067 congestion_controller->pacer(),
nisse0245da02016-11-30 03:35:20 -080068 congestion_controller->GetTransportFeedbackObserver(), packet_router);
solenberg13725082015-11-25 08:16:52 -080069 channel_proxy_->SetRTCPStatus(true);
70 channel_proxy_->SetLocalSSRC(config.rtp.ssrc);
71 channel_proxy_->SetRTCP_CNAME(config.rtp.c_name);
solenberg971cab02016-06-14 10:02:41 -070072 // TODO(solenberg): Config NACK history window (which is a packet count),
73 // using the actual packet size for the configured codec.
74 channel_proxy_->SetNACKStatus(config_.rtp.nack.rtp_history_ms != 0,
75 config_.rtp.nack.rtp_history_ms / 20);
Stefan Holmerb86d4e42015-12-07 10:26:18 +010076
mflodman3d7db262016-04-29 00:57:13 -070077 channel_proxy_->RegisterExternalTransport(config.send_transport);
78
solenberg3a941542015-11-16 07:34:50 -080079 for (const auto& extension : config.rtp.extensions) {
stefanb521aa72016-11-01 03:17:16 -070080 if (extension.uri == RtpExtension::kAudioLevelUri) {
solenberg358057b2015-11-27 10:46:42 -080081 channel_proxy_->SetSendAudioLevelIndicationStatus(true, extension.id);
isheriff6f8d6862016-05-26 11:24:55 -070082 } else if (extension.uri == RtpExtension::kTransportSequenceNumberUri) {
Stefan Holmerb86d4e42015-12-07 10:26:18 +010083 channel_proxy_->EnableSendTransportSequenceNumber(extension.id);
solenberg3a941542015-11-16 07:34:50 -080084 } else {
85 RTC_NOTREACHED() << "Registering unsupported RTP extension.";
86 }
87 }
minyue7a973442016-10-20 03:27:12 -070088 if (!SetupSendCodec()) {
89 LOG(LS_ERROR) << "Failed to set up send codec state.";
90 }
solenbergc7a8b082015-10-16 14:35:07 -070091}
92
93AudioSendStream::~AudioSendStream() {
solenberg85a04962015-10-27 03:35:21 -070094 RTC_DCHECK(thread_checker_.CalledOnValidThread());
solenbergc7a8b082015-10-16 14:35:07 -070095 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString();
mflodman3d7db262016-04-29 00:57:13 -070096 channel_proxy_->DeRegisterExternalTransport();
stefanbba9dec2016-02-01 04:39:55 -080097 channel_proxy_->ResetCongestionControlObjects();
tereliuse035e2d2016-09-21 06:51:47 -070098 channel_proxy_->SetRtcEventLog(nullptr);
michaelt9332b7d2016-11-30 07:51:13 -080099 channel_proxy_->SetRtcpRttStats(nullptr);
solenbergc7a8b082015-10-16 14:35:07 -0700100}
101
solenberg3a941542015-11-16 07:34:50 -0800102void AudioSendStream::Start() {
103 RTC_DCHECK(thread_checker_.CalledOnValidThread());
minyue10cbb462016-11-07 09:29:22 -0800104 if (config_.min_bitrate_bps != -1 && config_.max_bitrate_bps != -1) {
105 RTC_DCHECK_GE(config_.max_bitrate_bps, config_.min_bitrate_bps);
perkj26091b12016-09-01 01:17:40 -0700106 rtc::Event thread_sync_event(false /* manual_reset */, false);
107 worker_queue_->PostTask([this, &thread_sync_event] {
minyue10cbb462016-11-07 09:29:22 -0800108 bitrate_allocator_->AddObserver(this, config_.min_bitrate_bps,
109 config_.max_bitrate_bps, 0, true);
perkj26091b12016-09-01 01:17:40 -0700110 thread_sync_event.Set();
111 });
112 thread_sync_event.Wait(rtc::Event::kForever);
mflodman86cc6ff2016-07-26 04:44:06 -0700113 }
114
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800115 ScopedVoEInterface<VoEBase> base(voice_engine());
116 int error = base->StartSend(config_.voe_channel_id);
117 if (error != 0) {
118 LOG(LS_ERROR) << "AudioSendStream::Start failed with error: " << error;
119 }
solenberg3a941542015-11-16 07:34:50 -0800120}
121
122void AudioSendStream::Stop() {
123 RTC_DCHECK(thread_checker_.CalledOnValidThread());
perkj26091b12016-09-01 01:17:40 -0700124 rtc::Event thread_sync_event(false /* manual_reset */, false);
125 worker_queue_->PostTask([this, &thread_sync_event] {
126 bitrate_allocator_->RemoveObserver(this);
127 thread_sync_event.Set();
128 });
129 thread_sync_event.Wait(rtc::Event::kForever);
130
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800131 ScopedVoEInterface<VoEBase> base(voice_engine());
132 int error = base->StopSend(config_.voe_channel_id);
133 if (error != 0) {
134 LOG(LS_ERROR) << "AudioSendStream::Stop failed with error: " << error;
135 }
solenberg3a941542015-11-16 07:34:50 -0800136}
137
solenbergffbbcac2016-11-17 05:25:37 -0800138bool AudioSendStream::SendTelephoneEvent(int payload_type,
139 int payload_frequency, int event,
solenberg8842c3e2016-03-11 03:06:41 -0800140 int duration_ms) {
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100141 RTC_DCHECK(thread_checker_.CalledOnValidThread());
solenbergffbbcac2016-11-17 05:25:37 -0800142 return channel_proxy_->SetSendTelephoneEventPayloadType(payload_type,
143 payload_frequency) &&
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100144 channel_proxy_->SendTelephoneEventOutband(event, duration_ms);
145}
146
solenberg94218532016-06-16 10:53:22 -0700147void AudioSendStream::SetMuted(bool muted) {
148 RTC_DCHECK(thread_checker_.CalledOnValidThread());
149 channel_proxy_->SetInputMute(muted);
150}
151
solenbergc7a8b082015-10-16 14:35:07 -0700152webrtc::AudioSendStream::Stats AudioSendStream::GetStats() const {
solenberg85a04962015-10-27 03:35:21 -0700153 RTC_DCHECK(thread_checker_.CalledOnValidThread());
154 webrtc::AudioSendStream::Stats stats;
155 stats.local_ssrc = config_.rtp.ssrc;
solenberg3a941542015-11-16 07:34:50 -0800156 ScopedVoEInterface<VoEAudioProcessing> processing(voice_engine());
157 ScopedVoEInterface<VoECodec> codec(voice_engine());
solenberg3a941542015-11-16 07:34:50 -0800158 ScopedVoEInterface<VoEVolumeControl> volume(voice_engine());
solenberg85a04962015-10-27 03:35:21 -0700159
solenberg358057b2015-11-27 10:46:42 -0800160 webrtc::CallStatistics call_stats = channel_proxy_->GetRTCPStatistics();
solenberg85a04962015-10-27 03:35:21 -0700161 stats.bytes_sent = call_stats.bytesSent;
162 stats.packets_sent = call_stats.packetsSent;
solenberg8b85de22015-11-16 09:48:04 -0800163 // RTT isn't known until a RTCP report is received. Until then, VoiceEngine
164 // returns 0 to indicate an error value.
165 if (call_stats.rttMs > 0) {
166 stats.rtt_ms = call_stats.rttMs;
167 }
168 // TODO(solenberg): [was ajm]: Re-enable this metric once we have a reliable
169 // implementation.
170 stats.aec_quality_min = -1;
solenberg85a04962015-10-27 03:35:21 -0700171
172 webrtc::CodecInst codec_inst = {0};
173 if (codec->GetSendCodec(config_.voe_channel_id, codec_inst) != -1) {
174 RTC_DCHECK_NE(codec_inst.pltype, -1);
175 stats.codec_name = codec_inst.plname;
hbos1acfbd22016-11-17 23:43:29 -0800176 stats.codec_payload_type = rtc::Optional<int>(codec_inst.pltype);
solenberg85a04962015-10-27 03:35:21 -0700177
178 // Get data from the last remote RTCP report.
solenberg358057b2015-11-27 10:46:42 -0800179 for (const auto& block : channel_proxy_->GetRemoteRTCPReportBlocks()) {
solenberg8b85de22015-11-16 09:48:04 -0800180 // Lookup report for send ssrc only.
181 if (block.source_SSRC == stats.local_ssrc) {
182 stats.packets_lost = block.cumulative_num_packets_lost;
183 stats.fraction_lost = Q8ToFloat(block.fraction_lost);
184 stats.ext_seqnum = block.extended_highest_sequence_number;
185 // Convert samples to milliseconds.
186 if (codec_inst.plfreq / 1000 > 0) {
187 stats.jitter_ms =
188 block.interarrival_jitter / (codec_inst.plfreq / 1000);
solenberg85a04962015-10-27 03:35:21 -0700189 }
solenberg8b85de22015-11-16 09:48:04 -0800190 break;
solenberg85a04962015-10-27 03:35:21 -0700191 }
192 }
193 }
194
solenberg85a04962015-10-27 03:35:21 -0700195 // Local speech level.
196 {
197 unsigned int level = 0;
solenberg358057b2015-11-27 10:46:42 -0800198 int error = volume->GetSpeechInputLevelFullRange(level);
solenberg8b85de22015-11-16 09:48:04 -0800199 RTC_DCHECK_EQ(0, error);
200 stats.audio_level = static_cast<int32_t>(level);
solenberg85a04962015-10-27 03:35:21 -0700201 }
202
ivoc7aba0292016-11-14 04:52:06 -0800203 ScopedVoEInterface<VoEBase> base(voice_engine());
204 RTC_DCHECK(base->audio_processing());
205 auto audio_processing_stats = base->audio_processing()->GetStatistics();
206 stats.echo_delay_median_ms = audio_processing_stats.delay_median;
207 stats.echo_delay_std_ms = audio_processing_stats.delay_standard_deviation;
208 stats.echo_return_loss = audio_processing_stats.echo_return_loss.instant();
209 stats.echo_return_loss_enhancement =
210 audio_processing_stats.echo_return_loss_enhancement.instant();
211 stats.residual_echo_likelihood =
212 audio_processing_stats.residual_echo_likelihood;
ivoc4e477a12017-01-15 08:29:46 -0800213 stats.residual_echo_likelihood_recent_max =
214 audio_processing_stats.residual_echo_likelihood_recent_max;
ivoc8c63a822016-10-21 04:10:03 -0700215
solenberg3a941542015-11-16 07:34:50 -0800216 internal::AudioState* audio_state =
217 static_cast<internal::AudioState*>(audio_state_.get());
solenberg566ef242015-11-06 15:34:49 -0800218 stats.typing_noise_detected = audio_state->typing_noise_detected();
solenberg85a04962015-10-27 03:35:21 -0700219
220 return stats;
221}
222
pbos1ba8d392016-05-01 20:18:34 -0700223void AudioSendStream::SignalNetworkState(NetworkState state) {
224 RTC_DCHECK(thread_checker_.CalledOnValidThread());
225}
226
227bool AudioSendStream::DeliverRtcp(const uint8_t* packet, size_t length) {
228 // TODO(solenberg): Tests call this function on a network thread, libjingle
229 // calls on the worker thread. We should move towards always using a network
230 // thread. Then this check can be enabled.
231 // RTC_DCHECK(!thread_checker_.CalledOnValidThread());
232 return channel_proxy_->ReceivedRTCPPacket(packet, length);
233}
234
mflodman86cc6ff2016-07-26 04:44:06 -0700235uint32_t AudioSendStream::OnBitrateUpdated(uint32_t bitrate_bps,
236 uint8_t fraction_loss,
minyue78b4d562016-11-30 04:47:39 -0800237 int64_t rtt,
238 int64_t probing_interval_ms) {
mflodman86cc6ff2016-07-26 04:44:06 -0700239 RTC_DCHECK_GE(bitrate_bps,
minyue10cbb462016-11-07 09:29:22 -0800240 static_cast<uint32_t>(config_.min_bitrate_bps));
mflodman86cc6ff2016-07-26 04:44:06 -0700241 // The bitrate allocator might allocate an higher than max configured bitrate
242 // if there is room, to allow for, as example, extra FEC. Ignore that for now.
minyue10cbb462016-11-07 09:29:22 -0800243 const uint32_t max_bitrate_bps = config_.max_bitrate_bps;
mflodman86cc6ff2016-07-26 04:44:06 -0700244 if (bitrate_bps > max_bitrate_bps)
245 bitrate_bps = max_bitrate_bps;
246
minyue78b4d562016-11-30 04:47:39 -0800247 channel_proxy_->SetBitrate(bitrate_bps, probing_interval_ms);
mflodman86cc6ff2016-07-26 04:44:06 -0700248
249 // The amount of audio protection is not exposed by the encoder, hence
250 // always returning 0.
251 return 0;
252}
253
solenberg85a04962015-10-27 03:35:21 -0700254const webrtc::AudioSendStream::Config& AudioSendStream::config() const {
255 RTC_DCHECK(thread_checker_.CalledOnValidThread());
256 return config_;
solenbergc7a8b082015-10-16 14:35:07 -0700257}
258
michaelt79e05882016-11-08 02:50:09 -0800259void AudioSendStream::SetTransportOverhead(int transport_overhead_per_packet) {
260 RTC_DCHECK(thread_checker_.CalledOnValidThread());
261 channel_proxy_->SetTransportOverhead(transport_overhead_per_packet);
262}
263
solenberg3a941542015-11-16 07:34:50 -0800264VoiceEngine* AudioSendStream::voice_engine() const {
265 internal::AudioState* audio_state =
266 static_cast<internal::AudioState*>(audio_state_.get());
267 VoiceEngine* voice_engine = audio_state->voice_engine();
268 RTC_DCHECK(voice_engine);
269 return voice_engine;
solenbergc7a8b082015-10-16 14:35:07 -0700270}
minyue7a973442016-10-20 03:27:12 -0700271
272// Apply current codec settings to a single voe::Channel used for sending.
273bool AudioSendStream::SetupSendCodec() {
274 ScopedVoEInterface<VoEBase> base(voice_engine());
275 ScopedVoEInterface<VoECodec> codec(voice_engine());
276
277 const int channel = config_.voe_channel_id;
278
279 // Disable VAD and FEC unless we know the other side wants them.
280 codec->SetVADStatus(channel, false);
281 codec->SetFECStatus(channel, false);
282
minyue6f0b9fd2016-11-14 00:51:50 -0800283 // We disable audio network adaptor here. This will on one hand make sure that
284 // audio network adaptor is disabled by default, and on the other allow audio
285 // network adaptor to be reconfigured, since SetReceiverFrameLengthRange can
286 // be only called when audio network adaptor is disabled.
287 channel_proxy_->DisableAudioNetworkAdaptor();
288
minyue7a973442016-10-20 03:27:12 -0700289 const auto& send_codec_spec = config_.send_codec_spec;
290
solenberg940b6d62016-10-25 11:19:07 -0700291 // We set the codec first, since the below extra configuration is only applied
292 // to the "current" codec.
minyue7a973442016-10-20 03:27:12 -0700293
294 // If codec is already configured, we do not it again.
295 // TODO(minyue): check if this check is really needed, or can we move it into
296 // |codec->SetSendCodec|.
297 webrtc::CodecInst current_codec = {0};
298 if (codec->GetSendCodec(channel, current_codec) != 0 ||
299 (send_codec_spec.codec_inst != current_codec)) {
300 if (codec->SetSendCodec(channel, send_codec_spec.codec_inst) == -1) {
solenberg940b6d62016-10-25 11:19:07 -0700301 LOG(LS_WARNING) << "SetSendCodec() failed: " << base->LastError();
minyue7a973442016-10-20 03:27:12 -0700302 return false;
303 }
304 }
305
solenberg940b6d62016-10-25 11:19:07 -0700306 // Codec internal FEC. Treat any failure as fatal internal error.
minyue7a973442016-10-20 03:27:12 -0700307 if (send_codec_spec.enable_codec_fec) {
solenberg940b6d62016-10-25 11:19:07 -0700308 if (codec->SetFECStatus(channel, true) != 0) {
309 LOG(LS_WARNING) << "SetFECStatus() failed: " << base->LastError();
minyue7a973442016-10-20 03:27:12 -0700310 return false;
311 }
312 }
313
solenberg940b6d62016-10-25 11:19:07 -0700314 // DTX and maxplaybackrate are only set if current codec is Opus.
minyue7a973442016-10-20 03:27:12 -0700315 if (IsCodec(send_codec_spec.codec_inst, kOpusCodecName)) {
solenberg940b6d62016-10-25 11:19:07 -0700316 if (codec->SetOpusDtx(channel, send_codec_spec.enable_opus_dtx) != 0) {
317 LOG(LS_WARNING) << "SetOpusDtx() failed: " << base->LastError();
minyue7a973442016-10-20 03:27:12 -0700318 return false;
319 }
320
321 // If opus_max_playback_rate <= 0, the default maximum playback rate
322 // (48 kHz) will be used.
323 if (send_codec_spec.opus_max_playback_rate > 0) {
minyue7a973442016-10-20 03:27:12 -0700324 if (codec->SetOpusMaxPlaybackRate(
solenberg940b6d62016-10-25 11:19:07 -0700325 channel, send_codec_spec.opus_max_playback_rate) != 0) {
326 LOG(LS_WARNING) << "SetOpusMaxPlaybackRate() failed: "
327 << base->LastError();
minyue7a973442016-10-20 03:27:12 -0700328 return false;
329 }
330 }
minyue6b825df2016-10-31 04:08:32 -0700331
332 if (config_.audio_network_adaptor_config) {
333 // Audio network adaptor is only allowed for Opus currently.
334 // |SetReceiverFrameLengthRange| needs to be called before
335 // |EnableAudioNetworkAdaptor|.
336 channel_proxy_->SetReceiverFrameLengthRange(send_codec_spec.min_ptime_ms,
337 send_codec_spec.max_ptime_ms);
338 channel_proxy_->EnableAudioNetworkAdaptor(
339 *config_.audio_network_adaptor_config);
340 LOG(LS_INFO) << "Audio network adaptor enabled on SSRC "
341 << config_.rtp.ssrc;
minyue6b825df2016-10-31 04:08:32 -0700342 }
minyue7a973442016-10-20 03:27:12 -0700343 }
344
345 // Set the CN payloadtype and the VAD status.
346 if (send_codec_spec.cng_payload_type != -1) {
347 // The CN payload type for 8000 Hz clockrate is fixed at 13.
348 if (send_codec_spec.cng_plfreq != 8000) {
349 webrtc::PayloadFrequencies cn_freq;
350 switch (send_codec_spec.cng_plfreq) {
351 case 16000:
352 cn_freq = webrtc::kFreq16000Hz;
353 break;
354 case 32000:
355 cn_freq = webrtc::kFreq32000Hz;
356 break;
357 default:
358 RTC_NOTREACHED();
359 return false;
360 }
361 if (codec->SetSendCNPayloadType(channel, send_codec_spec.cng_payload_type,
solenberg940b6d62016-10-25 11:19:07 -0700362 cn_freq) != 0) {
363 LOG(LS_WARNING) << "SetSendCNPayloadType() failed: "
364 << base->LastError();
minyue7a973442016-10-20 03:27:12 -0700365 // TODO(ajm): This failure condition will be removed from VoE.
366 // Restore the return here when we update to a new enough webrtc.
367 //
368 // Not returning false because the SetSendCNPayloadType will fail if
369 // the channel is already sending.
370 // This can happen if the remote description is applied twice, for
371 // example in the case of ROAP on top of JSEP, where both side will
372 // send the offer.
373 }
374 }
375
376 // Only turn on VAD if we have a CN payload type that matches the
377 // clockrate for the codec we are going to use.
378 if (send_codec_spec.cng_plfreq == send_codec_spec.codec_inst.plfreq &&
379 send_codec_spec.codec_inst.channels == 1) {
380 // TODO(minyue): If CN frequency == 48000 Hz is allowed, consider the
381 // interaction between VAD and Opus FEC.
solenberg940b6d62016-10-25 11:19:07 -0700382 if (codec->SetVADStatus(channel, true) != 0) {
383 LOG(LS_WARNING) << "SetVADStatus() failed: " << base->LastError();
minyue7a973442016-10-20 03:27:12 -0700384 return false;
385 }
386 }
387 }
388 return true;
389}
390
solenbergc7a8b082015-10-16 14:35:07 -0700391} // namespace internal
392} // namespace webrtc