Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: webrtc/audio/audio_send_stream.cc

Issue 2405183002: Moving WebRtcVoiceMediaChannel::SendSetCodec to AudioSendStream. (Closed)
Patch Set: removing ApplyMaxSendBitrate Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm>
13 #include <string> 14 #include <string>
14 15
15 #include "webrtc/audio/audio_state.h" 16 #include "webrtc/audio/audio_state.h"
16 #include "webrtc/audio/conversion.h" 17 #include "webrtc/audio/conversion.h"
17 #include "webrtc/audio/scoped_voe_interface.h" 18 #include "webrtc/audio/scoped_voe_interface.h"
18 #include "webrtc/base/checks.h" 19 #include "webrtc/base/checks.h"
19 #include "webrtc/base/event.h" 20 #include "webrtc/base/event.h"
20 #include "webrtc/base/logging.h" 21 #include "webrtc/base/logging.h"
21 #include "webrtc/base/task_queue.h" 22 #include "webrtc/base/task_queue.h"
22 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" 23 #include "webrtc/modules/congestion_controller/include/congestion_controller.h"
23 #include "webrtc/modules/pacing/paced_sender.h" 24 #include "webrtc/modules/pacing/paced_sender.h"
24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 25 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
25 #include "webrtc/voice_engine/channel_proxy.h" 26 #include "webrtc/voice_engine/channel_proxy.h"
26 #include "webrtc/voice_engine/include/voe_audio_processing.h" 27 #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_codec.h"
28 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" 29 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h"
29 #include "webrtc/voice_engine/include/voe_volume_control.h" 30 #include "webrtc/voice_engine/include/voe_volume_control.h"
30 #include "webrtc/voice_engine/voice_engine_impl.h" 31 #include "webrtc/voice_engine/voice_engine_impl.h"
31 32
32 namespace webrtc { 33 namespace webrtc {
34
35 namespace {
36
37 constexpr char kOpusCodecName[] = "opus";
38
39 bool IsCodec(const webrtc::CodecInst& codec, const char* ref_name) {
40 return (_stricmp(codec.plname, ref_name) == 0);
41 }
42
43 } // namespace
44
33 std::string AudioSendStream::Config::Rtp::ToString() const { 45 std::string AudioSendStream::Config::Rtp::ToString() const {
34 std::stringstream ss; 46 std::stringstream ss;
35 ss << "{ssrc: " << ssrc; 47 ss << "{ssrc: " << ssrc;
36 ss << ", extensions: ["; 48 ss << ", extensions: [";
37 for (size_t i = 0; i < extensions.size(); ++i) { 49 for (size_t i = 0; i < extensions.size(); ++i) {
38 ss << extensions[i].ToString(); 50 ss << extensions[i].ToString();
39 if (i != extensions.size() - 1) { 51 if (i != extensions.size() - 1) {
40 ss << ", "; 52 ss << ", ";
41 } 53 }
42 } 54 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 if (extension.uri == RtpExtension::kAbsSendTimeUri) { 107 if (extension.uri == RtpExtension::kAbsSendTimeUri) {
96 channel_proxy_->SetSendAbsoluteSenderTimeStatus(true, extension.id); 108 channel_proxy_->SetSendAbsoluteSenderTimeStatus(true, extension.id);
97 } else if (extension.uri == RtpExtension::kAudioLevelUri) { 109 } else if (extension.uri == RtpExtension::kAudioLevelUri) {
98 channel_proxy_->SetSendAudioLevelIndicationStatus(true, extension.id); 110 channel_proxy_->SetSendAudioLevelIndicationStatus(true, extension.id);
99 } else if (extension.uri == RtpExtension::kTransportSequenceNumberUri) { 111 } else if (extension.uri == RtpExtension::kTransportSequenceNumberUri) {
100 channel_proxy_->EnableSendTransportSequenceNumber(extension.id); 112 channel_proxy_->EnableSendTransportSequenceNumber(extension.id);
101 } else { 113 } else {
102 RTC_NOTREACHED() << "Registering unsupported RTP extension."; 114 RTC_NOTREACHED() << "Registering unsupported RTP extension.";
103 } 115 }
104 } 116 }
117 SetSendCodecs();
the sun 2016/10/13 13:15:05 if (!SetupSendCodec()) { LOG(LS_ERROR) << "Faile
105 } 118 }
106 119
107 AudioSendStream::~AudioSendStream() { 120 AudioSendStream::~AudioSendStream() {
108 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 121 RTC_DCHECK(thread_checker_.CalledOnValidThread());
109 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString(); 122 LOG(LS_INFO) << "~AudioSendStream: " << config_.ToString();
110 channel_proxy_->DeRegisterExternalTransport(); 123 channel_proxy_->DeRegisterExternalTransport();
111 channel_proxy_->ResetCongestionControlObjects(); 124 channel_proxy_->ResetCongestionControlObjects();
112 channel_proxy_->SetRtcEventLog(nullptr); 125 channel_proxy_->SetRtcEventLog(nullptr);
113 } 126 }
114 127
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 return config_; 291 return config_;
279 } 292 }
280 293
281 VoiceEngine* AudioSendStream::voice_engine() const { 294 VoiceEngine* AudioSendStream::voice_engine() const {
282 internal::AudioState* audio_state = 295 internal::AudioState* audio_state =
283 static_cast<internal::AudioState*>(audio_state_.get()); 296 static_cast<internal::AudioState*>(audio_state_.get());
284 VoiceEngine* voice_engine = audio_state->voice_engine(); 297 VoiceEngine* voice_engine = audio_state->voice_engine();
285 RTC_DCHECK(voice_engine); 298 RTC_DCHECK(voice_engine);
286 return voice_engine; 299 return voice_engine;
287 } 300 }
301
302 // Apply current codec settings to a single voe::Channel used for sending.
303 bool AudioSendStream::SetSendCodecs() {
the sun 2016/10/13 13:15:05 Rename to SetupSendCodec() instead.
304 ScopedVoEInterface<VoECodec> codec(voice_engine());
305 const int channel = config_.voe_channel_id;
306
307 // Disable VAD and FEC unless we know the other side wants them.
308 codec->SetVADStatus(channel, false);
309 codec->SetFECStatus(channel, false);
310
311 // Set the codec immediately, since SetVADStatus() depends on whether
the sun 2016/10/13 13:15:05 Do we need to check whether the codec_inst is init
minyue-webrtc 2016/10/17 07:41:59 SetSendCodec checks pltype and return false if it
312 // the current codec is mono or stereo.
313 if (!SetSendCodec(config_.send_codec_spec.codec_inst)) {
314 return false;
315 }
316
317 // FEC should be enabled after SetSendCodec.
318 if (config_.send_codec_spec.enable_codec_fec) {
319 LOG(LS_INFO) << "Attempt to enable codec internal FEC on channel "
320 << channel;
321 if (codec->SetFECStatus(channel, true) == -1) {
322 // Enable codec internal FEC. Treat any failure as fatal internal error.
323 // TODO(minyue): use normal logging.
324 // LOG_RTCERR2(SetFECStatus, channel, true);
325 return false;
326 }
327 }
328
329 if (IsCodec(config_.send_codec_spec.codec_inst, kOpusCodecName)) {
330 // DTX and maxplaybackrate should be set after SetSendCodec. Because current
331 // send codec has to be Opus.
332
333 // Set Opus internal DTX.
334 LOG(LS_INFO) << "Attempt to "
335 << (config_.send_codec_spec.enable_opus_dtx ? "enable"
336 : "disable")
337 << " Opus DTX on channel " << channel;
338 if (codec->SetOpusDtx(channel, config_.send_codec_spec.enable_opus_dtx)) {
339 // TODO(minyue): use normal logging.
340 // LOG_RTCERR2(SetOpusDtx, channel,
341 // config_.send_codec_spec.enable_opus_dtx);
342 return false;
343 }
344
345 // If opus_max_playback_rate <= 0, the default maximum playback rate
346 // (48 kHz) will be used.
347 if (config_.send_codec_spec.opus_max_playback_rate > 0) {
348 LOG(LS_INFO) << "Attempt to set maximum playback rate to "
349 << config_.send_codec_spec.opus_max_playback_rate
350 << " Hz on channel " << channel;
351 if (codec->SetOpusMaxPlaybackRate(
352 channel, config_.send_codec_spec.opus_max_playback_rate) == -1) {
353 // TODO(minyue): use normal logging.
354 // LOG_RTCERR2(SetOpusMaxPlaybackRate, channel,
355 // config_.send_codec_spec.opus_max_playback_rate);
356 return false;
357 }
358 }
359 }
360
361 // Set the CN payloadtype and the VAD status.
362 if (config_.send_codec_spec.cng_payload_type != -1) {
363 // The CN payload type for 8000 Hz clockrate is fixed at 13.
364 if (config_.send_codec_spec.cng_plfreq != 8000) {
365 webrtc::PayloadFrequencies cn_freq;
366 switch (config_.send_codec_spec.cng_plfreq) {
367 case 16000:
368 cn_freq = webrtc::kFreq16000Hz;
369 break;
370 case 32000:
371 cn_freq = webrtc::kFreq32000Hz;
372 break;
373 default:
374 RTC_NOTREACHED();
375 return false;
376 }
377 if (codec->SetSendCNPayloadType(channel,
378 config_.send_codec_spec.cng_payload_type,
379 cn_freq) == -1) {
380 // TODO(minyue): use normal logging.
381 // LOG_RTCERR3(SetSendCNPayloadType, channel,
382 // config_.send_codec_spec.cng_payload_type, cn_freq);
383
384 // TODO(ajm): This failure condition will be removed from VoE.
385 // Restore the return here when we update to a new enough webrtc.
386 //
387 // Not returning false because the SetSendCNPayloadType will fail if
388 // the channel is already sending.
389 // This can happen if the remote description is applied twice, for
390 // example in the case of ROAP on top of JSEP, where both side will
391 // send the offer.
392 }
393 }
394
395 // Only turn on VAD if we have a CN payload type that matches the
396 // clockrate for the codec we are going to use.
397 if (config_.send_codec_spec.cng_plfreq ==
398 config_.send_codec_spec.codec_inst.plfreq &&
399 config_.send_codec_spec.codec_inst.channels == 1) {
400 // TODO(minyue): If CN frequency == 48000 Hz is allowed, consider the
401 // interaction between VAD and Opus FEC.
402 LOG(LS_INFO) << "Enabling VAD";
403 if (codec->SetVADStatus(channel, true) == -1) {
404 // TODO(minyue): use normal logging.
405 // LOG_RTCERR2(SetVADStatus, channel, true);
406 return false;
407 }
408 }
409 }
410 return true;
411 }
412
413 bool AudioSendStream::SetSendCodec(const webrtc::CodecInst& send_codec) {
414 // TODO(minyue): avoid ToString
415 // LOG(LS_INFO) << "Send channel " << channel << " selected voice codec "
416 // << ToString(send_codec) << ", bitrate=" << send_codec.rate;
417
418 ScopedVoEInterface<VoECodec> codec(voice_engine());
419 int channel = config_.voe_channel_id;
420
421 webrtc::CodecInst current_codec = {0};
422 if (codec->GetSendCodec(channel, current_codec) == 0 &&
the sun 2016/10/13 13:15:05 Add a TODO to look into whether this optimization
minyue-webrtc 2016/10/17 07:41:59 yes, added TODO and moved the function inline.
423 (send_codec == current_codec)) {
424 // Codec is already configured, we can return without setting it again.
425 return true;
426 }
427
428 if (codec->SetSendCodec(channel, send_codec) == -1) {
429 // TODO(minyue): use normal logging.
430 // LOG_RTCERR2(SetSendCodec, channel, ToString(send_codec));
431 return false;
432 }
433 return true;
434 }
435
288 } // namespace internal 436 } // namespace internal
289 } // namespace webrtc 437 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698