blob: 3a3fe82431cded10622cbe35727e6788c3b4321a [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"
19#include "test/video_capturer.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020020#include "typedefs.h" // NOLINT(build/include)
pbos@webrtc.org26d12102013-05-29 13:41:03 +000021
22namespace webrtc {
23
Peter Boström64c03662015-04-08 11:24:19 +020024class EventTimerWrapper;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000025
26namespace test {
27
28class FrameGenerator;
29
30class FrameGeneratorCapturer : public VideoCapturer {
31 public:
perkj803d97f2016-11-01 11:45:46 -070032 class SinkWantsObserver {
33 public:
34 // OnSinkWantsChanged is called when FrameGeneratorCapturer::AddOrUpdateSink
35 // is called.
36 virtual void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink,
37 const rtc::VideoSinkWants& wants) = 0;
38
39 protected:
40 virtual ~SinkWantsObserver() {}
41 };
42
perkja8ba1952017-02-27 06:52:10 -080043 static FrameGeneratorCapturer* Create(int width,
44 int height,
andresp@webrtc.orgab654952013-09-19 12:14:03 +000045 int target_fps,
46 Clock* clock);
47
erikvarga@webrtc.orgc774d5d2017-10-10 14:34:38 +020048 static FrameGeneratorCapturer* Create(int width,
49 int height,
50 int num_squares,
51 int target_fps,
52 Clock* clock);
53
perkja49cbd32016-09-16 07:53:41 -070054 static FrameGeneratorCapturer* CreateFromYuvFile(const std::string& file_name,
andresp@webrtc.orgab654952013-09-19 12:14:03 +000055 size_t width,
56 size_t height,
57 int target_fps,
58 Clock* clock);
erikvarga579de6f2017-08-29 09:12:57 -070059
60 static FrameGeneratorCapturer* CreateSlideGenerator(int width,
61 int height,
62 int frame_repeat_count,
63 int target_fps,
64 Clock* clock);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000065 virtual ~FrameGeneratorCapturer();
66
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000067 void Start() override;
68 void Stop() override;
perkjfa10b552016-10-02 23:45:26 -070069 void ChangeResolution(size_t width, size_t height);
perkja49cbd32016-09-16 07:53:41 -070070
perkj803d97f2016-11-01 11:45:46 -070071 void SetSinkWantsObserver(SinkWantsObserver* observer);
72
perkja49cbd32016-09-16 07:53:41 -070073 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
74 const rtc::VideoSinkWants& wants) override;
75 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
76
sprang867fb522015-08-03 04:38:41 -070077 void ForceFrame();
Perba7dc722016-04-19 15:01:23 +020078 void SetFakeRotation(VideoRotation rotation);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000079
wu@webrtc.orgcd701192014-04-24 22:10:24 +000080 int64_t first_frame_capture_time() const { return first_frame_capture_time_; }
81
andresp@webrtc.orgab654952013-09-19 12:14:03 +000082 FrameGeneratorCapturer(Clock* clock,
perkja8ba1952017-02-27 06:52:10 -080083 std::unique_ptr<FrameGenerator> frame_generator,
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000084 int target_fps);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000085 bool Init();
sprang@webrtc.org131bea82015-02-18 12:46:06 +000086
87 private:
ilnikbaded152017-03-17 05:55:25 -070088 class InsertFrameTask;
89
pbos@webrtc.org26d12102013-05-29 13:41:03 +000090 void InsertFrame();
91 static bool Run(void* obj);
sprangc5d62e22017-04-02 23:53:04 -070092 int GetCurrentConfiguredFramerate();
pbos@webrtc.org26d12102013-05-29 13:41:03 +000093
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000094 Clock* const clock_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000095 bool sending_;
danilchapa37de392017-09-09 04:17:22 -070096 rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(&lock_);
97 SinkWantsObserver* sink_wants_observer_ RTC_GUARDED_BY(&lock_);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000098
Peter Boströmf2f82832015-05-01 13:00:41 +020099 rtc::CriticalSection lock_;
kwibergbfefb032016-05-01 14:53:46 -0700100 std::unique_ptr<FrameGenerator> frame_generator_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000101
danilchapa37de392017-09-09 04:17:22 -0700102 int target_fps_ RTC_GUARDED_BY(&lock_);
103 rtc::Optional<int> wanted_fps_ RTC_GUARDED_BY(&lock_);
Perba7dc722016-04-19 15:01:23 +0200104 VideoRotation fake_rotation_ = kVideoRotation_0;
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000105
106 int64_t first_frame_capture_time_;
ilnikbaded152017-03-17 05:55:25 -0700107 // Must be the last field, so it will be deconstructed first as tasks
108 // in the TaskQueue access other fields of the instance of this class.
109 rtc::TaskQueue task_queue_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000110};
ilnikbaded152017-03-17 05:55:25 -0700111} // namespace test
112} // namespace webrtc
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000113
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200114#endif // TEST_FRAME_GENERATOR_CAPTURER_H_