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

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

Issue 2446963003: Clean up logging in AudioSendStream::SetupSendCodec(). (Closed)
Patch Set: fix build breakage? Created 4 years, 1 month 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
« no previous file with comments | « webrtc/api/call/audio_send_stream.cc ('k') | webrtc/audio/audio_send_stream_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 17 matching lines...) Expand all
28 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" 28 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h"
29 #include "webrtc/voice_engine/include/voe_volume_control.h" 29 #include "webrtc/voice_engine/include/voe_volume_control.h"
30 #include "webrtc/voice_engine/voice_engine_impl.h" 30 #include "webrtc/voice_engine/voice_engine_impl.h"
31 31
32 namespace webrtc { 32 namespace webrtc {
33 33
34 namespace { 34 namespace {
35 35
36 constexpr char kOpusCodecName[] = "opus"; 36 constexpr char kOpusCodecName[] = "opus";
37 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
48 std::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
55 bool IsCodec(const webrtc::CodecInst& codec, const char* ref_name) { 38 bool IsCodec(const webrtc::CodecInst& codec, const char* ref_name) {
56 return (_stricmp(codec.plname, ref_name) == 0); 39 return (_stricmp(codec.plname, ref_name) == 0);
57 } 40 }
58
59 } // namespace 41 } // namespace
60 42
61 std::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();
67 if (i != extensions.size() - 1) {
68 ss << ", ";
69 }
70 }
71 ss << ']';
72 ss << ", nack: " << nack.ToString();
73 ss << ", c_name: " << c_name;
74 ss << '}';
75 return ss.str();
76 }
77
78 std::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.
83 ss << ", cng_payload_type: " << send_codec_spec.cng_payload_type;
84 ss << '}';
85 return ss.str();
86 }
87
88 namespace internal { 43 namespace internal {
89 AudioSendStream::AudioSendStream( 44 AudioSendStream::AudioSendStream(
90 const webrtc::AudioSendStream::Config& config, 45 const webrtc::AudioSendStream::Config& config,
91 const rtc::scoped_refptr<webrtc::AudioState>& audio_state, 46 const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
92 rtc::TaskQueue* worker_queue, 47 rtc::TaskQueue* worker_queue,
93 CongestionController* congestion_controller, 48 CongestionController* congestion_controller,
94 BitrateAllocator* bitrate_allocator, 49 BitrateAllocator* bitrate_allocator,
95 RtcEventLog* event_log) 50 RtcEventLog* event_log)
96 : worker_queue_(worker_queue), 51 : worker_queue_(worker_queue),
97 config_(config), 52 config_(config),
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 ScopedVoEInterface<VoECodec> codec(voice_engine()); 281 ScopedVoEInterface<VoECodec> codec(voice_engine());
327 282
328 const int channel = config_.voe_channel_id; 283 const int channel = config_.voe_channel_id;
329 284
330 // Disable VAD and FEC unless we know the other side wants them. 285 // Disable VAD and FEC unless we know the other side wants them.
331 codec->SetVADStatus(channel, false); 286 codec->SetVADStatus(channel, false);
332 codec->SetFECStatus(channel, false); 287 codec->SetFECStatus(channel, false);
333 288
334 const auto& send_codec_spec = config_.send_codec_spec; 289 const auto& send_codec_spec = config_.send_codec_spec;
335 290
336 // Set the codec immediately, since SetVADStatus() depends on whether 291 // We set the codec first, since the below extra configuration is only applied
337 // the current codec is mono or stereo. 292 // to the "current" codec.
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 293
342 // If codec is already configured, we do not it again. 294 // 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 295 // TODO(minyue): check if this check is really needed, or can we move it into
344 // |codec->SetSendCodec|. 296 // |codec->SetSendCodec|.
345 webrtc::CodecInst current_codec = {0}; 297 webrtc::CodecInst current_codec = {0};
346 if (codec->GetSendCodec(channel, current_codec) != 0 || 298 if (codec->GetSendCodec(channel, current_codec) != 0 ||
347 (send_codec_spec.codec_inst != current_codec)) { 299 (send_codec_spec.codec_inst != current_codec)) {
348 if (codec->SetSendCodec(channel, send_codec_spec.codec_inst) == -1) { 300 if (codec->SetSendCodec(channel, send_codec_spec.codec_inst) == -1) {
349 LOG_RTCERR2(SetSendCodec, channel, ToString(send_codec_spec.codec_inst), 301 LOG(LS_WARNING) << "SetSendCodec() failed: " << base->LastError();
350 base->LastError());
351 return false; 302 return false;
352 } 303 }
353 } 304 }
354 305
355 // FEC should be enabled after SetSendCodec. 306 // Codec internal FEC. Treat any failure as fatal internal error.
356 if (send_codec_spec.enable_codec_fec) { 307 if (send_codec_spec.enable_codec_fec) {
357 LOG(LS_INFO) << "Attempt to enable codec internal FEC on channel " 308 if (codec->SetFECStatus(channel, true) != 0) {
358 << channel; 309 LOG(LS_WARNING) << "SetFECStatus() failed: " << base->LastError();
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; 310 return false;
363 } 311 }
364 } 312 }
365 313
314 // DTX and maxplaybackrate are only set if current codec is Opus.
366 if (IsCodec(send_codec_spec.codec_inst, kOpusCodecName)) { 315 if (IsCodec(send_codec_spec.codec_inst, kOpusCodecName)) {
367 // DTX and maxplaybackrate should be set after SetSendCodec. Because current 316 if (codec->SetOpusDtx(channel, send_codec_spec.enable_opus_dtx) != 0) {
368 // send codec has to be Opus. 317 LOG(LS_WARNING) << "SetOpusDtx() failed: " << base->LastError();
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; 318 return false;
378 } 319 }
379 320
380 // If opus_max_playback_rate <= 0, the default maximum playback rate 321 // If opus_max_playback_rate <= 0, the default maximum playback rate
381 // (48 kHz) will be used. 322 // (48 kHz) will be used.
382 if (send_codec_spec.opus_max_playback_rate > 0) { 323 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( 324 if (codec->SetOpusMaxPlaybackRate(
387 channel, send_codec_spec.opus_max_playback_rate) == -1) { 325 channel, send_codec_spec.opus_max_playback_rate) != 0) {
388 LOG_RTCERR2(SetOpusMaxPlaybackRate, channel, 326 LOG(LS_WARNING) << "SetOpusMaxPlaybackRate() failed: "
389 send_codec_spec.opus_max_playback_rate, base->LastError()); 327 << base->LastError();
390 return false; 328 return false;
391 } 329 }
392 } 330 }
393 } 331 }
394 332
395 // Set the CN payloadtype and the VAD status. 333 // Set the CN payloadtype and the VAD status.
396 if (send_codec_spec.cng_payload_type != -1) { 334 if (send_codec_spec.cng_payload_type != -1) {
397 // The CN payload type for 8000 Hz clockrate is fixed at 13. 335 // The CN payload type for 8000 Hz clockrate is fixed at 13.
398 if (send_codec_spec.cng_plfreq != 8000) { 336 if (send_codec_spec.cng_plfreq != 8000) {
399 webrtc::PayloadFrequencies cn_freq; 337 webrtc::PayloadFrequencies cn_freq;
400 switch (send_codec_spec.cng_plfreq) { 338 switch (send_codec_spec.cng_plfreq) {
401 case 16000: 339 case 16000:
402 cn_freq = webrtc::kFreq16000Hz; 340 cn_freq = webrtc::kFreq16000Hz;
403 break; 341 break;
404 case 32000: 342 case 32000:
405 cn_freq = webrtc::kFreq32000Hz; 343 cn_freq = webrtc::kFreq32000Hz;
406 break; 344 break;
407 default: 345 default:
408 RTC_NOTREACHED(); 346 RTC_NOTREACHED();
409 return false; 347 return false;
410 } 348 }
411 if (codec->SetSendCNPayloadType(channel, send_codec_spec.cng_payload_type, 349 if (codec->SetSendCNPayloadType(channel, send_codec_spec.cng_payload_type,
412 cn_freq) == -1) { 350 cn_freq) != 0) {
413 LOG_RTCERR3(SetSendCNPayloadType, channel, 351 LOG(LS_WARNING) << "SetSendCNPayloadType() failed: "
414 send_codec_spec.cng_payload_type, cn_freq, 352 << base->LastError();
415 base->LastError());
416
417 // TODO(ajm): This failure condition will be removed from VoE. 353 // TODO(ajm): This failure condition will be removed from VoE.
418 // Restore the return here when we update to a new enough webrtc. 354 // Restore the return here when we update to a new enough webrtc.
419 // 355 //
420 // Not returning false because the SetSendCNPayloadType will fail if 356 // Not returning false because the SetSendCNPayloadType will fail if
421 // the channel is already sending. 357 // the channel is already sending.
422 // This can happen if the remote description is applied twice, for 358 // 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 359 // example in the case of ROAP on top of JSEP, where both side will
424 // send the offer. 360 // send the offer.
425 } 361 }
426 } 362 }
427 363
428 // Only turn on VAD if we have a CN payload type that matches the 364 // Only turn on VAD if we have a CN payload type that matches the
429 // clockrate for the codec we are going to use. 365 // clockrate for the codec we are going to use.
430 if (send_codec_spec.cng_plfreq == send_codec_spec.codec_inst.plfreq && 366 if (send_codec_spec.cng_plfreq == send_codec_spec.codec_inst.plfreq &&
431 send_codec_spec.codec_inst.channels == 1) { 367 send_codec_spec.codec_inst.channels == 1) {
432 // TODO(minyue): If CN frequency == 48000 Hz is allowed, consider the 368 // TODO(minyue): If CN frequency == 48000 Hz is allowed, consider the
433 // interaction between VAD and Opus FEC. 369 // interaction between VAD and Opus FEC.
434 LOG(LS_INFO) << "Enabling VAD"; 370 if (codec->SetVADStatus(channel, true) != 0) {
435 if (codec->SetVADStatus(channel, true) == -1) { 371 LOG(LS_WARNING) << "SetVADStatus() failed: " << base->LastError();
436 LOG_RTCERR2(SetVADStatus, channel, true, base->LastError());
437 return false; 372 return false;
438 } 373 }
439 } 374 }
440 } 375 }
441 return true; 376 return true;
442 } 377 }
443 378
444 } // namespace internal 379 } // namespace internal
445 } // namespace webrtc 380 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/call/audio_send_stream.cc ('k') | webrtc/audio/audio_send_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698