tor-browser

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

rampup_tests.h (5822B)


      1 /*
      2 *  Copyright (c) 2014 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 #ifndef CALL_RAMPUP_TESTS_H_
     12 #define CALL_RAMPUP_TESTS_H_
     13 
     14 #include <cstddef>
     15 #include <cstdint>
     16 #include <map>
     17 #include <string>
     18 #include <vector>
     19 
     20 #include "absl/strings/string_view.h"
     21 #include "api/task_queue/task_queue_base.h"
     22 #include "api/test/metrics/metric.h"
     23 #include "api/test/simulated_network.h"
     24 #include "api/transport/bitrate_settings.h"
     25 #include "call/audio_receive_stream.h"
     26 #include "call/audio_send_stream.h"
     27 #include "call/call.h"
     28 #include "call/flexfec_receive_stream.h"
     29 #include "call/video_receive_stream.h"
     30 #include "call/video_send_stream.h"
     31 #include "rtc_base/task_utils/repeating_task.h"
     32 #include "test/call_test.h"
     33 #include "test/rtp_rtcp_observer.h"
     34 #include "video/config/video_encoder_config.h"
     35 
     36 namespace webrtc {
     37 
     38 static const int kTransmissionTimeOffsetExtensionId = 6;
     39 static const int kAbsSendTimeExtensionId = 7;
     40 static const int kTransportSequenceNumberExtensionId = 8;
     41 static const unsigned int kSingleStreamTargetBps = 1000000;
     42 
     43 class Clock;
     44 
     45 class RampUpTester : public test::EndToEndTest {
     46 public:
     47  RampUpTester(size_t num_video_streams,
     48               size_t num_audio_streams,
     49               size_t num_flexfec_streams,
     50               unsigned int start_bitrate_bps,
     51               int64_t min_run_time_ms,
     52               bool rtx,
     53               bool red,
     54               bool report_perf_stats,
     55               TaskQueueBase* task_queue);
     56  ~RampUpTester() override;
     57 
     58  size_t GetNumVideoStreams() const override;
     59  size_t GetNumAudioStreams() const override;
     60  size_t GetNumFlexfecStreams() const override;
     61 
     62  void PerformTest() override;
     63 
     64 protected:
     65  virtual void PollStats();
     66 
     67  void AccumulateStats(const VideoSendStream::StreamStats& stream,
     68                       size_t* total_packets_sent,
     69                       size_t* total_sent,
     70                       size_t* padding_sent,
     71                       size_t* media_sent) const;
     72 
     73  void ReportResult(absl::string_view measurement,
     74                    size_t value,
     75                    test::Unit unit,
     76                    test::ImprovementDirection improvement_direction) const;
     77  void TriggerTestDone();
     78 
     79  Clock* const clock_;
     80  BuiltInNetworkBehaviorConfig forward_transport_config_;
     81  const size_t num_video_streams_;
     82  const size_t num_audio_streams_;
     83  const size_t num_flexfec_streams_;
     84  const bool rtx_;
     85  const bool red_;
     86  const bool report_perf_stats_;
     87  Call* sender_call_;
     88  VideoSendStream* send_stream_;
     89  test::PacketTransport* send_transport_;
     90  SimulatedNetworkInterface* send_simulated_network_;
     91 
     92 private:
     93  typedef std::map<uint32_t, uint32_t> SsrcMap;
     94  class VideoStreamFactory;
     95 
     96  void ModifySenderBitrateConfig(BitrateConstraints* bitrate_config) override;
     97  void OnVideoStreamsCreated(VideoSendStream* send_stream,
     98                             const std::vector<VideoReceiveStreamInterface*>&
     99                                 receive_streams) override;
    100  BuiltInNetworkBehaviorConfig GetSendTransportConfig() const override;
    101  void ModifyVideoConfigs(
    102      VideoSendStream::Config* send_config,
    103      std::vector<VideoReceiveStreamInterface::Config>* receive_configs,
    104      VideoEncoderConfig* encoder_config) override;
    105  void ModifyAudioConfigs(AudioSendStream::Config* send_config,
    106                          std::vector<AudioReceiveStreamInterface::Config>*
    107                              receive_configs) override;
    108  void ModifyFlexfecConfigs(
    109      std::vector<FlexfecReceiveStream::Config>* receive_configs) override;
    110  void OnCallsCreated(Call* sender_call, Call* receiver_call) override;
    111  void OnTransportCreated(test::PacketTransport* to_receiver,
    112                          SimulatedNetworkInterface* sender_network,
    113                          test::PacketTransport* to_sender,
    114                          SimulatedNetworkInterface* receiver_network) override;
    115 
    116  const int start_bitrate_bps_;
    117  const int64_t min_run_time_ms_;
    118  int expected_bitrate_bps_;
    119  int64_t test_start_ms_;
    120  int64_t ramp_up_finished_ms_;
    121 
    122  std::vector<uint32_t> video_ssrcs_;
    123  std::vector<uint32_t> video_rtx_ssrcs_;
    124  std::vector<uint32_t> audio_ssrcs_;
    125 
    126 protected:
    127  TaskQueueBase* const task_queue_;
    128  RepeatingTaskHandle pending_task_;
    129 };
    130 
    131 class RampUpDownUpTester : public RampUpTester {
    132 public:
    133  RampUpDownUpTester(size_t num_video_streams,
    134                     size_t num_audio_streams,
    135                     size_t num_flexfec_streams,
    136                     unsigned int start_bitrate_bps,
    137                     bool rtx,
    138                     bool red,
    139                     const std::vector<int>& loss_rates,
    140                     bool report_perf_stats,
    141                     TaskQueueBase* task_queue);
    142  ~RampUpDownUpTester() override;
    143 
    144 protected:
    145  void PollStats() override;
    146 
    147 private:
    148  enum TestStates {
    149    kFirstRampup = 0,
    150    kLowRate,
    151    kSecondRampup,
    152    kTestEnd,
    153    kTransitionToNextState,
    154  };
    155 
    156  void ModifyReceiverBitrateConfig(BitrateConstraints* bitrate_config) override;
    157 
    158  std::string GetModifierString() const;
    159  int GetExpectedHighBitrate() const;
    160  int GetHighLinkCapacity() const;
    161  size_t GetFecBytes() const;
    162  bool ExpectingFec() const;
    163  void EvolveTestState(int bitrate_bps, bool suspended);
    164 
    165  const std::vector<int> link_rates_;
    166  TestStates test_state_;
    167  TestStates next_state_;
    168  int64_t state_start_ms_;
    169  int64_t interval_start_ms_;
    170  int sent_bytes_;
    171  std::vector<int> loss_rates_;
    172 };
    173 
    174 }  // namespace webrtc
    175 #endif  // CALL_RAMPUP_TESTS_H_