| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 "webrtc/audio/audio_send_stream.h" | 11 #include "webrtc/audio/audio_send_stream.h" |
| 12 | 12 |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "webrtc/audio/audio_state.h" | 15 #include "webrtc/audio/audio_state.h" |
| 16 #include "webrtc/audio/conversion.h" | 16 #include "webrtc/audio/conversion.h" |
| 17 #include "webrtc/audio/scoped_voe_interface.h" | 17 #include "webrtc/audio/scoped_voe_interface.h" |
| 18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
| 19 #include "webrtc/base/event.h" | 19 #include "webrtc/base/event.h" |
| 20 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
| 21 #include "webrtc/base/task_queue.h" | 21 #include "webrtc/base/task_queue.h" |
| 22 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 22 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
| 23 #include "webrtc/modules/pacing/paced_sender.h" | 23 #include "webrtc/modules/pacing/paced_sender.h" |
| 24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 25 #include "webrtc/voice_engine/channel_proxy.h" | 25 #include "webrtc/voice_engine/channel_proxy.h" |
| 26 #include "webrtc/voice_engine/include/voe_audio_processing.h" | 26 #include "webrtc/voice_engine/include/voe_base.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" | 27 #include "webrtc/voice_engine/include/voe_volume_control.h" |
| 30 #include "webrtc/voice_engine/voice_engine_impl.h" | 28 #include "webrtc/voice_engine/voice_engine_impl.h" |
| 31 | 29 |
| 32 namespace webrtc { | 30 namespace webrtc { |
| 33 | 31 |
| 34 namespace { | 32 namespace { |
| 35 | 33 |
| 36 constexpr char kOpusCodecName[] = "opus"; | 34 constexpr char kOpusCodecName[] = "opus"; |
| 37 | 35 |
| 38 bool IsCodec(const webrtc::CodecInst& codec, const char* ref_name) { | 36 bool IsCodec(const webrtc::CodecInst& codec, const char* ref_name) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 146 |
| 149 void AudioSendStream::SetMuted(bool muted) { | 147 void AudioSendStream::SetMuted(bool muted) { |
| 150 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 148 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 151 channel_proxy_->SetInputMute(muted); | 149 channel_proxy_->SetInputMute(muted); |
| 152 } | 150 } |
| 153 | 151 |
| 154 webrtc::AudioSendStream::Stats AudioSendStream::GetStats() const { | 152 webrtc::AudioSendStream::Stats AudioSendStream::GetStats() const { |
| 155 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 153 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 156 webrtc::AudioSendStream::Stats stats; | 154 webrtc::AudioSendStream::Stats stats; |
| 157 stats.local_ssrc = config_.rtp.ssrc; | 155 stats.local_ssrc = config_.rtp.ssrc; |
| 158 ScopedVoEInterface<VoEAudioProcessing> processing(voice_engine()); | |
| 159 ScopedVoEInterface<VoECodec> codec(voice_engine()); | |
| 160 ScopedVoEInterface<VoEVolumeControl> volume(voice_engine()); | |
| 161 | 156 |
| 162 webrtc::CallStatistics call_stats = channel_proxy_->GetRTCPStatistics(); | 157 webrtc::CallStatistics call_stats = channel_proxy_->GetRTCPStatistics(); |
| 163 stats.bytes_sent = call_stats.bytesSent; | 158 stats.bytes_sent = call_stats.bytesSent; |
| 164 stats.packets_sent = call_stats.packetsSent; | 159 stats.packets_sent = call_stats.packetsSent; |
| 165 // RTT isn't known until a RTCP report is received. Until then, VoiceEngine | 160 // RTT isn't known until a RTCP report is received. Until then, VoiceEngine |
| 166 // returns 0 to indicate an error value. | 161 // returns 0 to indicate an error value. |
| 167 if (call_stats.rttMs > 0) { | 162 if (call_stats.rttMs > 0) { |
| 168 stats.rtt_ms = call_stats.rttMs; | 163 stats.rtt_ms = call_stats.rttMs; |
| 169 } | 164 } |
| 170 // TODO(solenberg): [was ajm]: Re-enable this metric once we have a reliable | 165 // TODO(solenberg): [was ajm]: Re-enable this metric once we have a reliable |
| 171 // implementation. | 166 // implementation. |
| 172 stats.aec_quality_min = -1; | 167 stats.aec_quality_min = -1; |
| 173 | 168 |
| 174 webrtc::CodecInst codec_inst = {0}; | 169 webrtc::CodecInst codec_inst = {0}; |
| 175 if (codec->GetSendCodec(config_.voe_channel_id, codec_inst) != -1) { | 170 if (channel_proxy_->GetSendCodec(&codec_inst)) { |
| 176 RTC_DCHECK_NE(codec_inst.pltype, -1); | 171 RTC_DCHECK_NE(codec_inst.pltype, -1); |
| 177 stats.codec_name = codec_inst.plname; | 172 stats.codec_name = codec_inst.plname; |
| 178 stats.codec_payload_type = rtc::Optional<int>(codec_inst.pltype); | 173 stats.codec_payload_type = rtc::Optional<int>(codec_inst.pltype); |
| 179 | 174 |
| 180 // Get data from the last remote RTCP report. | 175 // Get data from the last remote RTCP report. |
| 181 for (const auto& block : channel_proxy_->GetRemoteRTCPReportBlocks()) { | 176 for (const auto& block : channel_proxy_->GetRemoteRTCPReportBlocks()) { |
| 182 // Lookup report for send ssrc only. | 177 // Lookup report for send ssrc only. |
| 183 if (block.source_SSRC == stats.local_ssrc) { | 178 if (block.source_SSRC == stats.local_ssrc) { |
| 184 stats.packets_lost = block.cumulative_num_packets_lost; | 179 stats.packets_lost = block.cumulative_num_packets_lost; |
| 185 stats.fraction_lost = Q8ToFloat(block.fraction_lost); | 180 stats.fraction_lost = Q8ToFloat(block.fraction_lost); |
| 186 stats.ext_seqnum = block.extended_highest_sequence_number; | 181 stats.ext_seqnum = block.extended_highest_sequence_number; |
| 187 // Convert samples to milliseconds. | 182 // Convert samples to milliseconds. |
| 188 if (codec_inst.plfreq / 1000 > 0) { | 183 if (codec_inst.plfreq / 1000 > 0) { |
| 189 stats.jitter_ms = | 184 stats.jitter_ms = |
| 190 block.interarrival_jitter / (codec_inst.plfreq / 1000); | 185 block.interarrival_jitter / (codec_inst.plfreq / 1000); |
| 191 } | 186 } |
| 192 break; | 187 break; |
| 193 } | 188 } |
| 194 } | 189 } |
| 195 } | 190 } |
| 196 | 191 |
| 197 // Local speech level. | 192 // Local speech level. |
| 198 { | 193 { |
| 194 ScopedVoEInterface<VoEVolumeControl> volume(voice_engine()); |
| 199 unsigned int level = 0; | 195 unsigned int level = 0; |
| 200 int error = volume->GetSpeechInputLevelFullRange(level); | 196 int error = volume->GetSpeechInputLevelFullRange(level); |
| 201 RTC_DCHECK_EQ(0, error); | 197 RTC_DCHECK_EQ(0, error); |
| 202 stats.audio_level = static_cast<int32_t>(level); | 198 stats.audio_level = static_cast<int32_t>(level); |
| 203 } | 199 } |
| 204 | 200 |
| 205 ScopedVoEInterface<VoEBase> base(voice_engine()); | 201 ScopedVoEInterface<VoEBase> base(voice_engine()); |
| 206 RTC_DCHECK(base->audio_processing()); | 202 RTC_DCHECK(base->audio_processing()); |
| 207 auto audio_processing_stats = base->audio_processing()->GetStatistics(); | 203 auto audio_processing_stats = base->audio_processing()->GetStatistics(); |
| 208 stats.echo_delay_median_ms = audio_processing_stats.delay_median; | 204 stats.echo_delay_median_ms = audio_processing_stats.delay_median; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 VoiceEngine* AudioSendStream::voice_engine() const { | 263 VoiceEngine* AudioSendStream::voice_engine() const { |
| 268 internal::AudioState* audio_state = | 264 internal::AudioState* audio_state = |
| 269 static_cast<internal::AudioState*>(audio_state_.get()); | 265 static_cast<internal::AudioState*>(audio_state_.get()); |
| 270 VoiceEngine* voice_engine = audio_state->voice_engine(); | 266 VoiceEngine* voice_engine = audio_state->voice_engine(); |
| 271 RTC_DCHECK(voice_engine); | 267 RTC_DCHECK(voice_engine); |
| 272 return voice_engine; | 268 return voice_engine; |
| 273 } | 269 } |
| 274 | 270 |
| 275 // Apply current codec settings to a single voe::Channel used for sending. | 271 // Apply current codec settings to a single voe::Channel used for sending. |
| 276 bool AudioSendStream::SetupSendCodec() { | 272 bool AudioSendStream::SetupSendCodec() { |
| 277 ScopedVoEInterface<VoEBase> base(voice_engine()); | |
| 278 ScopedVoEInterface<VoECodec> codec(voice_engine()); | |
| 279 | |
| 280 const int channel = config_.voe_channel_id; | |
| 281 | |
| 282 // Disable VAD and FEC unless we know the other side wants them. | 273 // Disable VAD and FEC unless we know the other side wants them. |
| 283 codec->SetVADStatus(channel, false); | 274 channel_proxy_->SetVADStatus(false); |
| 284 codec->SetFECStatus(channel, false); | 275 channel_proxy_->SetCodecFECStatus(false); |
| 285 | 276 |
| 286 // We disable audio network adaptor here. This will on one hand make sure that | 277 // We disable audio network adaptor here. This will on one hand make sure that |
| 287 // audio network adaptor is disabled by default, and on the other allow audio | 278 // audio network adaptor is disabled by default, and on the other allow audio |
| 288 // network adaptor to be reconfigured, since SetReceiverFrameLengthRange can | 279 // network adaptor to be reconfigured, since SetReceiverFrameLengthRange can |
| 289 // be only called when audio network adaptor is disabled. | 280 // be only called when audio network adaptor is disabled. |
| 290 channel_proxy_->DisableAudioNetworkAdaptor(); | 281 channel_proxy_->DisableAudioNetworkAdaptor(); |
| 291 | 282 |
| 292 const auto& send_codec_spec = config_.send_codec_spec; | 283 const auto& send_codec_spec = config_.send_codec_spec; |
| 293 | 284 |
| 294 // We set the codec first, since the below extra configuration is only applied | 285 // We set the codec first, since the below extra configuration is only applied |
| 295 // to the "current" codec. | 286 // to the "current" codec. |
| 296 | 287 |
| 297 // If codec is already configured, we do not it again. | 288 // If codec is already configured, we do not it again. |
| 298 // TODO(minyue): check if this check is really needed, or can we move it into | 289 // TODO(minyue): check if this check is really needed, or can we move it into |
| 299 // |codec->SetSendCodec|. | 290 // |codec->SetSendCodec|. |
| 300 webrtc::CodecInst current_codec = {0}; | 291 webrtc::CodecInst current_codec = {0}; |
| 301 if (codec->GetSendCodec(channel, current_codec) != 0 || | 292 if (!channel_proxy_->GetSendCodec(¤t_codec) || |
| 302 (send_codec_spec.codec_inst != current_codec)) { | 293 (send_codec_spec.codec_inst != current_codec)) { |
| 303 if (codec->SetSendCodec(channel, send_codec_spec.codec_inst) == -1) { | 294 if (!channel_proxy_->SetSendCodec(send_codec_spec.codec_inst)) { |
| 304 LOG(LS_WARNING) << "SetSendCodec() failed: " << base->LastError(); | 295 LOG(LS_WARNING) << "SetSendCodec() failed"; |
| 305 return false; | 296 return false; |
| 306 } | 297 } |
| 307 } | 298 } |
| 308 | 299 |
| 309 // Codec internal FEC. Treat any failure as fatal internal error. | 300 // Codec internal FEC. Treat any failure as fatal internal error. |
| 310 if (send_codec_spec.enable_codec_fec) { | 301 if (send_codec_spec.enable_codec_fec) { |
| 311 if (codec->SetFECStatus(channel, true) != 0) { | 302 if (!channel_proxy_->SetCodecFECStatus(true)) { |
| 312 LOG(LS_WARNING) << "SetFECStatus() failed: " << base->LastError(); | 303 LOG(LS_WARNING) << "SetCodecFECStatus() failed"; |
| 313 return false; | 304 return false; |
| 314 } | 305 } |
| 315 } | 306 } |
| 316 | 307 |
| 317 // DTX and maxplaybackrate are only set if current codec is Opus. | 308 // DTX and maxplaybackrate are only set if current codec is Opus. |
| 318 if (IsCodec(send_codec_spec.codec_inst, kOpusCodecName)) { | 309 if (IsCodec(send_codec_spec.codec_inst, kOpusCodecName)) { |
| 319 if (codec->SetOpusDtx(channel, send_codec_spec.enable_opus_dtx) != 0) { | 310 if (!channel_proxy_->SetOpusDtx(send_codec_spec.enable_opus_dtx)) { |
| 320 LOG(LS_WARNING) << "SetOpusDtx() failed: " << base->LastError(); | 311 LOG(LS_WARNING) << "SetOpusDtx() failed"; |
| 321 return false; | 312 return false; |
| 322 } | 313 } |
| 323 | 314 |
| 324 // If opus_max_playback_rate <= 0, the default maximum playback rate | 315 // If opus_max_playback_rate <= 0, the default maximum playback rate |
| 325 // (48 kHz) will be used. | 316 // (48 kHz) will be used. |
| 326 if (send_codec_spec.opus_max_playback_rate > 0) { | 317 if (send_codec_spec.opus_max_playback_rate > 0) { |
| 327 if (codec->SetOpusMaxPlaybackRate( | 318 if (!channel_proxy_->SetOpusMaxPlaybackRate( |
| 328 channel, send_codec_spec.opus_max_playback_rate) != 0) { | 319 send_codec_spec.opus_max_playback_rate)) { |
| 329 LOG(LS_WARNING) << "SetOpusMaxPlaybackRate() failed: " | 320 LOG(LS_WARNING) << "SetOpusMaxPlaybackRate() failed"; |
| 330 << base->LastError(); | |
| 331 return false; | 321 return false; |
| 332 } | 322 } |
| 333 } | 323 } |
| 334 | 324 |
| 335 if (config_.audio_network_adaptor_config) { | 325 if (config_.audio_network_adaptor_config) { |
| 336 // Audio network adaptor is only allowed for Opus currently. | 326 // Audio network adaptor is only allowed for Opus currently. |
| 337 // |SetReceiverFrameLengthRange| needs to be called before | 327 // |SetReceiverFrameLengthRange| needs to be called before |
| 338 // |EnableAudioNetworkAdaptor|. | 328 // |EnableAudioNetworkAdaptor|. |
| 339 channel_proxy_->SetReceiverFrameLengthRange(send_codec_spec.min_ptime_ms, | 329 channel_proxy_->SetReceiverFrameLengthRange(send_codec_spec.min_ptime_ms, |
| 340 send_codec_spec.max_ptime_ms); | 330 send_codec_spec.max_ptime_ms); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 354 case 16000: | 344 case 16000: |
| 355 cn_freq = webrtc::kFreq16000Hz; | 345 cn_freq = webrtc::kFreq16000Hz; |
| 356 break; | 346 break; |
| 357 case 32000: | 347 case 32000: |
| 358 cn_freq = webrtc::kFreq32000Hz; | 348 cn_freq = webrtc::kFreq32000Hz; |
| 359 break; | 349 break; |
| 360 default: | 350 default: |
| 361 RTC_NOTREACHED(); | 351 RTC_NOTREACHED(); |
| 362 return false; | 352 return false; |
| 363 } | 353 } |
| 364 if (codec->SetSendCNPayloadType(channel, send_codec_spec.cng_payload_type, | 354 if (channel_proxy_->SetSendCNPayloadType(send_codec_spec.cng_payload_type, |
| 365 cn_freq) != 0) { | 355 cn_freq) != 0) { |
| 366 LOG(LS_WARNING) << "SetSendCNPayloadType() failed: " | 356 LOG(LS_WARNING) << "SetSendCNPayloadType() failed"; |
| 367 << base->LastError(); | |
| 368 // TODO(ajm): This failure condition will be removed from VoE. | 357 // TODO(ajm): This failure condition will be removed from VoE. |
| 369 // Restore the return here when we update to a new enough webrtc. | 358 // Restore the return here when we update to a new enough webrtc. |
| 370 // | 359 // |
| 371 // Not returning false because the SetSendCNPayloadType will fail if | 360 // Not returning false because the SetSendCNPayloadType will fail if |
| 372 // the channel is already sending. | 361 // the channel is already sending. |
| 373 // This can happen if the remote description is applied twice, for | 362 // This can happen if the remote description is applied twice, for |
| 374 // example in the case of ROAP on top of JSEP, where both side will | 363 // example in the case of ROAP on top of JSEP, where both side will |
| 375 // send the offer. | 364 // send the offer. |
| 376 } | 365 } |
| 377 } | 366 } |
| 378 | 367 |
| 379 // Only turn on VAD if we have a CN payload type that matches the | 368 // Only turn on VAD if we have a CN payload type that matches the |
| 380 // clockrate for the codec we are going to use. | 369 // clockrate for the codec we are going to use. |
| 381 if (send_codec_spec.cng_plfreq == send_codec_spec.codec_inst.plfreq && | 370 if (send_codec_spec.cng_plfreq == send_codec_spec.codec_inst.plfreq && |
| 382 send_codec_spec.codec_inst.channels == 1) { | 371 send_codec_spec.codec_inst.channels == 1) { |
| 383 // TODO(minyue): If CN frequency == 48000 Hz is allowed, consider the | 372 // TODO(minyue): If CN frequency == 48000 Hz is allowed, consider the |
| 384 // interaction between VAD and Opus FEC. | 373 // interaction between VAD and Opus FEC. |
| 385 if (codec->SetVADStatus(channel, true) != 0) { | 374 if (!channel_proxy_->SetVADStatus(true)) { |
| 386 LOG(LS_WARNING) << "SetVADStatus() failed: " << base->LastError(); | 375 LOG(LS_WARNING) << "SetVADStatus() failed"; |
| 387 return false; | 376 return false; |
| 388 } | 377 } |
| 389 } | 378 } |
| 390 } | 379 } |
| 391 return true; | 380 return true; |
| 392 } | 381 } |
| 393 | 382 |
| 394 } // namespace internal | 383 } // namespace internal |
| 395 } // namespace webrtc | 384 } // namespace webrtc |
| OLD | NEW |