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 <memory> 14 #include <vector> 15 16 #include "webrtc/call/call.h" 17 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" 18 #include "webrtc/test/encoder_settings.h" 19 #include "webrtc/test/fake_audio_device.h" 20 #include "webrtc/test/fake_decoder.h" 21 #include "webrtc/test/fake_encoder.h" 22 #include "webrtc/test/fake_videorenderer.h" 23 #include "webrtc/test/frame_generator_capturer.h" 24 #include "webrtc/test/rtp_rtcp_observer.h" 25 26 namespace webrtc { 27 28 class VoEBase; 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 static const int kDefaultWidth = 320; 41 static const int kDefaultHeight = 180; 42 static const int kDefaultFramerate = 30; 43 static const int kDefaultTimeoutMs; 44 static const int kLongTimeoutMs; 45 static const uint8_t kVideoSendPayloadType; 46 static const uint8_t kSendRtxPayloadType; 47 static const uint8_t kFakeVideoSendPayloadType; 48 static const uint8_t kRedPayloadType; 49 static const uint8_t kRtxRedPayloadType; 50 static const uint8_t kUlpfecPayloadType; 51 static const uint8_t kFlexfecPayloadType; 52 static const uint8_t kAudioSendPayloadType; 53 static const uint32_t kSendRtxSsrcs[kNumSsrcs]; 54 static const uint32_t kVideoSendSsrcs[kNumSsrcs]; 55 static const uint32_t kAudioSendSsrc; 56 static const uint32_t kFlexfecSendSsrc; 57 static const uint32_t kReceiverLocalVideoSsrc; 58 static const uint32_t kReceiverLocalAudioSsrc; 59 static const int kNackRtpHistoryMs; 60 61 protected: 62 // RunBaseTest overwrites the audio_state and the voice_engine of the send and 63 // receive Call configs to simplify test code and avoid having old VoiceEngine 64 // APIs in the tests. 65 void RunBaseTest(BaseTest* test); 66 67 void CreateCalls(const Call::Config& sender_config, 68 const Call::Config& receiver_config); 69 void CreateSenderCall(const Call::Config& config); 70 void CreateReceiverCall(const Call::Config& config); 71 void DestroyCalls(); 72 73 void CreateSendConfig(size_t num_video_streams, 74 size_t num_audio_streams, 75 size_t num_flexfec_streams, 76 Transport* send_transport); 77 void CreateMatchingReceiveConfigs(Transport* rtcp_send_transport); 78 79 void CreateFrameGeneratorCapturerWithDrift(Clock* drift_clock, 80 float speed, 81 int framerate, 82 int width, 83 int height); 84 void CreateFrameGeneratorCapturer(int framerate, int width, int height); 85 void CreateFakeAudioDevices(); 86 87 void CreateVideoStreams(); 88 void CreateAudioStreams(); 89 void CreateFlexfecStreams(); 90 void Start(); 91 void Stop(); 92 void DestroyStreams(); 93 void SetFakeVideoCaptureRotation(VideoRotation rotation); 94 95 Clock* const clock_; 96 97 webrtc::RtcEventLogNullImpl event_log_; 98 std::unique_ptr<Call> sender_call_; 99 std::unique_ptr<PacketTransport> send_transport_; 100 VideoSendStream::Config video_send_config_; 101 VideoEncoderConfig video_encoder_config_; 102 VideoSendStream* video_send_stream_; 103 AudioSendStream::Config audio_send_config_; 104 AudioSendStream* audio_send_stream_; 105 106 std::unique_ptr<Call> receiver_call_; 107 std::unique_ptr<PacketTransport> receive_transport_; 108 std::vector<VideoReceiveStream::Config> video_receive_configs_; 109 std::vector<VideoReceiveStream*> video_receive_streams_; 110 std::vector<AudioReceiveStream::Config> audio_receive_configs_; 111 std::vector<AudioReceiveStream*> audio_receive_streams_; 112 std::vector<FlexfecReceiveStream::Config> flexfec_receive_configs_; 113 std::vector<FlexfecReceiveStream*> flexfec_receive_streams_; 114 115 std::unique_ptr<test::FrameGeneratorCapturer> frame_generator_capturer_; 116 test::FakeEncoder fake_encoder_; 117 std::vector<std::unique_ptr<VideoDecoder>> allocated_decoders_; 118 size_t num_video_streams_; 119 size_t num_audio_streams_; 120 size_t num_flexfec_streams_; 121 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; 122 test::FakeVideoRenderer fake_renderer_; 123 124 private: 125 // TODO(holmer): Remove once VoiceEngine is fully refactored to the new API. 126 // These methods are used to set up legacy voice engines and channels which is 127 // necessary while voice engine is being refactored to the new stream API. 128 struct VoiceEngineState { VoiceEngineStateVoiceEngineState129 VoiceEngineState() 130 : voice_engine(nullptr), 131 base(nullptr), 132 channel_id(-1) {} 133 134 VoiceEngine* voice_engine; 135 VoEBase* base; 136 int channel_id; 137 }; 138 139 void CreateVoiceEngines(); 140 void DestroyVoiceEngines(); 141 142 VoiceEngineState voe_send_; 143 VoiceEngineState voe_recv_; 144 145 // The audio devices must outlive the voice engines. 146 std::unique_ptr<test::FakeAudioDevice> fake_send_audio_device_; 147 std::unique_ptr<test::FakeAudioDevice> fake_recv_audio_device_; 148 }; 149 150 class BaseTest : public RtpRtcpObserver { 151 public: 152 explicit BaseTest(unsigned int timeout_ms); 153 virtual ~BaseTest(); 154 155 virtual void PerformTest() = 0; 156 virtual bool ShouldCreateReceivers() const = 0; 157 158 virtual size_t GetNumVideoStreams() const; 159 virtual size_t GetNumAudioStreams() const; 160 virtual size_t GetNumFlexfecStreams() const; 161 162 virtual Call::Config GetSenderCallConfig(); 163 virtual Call::Config GetReceiverCallConfig(); 164 virtual void OnCallsCreated(Call* sender_call, Call* receiver_call); 165 166 virtual test::PacketTransport* CreateSendTransport(Call* sender_call); 167 virtual test::PacketTransport* CreateReceiveTransport(); 168 169 virtual void ModifyVideoConfigs( 170 VideoSendStream::Config* send_config, 171 std::vector<VideoReceiveStream::Config>* receive_configs, 172 VideoEncoderConfig* encoder_config); 173 virtual void ModifyVideoCaptureStartResolution(int* width, 174 int* heigt, 175 int* frame_rate); 176 virtual void OnVideoStreamsCreated( 177 VideoSendStream* send_stream, 178 const std::vector<VideoReceiveStream*>& receive_streams); 179 180 virtual void ModifyAudioConfigs( 181 AudioSendStream::Config* send_config, 182 std::vector<AudioReceiveStream::Config>* receive_configs); 183 virtual void OnAudioStreamsCreated( 184 AudioSendStream* send_stream, 185 const std::vector<AudioReceiveStream*>& receive_streams); 186 187 virtual void ModifyFlexfecConfigs( 188 std::vector<FlexfecReceiveStream::Config>* receive_configs); 189 virtual void OnFlexfecStreamsCreated( 190 const std::vector<FlexfecReceiveStream*>& receive_streams); 191 192 virtual void OnFrameGeneratorCapturerCreated( 193 FrameGeneratorCapturer* frame_generator_capturer); 194 195 webrtc::RtcEventLogNullImpl event_log_; 196 }; 197 198 class SendTest : public BaseTest { 199 public: 200 explicit SendTest(unsigned int timeout_ms); 201 202 bool ShouldCreateReceivers() const override; 203 }; 204 205 class EndToEndTest : public BaseTest { 206 public: 207 explicit EndToEndTest(unsigned int timeout_ms); 208 209 bool ShouldCreateReceivers() const override; 210 }; 211 212 } // namespace test 213 } // namespace webrtc 214 215 #endif // WEBRTC_TEST_CALL_TEST_H_ 216