Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / video / rampup_tests.h
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 WEBRTC_VIDEO_RAMPUP_TESTS_H_
12 #define WEBRTC_VIDEO_RAMPUP_TESTS_H_
13
14 #include <map>
15 #include <string>
16 #include <vector>
17
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"
24
25 namespace webrtc {
26
27 static const int kTransmissionTimeOffsetExtensionId = 6;
28 static const int kAbsSendTimeExtensionId = 7;
29 static const unsigned int kSingleStreamTargetBps = 1000000;
30
31 class Clock;
32 class CriticalSectionWrapper;
33 class ReceiveStatistics;
34 class RtpHeaderParser;
35 class RTPPayloadRegistry;
36 class RtpRtcp;
37
38 class StreamObserver : public newapi::Transport, public RemoteBitrateObserver {
39  public:
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,
44                  Clock* clock,
45                  RemoteBitrateEstimatorFactory* rbe_factory,
46                  RateControlType control_type);
47
48   void set_expected_bitrate_bps(unsigned int expected_bitrate_bps);
49
50   void set_start_bitrate_bps(unsigned int start_bitrate_bps);
51
52   virtual void OnReceiveBitrateChanged(const std::vector<unsigned int>& ssrcs,
53                                        unsigned int bitrate) OVERRIDE;
54
55   virtual bool SendRtp(const uint8_t* packet, size_t length) OVERRIDE;
56
57   virtual bool SendRtcp(const uint8_t* packet, size_t length) OVERRIDE;
58
59   EventTypeWrapper Wait();
60
61  private:
62   void ReportResult(const std::string& measurement,
63                     size_t value,
64                     const std::string& units);
65   void TriggerTestDone() EXCLUSIVE_LOCKS_REQUIRED(crit_);
66
67   Clock* const clock_;
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_;
75
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_);
88 };
89
90 class LowRateStreamObserver : public test::DirectTransport,
91                               public RemoteBitrateObserver,
92                               public PacketReceiver {
93  public:
94   LowRateStreamObserver(newapi::Transport* feedback_transport,
95                         Clock* clock,
96                         size_t number_of_streams,
97                         bool rtx_used);
98
99   virtual void SetSendStream(const VideoSendStream* send_stream);
100
101   virtual void OnReceiveBitrateChanged(const std::vector<unsigned int>& ssrcs,
102                                        unsigned int bitrate);
103
104   virtual bool SendRtp(const uint8_t* data, size_t length) OVERRIDE;
105
106   virtual DeliveryStatus DeliverPacket(const uint8_t* packet,
107                                        size_t length) OVERRIDE;
108
109   virtual bool SendRtcp(const uint8_t* packet, size_t length) OVERRIDE;
110
111   // Produces a string similar to "1stream_nortx", depending on the values of
112   // number_of_streams_ and rtx_used_;
113   std::string GetModifierString();
114
115   // This method defines the state machine for the ramp up-down-up test.
116   void EvolveTestState(unsigned int bitrate_bps);
117
118   EventTypeWrapper Wait();
119
120  private:
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 };
126
127   Clock* const clock_;
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_;
136
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_);
147 };
148
149 class RampUpTest : public test::CallTest {
150  protected:
151   void RunRampUpTest(bool rtx,
152                      size_t num_streams,
153                      unsigned int start_bitrate_bps,
154                      const std::string& extension_type);
155
156   void RunRampUpDownUpTest(size_t number_of_streams, bool rtx);
157 };
158 }  // namespace webrtc
159 #endif  // WEBRTC_VIDEO_RAMPUP_TESTS_H_