2013-09-19 12:14:03 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef TEST_FRAME_GENERATOR_H_
|
|
|
|
|
#define TEST_FRAME_GENERATOR_H_
|
2013-09-19 12:14:03 +00:00
|
|
|
|
2017-02-27 06:52:10 -08:00
|
|
|
#include <memory>
|
2015-02-18 12:46:06 +00:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/video/video_frame.h"
|
2018-05-21 14:09:31 +02:00
|
|
|
#include "api/video/video_source_interface.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/critical_section.h"
|
2013-09-19 12:14:03 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2015-07-29 07:58:13 -07:00
|
|
|
class Clock;
|
2013-09-19 12:14:03 +00:00
|
|
|
namespace test {
|
|
|
|
|
|
2016-09-16 07:53:41 -07:00
|
|
|
// FrameForwarder can be used as an implementation
|
|
|
|
|
// of rtc::VideoSourceInterface<VideoFrame> where the caller controls when
|
|
|
|
|
// a frame should be forwarded to its sink.
|
|
|
|
|
// Currently this implementation only support one sink.
|
|
|
|
|
class FrameForwarder : public rtc::VideoSourceInterface<VideoFrame> {
|
|
|
|
|
public:
|
|
|
|
|
FrameForwarder();
|
2019-01-24 16:54:03 +01:00
|
|
|
~FrameForwarder() override;
|
2016-09-16 07:53:41 -07:00
|
|
|
// Forwards |video_frame| to the registered |sink_|.
|
2017-02-01 08:38:12 -08:00
|
|
|
virtual void IncomingCapturedFrame(const VideoFrame& video_frame);
|
2016-11-01 11:45:46 -07:00
|
|
|
rtc::VideoSinkWants sink_wants() const;
|
|
|
|
|
bool has_sinks() const;
|
2016-09-16 07:53:41 -07:00
|
|
|
|
2017-02-01 08:38:12 -08:00
|
|
|
protected:
|
2016-09-16 07:53:41 -07:00
|
|
|
void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
|
|
|
|
|
const rtc::VideoSinkWants& wants) override;
|
|
|
|
|
void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
|
|
|
|
|
|
|
|
|
|
rtc::CriticalSection crit_;
|
2017-09-09 04:17:22 -07:00
|
|
|
rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(crit_);
|
|
|
|
|
rtc::VideoSinkWants sink_wants_ RTC_GUARDED_BY(crit_);
|
2016-09-16 07:53:41 -07:00
|
|
|
};
|
|
|
|
|
|
2013-09-19 12:14:03 +00:00
|
|
|
class FrameGenerator {
|
|
|
|
|
public:
|
2017-02-27 06:52:10 -08:00
|
|
|
virtual ~FrameGenerator() = default;
|
2013-09-19 12:14:03 +00:00
|
|
|
|
|
|
|
|
// Returns video frame that remains valid until next call.
|
2018-12-12 11:17:43 +01:00
|
|
|
// TODO(kron): Return rtc::scoped_refptr<VideoFrameBuffer> instead of
|
|
|
|
|
// VideoFrame* and populate the VideoFrame struct in FrameGeneratorCapturer
|
|
|
|
|
// using VideoFrame::Builder.
|
2015-05-29 17:21:40 -07:00
|
|
|
virtual VideoFrame* NextFrame() = 0;
|
2013-09-19 12:14:03 +00:00
|
|
|
|
2016-10-02 23:45:26 -07:00
|
|
|
// Change the capture resolution.
|
2019-01-24 16:54:03 +01:00
|
|
|
virtual void ChangeResolution(size_t width, size_t height);
|
2016-10-02 23:45:26 -07:00
|
|
|
|
2019-07-26 15:58:11 +02:00
|
|
|
enum class OutputType {
|
|
|
|
|
kI420,
|
|
|
|
|
kI420A,
|
|
|
|
|
kI010
|
|
|
|
|
};
|
2018-03-12 14:12:14 -07:00
|
|
|
|
2017-02-27 06:52:10 -08:00
|
|
|
// Creates a frame generator that produces frames with small squares that
|
|
|
|
|
// move randomly towards the lower right corner.
|
2018-03-12 14:12:14 -07:00
|
|
|
// |type| has the default value OutputType::I420. |num_squares| has the
|
|
|
|
|
// default value 10.
|
2018-03-09 15:03:26 -08:00
|
|
|
static std::unique_ptr<FrameGenerator> CreateSquareGenerator(
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
2018-06-18 12:54:17 +02:00
|
|
|
absl::optional<OutputType> type,
|
|
|
|
|
absl::optional<int> num_squares);
|
2015-02-18 12:46:06 +00:00
|
|
|
|
|
|
|
|
// Creates a frame generator that repeatedly plays a set of yuv files.
|
|
|
|
|
// The frame_repeat_count determines how many times each frame is shown,
|
2015-03-02 11:55:45 +00:00
|
|
|
// with 1 = show each frame once, etc.
|
2017-02-27 06:52:10 -08:00
|
|
|
static std::unique_ptr<FrameGenerator> CreateFromYuvFile(
|
|
|
|
|
std::vector<std::string> files,
|
|
|
|
|
size_t width,
|
|
|
|
|
size_t height,
|
|
|
|
|
int frame_repeat_count);
|
2015-07-29 07:58:13 -07:00
|
|
|
|
|
|
|
|
// Creates a frame generator which takes a set of yuv files (wrapping a
|
|
|
|
|
// frame generator created by CreateFromYuvFile() above), but outputs frames
|
|
|
|
|
// that have been cropped to specified resolution: source_width/source_height
|
|
|
|
|
// is the size of the source images, target_width/target_height is the size of
|
|
|
|
|
// the cropped output. For each source image read, the cropped viewport will
|
|
|
|
|
// be scrolled top to bottom/left to right for scroll_tim_ms milliseconds.
|
|
|
|
|
// After that the image will stay in place for pause_time_ms milliseconds,
|
|
|
|
|
// and then this will be repeated with the next file from the input set.
|
2017-02-27 06:52:10 -08:00
|
|
|
static std::unique_ptr<FrameGenerator> CreateScrollingInputFromYuvFiles(
|
2015-07-29 07:58:13 -07:00
|
|
|
Clock* clock,
|
|
|
|
|
std::vector<std::string> filenames,
|
|
|
|
|
size_t source_width,
|
|
|
|
|
size_t source_height,
|
|
|
|
|
size_t target_width,
|
|
|
|
|
size_t target_height,
|
|
|
|
|
int64_t scroll_time_ms,
|
|
|
|
|
int64_t pause_time_ms);
|
2017-08-29 09:12:57 -07:00
|
|
|
|
|
|
|
|
// Creates a frame generator that produces randomly generated slides.
|
|
|
|
|
// frame_repeat_count determines how many times each slide is shown.
|
|
|
|
|
static std::unique_ptr<FrameGenerator>
|
|
|
|
|
CreateSlideGenerator(int width, int height, int frame_repeat_count);
|
2013-09-19 12:14:03 +00:00
|
|
|
};
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // TEST_FRAME_GENERATOR_H_
|