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

Side by Side Diff: webrtc/media/engine/webrtcvoiceengine.cc

Issue 2532433002: Add overhead to audio bwe min, max. (Closed)
Patch Set: Response to comments Created 3 years, 11 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
« no previous file with comments | « no previous file | webrtc/media/engine/webrtcvoiceengine_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) 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
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 size_t num_packet_sizes = kMaxNumPacketSize;
407 for (int index = 0; index < kMaxNumPacketSize; index++) {
408 if (kCodecPrefs[i].packet_sizes_ms[index] == 0) {
409 num_packet_sizes = index;
410 break;
411 }
412 }
413 return rtc::ArrayView<const int>(kCodecPrefs[i].packet_sizes_ms,
414 num_packet_sizes);
415 }
416 }
417 return rtc::ArrayView<const int>();
418 }
419
402 // If the AudioCodec param kCodecParamPTime is set, then we will set it to 420 // 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 421 // codec pacsize if it's valid, or we will pick the next smallest value we
404 // support. 422 // support.
405 // TODO(Brave): Query supported packet sizes from ACM when the API is ready. 423 // TODO(Brave): Query supported packet sizes from ACM when the API is ready.
406 static bool SetPTimeAsPacketSize(webrtc::CodecInst* codec, int ptime_ms) { 424 static bool SetPTimeAsPacketSize(webrtc::CodecInst* codec, int ptime_ms) {
407 for (const CodecPref& codec_pref : kCodecPrefs) { 425 for (const CodecPref& codec_pref : kCodecPrefs) {
408 if ((IsCodec(*codec, codec_pref.name) && 426 if ((IsCodec(*codec, codec_pref.name) &&
409 codec_pref.clockrate == codec->plfreq) || 427 codec_pref.clockrate == codec->plfreq) ||
410 IsCodec(*codec, kG722CodecName)) { 428 IsCodec(*codec, kG722CodecName)) {
411 int packet_size_ms = SelectPacketSize(codec_pref, ptime_ms); 429 int packet_size_ms = SelectPacketSize(codec_pref, ptime_ms);
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1431 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1414 if (stream_) { 1432 if (stream_) {
1415 call_->DestroyAudioSendStream(stream_); 1433 call_->DestroyAudioSendStream(stream_);
1416 stream_ = nullptr; 1434 stream_ = nullptr;
1417 } 1435 }
1418 RTC_DCHECK(!stream_); 1436 RTC_DCHECK(!stream_);
1419 if (webrtc::field_trial::FindFullName("WebRTC-Audio-SendSideBwe") == 1437 if (webrtc::field_trial::FindFullName("WebRTC-Audio-SendSideBwe") ==
1420 "Enabled") { 1438 "Enabled") {
1421 // TODO(mflodman): Keep testing this and set proper values. 1439 // TODO(mflodman): Keep testing this and set proper values.
1422 // Note: This is an early experiment currently only supported by Opus. 1440 // Note: This is an early experiment currently only supported by Opus.
1423 config_.min_bitrate_bps = kOpusMinBitrateBps; 1441 if (webrtc::field_trial::FindFullName(
1424 config_.max_bitrate_bps = kOpusBitrateFbBps; 1442 "WebRTC-SendSideBwe-WithOverhead") == "Enabled") {
1443 auto packet_sizes_ms = WebRtcVoiceCodecs::GetPacketSizesMs(
1444 config_.send_codec_spec.codec_inst);
1445 if (packet_sizes_ms.size() > 0) {
1446 const int* max_packet_size_ms =
1447 std::max_element(packet_sizes_ms.begin(), packet_sizes_ms.end());
1448 const int* min_packet_size_ms =
1449 std::min_element(packet_sizes_ms.begin(), packet_sizes_ms.end());
1450
1451 // OverheadPerPacket = Ipv4(20B) + UDP(8B) + SRTP(10B) + RTP(12)
1452 constexpr int kOverheadPerPacket = 20 + 8 + 10 + 12;
1453
1454 int min_overhead_bps =
1455 kOverheadPerPacket * 8 * 1000 / *max_packet_size_ms;
1456
1457 // Opus will not use a shorter frame length than kOpusDefaultPTime.
minyue-webrtc 2017/01/10 22:28:40 where can I prove this fact?
michaelt 2017/01/11 10:49:13 I rephrased the comment a bit. Since Opus without
1458 int max_overhead_bps =
1459 kOverheadPerPacket * 8 * 1000 /
1460 std::max(*min_packet_size_ms, kOpusDefaultPTime);
1461
1462 config_.min_bitrate_bps = kOpusMinBitrateBps + min_overhead_bps;
1463 config_.max_bitrate_bps = kOpusBitrateFbBps + max_overhead_bps;
1464 }
1465 } else {
1466 config_.min_bitrate_bps = kOpusMinBitrateBps;
1467 config_.max_bitrate_bps = kOpusBitrateFbBps;
1468 }
1425 } 1469 }
1426 stream_ = call_->CreateAudioSendStream(config_); 1470 stream_ = call_->CreateAudioSendStream(config_);
1427 RTC_CHECK(stream_); 1471 RTC_CHECK(stream_);
1428 UpdateSendState(); 1472 UpdateSendState();
1429 } 1473 }
1430 1474
1431 rtc::ThreadChecker worker_thread_checker_; 1475 rtc::ThreadChecker worker_thread_checker_;
1432 rtc::RaceChecker audio_capture_race_checker_; 1476 rtc::RaceChecker audio_capture_race_checker_;
1433 webrtc::AudioTransport* const voe_audio_transport_ = nullptr; 1477 webrtc::AudioTransport* const voe_audio_transport_ = nullptr;
1434 webrtc::Call* call_ = nullptr; 1478 webrtc::Call* call_ = nullptr;
(...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2638 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 2682 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2639 const auto it = send_streams_.find(ssrc); 2683 const auto it = send_streams_.find(ssrc);
2640 if (it != send_streams_.end()) { 2684 if (it != send_streams_.end()) {
2641 return it->second->channel(); 2685 return it->second->channel();
2642 } 2686 }
2643 return -1; 2687 return -1;
2644 } 2688 }
2645 } // namespace cricket 2689 } // namespace cricket
2646 2690
2647 #endif // HAVE_WEBRTC_VOICE 2691 #endif // HAVE_WEBRTC_VOICE
OLDNEW
« no previous file with comments | « no previous file | webrtc/media/engine/webrtcvoiceengine_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698