You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

321 lines
12 KiB

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