video_stream.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright 2018 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_SCENARIO_VIDEO_STREAM_H_
  11. #define TEST_SCENARIO_VIDEO_STREAM_H_
  12. #include <memory>
  13. #include <string>
  14. #include <vector>
  15. #include "rtc_base/constructor_magic.h"
  16. #include "test/fake_encoder.h"
  17. #include "test/fake_videorenderer.h"
  18. #include "test/frame_generator_capturer.h"
  19. #include "test/logging/log_writer.h"
  20. #include "test/scenario/call_client.h"
  21. #include "test/scenario/column_printer.h"
  22. #include "test/scenario/network_node.h"
  23. #include "test/scenario/scenario_config.h"
  24. #include "test/scenario/video_frame_matcher.h"
  25. #include "test/test_video_capturer.h"
  26. namespace webrtc {
  27. namespace test {
  28. // SendVideoStream provides an interface for changing parameters and retrieving
  29. // states at run time.
  30. class SendVideoStream {
  31. public:
  32. RTC_DISALLOW_COPY_AND_ASSIGN(SendVideoStream);
  33. ~SendVideoStream();
  34. void SetCaptureFramerate(int framerate);
  35. VideoSendStream::Stats GetStats() const;
  36. ColumnPrinter StatsPrinter();
  37. void Start();
  38. void Stop();
  39. void UpdateConfig(std::function<void(VideoStreamConfig*)> modifier);
  40. void UpdateActiveLayers(std::vector<bool> active_layers);
  41. bool UsingSsrc(uint32_t ssrc) const;
  42. bool UsingRtxSsrc(uint32_t ssrc) const;
  43. private:
  44. friend class Scenario;
  45. friend class VideoStreamPair;
  46. friend class ReceiveVideoStream;
  47. // Handles RTCP feedback for this stream.
  48. SendVideoStream(CallClient* sender,
  49. VideoStreamConfig config,
  50. Transport* send_transport,
  51. VideoFrameMatcher* matcher);
  52. rtc::CriticalSection crit_;
  53. std::vector<uint32_t> ssrcs_;
  54. std::vector<uint32_t> rtx_ssrcs_;
  55. VideoSendStream* send_stream_ = nullptr;
  56. CallClient* const sender_;
  57. VideoStreamConfig config_ RTC_GUARDED_BY(crit_);
  58. std::unique_ptr<VideoEncoderFactory> encoder_factory_;
  59. std::vector<test::FakeEncoder*> fake_encoders_ RTC_GUARDED_BY(crit_);
  60. std::unique_ptr<VideoBitrateAllocatorFactory> bitrate_allocator_factory_;
  61. std::unique_ptr<FrameGeneratorCapturer> video_capturer_;
  62. std::unique_ptr<ForwardingCapturedFrameTap> frame_tap_;
  63. int next_local_network_id_ = 0;
  64. int next_remote_network_id_ = 0;
  65. };
  66. // ReceiveVideoStream represents a video receiver. It can't be used directly.
  67. class ReceiveVideoStream {
  68. public:
  69. RTC_DISALLOW_COPY_AND_ASSIGN(ReceiveVideoStream);
  70. ~ReceiveVideoStream();
  71. void Start();
  72. void Stop();
  73. VideoReceiveStream::Stats GetStats() const;
  74. private:
  75. friend class Scenario;
  76. friend class VideoStreamPair;
  77. ReceiveVideoStream(CallClient* receiver,
  78. VideoStreamConfig config,
  79. SendVideoStream* send_stream,
  80. size_t chosen_stream,
  81. Transport* feedback_transport,
  82. VideoFrameMatcher* matcher);
  83. std::vector<VideoReceiveStream*> receive_streams_;
  84. FlexfecReceiveStream* flecfec_stream_ = nullptr;
  85. FakeVideoRenderer fake_renderer_;
  86. std::vector<std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>>>
  87. render_taps_;
  88. CallClient* const receiver_;
  89. const VideoStreamConfig config_;
  90. std::unique_ptr<VideoDecoderFactory> decoder_factory_;
  91. };
  92. // VideoStreamPair represents a video streaming session. It can be used to
  93. // access underlying send and receive classes. It can also be used in calls to
  94. // the Scenario class.
  95. class VideoStreamPair {
  96. public:
  97. RTC_DISALLOW_COPY_AND_ASSIGN(VideoStreamPair);
  98. ~VideoStreamPair();
  99. SendVideoStream* send() { return &send_stream_; }
  100. ReceiveVideoStream* receive() { return &receive_stream_; }
  101. VideoFrameMatcher* matcher() { return &matcher_; }
  102. private:
  103. friend class Scenario;
  104. VideoStreamPair(CallClient* sender,
  105. CallClient* receiver,
  106. VideoStreamConfig config);
  107. const VideoStreamConfig config_;
  108. VideoFrameMatcher matcher_;
  109. SendVideoStream send_stream_;
  110. ReceiveVideoStream receive_stream_;
  111. };
  112. } // namespace test
  113. } // namespace webrtc
  114. #endif // TEST_SCENARIO_VIDEO_STREAM_H_