Home | History | Annotate | Download | only in call
      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_CALL_RAMPUP_TESTS_H_
     12 #define WEBRTC_CALL_RAMPUP_TESTS_H_
     13 
     14 #include <map>
     15 #include <string>
     16 #include <vector>
     17 
     18 #include "webrtc/base/event.h"
     19 #include "webrtc/base/scoped_ptr.h"
     20 #include "webrtc/call.h"
     21 #include "webrtc/test/call_test.h"
     22 
     23 namespace webrtc {
     24 
     25 static const int kTransmissionTimeOffsetExtensionId = 6;
     26 static const int kAbsSendTimeExtensionId = 7;
     27 static const int kTransportSequenceNumberExtensionId = 8;
     28 static const unsigned int kSingleStreamTargetBps = 1000000;
     29 
     30 class Clock;
     31 
     32 class RampUpTester : public test::EndToEndTest {
     33  public:
     34   RampUpTester(size_t num_video_streams,
     35                size_t num_audio_streams,
     36                unsigned int start_bitrate_bps,
     37                const std::string& extension_type,
     38                bool rtx,
     39                bool red);
     40   ~RampUpTester() override;
     41 
     42   size_t GetNumVideoStreams() const override;
     43   size_t GetNumAudioStreams() const override;
     44 
     45   void PerformTest() override;
     46 
     47  protected:
     48   virtual bool PollStats();
     49 
     50   void AccumulateStats(const VideoSendStream::StreamStats& stream,
     51                        size_t* total_packets_sent,
     52                        size_t* total_sent,
     53                        size_t* padding_sent,
     54                        size_t* media_sent) const;
     55 
     56   void ReportResult(const std::string& measurement,
     57                     size_t value,
     58                     const std::string& units) const;
     59   void TriggerTestDone();
     60 
     61   rtc::Event event_;
     62   Clock* const clock_;
     63   FakeNetworkPipe::Config forward_transport_config_;
     64   const size_t num_video_streams_;
     65   const size_t num_audio_streams_;
     66   const bool rtx_;
     67   const bool red_;
     68   VideoSendStream* send_stream_;
     69   test::PacketTransport* send_transport_;
     70 
     71  private:
     72   typedef std::map<uint32_t, uint32_t> SsrcMap;
     73 
     74   Call::Config GetSenderCallConfig() override;
     75   void OnVideoStreamsCreated(
     76       VideoSendStream* send_stream,
     77       const std::vector<VideoReceiveStream*>& receive_streams) override;
     78   test::PacketTransport* CreateSendTransport(Call* sender_call) override;
     79   void ModifyVideoConfigs(
     80       VideoSendStream::Config* send_config,
     81       std::vector<VideoReceiveStream::Config>* receive_configs,
     82       VideoEncoderConfig* encoder_config) override;
     83   void ModifyAudioConfigs(
     84       AudioSendStream::Config* send_config,
     85       std::vector<AudioReceiveStream::Config>* receive_configs) override;
     86   void OnCallsCreated(Call* sender_call, Call* receiver_call) override;
     87 
     88   static bool BitrateStatsPollingThread(void* obj);
     89 
     90   const int start_bitrate_bps_;
     91   bool start_bitrate_verified_;
     92   int expected_bitrate_bps_;
     93   int64_t test_start_ms_;
     94   int64_t ramp_up_finished_ms_;
     95 
     96   const std::string extension_type_;
     97   std::vector<uint32_t> video_ssrcs_;
     98   std::vector<uint32_t> video_rtx_ssrcs_;
     99   std::vector<uint32_t> audio_ssrcs_;
    100   SsrcMap rtx_ssrc_map_;
    101 
    102   rtc::PlatformThread poller_thread_;
    103   Call* sender_call_;
    104 };
    105 
    106 class RampUpDownUpTester : public RampUpTester {
    107  public:
    108   RampUpDownUpTester(size_t num_video_streams,
    109                      size_t num_audio_streams,
    110                      unsigned int start_bitrate_bps,
    111                      const std::string& extension_type,
    112                      bool rtx,
    113                      bool red);
    114   ~RampUpDownUpTester() override;
    115 
    116  protected:
    117   bool PollStats() override;
    118 
    119  private:
    120   static const int kHighBandwidthLimitBps = 80000;
    121   static const int kExpectedHighBitrateBps = 60000;
    122   static const int kLowBandwidthLimitBps = 20000;
    123   static const int kExpectedLowBitrateBps = 20000;
    124   enum TestStates { kFirstRampup, kLowRate, kSecondRampup };
    125 
    126   Call::Config GetReceiverCallConfig() override;
    127 
    128   std::string GetModifierString() const;
    129   void EvolveTestState(int bitrate_bps, bool suspended);
    130 
    131   TestStates test_state_;
    132   int64_t state_start_ms_;
    133   int64_t interval_start_ms_;
    134   int sent_bytes_;
    135 };
    136 }  // namespace webrtc
    137 #endif  // WEBRTC_CALL_RAMPUP_TESTS_H_
    138