blob: ac32fa45b4d35cea57af14028effe4d7b4c942a8 [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"
Sebastian Janssonf1f363f2018-08-13 14:24:58 +020020#include "test/test_video_capturer.h"
pbos@webrtc.org26d12102013-05-29 13:41:03 +000021
22namespace webrtc {
23
pbos@webrtc.org26d12102013-05-29 13:41:03 +000024namespace test {
25
26class FrameGenerator;
27
Sebastian Janssonf1f363f2018-08-13 14:24:58 +020028class FrameGeneratorCapturer : public TestVideoCapturer {
pbos@webrtc.org26d12102013-05-29 13:41:03 +000029 public:
perkj803d97f2016-11-01 11:45:46 -070030 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 14:12:14 -070041 // |type| has the default value OutputType::I420. |num_squares| has the
42 // default value 10.
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080043 static FrameGeneratorCapturer* Create(
44 int width,
45 int height,
Danil Chapovalov431abd92018-06-18 12:54:17 +020046 absl::optional<FrameGenerator::OutputType> type,
47 absl::optional<int> num_squares,
Emircan Uysaler03e6ec92018-03-09 15:03:26 -080048 int target_fps,
49 Clock* clock);
Taylor Brandstetter081136f2018-03-08 01:54:10 +000050
perkja49cbd32016-09-16 07:53:41 -070051 static FrameGeneratorCapturer* CreateFromYuvFile(const std::string& file_name,
andresp@webrtc.orgab654952013-09-19 12:14:03 +000052 size_t width,
53 size_t height,
54 int target_fps,
55 Clock* clock);
erikvarga579de6f2017-08-29 09:12:57 -070056
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:03 +000062 virtual ~FrameGeneratorCapturer();
63
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000064 void Start() override;
65 void Stop() override;
perkjfa10b552016-10-02 23:45:26 -070066 void ChangeResolution(size_t width, size_t height);
perkja49cbd32016-09-16 07:53:41 -070067
perkj803d97f2016-11-01 11:45:46 -070068 void SetSinkWantsObserver(SinkWantsObserver* observer);
69
perkja49cbd32016-09-16 07:53:41 -070070 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
71 const rtc::VideoSinkWants& wants) override;
72 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
73
sprang867fb522015-08-03 04:38:41 -070074 void ForceFrame();
Perba7dc722016-04-19 15:01:23 +020075 void SetFakeRotation(VideoRotation rotation);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000076
wu@webrtc.orgcd701192014-04-24 22:10:24 +000077 int64_t first_frame_capture_time() const { return first_frame_capture_time_; }
78
andresp@webrtc.orgab654952013-09-19 12:14:03 +000079 FrameGeneratorCapturer(Clock* clock,
perkja8ba1952017-02-27 06:52:10 -080080 std::unique_ptr<FrameGenerator> frame_generator,
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000081 int target_fps);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000082 bool Init();
sprang@webrtc.org131bea82015-02-18 12:46:06 +000083
84 private:
ilnikbaded152017-03-17 05:55:25 -070085 class InsertFrameTask;
86
pbos@webrtc.org26d12102013-05-29 13:41:03 +000087 void InsertFrame();
88 static bool Run(void* obj);
sprangc5d62e22017-04-02 23:53:04 -070089 int GetCurrentConfiguredFramerate();
pbos@webrtc.org26d12102013-05-29 13:41:03 +000090
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000091 Clock* const clock_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000092 bool sending_;
danilchapa37de392017-09-09 04:17:22 -070093 rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(&lock_);
94 SinkWantsObserver* sink_wants_observer_ RTC_GUARDED_BY(&lock_);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000095
Peter Boströmf2f82832015-05-01 13:00:41 +020096 rtc::CriticalSection lock_;
kwibergbfefb032016-05-01 14:53:46 -070097 std::unique_ptr<FrameGenerator> frame_generator_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000098
danilchapa37de392017-09-09 04:17:22 -070099 int target_fps_ RTC_GUARDED_BY(&lock_);
Danil Chapovalov431abd92018-06-18 12:54:17 +0200100 absl::optional<int> wanted_fps_ RTC_GUARDED_BY(&lock_);
Perba7dc722016-04-19 15:01:23 +0200101 VideoRotation fake_rotation_ = kVideoRotation_0;
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000102
103 int64_t first_frame_capture_time_;
ilnikbaded152017-03-17 05:55:25 -0700104 // Must be the last field, so it will be deconstructed first as tasks
105 // in the TaskQueue access other fields of the instance of this class.
106 rtc::TaskQueue task_queue_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000107};
ilnikbaded152017-03-17 05:55:25 -0700108} // namespace test
109} // namespace webrtc
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000110
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200111#endif // TEST_FRAME_GENERATOR_CAPTURER_H_