call_test.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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 TEST_CALL_TEST_H_
  11. #define TEST_CALL_TEST_H_
  12. #include <map>
  13. #include <memory>
  14. #include <string>
  15. #include <vector>
  16. #include "absl/types/optional.h"
  17. #include "api/rtc_event_log/rtc_event_log.h"
  18. #include "api/task_queue/task_queue_base.h"
  19. #include "api/task_queue/task_queue_factory.h"
  20. #include "api/test/video/function_video_decoder_factory.h"
  21. #include "api/test/video/function_video_encoder_factory.h"
  22. #include "api/transport/field_trial_based_config.h"
  23. #include "api/video/video_bitrate_allocator_factory.h"
  24. #include "call/call.h"
  25. #include "modules/audio_device/include/test_audio_device.h"
  26. #include "test/encoder_settings.h"
  27. #include "test/fake_decoder.h"
  28. #include "test/fake_videorenderer.h"
  29. #include "test/fake_vp8_encoder.h"
  30. #include "test/frame_generator_capturer.h"
  31. #include "test/rtp_rtcp_observer.h"
  32. #include "test/run_loop.h"
  33. namespace webrtc {
  34. namespace test {
  35. class BaseTest;
  36. class CallTest : public ::testing::Test {
  37. public:
  38. CallTest();
  39. virtual ~CallTest();
  40. static constexpr size_t kNumSsrcs = 6;
  41. static const int kNumSimulcastStreams = 3;
  42. static const int kDefaultWidth = 320;
  43. static const int kDefaultHeight = 180;
  44. static const int kDefaultFramerate = 30;
  45. static const int kDefaultTimeoutMs;
  46. static const int kLongTimeoutMs;
  47. enum classPayloadTypes : uint8_t {
  48. kSendRtxPayloadType = 98,
  49. kRtxRedPayloadType = 99,
  50. kVideoSendPayloadType = 100,
  51. kAudioSendPayloadType = 103,
  52. kRedPayloadType = 118,
  53. kUlpfecPayloadType = 119,
  54. kFlexfecPayloadType = 120,
  55. kPayloadTypeH264 = 122,
  56. kPayloadTypeVP8 = 123,
  57. kPayloadTypeVP9 = 124,
  58. kPayloadTypeGeneric = 125,
  59. kFakeVideoSendPayloadType = 126,
  60. };
  61. static const uint32_t kSendRtxSsrcs[kNumSsrcs];
  62. static const uint32_t kVideoSendSsrcs[kNumSsrcs];
  63. static const uint32_t kAudioSendSsrc;
  64. static const uint32_t kFlexfecSendSsrc;
  65. static const uint32_t kReceiverLocalVideoSsrc;
  66. static const uint32_t kReceiverLocalAudioSsrc;
  67. static const int kNackRtpHistoryMs;
  68. static const std::map<uint8_t, MediaType> payload_type_map_;
  69. protected:
  70. void RegisterRtpExtension(const RtpExtension& extension);
  71. // RunBaseTest overwrites the audio_state of the send and receive Call configs
  72. // to simplify test code.
  73. void RunBaseTest(BaseTest* test);
  74. void CreateCalls();
  75. void CreateCalls(const Call::Config& sender_config,
  76. const Call::Config& receiver_config);
  77. void CreateSenderCall();
  78. void CreateSenderCall(const Call::Config& config);
  79. void CreateReceiverCall(const Call::Config& config);
  80. void DestroyCalls();
  81. void CreateVideoSendConfig(VideoSendStream::Config* video_config,
  82. size_t num_video_streams,
  83. size_t num_used_ssrcs,
  84. Transport* send_transport);
  85. void CreateAudioAndFecSendConfigs(size_t num_audio_streams,
  86. size_t num_flexfec_streams,
  87. Transport* send_transport);
  88. void SetAudioConfig(const AudioSendStream::Config& config);
  89. void SetSendFecConfig(std::vector<uint32_t> video_send_ssrcs);
  90. void SetSendUlpFecConfig(VideoSendStream::Config* send_config);
  91. void SetReceiveUlpFecConfig(VideoReceiveStream::Config* receive_config);
  92. void CreateSendConfig(size_t num_video_streams,
  93. size_t num_audio_streams,
  94. size_t num_flexfec_streams,
  95. Transport* send_transport);
  96. void CreateMatchingVideoReceiveConfigs(
  97. const VideoSendStream::Config& video_send_config,
  98. Transport* rtcp_send_transport);
  99. void CreateMatchingVideoReceiveConfigs(
  100. const VideoSendStream::Config& video_send_config,
  101. Transport* rtcp_send_transport,
  102. bool send_side_bwe,
  103. VideoDecoderFactory* decoder_factory,
  104. absl::optional<size_t> decode_sub_stream,
  105. bool receiver_reference_time_report,
  106. int rtp_history_ms);
  107. void AddMatchingVideoReceiveConfigs(
  108. std::vector<VideoReceiveStream::Config>* receive_configs,
  109. const VideoSendStream::Config& video_send_config,
  110. Transport* rtcp_send_transport,
  111. bool send_side_bwe,
  112. VideoDecoderFactory* decoder_factory,
  113. absl::optional<size_t> decode_sub_stream,
  114. bool receiver_reference_time_report,
  115. int rtp_history_ms);
  116. void CreateMatchingAudioAndFecConfigs(Transport* rtcp_send_transport);
  117. void CreateMatchingAudioConfigs(Transport* transport, std::string sync_group);
  118. static AudioReceiveStream::Config CreateMatchingAudioConfig(
  119. const AudioSendStream::Config& send_config,
  120. rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
  121. Transport* transport,
  122. std::string sync_group);
  123. void CreateMatchingFecConfig(
  124. Transport* transport,
  125. const VideoSendStream::Config& video_send_config);
  126. void CreateMatchingReceiveConfigs(Transport* rtcp_send_transport);
  127. void CreateFrameGeneratorCapturerWithDrift(Clock* drift_clock,
  128. float speed,
  129. int framerate,
  130. int width,
  131. int height);
  132. void CreateFrameGeneratorCapturer(int framerate, int width, int height);
  133. void CreateFakeAudioDevices(
  134. std::unique_ptr<TestAudioDeviceModule::Capturer> capturer,
  135. std::unique_ptr<TestAudioDeviceModule::Renderer> renderer);
  136. void CreateVideoStreams();
  137. void CreateVideoSendStreams();
  138. void CreateVideoSendStream(const VideoEncoderConfig& encoder_config);
  139. void CreateAudioStreams();
  140. void CreateFlexfecStreams();
  141. void ConnectVideoSourcesToStreams();
  142. void AssociateFlexfecStreamsWithVideoStreams();
  143. void DissociateFlexfecStreamsFromVideoStreams();
  144. void Start();
  145. void StartVideoStreams();
  146. void Stop();
  147. void StopVideoStreams();
  148. void DestroyStreams();
  149. void DestroyVideoSendStreams();
  150. void SetFakeVideoCaptureRotation(VideoRotation rotation);
  151. void SetVideoDegradation(DegradationPreference preference);
  152. VideoSendStream::Config* GetVideoSendConfig();
  153. void SetVideoSendConfig(const VideoSendStream::Config& config);
  154. VideoEncoderConfig* GetVideoEncoderConfig();
  155. void SetVideoEncoderConfig(const VideoEncoderConfig& config);
  156. VideoSendStream* GetVideoSendStream();
  157. FlexfecReceiveStream::Config* GetFlexFecConfig();
  158. TaskQueueBase* task_queue() { return task_queue_.get(); }
  159. test::RunLoop loop_;
  160. Clock* const clock_;
  161. const FieldTrialBasedConfig field_trials_;
  162. std::unique_ptr<TaskQueueFactory> task_queue_factory_;
  163. std::unique_ptr<webrtc::RtcEventLog> send_event_log_;
  164. std::unique_ptr<webrtc::RtcEventLog> recv_event_log_;
  165. std::unique_ptr<Call> sender_call_;
  166. std::unique_ptr<PacketTransport> send_transport_;
  167. std::vector<VideoSendStream::Config> video_send_configs_;
  168. std::vector<VideoEncoderConfig> video_encoder_configs_;
  169. std::vector<VideoSendStream*> video_send_streams_;
  170. AudioSendStream::Config audio_send_config_;
  171. AudioSendStream* audio_send_stream_;
  172. std::unique_ptr<Call> receiver_call_;
  173. std::unique_ptr<PacketTransport> receive_transport_;
  174. std::vector<VideoReceiveStream::Config> video_receive_configs_;
  175. std::vector<VideoReceiveStream*> video_receive_streams_;
  176. std::vector<AudioReceiveStream::Config> audio_receive_configs_;
  177. std::vector<AudioReceiveStream*> audio_receive_streams_;
  178. std::vector<FlexfecReceiveStream::Config> flexfec_receive_configs_;
  179. std::vector<FlexfecReceiveStream*> flexfec_receive_streams_;
  180. test::FrameGeneratorCapturer* frame_generator_capturer_;
  181. std::vector<std::unique_ptr<rtc::VideoSourceInterface<VideoFrame>>>
  182. video_sources_;
  183. DegradationPreference degradation_preference_ =
  184. DegradationPreference::MAINTAIN_FRAMERATE;
  185. std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory_;
  186. std::unique_ptr<NetworkStatePredictorFactoryInterface>
  187. network_state_predictor_factory_;
  188. std::unique_ptr<NetworkControllerFactoryInterface>
  189. network_controller_factory_;
  190. test::FunctionVideoEncoderFactory fake_encoder_factory_;
  191. int fake_encoder_max_bitrate_ = -1;
  192. test::FunctionVideoDecoderFactory fake_decoder_factory_;
  193. std::unique_ptr<VideoBitrateAllocatorFactory> bitrate_allocator_factory_;
  194. // Number of simulcast substreams.
  195. size_t num_video_streams_;
  196. size_t num_audio_streams_;
  197. size_t num_flexfec_streams_;
  198. rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory_;
  199. rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory_;
  200. test::FakeVideoRenderer fake_renderer_;
  201. private:
  202. absl::optional<RtpExtension> GetRtpExtensionByUri(
  203. const std::string& uri) const;
  204. void AddRtpExtensionByUri(const std::string& uri,
  205. std::vector<RtpExtension>* extensions) const;
  206. std::unique_ptr<TaskQueueBase, TaskQueueDeleter> task_queue_;
  207. std::vector<RtpExtension> rtp_extensions_;
  208. rtc::scoped_refptr<AudioProcessing> apm_send_;
  209. rtc::scoped_refptr<AudioProcessing> apm_recv_;
  210. rtc::scoped_refptr<TestAudioDeviceModule> fake_send_audio_device_;
  211. rtc::scoped_refptr<TestAudioDeviceModule> fake_recv_audio_device_;
  212. };
  213. class BaseTest : public RtpRtcpObserver {
  214. public:
  215. BaseTest();
  216. explicit BaseTest(int timeout_ms);
  217. virtual ~BaseTest();
  218. virtual void PerformTest() = 0;
  219. virtual bool ShouldCreateReceivers() const = 0;
  220. virtual size_t GetNumVideoStreams() const;
  221. virtual size_t GetNumAudioStreams() const;
  222. virtual size_t GetNumFlexfecStreams() const;
  223. virtual std::unique_ptr<TestAudioDeviceModule::Capturer> CreateCapturer();
  224. virtual std::unique_ptr<TestAudioDeviceModule::Renderer> CreateRenderer();
  225. virtual void OnFakeAudioDevicesCreated(
  226. TestAudioDeviceModule* send_audio_device,
  227. TestAudioDeviceModule* recv_audio_device);
  228. virtual void ModifySenderBitrateConfig(BitrateConstraints* bitrate_config);
  229. virtual void ModifyReceiverBitrateConfig(BitrateConstraints* bitrate_config);
  230. virtual void OnCallsCreated(Call* sender_call, Call* receiver_call);
  231. virtual std::unique_ptr<test::PacketTransport> CreateSendTransport(
  232. TaskQueueBase* task_queue,
  233. Call* sender_call);
  234. virtual std::unique_ptr<test::PacketTransport> CreateReceiveTransport(
  235. TaskQueueBase* task_queue);
  236. virtual void ModifyVideoConfigs(
  237. VideoSendStream::Config* send_config,
  238. std::vector<VideoReceiveStream::Config>* receive_configs,
  239. VideoEncoderConfig* encoder_config);
  240. virtual void ModifyVideoCaptureStartResolution(int* width,
  241. int* heigt,
  242. int* frame_rate);
  243. virtual void ModifyVideoDegradationPreference(
  244. DegradationPreference* degradation_preference);
  245. virtual void OnVideoStreamsCreated(
  246. VideoSendStream* send_stream,
  247. const std::vector<VideoReceiveStream*>& receive_streams);
  248. virtual void ModifyAudioConfigs(
  249. AudioSendStream::Config* send_config,
  250. std::vector<AudioReceiveStream::Config>* receive_configs);
  251. virtual void OnAudioStreamsCreated(
  252. AudioSendStream* send_stream,
  253. const std::vector<AudioReceiveStream*>& receive_streams);
  254. virtual void ModifyFlexfecConfigs(
  255. std::vector<FlexfecReceiveStream::Config>* receive_configs);
  256. virtual void OnFlexfecStreamsCreated(
  257. const std::vector<FlexfecReceiveStream*>& receive_streams);
  258. virtual void OnFrameGeneratorCapturerCreated(
  259. FrameGeneratorCapturer* frame_generator_capturer);
  260. virtual void OnStreamsStopped();
  261. };
  262. class SendTest : public BaseTest {
  263. public:
  264. explicit SendTest(int timeout_ms);
  265. bool ShouldCreateReceivers() const override;
  266. };
  267. class EndToEndTest : public BaseTest {
  268. public:
  269. EndToEndTest();
  270. explicit EndToEndTest(int timeout_ms);
  271. bool ShouldCreateReceivers() const override;
  272. };
  273. } // namespace test
  274. } // namespace webrtc
  275. #endif // TEST_CALL_TEST_H_