Chromium Code Reviews| 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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 static int MaxBitrateBps(const webrtc::CodecInst& codec) { | 392 static int MaxBitrateBps(const webrtc::CodecInst& codec) { |
| 393 for (size_t i = 0; i < arraysize(kCodecPrefs); ++i) { | 393 for (size_t i = 0; i < arraysize(kCodecPrefs); ++i) { |
| 394 if (IsCodec(codec, kCodecPrefs[i].name) && | 394 if (IsCodec(codec, kCodecPrefs[i].name) && |
| 395 kCodecPrefs[i].clockrate == codec.plfreq) { | 395 kCodecPrefs[i].clockrate == codec.plfreq) { |
| 396 return kCodecPrefs[i].max_bitrate_bps; | 396 return kCodecPrefs[i].max_bitrate_bps; |
| 397 } | 397 } |
| 398 } | 398 } |
| 399 return 0; | 399 return 0; |
| 400 } | 400 } |
| 401 | 401 |
| 402 static rtc::ArrayView<const int> GetPacketSizesMs( | |
| 403 const webrtc::CodecInst& codec) { | |
| 404 for (size_t i = 0; i < arraysize(kCodecPrefs); ++i) { | |
| 405 if (IsCodec(codec, kCodecPrefs[i].name)) { | |
| 406 int packet_sizes_ms_size = [&]() { | |
|
stefan-webrtc
2017/01/10 13:42:04
I'd simply write it like this:
size_t num_packet_
michaelt
2017/01/10 14:55:21
Done.
| |
| 407 for (int index = 0; index < kMaxNumPacketSize; index++) { | |
| 408 if (kCodecPrefs[i].packet_sizes_ms[index] == 0) { | |
| 409 return index; | |
| 410 } | |
| 411 } | |
| 412 return kMaxNumPacketSize; | |
| 413 }(); | |
| 414 return rtc::ArrayView<const int>(kCodecPrefs[i].packet_sizes_ms, | |
| 415 packet_sizes_ms_size); | |
| 416 } | |
| 417 } | |
| 418 return rtc::ArrayView<const int>(); | |
| 419 } | |
| 420 | |
| 402 // If the AudioCodec param kCodecParamPTime is set, then we will set it to | 421 // If the AudioCodec param kCodecParamPTime is set, then we will set it to |
| 403 // codec pacsize if it's valid, or we will pick the next smallest value we | 422 // codec pacsize if it's valid, or we will pick the next smallest value we |
| 404 // support. | 423 // support. |
| 405 // TODO(Brave): Query supported packet sizes from ACM when the API is ready. | 424 // TODO(Brave): Query supported packet sizes from ACM when the API is ready. |
| 406 static bool SetPTimeAsPacketSize(webrtc::CodecInst* codec, int ptime_ms) { | 425 static bool SetPTimeAsPacketSize(webrtc::CodecInst* codec, int ptime_ms) { |
| 407 for (const CodecPref& codec_pref : kCodecPrefs) { | 426 for (const CodecPref& codec_pref : kCodecPrefs) { |
| 408 if ((IsCodec(*codec, codec_pref.name) && | 427 if ((IsCodec(*codec, codec_pref.name) && |
| 409 codec_pref.clockrate == codec->plfreq) || | 428 codec_pref.clockrate == codec->plfreq) || |
| 410 IsCodec(*codec, kG722CodecName)) { | 429 IsCodec(*codec, kG722CodecName)) { |
| 411 int packet_size_ms = SelectPacketSize(codec_pref, ptime_ms); | 430 int packet_size_ms = SelectPacketSize(codec_pref, ptime_ms); |
| (...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1413 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1432 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 1414 if (stream_) { | 1433 if (stream_) { |
| 1415 call_->DestroyAudioSendStream(stream_); | 1434 call_->DestroyAudioSendStream(stream_); |
| 1416 stream_ = nullptr; | 1435 stream_ = nullptr; |
| 1417 } | 1436 } |
| 1418 RTC_DCHECK(!stream_); | 1437 RTC_DCHECK(!stream_); |
| 1419 if (webrtc::field_trial::FindFullName("WebRTC-Audio-SendSideBwe") == | 1438 if (webrtc::field_trial::FindFullName("WebRTC-Audio-SendSideBwe") == |
| 1420 "Enabled") { | 1439 "Enabled") { |
| 1421 // TODO(mflodman): Keep testing this and set proper values. | 1440 // TODO(mflodman): Keep testing this and set proper values. |
| 1422 // Note: This is an early experiment currently only supported by Opus. | 1441 // Note: This is an early experiment currently only supported by Opus. |
| 1423 config_.min_bitrate_bps = kOpusMinBitrateBps; | 1442 if (webrtc::field_trial::FindFullName( |
| 1424 config_.max_bitrate_bps = kOpusBitrateFbBps; | 1443 "WebRTC-SendSideBwe-WithOverhead") == "Enabled") { |
| 1444 auto packet_sizes_ms = WebRtcVoiceCodecs::GetPacketSizesMs( | |
| 1445 config_.send_codec_spec.codec_inst); | |
| 1446 if (packet_sizes_ms.size() > 0) { | |
| 1447 const int* max_packet_size_ms = | |
| 1448 std::max_element(packet_sizes_ms.begin(), packet_sizes_ms.end()); | |
| 1449 const int* min_packet_size_ms = | |
| 1450 std::min_element(packet_sizes_ms.begin(), packet_sizes_ms.end()); | |
| 1451 | |
| 1452 // OverheadPerPacket = Ipv4(20B) + UDP(8B) + SRTP(10B) + RTP(12) | |
| 1453 constexpr int kOverheadPerPacket = 20 + 8 + 10 + 12; | |
| 1454 | |
| 1455 int min_overhead_bps = | |
| 1456 kOverheadPerPacket * 8 * 1000 / *max_packet_size_ms; | |
| 1457 | |
| 1458 // Opus will not use a shorter frame length than kOpusDefaultPTime. | |
| 1459 int max_overhead_bps = | |
| 1460 kOverheadPerPacket * 8 * 1000 / | |
| 1461 std::max(*min_packet_size_ms, kOpusDefaultPTime); | |
| 1462 | |
| 1463 config_.min_bitrate_bps = kOpusMinBitrateBps + min_overhead_bps; | |
| 1464 config_.max_bitrate_bps = kOpusBitrateFbBps + max_overhead_bps; | |
| 1465 } | |
| 1466 } else { | |
| 1467 config_.min_bitrate_bps = kOpusMinBitrateBps; | |
| 1468 config_.max_bitrate_bps = kOpusBitrateFbBps; | |
| 1469 } | |
| 1425 } | 1470 } |
| 1426 stream_ = call_->CreateAudioSendStream(config_); | 1471 stream_ = call_->CreateAudioSendStream(config_); |
| 1427 RTC_CHECK(stream_); | 1472 RTC_CHECK(stream_); |
| 1428 UpdateSendState(); | 1473 UpdateSendState(); |
| 1429 } | 1474 } |
| 1430 | 1475 |
| 1431 rtc::ThreadChecker worker_thread_checker_; | 1476 rtc::ThreadChecker worker_thread_checker_; |
| 1432 rtc::RaceChecker audio_capture_race_checker_; | 1477 rtc::RaceChecker audio_capture_race_checker_; |
| 1433 webrtc::AudioTransport* const voe_audio_transport_ = nullptr; | 1478 webrtc::AudioTransport* const voe_audio_transport_ = nullptr; |
| 1434 webrtc::Call* call_ = nullptr; | 1479 webrtc::Call* call_ = nullptr; |
| (...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2638 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2683 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 2639 const auto it = send_streams_.find(ssrc); | 2684 const auto it = send_streams_.find(ssrc); |
| 2640 if (it != send_streams_.end()) { | 2685 if (it != send_streams_.end()) { |
| 2641 return it->second->channel(); | 2686 return it->second->channel(); |
| 2642 } | 2687 } |
| 2643 return -1; | 2688 return -1; |
| 2644 } | 2689 } |
| 2645 } // namespace cricket | 2690 } // namespace cricket |
| 2646 | 2691 |
| 2647 #endif // HAVE_WEBRTC_VOICE | 2692 #endif // HAVE_WEBRTC_VOICE |
| OLD | NEW |