Home | History | Annotate | Download | only in test
      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 #ifndef WEBRTC_TEST_CALL_TEST_H_
     11 #define WEBRTC_TEST_CALL_TEST_H_
     12 
     13 #include <vector>
     14 
     15 #include "webrtc/call.h"
     16 #include "webrtc/call/transport_adapter.h"
     17 #include "webrtc/system_wrappers/include/scoped_vector.h"
     18 #include "webrtc/test/fake_audio_device.h"
     19 #include "webrtc/test/fake_decoder.h"
     20 #include "webrtc/test/fake_encoder.h"
     21 #include "webrtc/test/frame_generator_capturer.h"
     22 #include "webrtc/test/rtp_rtcp_observer.h"
     23 
     24 namespace webrtc {
     25 
     26 class VoEBase;
     27 class VoECodec;
     28 class VoENetwork;
     29 
     30 namespace test {
     31 
     32 class BaseTest;
     33 
     34 class CallTest : public ::testing::Test {
     35  public:
     36   CallTest();
     37   virtual ~CallTest();
     38 
     39   static const size_t kNumSsrcs = 3;
     40 
     41   static const int kDefaultTimeoutMs;
     42   static const int kLongTimeoutMs;
     43   static const uint8_t kVideoSendPayloadType;
     44   static const uint8_t kSendRtxPayloadType;
     45   static const uint8_t kFakeVideoSendPayloadType;
     46   static const uint8_t kRedPayloadType;
     47   static const uint8_t kRtxRedPayloadType;
     48   static const uint8_t kUlpfecPayloadType;
     49   static const uint8_t kAudioSendPayloadType;
     50   static const uint32_t kSendRtxSsrcs[kNumSsrcs];
     51   static const uint32_t kVideoSendSsrcs[kNumSsrcs];
     52   static const uint32_t kAudioSendSsrc;
     53   static const uint32_t kReceiverLocalVideoSsrc;
     54   static const uint32_t kReceiverLocalAudioSsrc;
     55   static const int kNackRtpHistoryMs;
     56 
     57  protected:
     58   // RunBaseTest overwrites the audio_state and the voice_engine of the send and
     59   // receive Call configs to simplify test code and avoid having old VoiceEngine
     60   // APIs in the tests.
     61   void RunBaseTest(BaseTest* test);
     62 
     63   void CreateCalls(const Call::Config& sender_config,
     64                    const Call::Config& receiver_config);
     65   void CreateSenderCall(const Call::Config& config);
     66   void CreateReceiverCall(const Call::Config& config);
     67   void DestroyCalls();
     68 
     69   void CreateSendConfig(size_t num_video_streams,
     70                         size_t num_audio_streams,
     71                         Transport* send_transport);
     72   void CreateMatchingReceiveConfigs(Transport* rtcp_send_transport);
     73 
     74   void CreateFrameGeneratorCapturer();
     75   void CreateFakeAudioDevices();
     76 
     77   void CreateVideoStreams();
     78   void CreateAudioStreams();
     79   void Start();
     80   void Stop();
     81   void DestroyStreams();
     82 
     83   Clock* const clock_;
     84 
     85   rtc::scoped_ptr<Call> sender_call_;
     86   rtc::scoped_ptr<PacketTransport> send_transport_;
     87   VideoSendStream::Config video_send_config_;
     88   VideoEncoderConfig video_encoder_config_;
     89   VideoSendStream* video_send_stream_;
     90   AudioSendStream::Config audio_send_config_;
     91   AudioSendStream* audio_send_stream_;
     92 
     93   rtc::scoped_ptr<Call> receiver_call_;
     94   rtc::scoped_ptr<PacketTransport> receive_transport_;
     95   std::vector<VideoReceiveStream::Config> video_receive_configs_;
     96   std::vector<VideoReceiveStream*> video_receive_streams_;
     97   std::vector<AudioReceiveStream::Config> audio_receive_configs_;
     98   std::vector<AudioReceiveStream*> audio_receive_streams_;
     99 
    100   rtc::scoped_ptr<test::FrameGeneratorCapturer> frame_generator_capturer_;
    101   test::FakeEncoder fake_encoder_;
    102   ScopedVector<VideoDecoder> allocated_decoders_;
    103   size_t num_video_streams_;
    104   size_t num_audio_streams_;
    105 
    106  private:
    107   // TODO(holmer): Remove once VoiceEngine is fully refactored to the new API.
    108   // These methods are used to set up legacy voice engines and channels which is
    109   // necessary while voice engine is being refactored to the new stream API.
    110   struct VoiceEngineState {
    111     VoiceEngineState()
    112         : voice_engine(nullptr),
    113           base(nullptr),
    114           network(nullptr),
    115           codec(nullptr),
    116           channel_id(-1),
    117           transport_adapter(nullptr) {}
    118 
    119     VoiceEngine* voice_engine;
    120     VoEBase* base;
    121     VoENetwork* network;
    122     VoECodec* codec;
    123     int channel_id;
    124     rtc::scoped_ptr<internal::TransportAdapter> transport_adapter;
    125   };
    126 
    127   void CreateVoiceEngines();
    128   void SetupVoiceEngineTransports(PacketTransport* send_transport,
    129                                   PacketTransport* recv_transport);
    130   void DestroyVoiceEngines();
    131 
    132   VoiceEngineState voe_send_;
    133   VoiceEngineState voe_recv_;
    134 
    135   // The audio devices must outlive the voice engines.
    136   rtc::scoped_ptr<test::FakeAudioDevice> fake_send_audio_device_;
    137   rtc::scoped_ptr<test::FakeAudioDevice> fake_recv_audio_device_;
    138 };
    139 
    140 class BaseTest : public RtpRtcpObserver {
    141  public:
    142   explicit BaseTest(unsigned int timeout_ms);
    143   virtual ~BaseTest();
    144 
    145   virtual void PerformTest() = 0;
    146   virtual bool ShouldCreateReceivers() const = 0;
    147 
    148   virtual size_t GetNumVideoStreams() const;
    149   virtual size_t GetNumAudioStreams() const;
    150 
    151   virtual Call::Config GetSenderCallConfig();
    152   virtual Call::Config GetReceiverCallConfig();
    153   virtual void OnCallsCreated(Call* sender_call, Call* receiver_call);
    154 
    155   virtual test::PacketTransport* CreateSendTransport(Call* sender_call);
    156   virtual test::PacketTransport* CreateReceiveTransport();
    157 
    158   virtual void ModifyVideoConfigs(
    159       VideoSendStream::Config* send_config,
    160       std::vector<VideoReceiveStream::Config>* receive_configs,
    161       VideoEncoderConfig* encoder_config);
    162   virtual void OnVideoStreamsCreated(
    163       VideoSendStream* send_stream,
    164       const std::vector<VideoReceiveStream*>& receive_streams);
    165 
    166   virtual void ModifyAudioConfigs(
    167       AudioSendStream::Config* send_config,
    168       std::vector<AudioReceiveStream::Config>* receive_configs);
    169   virtual void OnAudioStreamsCreated(
    170       AudioSendStream* send_stream,
    171       const std::vector<AudioReceiveStream*>& receive_streams);
    172 
    173   virtual void OnFrameGeneratorCapturerCreated(
    174       FrameGeneratorCapturer* frame_generator_capturer);
    175 };
    176 
    177 class SendTest : public BaseTest {
    178  public:
    179   explicit SendTest(unsigned int timeout_ms);
    180 
    181   bool ShouldCreateReceivers() const override;
    182 };
    183 
    184 class EndToEndTest : public BaseTest {
    185  public:
    186   explicit EndToEndTest(unsigned int timeout_ms);
    187 
    188   bool ShouldCreateReceivers() const override;
    189 };
    190 
    191 }  // namespace test
    192 }  // namespace webrtc
    193 
    194 #endif  // WEBRTC_TEST_CALL_TEST_H_
    195