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

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.cc

Issue 2808513003: Add SafeClamp(), which accepts args of different types (Closed)
Patch Set: rebase Created 3 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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
11 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.h" 11 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.h"
12 12
13 #include <stdio.h> 13 #include <stdio.h>
14 14
15 #include <sstream> 15 #include <sstream>
16 16
17 #include "webrtc/base/constructormagic.h" 17 #include "webrtc/base/constructormagic.h"
18 #include "webrtc/base/safe_minmax.h"
18 19
19 namespace webrtc { 20 namespace webrtc {
20 namespace testing { 21 namespace testing {
21 namespace bwe { 22 namespace bwe {
22 23
23 class DelayCapHelper { 24 class DelayCapHelper {
24 public: 25 public:
25 // Max delay = 0 stands for +infinite. 26 // Max delay = 0 stands for +infinite.
26 DelayCapHelper() : max_delay_us_(0), delay_stats_() {} 27 DelayCapHelper() : max_delay_us_(0), delay_stats_() {}
27 28
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 BWE_TEST_LOGGING_LOG1("Max Jitter", "%d ms", static_cast<int>(max_jitter_ms)); 400 BWE_TEST_LOGGING_LOG1("Max Jitter", "%d ms", static_cast<int>(max_jitter_ms));
400 assert(max_jitter_ms >= 0); 401 assert(max_jitter_ms >= 0);
401 // Truncated gaussian, Max jitter = kN*sigma. 402 // Truncated gaussian, Max jitter = kN*sigma.
402 stddev_jitter_us_ = (max_jitter_ms * 1000 + kN / 2) / kN; 403 stddev_jitter_us_ = (max_jitter_ms * 1000 + kN / 2) / kN;
403 } 404 }
404 405
405 namespace { 406 namespace {
406 inline int64_t TruncatedNSigmaGaussian(Random* const random, 407 inline int64_t TruncatedNSigmaGaussian(Random* const random,
407 int64_t mean, 408 int64_t mean,
408 int64_t std_dev) { 409 int64_t std_dev) {
409 int64_t gaussian_random = random->Gaussian(mean, std_dev); 410 const int64_t gaussian_random = random->Gaussian(mean, std_dev);
410 return std::max(std::min(gaussian_random, kN * std_dev), -kN * std_dev); 411 return rtc::SafeClamp(gaussian_random, -kN * std_dev, kN * std_dev);
411 } 412 }
412 } 413 }
413 414
414 void JitterFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { 415 void JitterFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) {
415 assert(in_out); 416 assert(in_out);
416 for (Packet* packet : *in_out) { 417 for (Packet* packet : *in_out) {
417 int64_t jitter_us = 418 int64_t jitter_us =
418 std::abs(TruncatedNSigmaGaussian(&random_, 0, stddev_jitter_us_)); 419 std::abs(TruncatedNSigmaGaussian(&random_, 0, stddev_jitter_us_));
419 int64_t new_send_time_us = packet->send_time_us() + jitter_us; 420 int64_t new_send_time_us = packet->send_time_us() + jitter_us;
420 421
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 uint32_t PeriodicKeyFrameSource::NextPacketSize(uint32_t frame_size, 820 uint32_t PeriodicKeyFrameSource::NextPacketSize(uint32_t frame_size,
820 uint32_t remaining_payload) { 821 uint32_t remaining_payload) {
821 uint32_t fragments = 822 uint32_t fragments =
822 (frame_size + (kMaxPayloadSizeBytes - 1)) / kMaxPayloadSizeBytes; 823 (frame_size + (kMaxPayloadSizeBytes - 1)) / kMaxPayloadSizeBytes;
823 uint32_t avg_size = (frame_size + fragments - 1) / fragments; 824 uint32_t avg_size = (frame_size + fragments - 1) / fragments;
824 return std::min(avg_size, remaining_payload); 825 return std::min(avg_size, remaining_payload);
825 } 826 }
826 } // namespace bwe 827 } // namespace bwe
827 } // namespace testing 828 } // namespace testing
828 } // namespace webrtc 829 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.cc ('k') | webrtc/modules/rtp_rtcp/source/rtp_sender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698