blob: 6b2ed69bf00d6192b0581f871141d47be915f97b [file] [log] [blame]
pbos@webrtc.org26d12102013-05-29 13:41:031/*
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 04:47:3110#ifndef TEST_FRAME_GENERATOR_CAPTURER_H_
11#define TEST_FRAME_GENERATOR_CAPTURER_H_
pbos@webrtc.org26d12102013-05-29 13:41:0312
kwibergbfefb032016-05-01 21:53:4613#include <memory>
sprang@webrtc.org131bea82015-02-18 12:46:0614#include <string>
15
Mirko Bonadei92ea95e2017-09-15 04:47:3116#include "api/video/video_frame.h"
17#include "rtc_base/criticalsection.h"
18#include "rtc_base/task_queue.h"
Emircan Uysaler03e6ec92018-03-09 23:03:2619#include "test/frame_generator.h"
Sebastian Janssonf1f363f2018-08-13 12:24:5820#include "test/test_video_capturer.h"
pbos@webrtc.org26d12102013-05-29 13:41:0321
22namespace webrtc {
23
pbos@webrtc.org26d12102013-05-29 13:41:0324namespace test {
25
26class FrameGenerator;
27
Sebastian Janssonf1f363f2018-08-13 12:24:5828class FrameGeneratorCapturer : public TestVideoCapturer {
pbos@webrtc.org26d12102013-05-29 13:41:0329 public:
perkj803d97f2016-11-01 18:45:4630 class SinkWantsObserver {
31 public:
32 // OnSinkWantsChanged is called when FrameGeneratorCapturer::AddOrUpdateSink
33 // is called.
34 virtual void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink,
35 const rtc::VideoSinkWants& wants) = 0;
36
37 protected:
38 virtual ~SinkWantsObserver() {}
39 };
40
Emircan Uysaler207a75d2018-03-12 21:12:1441 // |type| has the default value OutputType::I420. |num_squares| has the
42 // default value 10.
Emircan Uysaler03e6ec92018-03-09 23:03:2643 static FrameGeneratorCapturer* Create(
44 int width,
45 int height,
Danil Chapovalov431abd92018-06-18 10:54:1746 absl::optional<FrameGenerator::OutputType> type,
47 absl::optional<int> num_squares,
Emircan Uysaler03e6ec92018-03-09 23:03:2648 int target_fps,
49 Clock* clock);
Taylor Brandstetter081136f2018-03-08 01:54:1050
perkja49cbd32016-09-16 14:53:4151 static FrameGeneratorCapturer* CreateFromYuvFile(const std::string& file_name,
andresp@webrtc.orgab654952013-09-19 12:14:0352 size_t width,
53 size_t height,
54 int target_fps,
55 Clock* clock);
erikvarga579de6f2017-08-29 16:12:5756
57 static FrameGeneratorCapturer* CreateSlideGenerator(int width,
58 int height,
59 int frame_repeat_count,
60 int target_fps,
61 Clock* clock);
pbos@webrtc.org26d12102013-05-29 13:41:0362 virtual ~FrameGeneratorCapturer();
63
kjellander@webrtc.org14665ff2015-03-04 12:58:3564 void Start() override;
65 void Stop() override;
perkjfa10b552016-10-03 06:45:2666 void ChangeResolution(size_t width, size_t height);
Sebastian Janssonba3decf2018-08-30 09:19:2367 void ChangeFramerate(int target_framerate);
perkja49cbd32016-09-16 14:53:4168
perkj803d97f2016-11-01 18:45:4669 void SetSinkWantsObserver(SinkWantsObserver* observer);
70
perkja49cbd32016-09-16 14:53:4171 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
72 const rtc::VideoSinkWants& wants) override;
73 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
74
sprang867fb522015-08-03 11:38:4175 void ForceFrame();
Perba7dc722016-04-19 13:01:2376 void SetFakeRotation(VideoRotation rotation);
pbos@webrtc.org26d12102013-05-29 13:41:0377
wu@webrtc.orgcd701192014-04-24 22:10:2478 int64_t first_frame_capture_time() const { return first_frame_capture_time_; }
79
andresp@webrtc.orgab654952013-09-19 12:14:0380 FrameGeneratorCapturer(Clock* clock,
perkja8ba1952017-02-27 14:52:1081 std::unique_ptr<FrameGenerator> frame_generator,
pbos@webrtc.orgaf8d5af2013-07-09 08:02:3382 int target_fps);
pbos@webrtc.org26d12102013-05-29 13:41:0383 bool Init();
sprang@webrtc.org131bea82015-02-18 12:46:0684
85 private:
ilnikbaded152017-03-17 12:55:2586 class InsertFrameTask;
87
pbos@webrtc.org26d12102013-05-29 13:41:0388 void InsertFrame();
89 static bool Run(void* obj);
sprangc5d62e22017-04-03 06:53:0490 int GetCurrentConfiguredFramerate();
pbos@webrtc.org26d12102013-05-29 13:41:0391
pbos@webrtc.orgde1429e2014-04-28 13:00:2192 Clock* const clock_;
pbos@webrtc.org26d12102013-05-29 13:41:0393 bool sending_;
danilchapa37de392017-09-09 11:17:2294 rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(&lock_);
95 SinkWantsObserver* sink_wants_observer_ RTC_GUARDED_BY(&lock_);
pbos@webrtc.org26d12102013-05-29 13:41:0396
Peter Boströmf2f82832015-05-01 11:00:4197 rtc::CriticalSection lock_;
kwibergbfefb032016-05-01 21:53:4698 std::unique_ptr<FrameGenerator> frame_generator_;
pbos@webrtc.org26d12102013-05-29 13:41:0399
Sebastian Janssonba3decf2018-08-30 09:19:23100 int source_fps_ RTC_GUARDED_BY(&lock_);
101 int target_capture_fps_ RTC_GUARDED_BY(&lock_);
Danil Chapovalov431abd92018-06-18 10:54:17102 absl::optional<int> wanted_fps_ RTC_GUARDED_BY(&lock_);
Perba7dc722016-04-19 13:01:23103 VideoRotation fake_rotation_ = kVideoRotation_0;
wu@webrtc.orgcd701192014-04-24 22:10:24104
105 int64_t first_frame_capture_time_;
ilnikbaded152017-03-17 12:55:25106 // Must be the last field, so it will be deconstructed first as tasks
107 // in the TaskQueue access other fields of the instance of this class.
108 rtc::TaskQueue task_queue_;
pbos@webrtc.org26d12102013-05-29 13:41:03109};
ilnikbaded152017-03-17 12:55:25110} // namespace test
111} // namespace webrtc
pbos@webrtc.org26d12102013-05-29 13:41:03112
Mirko Bonadei92ea95e2017-09-15 04:47:31113#endif // TEST_FRAME_GENERATOR_CAPTURER_H_