blob: 01bc04b688c66348471cf2ae22bdaa290faed9b9 [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
Peter Boströmf2f82832015-05-01 13:00:41 +020016#include "webrtc/base/criticalsection.h"
Peter Boström8c38e8b2015-11-26 17:45:47 +010017#include "webrtc/base/platform_thread.h"
Perba7dc722016-04-19 15:01:23 +020018#include "webrtc/common_video/rotation.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"
perkja49cbd32016-09-16 07:53:41 -070021#include "webrtc/video_frame.h"
pbos@webrtc.org26d12102013-05-29 13:41:03 +000022
23namespace webrtc {
24
pbos@webrtc.org26d12102013-05-29 13:41:03 +000025class CriticalSectionWrapper;
Peter Boström64c03662015-04-08 11:24:19 +020026class EventTimerWrapper;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000027
28namespace test {
29
30class FrameGenerator;
31
32class FrameGeneratorCapturer : public VideoCapturer {
33 public:
perkj803d97f2016-11-01 11:45:46 -070034 class SinkWantsObserver {
35 public:
36 // OnSinkWantsChanged is called when FrameGeneratorCapturer::AddOrUpdateSink
37 // is called.
38 virtual void OnSinkWantsChanged(rtc::VideoSinkInterface<VideoFrame>* sink,
39 const rtc::VideoSinkWants& wants) = 0;
40
41 protected:
42 virtual ~SinkWantsObserver() {}
43 };
44
perkja49cbd32016-09-16 07:53:41 -070045 static FrameGeneratorCapturer* Create(size_t width,
andresp@webrtc.orgab654952013-09-19 12:14:03 +000046 size_t height,
47 int target_fps,
48 Clock* clock);
49
perkja49cbd32016-09-16 07:53:41 -070050 static FrameGeneratorCapturer* CreateFromYuvFile(const std::string& file_name,
andresp@webrtc.orgab654952013-09-19 12:14:03 +000051 size_t width,
52 size_t height,
53 int target_fps,
54 Clock* clock);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000055 virtual ~FrameGeneratorCapturer();
56
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000057 void Start() override;
58 void Stop() override;
perkjfa10b552016-10-02 23:45:26 -070059 void ChangeResolution(size_t width, size_t height);
perkja49cbd32016-09-16 07:53:41 -070060
perkj803d97f2016-11-01 11:45:46 -070061 void SetSinkWantsObserver(SinkWantsObserver* observer);
62
perkja49cbd32016-09-16 07:53:41 -070063 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
64 const rtc::VideoSinkWants& wants) override;
65 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
66
sprang867fb522015-08-03 04:38:41 -070067 void ForceFrame();
Perba7dc722016-04-19 15:01:23 +020068 void SetFakeRotation(VideoRotation rotation);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000069
wu@webrtc.orgcd701192014-04-24 22:10:24 +000070 int64_t first_frame_capture_time() const { return first_frame_capture_time_; }
71
andresp@webrtc.orgab654952013-09-19 12:14:03 +000072 FrameGeneratorCapturer(Clock* clock,
pbos@webrtc.org26d12102013-05-29 13:41:03 +000073 FrameGenerator* frame_generator,
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000074 int target_fps);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000075 bool Init();
sprang@webrtc.org131bea82015-02-18 12:46:06 +000076
77 private:
pbos@webrtc.org26d12102013-05-29 13:41:03 +000078 void InsertFrame();
79 static bool Run(void* obj);
80
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000081 Clock* const clock_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000082 bool sending_;
perkja49cbd32016-09-16 07:53:41 -070083 rtc::VideoSinkInterface<VideoFrame>* sink_ GUARDED_BY(&lock_);
perkj803d97f2016-11-01 11:45:46 -070084 SinkWantsObserver* sink_wants_observer_ GUARDED_BY(&lock_);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000085
kwibergbfefb032016-05-01 14:53:46 -070086 std::unique_ptr<EventTimerWrapper> tick_;
Peter Boströmf2f82832015-05-01 13:00:41 +020087 rtc::CriticalSection lock_;
Peter Boström8c38e8b2015-11-26 17:45:47 +010088 rtc::PlatformThread thread_;
kwibergbfefb032016-05-01 14:53:46 -070089 std::unique_ptr<FrameGenerator> frame_generator_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000090
91 int target_fps_;
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_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000095};
96} // test
97} // webrtc
98
Peter Boström7623ce42015-12-09 12:13:30 +010099#endif // WEBRTC_TEST_FRAME_GENERATOR_CAPTURER_H_