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