blob: 1aecf497b2ddce910d2645c6828883efd1591c5f [file] [log] [blame]
pbos@webrtc.org26d12102013-05-29 13:41:03 +00001/*
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 */
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020010#ifndef TEST_FRAME_GENERATOR_CAPTURER_H_
11#define TEST_FRAME_GENERATOR_CAPTURER_H_
pbos@webrtc.org26d12102013-05-29 13:41:03 +000012
kwibergbfefb032016-05-01 14:53:46 -070013#include <memory>
sprang@webrtc.org131bea82015-02-18 12:46:06 +000014#include <string>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/video/video_frame.h"
17#include "rtc_base/criticalsection.h"
18#include "rtc_base/task_queue.h"
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080019#include "test/frame_generator.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "test/video_capturer.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020021#include "typedefs.h" // NOLINT(build/include)
pbos@webrtc.org26d12102013-05-29 13:41:03 +000022
23namespace webrtc {
24
pbos@webrtc.org26d12102013-05-29 13:41:03 +000025namespace test {
26
27class FrameGenerator;
28
29class FrameGeneratorCapturer : public VideoCapturer {
30 public:
perkj803d97f2016-11-01 11:45:46 -070031 class SinkWantsObserver {
32 public:
33 // OnSinkWantsChanged is called when FrameGeneratorCapturer::AddOrUpdateSink
34 // is called.
35 virtual void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink,
36 const rtc::VideoSinkWants& wants) = 0;
37
38 protected:
39 virtual ~SinkWantsObserver() {}
40 };
41
Emircan Uysaler207a75d2018-03-12 14:12:14 -070042 // |type| has the default value OutputType::I420. |num_squares| has the
43 // default value 10.
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080044 static FrameGeneratorCapturer* Create(
45 int width,
46 int height,
Danil Chapovalov431abd92018-06-18 12:54:17 +020047 absl::optional<FrameGenerator::OutputType> type,
48 absl::optional<int> num_squares,
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080049 int target_fps,
50 Clock* clock);
Taylor Brandstetter081136f2018-03-08 01:54:10 +000051
perkja49cbd32016-09-16 07:53:41 -070052 static FrameGeneratorCapturer* CreateFromYuvFile(const std::string& file_name,
andresp@webrtc.orgab654952013-09-19 12:14:03 +000053 size_t width,
54 size_t height,
55 int target_fps,
56 Clock* clock);
erikvarga579de6f2017-08-29 09:12:57 -070057
58 static FrameGeneratorCapturer* CreateSlideGenerator(int width,
59 int height,
60 int frame_repeat_count,
61 int target_fps,
62 Clock* clock);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000063 virtual ~FrameGeneratorCapturer();
64
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000065 void Start() override;
66 void Stop() override;
perkjfa10b552016-10-02 23:45:26 -070067 void ChangeResolution(size_t width, size_t height);
perkja49cbd32016-09-16 07:53:41 -070068
perkj803d97f2016-11-01 11:45:46 -070069 void SetSinkWantsObserver(SinkWantsObserver* observer);
70
perkja49cbd32016-09-16 07:53:41 -070071 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
72 const rtc::VideoSinkWants& wants) override;
73 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
74
sprang867fb522015-08-03 04:38:41 -070075 void ForceFrame();
Perba7dc722016-04-19 15:01:23 +020076 void SetFakeRotation(VideoRotation rotation);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000077
wu@webrtc.orgcd701192014-04-24 22:10:24 +000078 int64_t first_frame_capture_time() const { return first_frame_capture_time_; }
79
andresp@webrtc.orgab654952013-09-19 12:14:03 +000080 FrameGeneratorCapturer(Clock* clock,
perkja8ba1952017-02-27 06:52:10 -080081 std::unique_ptr<FrameGenerator> frame_generator,
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000082 int target_fps);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000083 bool Init();
sprang@webrtc.org131bea82015-02-18 12:46:06 +000084
85 private:
ilnikbaded152017-03-17 05:55:25 -070086 class InsertFrameTask;
87
pbos@webrtc.org26d12102013-05-29 13:41:03 +000088 void InsertFrame();
89 static bool Run(void* obj);
sprangc5d62e22017-04-02 23:53:04 -070090 int GetCurrentConfiguredFramerate();
pbos@webrtc.org26d12102013-05-29 13:41:03 +000091
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000092 Clock* const clock_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000093 bool sending_;
danilchapa37de392017-09-09 04:17:22 -070094 rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(&lock_);
95 SinkWantsObserver* sink_wants_observer_ RTC_GUARDED_BY(&lock_);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000096
Peter Boströmf2f82832015-05-01 13:00:41 +020097 rtc::CriticalSection lock_;
kwibergbfefb032016-05-01 14:53:46 -070098 std::unique_ptr<FrameGenerator> frame_generator_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000099
danilchapa37de392017-09-09 04:17:22 -0700100 int target_fps_ RTC_GUARDED_BY(&lock_);
Danil Chapovalov431abd92018-06-18 12:54:17 +0200101 absl::optional<int> wanted_fps_ RTC_GUARDED_BY(&lock_);
Perba7dc722016-04-19 15:01:23 +0200102 VideoRotation fake_rotation_ = kVideoRotation_0;
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000103
104 int64_t first_frame_capture_time_;
ilnikbaded152017-03-17 05:55:25 -0700105 // Must be the last field, so it will be deconstructed first as tasks
106 // in the TaskQueue access other fields of the instance of this class.
107 rtc::TaskQueue task_queue_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000108};
ilnikbaded152017-03-17 05:55:25 -0700109} // namespace test
110} // namespace webrtc
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000111
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200112#endif // TEST_FRAME_GENERATOR_CAPTURER_H_