blob: 8f3232c3e4479193e6e7a26711a8e8ffbaf1e2fd [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 */
Peter Boström7623ce42015-12-09 12:13:30 +010010#ifndef WEBRTC_TEST_FRAME_GENERATOR_CAPTURER_H_
11#define WEBRTC_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
nisseaf916892017-01-10 07:44:26 -080016#include "webrtc/api/video/video_frame.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020017#include "webrtc/rtc_base/criticalsection.h"
18#include "webrtc/rtc_base/task_queue.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000019#include "webrtc/test/video_capturer.h"
pbos@webrtc.org26d12102013-05-29 13:41:03 +000020#include "webrtc/typedefs.h"
21
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
perkja49cbd32016-09-16 07:53:41 -070048 static FrameGeneratorCapturer* CreateFromYuvFile(const std::string& file_name,
andresp@webrtc.orgab654952013-09-19 12:14:03 +000049 size_t width,
50 size_t height,
51 int target_fps,
52 Clock* clock);
erikvarga579de6f2017-08-29 09:12:57 -070053
54 static FrameGeneratorCapturer* CreateSlideGenerator(int width,
55 int height,
56 int frame_repeat_count,
57 int target_fps,
58 Clock* clock);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000059 virtual ~FrameGeneratorCapturer();
60
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000061 void Start() override;
62 void Stop() override;
perkjfa10b552016-10-02 23:45:26 -070063 void ChangeResolution(size_t width, size_t height);
perkja49cbd32016-09-16 07:53:41 -070064
perkj803d97f2016-11-01 11:45:46 -070065 void SetSinkWantsObserver(SinkWantsObserver* observer);
66
perkja49cbd32016-09-16 07:53:41 -070067 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
68 const rtc::VideoSinkWants& wants) override;
69 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
70
sprang867fb522015-08-03 04:38:41 -070071 void ForceFrame();
Perba7dc722016-04-19 15:01:23 +020072 void SetFakeRotation(VideoRotation rotation);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000073
wu@webrtc.orgcd701192014-04-24 22:10:24 +000074 int64_t first_frame_capture_time() const { return first_frame_capture_time_; }
75
andresp@webrtc.orgab654952013-09-19 12:14:03 +000076 FrameGeneratorCapturer(Clock* clock,
perkja8ba1952017-02-27 06:52:10 -080077 std::unique_ptr<FrameGenerator> frame_generator,
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000078 int target_fps);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000079 bool Init();
sprang@webrtc.org131bea82015-02-18 12:46:06 +000080
81 private:
ilnikbaded152017-03-17 05:55:25 -070082 class InsertFrameTask;
83
pbos@webrtc.org26d12102013-05-29 13:41:03 +000084 void InsertFrame();
85 static bool Run(void* obj);
sprangc5d62e22017-04-02 23:53:04 -070086 int GetCurrentConfiguredFramerate();
pbos@webrtc.org26d12102013-05-29 13:41:03 +000087
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000088 Clock* const clock_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000089 bool sending_;
danilchapa37de392017-09-09 04:17:22 -070090 rtc::VideoSinkInterface<VideoFrame>* sink_ RTC_GUARDED_BY(&lock_);
91 SinkWantsObserver* sink_wants_observer_ RTC_GUARDED_BY(&lock_);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000092
Peter Boströmf2f82832015-05-01 13:00:41 +020093 rtc::CriticalSection lock_;
kwibergbfefb032016-05-01 14:53:46 -070094 std::unique_ptr<FrameGenerator> frame_generator_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000095
danilchapa37de392017-09-09 04:17:22 -070096 int target_fps_ RTC_GUARDED_BY(&lock_);
97 rtc::Optional<int> wanted_fps_ RTC_GUARDED_BY(&lock_);
Perba7dc722016-04-19 15:01:23 +020098 VideoRotation fake_rotation_ = kVideoRotation_0;
wu@webrtc.orgcd701192014-04-24 22:10:24 +000099
100 int64_t first_frame_capture_time_;
ilnikbaded152017-03-17 05:55:25 -0700101 // Must be the last field, so it will be deconstructed first as tasks
102 // in the TaskQueue access other fields of the instance of this class.
103 rtc::TaskQueue task_queue_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000104};
ilnikbaded152017-03-17 05:55:25 -0700105} // namespace test
106} // namespace webrtc
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000107
Peter Boström7623ce42015-12-09 12:13:30 +0100108#endif // WEBRTC_TEST_FRAME_GENERATOR_CAPTURER_H_