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.

112 lines
4.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2013 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_FRAME_GENERATOR_H_
  11. #define TEST_FRAME_GENERATOR_H_
  12. #include <memory>
  13. #include <string>
  14. #include <vector>
  15. #include "api/video/video_frame.h"
  16. #include "api/video/video_source_interface.h"
  17. #include "rtc_base/critical_section.h"
  18. namespace webrtc {
  19. class Clock;
  20. namespace test {
  21. // FrameForwarder can be used as an implementation
  22. // of rtc::VideoSourceInterface<VideoFrame> where the caller controls when
  23. // a frame should be forwarded to its sink.
  24. // Currently this implementation only support one sink.
  25. class FrameForwarder : public rtc::VideoSourceInterface<VideoFrame> {
  26. public:
  27. FrameForwarder();
  28. ~FrameForwarder() override;
  29. // Forwards |video_frame| to the registered |sink_|.
  30. virtual void IncomingCapturedFrame(const VideoFrame& video_frame);
  31. rtc::VideoSinkWants sink_wants() const;
  32. bool has_sinks() const;
  33. protected:
  34. void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
  35. const rtc::VideoSinkWants& wants) override;
  36. void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
  37. rtc::CriticalSection crit_;
  38. rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(crit_);
  39. rtc::VideoSinkWants sink_wants_ RTC_GUARDED_BY(crit_);
  40. };
  41. class FrameGenerator {
  42. public:
  43. virtual ~FrameGenerator() = default;
  44. // Returns video frame that remains valid until next call.
  45. // TODO(kron): Return rtc::scoped_refptr<VideoFrameBuffer> instead of
  46. // VideoFrame* and populate the VideoFrame struct in FrameGeneratorCapturer
  47. // using VideoFrame::Builder.
  48. virtual VideoFrame* NextFrame() = 0;
  49. // Change the capture resolution.
  50. virtual void ChangeResolution(size_t width, size_t height);
  51. enum class OutputType {
  52. kI420,
  53. kI420A,
  54. kI010
  55. };
  56. // Creates a frame generator that produces frames with small squares that
  57. // move randomly towards the lower right corner.
  58. // |type| has the default value OutputType::I420. |num_squares| has the
  59. // default value 10.
  60. static std::unique_ptr<FrameGenerator> CreateSquareGenerator(
  61. int width,
  62. int height,
  63. absl::optional<OutputType> type,
  64. absl::optional<int> num_squares);
  65. // Creates a frame generator that repeatedly plays a set of yuv files.
  66. // The frame_repeat_count determines how many times each frame is shown,
  67. // with 1 = show each frame once, etc.
  68. static std::unique_ptr<FrameGenerator> CreateFromYuvFile(
  69. std::vector<std::string> files,
  70. size_t width,
  71. size_t height,
  72. int frame_repeat_count);
  73. // Creates a frame generator which takes a set of yuv files (wrapping a
  74. // frame generator created by CreateFromYuvFile() above), but outputs frames
  75. // that have been cropped to specified resolution: source_width/source_height
  76. // is the size of the source images, target_width/target_height is the size of
  77. // the cropped output. For each source image read, the cropped viewport will
  78. // be scrolled top to bottom/left to right for scroll_tim_ms milliseconds.
  79. // After that the image will stay in place for pause_time_ms milliseconds,
  80. // and then this will be repeated with the next file from the input set.
  81. static std::unique_ptr<FrameGenerator> CreateScrollingInputFromYuvFiles(
  82. Clock* clock,
  83. std::vector<std::string> filenames,
  84. size_t source_width,
  85. size_t source_height,
  86. size_t target_width,
  87. size_t target_height,
  88. int64_t scroll_time_ms,
  89. int64_t pause_time_ms);
  90. // Creates a frame generator that produces randomly generated slides.
  91. // frame_repeat_count determines how many times each slide is shown.
  92. static std::unique_ptr<FrameGenerator>
  93. CreateSlideGenerator(int width, int height, int frame_repeat_count);
  94. };
  95. } // namespace test
  96. } // namespace webrtc
  97. #endif // TEST_FRAME_GENERATOR_H_