blob: 36a79f9755da1f21f502a5b517f1b68376db64c2 [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"
Peter Boströmf2f82832015-05-01 13:00:41 +020017#include "webrtc/base/criticalsection.h"
ilnikbaded152017-03-17 05:55:25 -070018#include "webrtc/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);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000053 virtual ~FrameGeneratorCapturer();
54
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000055 void Start() override;
56 void Stop() override;
perkjfa10b552016-10-02 23:45:26 -070057 void ChangeResolution(size_t width, size_t height);
perkja49cbd32016-09-16 07:53:41 -070058
perkj803d97f2016-11-01 11:45:46 -070059 void SetSinkWantsObserver(SinkWantsObserver* observer);
60
perkja49cbd32016-09-16 07:53:41 -070061 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
62 const rtc::VideoSinkWants& wants) override;
63 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
64
sprang867fb522015-08-03 04:38:41 -070065 void ForceFrame();
Perba7dc722016-04-19 15:01:23 +020066 void SetFakeRotation(VideoRotation rotation);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000067
wu@webrtc.orgcd701192014-04-24 22:10:24 +000068 int64_t first_frame_capture_time() const { return first_frame_capture_time_; }
69
andresp@webrtc.orgab654952013-09-19 12:14:03 +000070 FrameGeneratorCapturer(Clock* clock,
perkja8ba1952017-02-27 06:52:10 -080071 std::unique_ptr<FrameGenerator> frame_generator,
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000072 int target_fps);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000073 bool Init();
sprang@webrtc.org131bea82015-02-18 12:46:06 +000074
75 private:
ilnikbaded152017-03-17 05:55:25 -070076 class InsertFrameTask;
77
pbos@webrtc.org26d12102013-05-29 13:41:03 +000078 void InsertFrame();
79 static bool Run(void* obj);
sprangc5d62e22017-04-02 23:53:04 -070080 int GetCurrentConfiguredFramerate();
pbos@webrtc.org26d12102013-05-29 13:41:03 +000081
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000082 Clock* const clock_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000083 bool sending_;
perkja49cbd32016-09-16 07:53:41 -070084 rtc::VideoSinkInterface<VideoFrame>* sink_ GUARDED_BY(&lock_);
perkj803d97f2016-11-01 11:45:46 -070085 SinkWantsObserver* sink_wants_observer_ GUARDED_BY(&lock_);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000086
Peter Boströmf2f82832015-05-01 13:00:41 +020087 rtc::CriticalSection lock_;
kwibergbfefb032016-05-01 14:53:46 -070088 std::unique_ptr<FrameGenerator> frame_generator_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000089
sprangc5d62e22017-04-02 23:53:04 -070090 int target_fps_ GUARDED_BY(&lock_);
91 rtc::Optional<int> wanted_fps_ GUARDED_BY(&lock_);
Perba7dc722016-04-19 15:01:23 +020092 VideoRotation fake_rotation_ = kVideoRotation_0;
wu@webrtc.orgcd701192014-04-24 22:10:24 +000093
94 int64_t first_frame_capture_time_;
ilnikbaded152017-03-17 05:55:25 -070095 // Must be the last field, so it will be deconstructed first as tasks
96 // in the TaskQueue access other fields of the instance of this class.
97 rtc::TaskQueue task_queue_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000098};
ilnikbaded152017-03-17 05:55:25 -070099} // namespace test
100} // namespace webrtc
pbos@webrtc.org26d12102013-05-29 13:41:03 +0000101
Peter Boström7623ce42015-12-09 12:13:30 +0100102#endif // WEBRTC_TEST_FRAME_GENERATOR_CAPTURER_H_