2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef WEBRTC_VIDEO_RAMPUP_TESTS_H_
12 #define WEBRTC_VIDEO_RAMPUP_TESTS_H_
18 #include "webrtc/call.h"
19 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
20 #include "webrtc/system_wrappers/interface/event_wrapper.h"
21 #include "webrtc/system_wrappers/interface/scoped_ptr.h"
22 #include "webrtc/test/call_test.h"
23 #include "webrtc/video/transport_adapter.h"
27 static const int kTransmissionTimeOffsetExtensionId = 6;
28 static const int kAbsSendTimeExtensionId = 7;
29 static const unsigned int kSingleStreamTargetBps = 1000000;
32 class CriticalSectionWrapper;
33 class ReceiveStatistics;
34 class RtpHeaderParser;
35 class RTPPayloadRegistry;
38 class StreamObserver : public newapi::Transport, public RemoteBitrateObserver {
40 typedef std::map<uint32_t, int> BytesSentMap;
41 typedef std::map<uint32_t, uint32_t> SsrcMap;
42 StreamObserver(const SsrcMap& rtx_media_ssrcs,
43 newapi::Transport* feedback_transport,
45 RemoteBitrateEstimatorFactory* rbe_factory,
46 RateControlType control_type);
48 void set_expected_bitrate_bps(unsigned int expected_bitrate_bps);
50 void set_start_bitrate_bps(unsigned int start_bitrate_bps);
52 virtual void OnReceiveBitrateChanged(const std::vector<unsigned int>& ssrcs,
53 unsigned int bitrate) OVERRIDE;
55 virtual bool SendRtp(const uint8_t* packet, size_t length) OVERRIDE;
57 virtual bool SendRtcp(const uint8_t* packet, size_t length) OVERRIDE;
59 EventTypeWrapper Wait();
62 void ReportResult(const std::string& measurement,
64 const std::string& units);
65 void TriggerTestDone() EXCLUSIVE_LOCKS_REQUIRED(crit_);
68 const scoped_ptr<EventWrapper> test_done_;
69 const scoped_ptr<RtpHeaderParser> rtp_parser_;
70 scoped_ptr<RtpRtcp> rtp_rtcp_;
71 internal::TransportAdapter feedback_transport_;
72 const scoped_ptr<ReceiveStatistics> receive_stats_;
73 const scoped_ptr<RTPPayloadRegistry> payload_registry_;
74 scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
76 const scoped_ptr<CriticalSectionWrapper> crit_;
77 unsigned int expected_bitrate_bps_ GUARDED_BY(crit_);
78 unsigned int start_bitrate_bps_ GUARDED_BY(crit_);
79 SsrcMap rtx_media_ssrcs_ GUARDED_BY(crit_);
80 size_t total_sent_ GUARDED_BY(crit_);
81 size_t padding_sent_ GUARDED_BY(crit_);
82 size_t rtx_media_sent_ GUARDED_BY(crit_);
83 int total_packets_sent_ GUARDED_BY(crit_);
84 int padding_packets_sent_ GUARDED_BY(crit_);
85 int rtx_media_packets_sent_ GUARDED_BY(crit_);
86 int64_t test_start_ms_ GUARDED_BY(crit_);
87 int64_t ramp_up_finished_ms_ GUARDED_BY(crit_);
90 class LowRateStreamObserver : public test::DirectTransport,
91 public RemoteBitrateObserver,
92 public PacketReceiver {
94 LowRateStreamObserver(newapi::Transport* feedback_transport,
96 size_t number_of_streams,
99 virtual void SetSendStream(const VideoSendStream* send_stream);
101 virtual void OnReceiveBitrateChanged(const std::vector<unsigned int>& ssrcs,
102 unsigned int bitrate);
104 virtual bool SendRtp(const uint8_t* data, size_t length) OVERRIDE;
106 virtual DeliveryStatus DeliverPacket(const uint8_t* packet,
107 size_t length) OVERRIDE;
109 virtual bool SendRtcp(const uint8_t* packet, size_t length) OVERRIDE;
111 // Produces a string similar to "1stream_nortx", depending on the values of
112 // number_of_streams_ and rtx_used_;
113 std::string GetModifierString();
115 // This method defines the state machine for the ramp up-down-up test.
116 void EvolveTestState(unsigned int bitrate_bps);
118 EventTypeWrapper Wait();
121 static const unsigned int kHighBandwidthLimitBps = 80000;
122 static const unsigned int kExpectedHighBitrateBps = 60000;
123 static const unsigned int kLowBandwidthLimitBps = 20000;
124 static const unsigned int kExpectedLowBitrateBps = 20000;
125 enum TestStates { kFirstRampup, kLowRate, kSecondRampup };
128 const size_t number_of_streams_;
129 const bool rtx_used_;
130 const scoped_ptr<EventWrapper> test_done_;
131 const scoped_ptr<RtpHeaderParser> rtp_parser_;
132 scoped_ptr<RtpRtcp> rtp_rtcp_;
133 internal::TransportAdapter feedback_transport_;
134 const scoped_ptr<ReceiveStatistics> receive_stats_;
135 scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
137 scoped_ptr<CriticalSectionWrapper> crit_;
138 const VideoSendStream* send_stream_ GUARDED_BY(crit_);
139 FakeNetworkPipe::Config forward_transport_config_ GUARDED_BY(crit_);
140 TestStates test_state_ GUARDED_BY(crit_);
141 int64_t state_start_ms_ GUARDED_BY(crit_);
142 int64_t interval_start_ms_ GUARDED_BY(crit_);
143 unsigned int last_remb_bps_ GUARDED_BY(crit_);
144 size_t sent_bytes_ GUARDED_BY(crit_);
145 size_t total_overuse_bytes_ GUARDED_BY(crit_);
146 bool suspended_in_stats_ GUARDED_BY(crit_);
149 class RampUpTest : public test::CallTest {
151 void RunRampUpTest(bool rtx,
153 unsigned int start_bitrate_bps,
154 const std::string& extension_type);
156 void RunRampUpDownUpTest(size_t number_of_streams, bool rtx);
158 } // namespace webrtc
159 #endif // WEBRTC_VIDEO_RAMPUP_TESTS_H_