video_stream.h 4.3 KB

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