tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

fec_controller_unittest.cc (4316B)


      1 /*
      2 *  Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
      3 *
      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
      6 *  tree. An additional intellectual property rights grant can be found
      7 *  in the file PATENTS.  All contributing project authors may
      8 *  be found in the AUTHORS file in the root of the source tree.
      9 */
     10 
     11 #include "api/fec_controller.h"
     12 
     13 #include <cstdint>
     14 #include <vector>
     15 
     16 #include "api/environment/environment_factory.h"
     17 #include "modules/include/module_fec_types.h"
     18 #include "modules/video_coding/fec_controller_default.h"
     19 #include "system_wrappers/include/clock.h"
     20 #include "test/gtest.h"
     21 
     22 namespace webrtc {
     23 
     24 static const int kCodecBitrateBps = 100000;
     25 
     26 class ProtectionBitrateCalculatorTest : public ::testing::Test {
     27 protected:
     28  enum {
     29    kSampleRate = 90000  // RTP timestamps per second.
     30  };
     31 
     32  class ProtectionCallback : public VCMProtectionCallback {
     33   public:
     34    int ProtectionRequest(const FecProtectionParams* /* delta_params */,
     35                          const FecProtectionParams* /* key_params */,
     36                          uint32_t* sent_video_rate_bps,
     37                          uint32_t* sent_nack_rate_bps,
     38                          uint32_t* sent_fec_rate_bps) override {
     39      *sent_video_rate_bps = kCodecBitrateBps;
     40      *sent_nack_rate_bps = nack_rate_bps_;
     41      *sent_fec_rate_bps = fec_rate_bps_;
     42      return 0;
     43    }
     44    void SetRetransmissionMode(int /* retransmission_mode */) override {}
     45 
     46    uint32_t fec_rate_bps_ = 0;
     47    uint32_t nack_rate_bps_ = 0;
     48  };
     49 
     50  // Note: simulated clock starts at 1 seconds, since parts of webrtc use 0 as
     51  // a special case (e.g. frame rate in media optimization).
     52  ProtectionBitrateCalculatorTest()
     53      : clock_(1000),
     54        fec_controller_(CreateEnvironment(&clock_), &protection_callback_) {}
     55 
     56  SimulatedClock clock_;
     57  ProtectionCallback protection_callback_;
     58  FecControllerDefault fec_controller_;
     59 };
     60 
     61 TEST_F(ProtectionBitrateCalculatorTest, ProtectsUsingFecBitrate) {
     62  static const uint32_t kMaxBitrateBps = 130000;
     63 
     64  fec_controller_.SetProtectionMethod(true /*enable_fec*/,
     65                                      false /* enable_nack */);
     66  fec_controller_.SetEncodingData(640, 480, 1, 1000);
     67 
     68  // Using 10% of codec bitrate for FEC.
     69  protection_callback_.fec_rate_bps_ = kCodecBitrateBps / 10;
     70  uint32_t target_bitrate = fec_controller_.UpdateFecRates(
     71      kMaxBitrateBps, 30, 0, std::vector<bool>(1, false), 0);
     72 
     73  EXPECT_GT(target_bitrate, 0u);
     74  EXPECT_GT(kMaxBitrateBps, target_bitrate);
     75 
     76  // Using as much for codec bitrate as fec rate, new target rate should share
     77  // both equally, but only be half of max (since that ceiling should be hit).
     78  protection_callback_.fec_rate_bps_ = kCodecBitrateBps;
     79  target_bitrate = fec_controller_.UpdateFecRates(
     80      kMaxBitrateBps, 30, 128, std::vector<bool>(1, false), 100);
     81  EXPECT_EQ(kMaxBitrateBps / 2, target_bitrate);
     82 }
     83 
     84 TEST_F(ProtectionBitrateCalculatorTest, ProtectsUsingNackBitrate) {
     85  static const uint32_t kMaxBitrateBps = 130000;
     86 
     87  fec_controller_.SetProtectionMethod(false /*enable_fec*/,
     88                                      true /* enable_nack */);
     89  fec_controller_.SetEncodingData(640, 480, 1, 1000);
     90 
     91  uint32_t target_bitrate = fec_controller_.UpdateFecRates(
     92      kMaxBitrateBps, 30, 0, std::vector<bool>(1, false), 0);
     93 
     94  EXPECT_EQ(kMaxBitrateBps, target_bitrate);
     95 
     96  // Using as much for codec bitrate as nack rate, new target rate should share
     97  // both equally, but only be half of max (since that ceiling should be hit).
     98  protection_callback_.nack_rate_bps_ = kMaxBitrateBps;
     99  target_bitrate = fec_controller_.UpdateFecRates(
    100      kMaxBitrateBps, 30, 128, std::vector<bool>(1, false), 100);
    101  EXPECT_EQ(kMaxBitrateBps / 2, target_bitrate);
    102 }
    103 
    104 TEST_F(ProtectionBitrateCalculatorTest, NoProtection) {
    105  static const uint32_t kMaxBitrateBps = 130000;
    106 
    107  fec_controller_.SetProtectionMethod(false /*enable_fec*/,
    108                                      false /* enable_nack */);
    109  fec_controller_.SetEncodingData(640, 480, 1, 1000);
    110 
    111  uint32_t target_bitrate = fec_controller_.UpdateFecRates(
    112      kMaxBitrateBps, 30, 128, std::vector<bool>(1, false), 100);
    113  EXPECT_EQ(kMaxBitrateBps, target_bitrate);
    114 }
    115 
    116 }  // namespace webrtc