1 /* 2 * Copyright (c) 2013 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 <map> 12 #include <string> 13 #include <vector> 14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "webrtc/base/constructormagic.h" 16 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" 17 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.h" 18 19 namespace webrtc { 20 21 struct RemoteBitrateEstimatorFactory; 22 23 namespace testing { 24 namespace bwe { 25 26 struct BweTestConfig { 27 struct EstimatorConfig { 28 EstimatorConfig() 29 : debug_name(), 30 flow_id(0), 31 estimator_factory(NULL), 32 control_type(kMimdControl), 33 update_baseline(false), 34 plot_delay(true), 35 plot_estimate(true) { 36 } 37 EstimatorConfig(std::string debug_name, 38 int flow_id, 39 const RemoteBitrateEstimatorFactory* estimator_factory, 40 bool plot_delay, 41 bool plot_estimate) 42 : debug_name(debug_name), 43 flow_id(flow_id), 44 estimator_factory(estimator_factory), 45 control_type(kMimdControl), 46 update_baseline(false), 47 plot_delay(plot_delay), 48 plot_estimate(plot_estimate) { 49 } 50 EstimatorConfig(std::string debug_name, 51 int flow_id, 52 const RemoteBitrateEstimatorFactory* estimator_factory, 53 RateControlType control_type, 54 bool plot_delay, 55 bool plot_estimate) 56 : debug_name(debug_name), 57 flow_id(flow_id), 58 estimator_factory(estimator_factory), 59 control_type(control_type), 60 update_baseline(false), 61 plot_delay(plot_delay), 62 plot_estimate(plot_estimate) { 63 } 64 EstimatorConfig(std::string debug_name, 65 int flow_id, 66 const RemoteBitrateEstimatorFactory* estimator_factory, 67 RateControlType control_type, 68 bool update_baseline) 69 : debug_name(debug_name), 70 flow_id(flow_id), 71 estimator_factory(estimator_factory), 72 control_type(control_type), 73 update_baseline(update_baseline), 74 plot_delay(false), 75 plot_estimate(false) { 76 } 77 std::string debug_name; 78 int flow_id; 79 const RemoteBitrateEstimatorFactory* estimator_factory; 80 RateControlType control_type; 81 bool update_baseline; 82 bool plot_delay; 83 bool plot_estimate; 84 }; 85 86 std::vector<EstimatorConfig> estimator_configs; 87 }; 88 89 class TestedEstimator; 90 class PacketProcessorRunner; 91 92 class BweTest : public PacketProcessorListener { 93 public: 94 BweTest(); 95 virtual ~BweTest(); 96 97 virtual void AddPacketProcessor(PacketProcessor* processor, bool is_sender); 98 virtual void RemovePacketProcessor(PacketProcessor* processor); 99 100 protected: 101 void SetupTestFromConfig(const BweTestConfig& config); 102 void VerboseLogging(bool enable); 103 void RunFor(int64_t time_ms); 104 std::string GetTestName() const; 105 106 private: 107 typedef std::map<int, TestedEstimator*> EstimatorMap; 108 109 void FindPacketsToProcess(const FlowIds& flow_ids, Packets* in, 110 Packets* out); 111 void GiveFeedbackToAffectedSenders(int flow_id, TestedEstimator* estimator); 112 113 int64_t run_time_ms_; 114 int64_t time_now_ms_; 115 int64_t simulation_interval_ms_; 116 EstimatorMap estimators_; 117 Packets previous_packets_; 118 std::vector<PacketSender*> senders_; 119 std::vector<PacketProcessorRunner> processors_; 120 121 DISALLOW_COPY_AND_ASSIGN(BweTest); 122 }; 123 } // namespace bwe 124 } // namespace testing 125 } // namespace webrtc 126