pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 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 | */ |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 10 | #ifndef WEBRTC_TEST_CALL_TEST_H_ |
| 11 | #define WEBRTC_TEST_CALL_TEST_H_ |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 12 | |
kwiberg | 4a206a9 | 2016-03-31 10:24:26 -0700 | [diff] [blame] | 13 | #include <memory> |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 16 | #include "webrtc/call/call.h" |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 17 | #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 18 | #include "webrtc/test/encoder_settings.h" |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 19 | #include "webrtc/test/fake_audio_device.h" |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 20 | #include "webrtc/test/fake_decoder.h" |
| 21 | #include "webrtc/test/fake_encoder.h" |
sakal | 55d932b | 2016-09-30 06:19:08 -0700 | [diff] [blame] | 22 | #include "webrtc/test/fake_videorenderer.h" |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 23 | #include "webrtc/test/frame_generator_capturer.h" |
| 24 | #include "webrtc/test/rtp_rtcp_observer.h" |
| 25 | |
| 26 | namespace webrtc { |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 27 | |
| 28 | class VoEBase; |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 29 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 30 | namespace test { |
| 31 | |
| 32 | class BaseTest; |
| 33 | |
| 34 | class CallTest : public ::testing::Test { |
| 35 | public: |
| 36 | CallTest(); |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 37 | virtual ~CallTest(); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 38 | |
| 39 | static const size_t kNumSsrcs = 3; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 40 | static const int kDefaultWidth = 320; |
| 41 | static const int kDefaultHeight = 180; |
| 42 | static const int kDefaultFramerate = 30; |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 43 | static const int kDefaultTimeoutMs; |
| 44 | static const int kLongTimeoutMs; |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 45 | static const uint8_t kVideoSendPayloadType; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 46 | static const uint8_t kSendRtxPayloadType; |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 47 | static const uint8_t kFakeVideoSendPayloadType; |
stefan@webrtc.org | 01581da | 2014-09-04 06:48:14 +0000 | [diff] [blame] | 48 | static const uint8_t kRedPayloadType; |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 49 | static const uint8_t kRtxRedPayloadType; |
stefan@webrtc.org | 01581da | 2014-09-04 06:48:14 +0000 | [diff] [blame] | 50 | static const uint8_t kUlpfecPayloadType; |
brandtr | 841de6a | 2016-11-15 07:10:52 -0800 | [diff] [blame] | 51 | static const uint8_t kFlexfecPayloadType; |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 52 | static const uint8_t kAudioSendPayloadType; |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 53 | static const uint32_t kSendRtxSsrcs[kNumSsrcs]; |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 54 | static const uint32_t kVideoSendSsrcs[kNumSsrcs]; |
| 55 | static const uint32_t kAudioSendSsrc; |
brandtr | 841de6a | 2016-11-15 07:10:52 -0800 | [diff] [blame] | 56 | static const uint32_t kFlexfecSendSsrc; |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 57 | static const uint32_t kReceiverLocalVideoSsrc; |
| 58 | static const uint32_t kReceiverLocalAudioSsrc; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 59 | static const int kNackRtpHistoryMs; |
| 60 | |
| 61 | protected: |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 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. |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 65 | void RunBaseTest(BaseTest* test); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 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); |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 71 | void DestroyCalls(); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 72 | |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 73 | void CreateSendConfig(size_t num_video_streams, |
| 74 | size_t num_audio_streams, |
brandtr | 841de6a | 2016-11-15 07:10:52 -0800 | [diff] [blame] | 75 | size_t num_flexfec_streams, |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 76 | Transport* send_transport); |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 77 | void CreateMatchingReceiveConfigs(Transport* rtcp_send_transport); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 78 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 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); |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 85 | void CreateFakeAudioDevices(); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 86 | |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 87 | void CreateVideoStreams(); |
| 88 | void CreateAudioStreams(); |
brandtr | 841de6a | 2016-11-15 07:10:52 -0800 | [diff] [blame] | 89 | void CreateFlexfecStreams(); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 90 | void Start(); |
| 91 | void Stop(); |
| 92 | void DestroyStreams(); |
Per | ba7dc72 | 2016-04-19 15:01:23 +0200 | [diff] [blame] | 93 | void SetFakeVideoCaptureRotation(VideoRotation rotation); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 94 | |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 95 | Clock* const clock_; |
| 96 | |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 97 | webrtc::RtcEventLogNullImpl event_log_; |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 98 | std::unique_ptr<Call> sender_call_; |
| 99 | std::unique_ptr<PacketTransport> send_transport_; |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 100 | VideoSendStream::Config video_send_config_; |
| 101 | VideoEncoderConfig video_encoder_config_; |
| 102 | VideoSendStream* video_send_stream_; |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 103 | AudioSendStream::Config audio_send_config_; |
| 104 | AudioSendStream* audio_send_stream_; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 105 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 106 | std::unique_ptr<Call> receiver_call_; |
| 107 | std::unique_ptr<PacketTransport> receive_transport_; |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 108 | std::vector<VideoReceiveStream::Config> video_receive_configs_; |
| 109 | std::vector<VideoReceiveStream*> video_receive_streams_; |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 110 | std::vector<AudioReceiveStream::Config> audio_receive_configs_; |
| 111 | std::vector<AudioReceiveStream*> audio_receive_streams_; |
brandtr | 841de6a | 2016-11-15 07:10:52 -0800 | [diff] [blame] | 112 | std::vector<FlexfecReceiveStream::Config> flexfec_receive_configs_; |
| 113 | std::vector<FlexfecReceiveStream*> flexfec_receive_streams_; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 114 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 115 | std::unique_ptr<test::FrameGeneratorCapturer> frame_generator_capturer_; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 116 | test::FakeEncoder fake_encoder_; |
kwiberg | 4a206a9 | 2016-03-31 10:24:26 -0700 | [diff] [blame] | 117 | std::vector<std::unique_ptr<VideoDecoder>> allocated_decoders_; |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 118 | size_t num_video_streams_; |
| 119 | size_t num_audio_streams_; |
brandtr | 841de6a | 2016-11-15 07:10:52 -0800 | [diff] [blame] | 120 | size_t num_flexfec_streams_; |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 121 | rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; |
sakal | 55d932b | 2016-09-30 06:19:08 -0700 | [diff] [blame] | 122 | test::FakeVideoRenderer fake_renderer_; |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 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 { |
| 129 | VoiceEngineState() |
| 130 | : voice_engine(nullptr), |
| 131 | base(nullptr), |
mflodman | 3d7db26 | 2016-04-29 00:57:13 -0700 | [diff] [blame] | 132 | channel_id(-1) {} |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 133 | |
| 134 | VoiceEngine* voice_engine; |
| 135 | VoEBase* base; |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 136 | int channel_id; |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | void CreateVoiceEngines(); |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 140 | void DestroyVoiceEngines(); |
| 141 | |
| 142 | VoiceEngineState voe_send_; |
| 143 | VoiceEngineState voe_recv_; |
| 144 | |
| 145 | // The audio devices must outlive the voice engines. |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 146 | std::unique_ptr<test::FakeAudioDevice> fake_send_audio_device_; |
| 147 | std::unique_ptr<test::FakeAudioDevice> fake_recv_audio_device_; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | class BaseTest : public RtpRtcpObserver { |
| 151 | public: |
| 152 | explicit BaseTest(unsigned int timeout_ms); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 153 | virtual ~BaseTest(); |
| 154 | |
| 155 | virtual void PerformTest() = 0; |
| 156 | virtual bool ShouldCreateReceivers() const = 0; |
| 157 | |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 158 | virtual size_t GetNumVideoStreams() const; |
| 159 | virtual size_t GetNumAudioStreams() const; |
brandtr | 841de6a | 2016-11-15 07:10:52 -0800 | [diff] [blame] | 160 | virtual size_t GetNumFlexfecStreams() const; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 161 | |
| 162 | virtual Call::Config GetSenderCallConfig(); |
| 163 | virtual Call::Config GetReceiverCallConfig(); |
| 164 | virtual void OnCallsCreated(Call* sender_call, Call* receiver_call); |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 165 | |
| 166 | virtual test::PacketTransport* CreateSendTransport(Call* sender_call); |
| 167 | virtual test::PacketTransport* CreateReceiveTransport(); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 168 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 169 | virtual void ModifyVideoConfigs( |
pbos@webrtc.org | be9d2a4 | 2014-06-30 13:19:09 +0000 | [diff] [blame] | 170 | VideoSendStream::Config* send_config, |
| 171 | std::vector<VideoReceiveStream::Config>* receive_configs, |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 172 | VideoEncoderConfig* encoder_config); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 173 | virtual void ModifyVideoCaptureStartResolution(int* width, |
| 174 | int* heigt, |
| 175 | int* frame_rate); |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 176 | virtual void OnVideoStreamsCreated( |
pbos@webrtc.org | be9d2a4 | 2014-06-30 13:19:09 +0000 | [diff] [blame] | 177 | VideoSendStream* send_stream, |
| 178 | const std::vector<VideoReceiveStream*>& receive_streams); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 179 | |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 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 | |
brandtr | 841de6a | 2016-11-15 07:10:52 -0800 | [diff] [blame] | 187 | virtual void ModifyFlexfecConfigs( |
| 188 | std::vector<FlexfecReceiveStream::Config>* receive_configs); |
| 189 | virtual void OnFlexfecStreamsCreated( |
| 190 | const std::vector<FlexfecReceiveStream*>& receive_streams); |
| 191 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 192 | virtual void OnFrameGeneratorCapturerCreated( |
| 193 | FrameGeneratorCapturer* frame_generator_capturer); |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 194 | |
| 195 | webrtc::RtcEventLogNullImpl event_log_; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 196 | }; |
| 197 | |
| 198 | class SendTest : public BaseTest { |
| 199 | public: |
| 200 | explicit SendTest(unsigned int timeout_ms); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 201 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 202 | bool ShouldCreateReceivers() const override; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | class EndToEndTest : public BaseTest { |
| 206 | public: |
| 207 | explicit EndToEndTest(unsigned int timeout_ms); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 208 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 209 | bool ShouldCreateReceivers() const override; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 210 | }; |
| 211 | |
| 212 | } // namespace test |
| 213 | } // namespace webrtc |
| 214 | |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 215 | #endif // WEBRTC_TEST_CALL_TEST_H_ |