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

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

Issue 1237303002: Modified Simulation Framework Jitter Model (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Updated Jitter expected value to suit the truncated gaussian Created 5 years, 5 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
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 int64_t new_send_time_us = packet->send_time_us() + one_way_delay_us_; 382 int64_t new_send_time_us = packet->send_time_us() + one_way_delay_us_;
383 last_send_time_us_ = std::max(last_send_time_us_, new_send_time_us); 383 last_send_time_us_ = std::max(last_send_time_us_, new_send_time_us);
384 packet->set_send_time_us(last_send_time_us_); 384 packet->set_send_time_us(last_send_time_us_);
385 } 385 }
386 } 386 }
387 387
388 JitterFilter::JitterFilter(PacketProcessorListener* listener, int flow_id) 388 JitterFilter::JitterFilter(PacketProcessorListener* listener, int flow_id)
389 : PacketProcessor(listener, flow_id, kRegular), 389 : PacketProcessor(listener, flow_id, kRegular),
390 random_(0x89674523), 390 random_(0x89674523),
391 stddev_jitter_us_(0), 391 stddev_jitter_us_(0),
392 last_send_time_us_(0) { 392 last_send_time_us_(0),
393 reordering_(false) {
393 } 394 }
394 395
395 JitterFilter::JitterFilter(PacketProcessorListener* listener, 396 JitterFilter::JitterFilter(PacketProcessorListener* listener,
396 const FlowIds& flow_ids) 397 const FlowIds& flow_ids)
397 : PacketProcessor(listener, flow_ids, kRegular), 398 : PacketProcessor(listener, flow_ids, kRegular),
398 random_(0x89674523), 399 random_(0x89674523),
399 stddev_jitter_us_(0), 400 stddev_jitter_us_(0),
400 last_send_time_us_(0) { 401 last_send_time_us_(0),
402 reordering_(false) {
401 } 403 }
402 404
403 void JitterFilter::SetJitter(int64_t stddev_jitter_ms) { 405 const int kN = 3; // Truncated N sigma gaussian.
406
407 void JitterFilter::SetMaxJitter(int64_t max_jitter_ms) {
404 BWE_TEST_LOGGING_ENABLE(false); 408 BWE_TEST_LOGGING_ENABLE(false);
405 BWE_TEST_LOGGING_LOG1("Jitter", "%d ms", 409 BWE_TEST_LOGGING_LOG1("Max Jitter", "%d ms", static_cast<int>(max_jitter_ms));
406 static_cast<int>(stddev_jitter_ms)); 410 assert(max_jitter_ms >= 0);
407 assert(stddev_jitter_ms >= 0); 411 // Truncated gaussian, Max jitter = kN*sigma.
408 stddev_jitter_us_ = stddev_jitter_ms * 1000; 412 stddev_jitter_us_ = (max_jitter_ms * 1000 + kN / 2) / kN;
413 }
414
415 namespace {
416 inline int64_t TruncatedNSigmaGaussian(Random* const random,
417 int64_t mean,
418 int64_t std_dev) {
419 int64_t gaussian_random = random->Gaussian(mean, std_dev);
420 return std::max(std::min(gaussian_random, kN * std_dev), -kN * std_dev);
421 }
409 } 422 }
410 423
411 void JitterFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { 424 void JitterFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) {
412 assert(in_out); 425 assert(in_out);
413 for (Packet* packet : *in_out) { 426 for (Packet* packet : *in_out) {
414 int64_t new_send_time_us = packet->send_time_us(); 427 int64_t jitter_us =
415 new_send_time_us += random_.Gaussian(0, stddev_jitter_us_); 428 std::abs(TruncatedNSigmaGaussian(&random_, 0, stddev_jitter_us_));
416 last_send_time_us_ = std::max(last_send_time_us_, new_send_time_us); 429 int64_t new_send_time_us = packet->send_time_us() + jitter_us;
417 packet->set_send_time_us(last_send_time_us_); 430
431 if (!reordering_) {
432 new_send_time_us = std::max(last_send_time_us_, new_send_time_us);
433 }
434
435 // Receiver timestamp cannot be lower than sender timestamp.
436 assert(new_send_time_us >= packet->sender_timestamp_us());
437
438 packet->set_send_time_us(new_send_time_us);
439 last_send_time_us_ = new_send_time_us;
418 } 440 }
419 } 441 }
420 442
443 // Computes the expected value for a right sided (abs) truncated gaussian.
444 // Does not take into account possible reoerdering updates.
445 int64_t JitterFilter::MeanUs() {
446 const double kPi = 3.1415926535897932;
447 double max_jitter_us = static_cast<double>(kN * stddev_jitter_us_);
448 double right_sided_mean_us =
449 static_cast<double>(stddev_jitter_us_) / sqrt(kPi / 2.0);
450 double truncated_mean_us =
451 right_sided_mean_us *
452 (1.0 - exp(-pow(static_cast<double>(kN), 2.0) / 2.0)) +
453 max_jitter_us * erfc(static_cast<double>(kN));
454 return static_cast<int64_t>(truncated_mean_us + 0.5);
455 }
456
421 ReorderFilter::ReorderFilter(PacketProcessorListener* listener, int flow_id) 457 ReorderFilter::ReorderFilter(PacketProcessorListener* listener, int flow_id)
422 : PacketProcessor(listener, flow_id, kRegular), 458 : PacketProcessor(listener, flow_id, kRegular),
423 random_(0x27452389), 459 random_(0x27452389),
424 reorder_fraction_(0.0f) { 460 reorder_fraction_(0.0f) {
425 } 461 }
426 462
427 ReorderFilter::ReorderFilter(PacketProcessorListener* listener, 463 ReorderFilter::ReorderFilter(PacketProcessorListener* listener,
428 const FlowIds& flow_ids) 464 const FlowIds& flow_ids)
429 : PacketProcessor(listener, flow_ids, kRegular), 465 : PacketProcessor(listener, flow_ids, kRegular),
430 random_(0x27452389), 466 random_(0x27452389),
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 uint32_t PeriodicKeyFrameSource::NextPacketSize(uint32_t frame_size, 831 uint32_t PeriodicKeyFrameSource::NextPacketSize(uint32_t frame_size,
796 uint32_t remaining_payload) { 832 uint32_t remaining_payload) {
797 uint32_t fragments = 833 uint32_t fragments =
798 (frame_size + (kMaxPayloadSizeBytes - 1)) / kMaxPayloadSizeBytes; 834 (frame_size + (kMaxPayloadSizeBytes - 1)) / kMaxPayloadSizeBytes;
799 uint32_t avg_size = (frame_size + fragments - 1) / fragments; 835 uint32_t avg_size = (frame_size + fragments - 1) / fragments;
800 return std::min(avg_size, remaining_payload); 836 return std::min(avg_size, remaining_payload);
801 } 837 }
802 } // namespace bwe 838 } // namespace bwe
803 } // namespace testing 839 } // namespace testing
804 } // namespace webrtc 840 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698