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

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

Issue 2532433002: Add overhead to audio bwe min, max. (Closed)
Patch Set: Respond to offline discussion 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 return rtc::ArrayView<const int>(
407 kCodecPrefs[i].packet_sizes_ms,
408 std::distance(
stefan-webrtc 2017/01/10 12:21:17 Hm, isn't this easier to write with a for loop? Pr
michaelt 2017/01/10 13:09:02 I use a loop now, but i'm not sure if its really b
409 std::begin(kCodecPrefs[i].packet_sizes_ms),
410 std::find_if(std::begin(kCodecPrefs[i].packet_sizes_ms),
411 std::end(kCodecPrefs[i].packet_sizes_ms),
412 [](const int packet_size_ms) {
413 return packet_size_ms == 0;
414 })));
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 int max_overhead_bps =
1457 kOverheadPerPacket * 8 * 1000 /
1458 std::max(*min_packet_size_ms, kOpusDefaultPTime);
stefan-webrtc 2017/01/10 12:21:17 Add a comment about this max(), so that it's clear
michaelt 2017/01/10 13:09:02 Done.
1459
1460 config_.min_bitrate_bps = kOpusMinBitrateBps + min_overhead_bps;
1461 config_.max_bitrate_bps = kOpusBitrateFbBps + max_overhead_bps;
1462 }
1463 } else {
1464 config_.min_bitrate_bps = kOpusMinBitrateBps;
1465 config_.max_bitrate_bps = kOpusBitrateFbBps;
1466 }
1425 } 1467 }
1426 stream_ = call_->CreateAudioSendStream(config_); 1468 stream_ = call_->CreateAudioSendStream(config_);
1427 RTC_CHECK(stream_); 1469 RTC_CHECK(stream_);
1428 UpdateSendState(); 1470 UpdateSendState();
1429 } 1471 }
1430 1472
1431 rtc::ThreadChecker worker_thread_checker_; 1473 rtc::ThreadChecker worker_thread_checker_;
1432 rtc::RaceChecker audio_capture_race_checker_; 1474 rtc::RaceChecker audio_capture_race_checker_;
1433 webrtc::AudioTransport* const voe_audio_transport_ = nullptr; 1475 webrtc::AudioTransport* const voe_audio_transport_ = nullptr;
1434 webrtc::Call* call_ = nullptr; 1476 webrtc::Call* call_ = nullptr;
(...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2638 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 2680 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2639 const auto it = send_streams_.find(ssrc); 2681 const auto it = send_streams_.find(ssrc);
2640 if (it != send_streams_.end()) { 2682 if (it != send_streams_.end()) {
2641 return it->second->channel(); 2683 return it->second->channel();
2642 } 2684 }
2643 return -1; 2685 return -1;
2644 } 2686 }
2645 } // namespace cricket 2687 } // namespace cricket
2646 2688
2647 #endif // HAVE_WEBRTC_VOICE 2689 #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