OLD | NEW |
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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 BWE_TEST_LOGGING_LOG1("Max Jitter", "%d ms", static_cast<int>(max_jitter_ms)); | 392 BWE_TEST_LOGGING_LOG1("Max Jitter", "%d ms", static_cast<int>(max_jitter_ms)); |
392 assert(max_jitter_ms >= 0); | 393 assert(max_jitter_ms >= 0); |
393 // Truncated gaussian, Max jitter = kN*sigma. | 394 // Truncated gaussian, Max jitter = kN*sigma. |
394 stddev_jitter_us_ = (max_jitter_ms * 1000 + kN / 2) / kN; | 395 stddev_jitter_us_ = (max_jitter_ms * 1000 + kN / 2) / kN; |
395 } | 396 } |
396 | 397 |
397 namespace { | 398 namespace { |
398 inline int64_t TruncatedNSigmaGaussian(Random* const random, | 399 inline int64_t TruncatedNSigmaGaussian(Random* const random, |
399 int64_t mean, | 400 int64_t mean, |
400 int64_t std_dev) { | 401 int64_t std_dev) { |
401 int64_t gaussian_random = random->Gaussian(mean, std_dev); | 402 const int64_t gaussian_random = random->Gaussian(mean, std_dev); |
402 return std::max(std::min(gaussian_random, kN * std_dev), -kN * std_dev); | 403 return rtc::SafeClamp(-kN * std_dev, kN * std_dev, gaussian_random); |
403 } | 404 } |
404 } | 405 } |
405 | 406 |
406 void JitterFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { | 407 void JitterFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { |
407 assert(in_out); | 408 assert(in_out); |
408 for (Packet* packet : *in_out) { | 409 for (Packet* packet : *in_out) { |
409 int64_t jitter_us = | 410 int64_t jitter_us = |
410 std::abs(TruncatedNSigmaGaussian(&random_, 0, stddev_jitter_us_)); | 411 std::abs(TruncatedNSigmaGaussian(&random_, 0, stddev_jitter_us_)); |
411 int64_t new_send_time_us = packet->send_time_us() + jitter_us; | 412 int64_t new_send_time_us = packet->send_time_us() + jitter_us; |
412 | 413 |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 uint32_t PeriodicKeyFrameSource::NextPacketSize(uint32_t frame_size, | 812 uint32_t PeriodicKeyFrameSource::NextPacketSize(uint32_t frame_size, |
812 uint32_t remaining_payload) { | 813 uint32_t remaining_payload) { |
813 uint32_t fragments = | 814 uint32_t fragments = |
814 (frame_size + (kMaxPayloadSizeBytes - 1)) / kMaxPayloadSizeBytes; | 815 (frame_size + (kMaxPayloadSizeBytes - 1)) / kMaxPayloadSizeBytes; |
815 uint32_t avg_size = (frame_size + fragments - 1) / fragments; | 816 uint32_t avg_size = (frame_size + fragments - 1) / fragments; |
816 return std::min(avg_size, remaining_payload); | 817 return std::min(avg_size, remaining_payload); |
817 } | 818 } |
818 } // namespace bwe | 819 } // namespace bwe |
819 } // namespace testing | 820 } // namespace testing |
820 } // namespace webrtc | 821 } // namespace webrtc |
OLD | NEW |