| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 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 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 static int MaxBitrateBps(const webrtc::CodecInst& codec) { | 398 static int MaxBitrateBps(const webrtc::CodecInst& codec) { |
| 399 for (size_t i = 0; i < arraysize(kCodecPrefs); ++i) { | 399 for (size_t i = 0; i < arraysize(kCodecPrefs); ++i) { |
| 400 if (IsCodec(codec, kCodecPrefs[i].name) && | 400 if (IsCodec(codec, kCodecPrefs[i].name) && |
| 401 kCodecPrefs[i].clockrate == codec.plfreq) { | 401 kCodecPrefs[i].clockrate == codec.plfreq) { |
| 402 return kCodecPrefs[i].max_bitrate_bps; | 402 return kCodecPrefs[i].max_bitrate_bps; |
| 403 } | 403 } |
| 404 } | 404 } |
| 405 return 0; | 405 return 0; |
| 406 } | 406 } |
| 407 | 407 |
| 408 static rtc::ArrayView<const int> GetPacketSizesMs( |
| 409 const webrtc::CodecInst& codec) { |
| 410 for (size_t i = 0; i < arraysize(kCodecPrefs); ++i) { |
| 411 if (IsCodec(codec, kCodecPrefs[i].name)) { |
| 412 size_t num_packet_sizes = kMaxNumPacketSize; |
| 413 for (int index = 0; index < kMaxNumPacketSize; index++) { |
| 414 if (kCodecPrefs[i].packet_sizes_ms[index] == 0) { |
| 415 num_packet_sizes = index; |
| 416 break; |
| 417 } |
| 418 } |
| 419 return rtc::ArrayView<const int>(kCodecPrefs[i].packet_sizes_ms, |
| 420 num_packet_sizes); |
| 421 } |
| 422 } |
| 423 return rtc::ArrayView<const int>(); |
| 424 } |
| 425 |
| 408 // If the AudioCodec param kCodecParamPTime is set, then we will set it to | 426 // If the AudioCodec param kCodecParamPTime is set, then we will set it to |
| 409 // codec pacsize if it's valid, or we will pick the next smallest value we | 427 // codec pacsize if it's valid, or we will pick the next smallest value we |
| 410 // support. | 428 // support. |
| 411 // TODO(Brave): Query supported packet sizes from ACM when the API is ready. | 429 // TODO(Brave): Query supported packet sizes from ACM when the API is ready. |
| 412 static bool SetPTimeAsPacketSize(webrtc::CodecInst* codec, int ptime_ms) { | 430 static bool SetPTimeAsPacketSize(webrtc::CodecInst* codec, int ptime_ms) { |
| 413 for (const CodecPref& codec_pref : kCodecPrefs) { | 431 for (const CodecPref& codec_pref : kCodecPrefs) { |
| 414 if ((IsCodec(*codec, codec_pref.name) && | 432 if ((IsCodec(*codec, codec_pref.name) && |
| 415 codec_pref.clockrate == codec->plfreq) || | 433 codec_pref.clockrate == codec->plfreq) || |
| 416 IsCodec(*codec, kG722CodecName)) { | 434 IsCodec(*codec, kG722CodecName)) { |
| 417 int packet_size_ms = SelectPacketSize(codec_pref, ptime_ms); | 435 int packet_size_ms = SelectPacketSize(codec_pref, ptime_ms); |
| (...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1456 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 1439 if (stream_) { | 1457 if (stream_) { |
| 1440 call_->DestroyAudioSendStream(stream_); | 1458 call_->DestroyAudioSendStream(stream_); |
| 1441 stream_ = nullptr; | 1459 stream_ = nullptr; |
| 1442 } | 1460 } |
| 1443 RTC_DCHECK(!stream_); | 1461 RTC_DCHECK(!stream_); |
| 1444 if (webrtc::field_trial::FindFullName("WebRTC-Audio-SendSideBwe") == | 1462 if (webrtc::field_trial::FindFullName("WebRTC-Audio-SendSideBwe") == |
| 1445 "Enabled") { | 1463 "Enabled") { |
| 1446 // TODO(mflodman): Keep testing this and set proper values. | 1464 // TODO(mflodman): Keep testing this and set proper values. |
| 1447 // Note: This is an early experiment currently only supported by Opus. | 1465 // Note: This is an early experiment currently only supported by Opus. |
| 1448 config_.min_bitrate_bps = kOpusMinBitrateBps; | 1466 if (webrtc::field_trial::FindFullName( |
| 1449 config_.max_bitrate_bps = kOpusBitrateFbBps; | 1467 "WebRTC-SendSideBwe-WithOverhead") == "Enabled") { |
| 1468 auto packet_sizes_ms = WebRtcVoiceCodecs::GetPacketSizesMs( |
| 1469 config_.send_codec_spec.codec_inst); |
| 1470 if (!packet_sizes_ms.empty()) { |
| 1471 int max_packet_size_ms = |
| 1472 *std::max_element(packet_sizes_ms.begin(), packet_sizes_ms.end()); |
| 1473 int min_packet_size_ms = |
| 1474 *std::min_element(packet_sizes_ms.begin(), packet_sizes_ms.end()); |
| 1475 |
| 1476 // Audio network adaptor will just use 20ms and 60ms frame lengths. |
| 1477 // The adaptor will only be active for the Opus encoder. |
| 1478 if (config_.audio_network_adaptor_config && |
| 1479 IsCodec(config_.send_codec_spec.codec_inst, kOpusCodecName)) { |
| 1480 max_packet_size_ms = 60; |
| 1481 min_packet_size_ms = 20; |
| 1482 } |
| 1483 |
| 1484 // OverheadPerPacket = Ipv4(20B) + UDP(8B) + SRTP(10B) + RTP(12) |
| 1485 constexpr int kOverheadPerPacket = 20 + 8 + 10 + 12; |
| 1486 |
| 1487 int min_overhead_bps = |
| 1488 kOverheadPerPacket * 8 * 1000 / max_packet_size_ms; |
| 1489 |
| 1490 int max_overhead_bps = |
| 1491 kOverheadPerPacket * 8 * 1000 / min_packet_size_ms; |
| 1492 |
| 1493 config_.min_bitrate_bps = kOpusMinBitrateBps + min_overhead_bps; |
| 1494 config_.max_bitrate_bps = kOpusBitrateFbBps + max_overhead_bps; |
| 1495 } |
| 1496 } else { |
| 1497 config_.min_bitrate_bps = kOpusMinBitrateBps; |
| 1498 config_.max_bitrate_bps = kOpusBitrateFbBps; |
| 1499 } |
| 1450 } | 1500 } |
| 1451 stream_ = call_->CreateAudioSendStream(config_); | 1501 stream_ = call_->CreateAudioSendStream(config_); |
| 1452 RTC_CHECK(stream_); | 1502 RTC_CHECK(stream_); |
| 1453 UpdateSendState(); | 1503 UpdateSendState(); |
| 1454 } | 1504 } |
| 1455 | 1505 |
| 1456 rtc::ThreadChecker worker_thread_checker_; | 1506 rtc::ThreadChecker worker_thread_checker_; |
| 1457 rtc::RaceChecker audio_capture_race_checker_; | 1507 rtc::RaceChecker audio_capture_race_checker_; |
| 1458 webrtc::AudioTransport* const voe_audio_transport_ = nullptr; | 1508 webrtc::AudioTransport* const voe_audio_transport_ = nullptr; |
| 1459 webrtc::Call* call_ = nullptr; | 1509 webrtc::Call* call_ = nullptr; |
| (...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2661 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2711 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 2662 const auto it = send_streams_.find(ssrc); | 2712 const auto it = send_streams_.find(ssrc); |
| 2663 if (it != send_streams_.end()) { | 2713 if (it != send_streams_.end()) { |
| 2664 return it->second->channel(); | 2714 return it->second->channel(); |
| 2665 } | 2715 } |
| 2666 return -1; | 2716 return -1; |
| 2667 } | 2717 } |
| 2668 } // namespace cricket | 2718 } // namespace cricket |
| 2669 | 2719 |
| 2670 #endif // HAVE_WEBRTC_VOICE | 2720 #endif // HAVE_WEBRTC_VOICE |
| OLD | NEW |