blob: fa001c4edff071a3da446e3aaad95538ece842d2 [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:
perkja49cbd32016-09-16 07:53:41 -070034 static FrameGeneratorCapturer* Create(size_t width,
andresp@webrtc.orgab654952013-09-19 12:14:03 +000035 size_t height,
36 int target_fps,
37 Clock* clock);
38
perkja49cbd32016-09-16 07:53:41 -070039 static FrameGeneratorCapturer* CreateFromYuvFile(const std::string& file_name,
andresp@webrtc.orgab654952013-09-19 12:14:03 +000040 size_t width,
41 size_t height,
42 int target_fps,
43 Clock* clock);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000044 virtual ~FrameGeneratorCapturer();
45
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000046 void Start() override;
47 void Stop() override;
perkjfa10b552016-10-02 23:45:26 -070048 void ChangeResolution(size_t width, size_t height);
perkja49cbd32016-09-16 07:53:41 -070049
50 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
51 const rtc::VideoSinkWants& wants) override;
52 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
53
sprang867fb522015-08-03 04:38:41 -070054 void ForceFrame();
Perba7dc722016-04-19 15:01:23 +020055 void SetFakeRotation(VideoRotation rotation);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000056
wu@webrtc.orgcd701192014-04-24 22:10:24 +000057 int64_t first_frame_capture_time() const { return first_frame_capture_time_; }
58
andresp@webrtc.orgab654952013-09-19 12:14:03 +000059 FrameGeneratorCapturer(Clock* clock,
pbos@webrtc.org26d12102013-05-29 13:41:03 +000060 FrameGenerator* frame_generator,
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000061 int target_fps);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000062 bool Init();
sprang@webrtc.org131bea82015-02-18 12:46:06 +000063
64 private:
pbos@webrtc.org26d12102013-05-29 13:41:03 +000065 void InsertFrame();
66 static bool Run(void* obj);
67
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000068 Clock* const clock_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000069 bool sending_;
perkja49cbd32016-09-16 07:53:41 -070070 rtc::VideoSinkInterface<VideoFrame>* sink_ GUARDED_BY(&lock_);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000071
kwibergbfefb032016-05-01 14:53:46 -070072 std::unique_ptr<EventTimerWrapper> tick_;
Peter Boströmf2f82832015-05-01 13:00:41 +020073 rtc::CriticalSection lock_;
Peter Boström8c38e8b2015-11-26 17:45:47 +010074 rtc::PlatformThread thread_;
kwibergbfefb032016-05-01 14:53:46 -070075 std::unique_ptr<FrameGenerator> frame_generator_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000076
77 int target_fps_;
Perba7dc722016-04-19 15:01:23 +020078 VideoRotation fake_rotation_ = kVideoRotation_0;
wu@webrtc.orgcd701192014-04-24 22:10:24 +000079
80 int64_t first_frame_capture_time_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000081};
82} // test
83} // webrtc
84
Peter Boström7623ce42015-12-09 12:13:30 +010085#endif // WEBRTC_TEST_FRAME_GENERATOR_CAPTURER_H_