blob: 7d478a8391f9c7c8784c07eb6675c6b156c91f95 [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
Peter Boström64c03662015-04-08 11:24:19 +020025class EventTimerWrapper;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000026
27namespace test {
28
29class FrameGenerator;
30
31class FrameGeneratorCapturer : public VideoCapturer {
32 public:
perkj803d97f2016-11-01 11:45:46 -070033 class SinkWantsObserver {
34 public:
35 // OnSinkWantsChanged is called when FrameGeneratorCapturer::AddOrUpdateSink
36 // is called.
37 virtual void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink,
38 const rtc::VideoSinkWants& wants) = 0;
39
40 protected:
41 virtual ~SinkWantsObserver() {}
42 };
43
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080044 static FrameGeneratorCapturer* Create(
45 int width,
46 int height,
47 rtc::Optional<FrameGenerator::OutputType> type,
48 rtc::Optional<int> num_squares,
49 int target_fps,
50 Clock* clock);
Taylor Brandstetter081136f2018-03-08 01:54:10 +000051
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080052 // TODO(emircan): Update all clients and delete this function in favor of the
53 // above Create() signature.
Taylor Brandstetter081136f2018-03-08 01:54:10 +000054 static FrameGeneratorCapturer* Create(int width,
55 int height,
56 int num_squares,
57 int target_fps,
58 Clock* clock);
erikvarga@webrtc.orgc774d5d2017-10-10 14:34:38 +020059
perkja49cbd32016-09-16 07:53:41 -070060 static FrameGeneratorCapturer* CreateFromYuvFile(const std::string& file_name,
andresp@webrtc.orgab654952013-09-19 12:14:03 +000061 size_t width,
62 size_t height,
63 int target_fps,
64 Clock* clock);
erikvarga579de6f2017-08-29 09:12:57 -070065
66 static FrameGeneratorCapturer* CreateSlideGenerator(int width,
67 int height,
68 int frame_repeat_count,
69 int target_fps,
70 Clock* clock);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000071 virtual ~FrameGeneratorCapturer();
72
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000073 void Start() override;
74 void Stop() override;
perkjfa10b552016-10-02 23:45:26 -070075 void ChangeResolution(size_t width, size_t height);
perkja49cbd32016-09-16 07:53:41 -070076
perkj803d97f2016-11-01 11:45:46 -070077 void SetSinkWantsObserver(SinkWantsObserver* observer);
78
perkja49cbd32016-09-16 07:53:41 -070079 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
80 const rtc::VideoSinkWants& wants) override;
81 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
82
sprang867fb522015-08-03 04:38:41 -070083 void ForceFrame();
Perba7dc722016-04-19 15:01:23 +020084 void SetFakeRotation(VideoRotation rotation);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000085
wu@webrtc.orgcd701192014-04-24 22:10:24 +000086 int64_t first_frame_capture_time() const { return first_frame_capture_time_; }
87
andresp@webrtc.orgab654952013-09-19 12:14:03 +000088 FrameGeneratorCapturer(Clock* clock,
perkja8ba1952017-02-27 06:52:10 -080089 std::unique_ptr<FrameGenerator> frame_generator,
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000090 int target_fps);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000091 bool Init();
sprang@webrtc.org131bea82015-02-18 12:46:06 +000092
93 private:
ilnikbaded152017-03-17 05:55:25 -070094 class InsertFrameTask;
95
pbos@webrtc.org26d12102013-05-29 13:41:03 +000096 void InsertFrame();
97 static bool Run(void* obj);
sprangc5d62e22017-04-02 23:53:04 -070098 int GetCurrentConfiguredFramerate();
pbos@webrtc.org26d12102013-05-29 13:41:03 +000099
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000100 Clock* const clock_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000101 bool sending_;
danilchapa37de392017-09-09 04:17:22 -0700102 rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(&lock_);
103 SinkWantsObserver* sink_wants_observer_ RTC_GUARDED_BY(&lock_);
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000104
Peter Boströmf2f82832015-05-01 13:00:41 +0200105 rtc::CriticalSection lock_;
kwibergbfefb032016-05-01 14:53:46 -0700106 std::unique_ptr<FrameGenerator> frame_generator_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000107
danilchapa37de392017-09-09 04:17:22 -0700108 int target_fps_ RTC_GUARDED_BY(&lock_);
109 rtc::Optional<int> wanted_fps_ RTC_GUARDED_BY(&lock_);
Perba7dc722016-04-19 15:01:23 +0200110 VideoRotation fake_rotation_ = kVideoRotation_0;
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000111
112 int64_t first_frame_capture_time_;
ilnikbaded152017-03-17 05:55:25 -0700113 // Must be the last field, so it will be deconstructed first as tasks
114 // in the TaskQueue access other fields of the instance of this class.
115 rtc::TaskQueue task_queue_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000116};
ilnikbaded152017-03-17 05:55:25 -0700117} // namespace test
118} // namespace webrtc
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000119
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200120#endif // TEST_FRAME_GENERATOR_CAPTURER_H_