blob: 2b2cfbc82133706b16aa67075823d32372731cd6 [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;
perkja49cbd32016-09-16 07:53:41 -070048
49 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
50 const rtc::VideoSinkWants& wants) override;
51 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
52
sprang867fb522015-08-03 04:38:41 -070053 void ForceFrame();
Perba7dc722016-04-19 15:01:23 +020054 void SetFakeRotation(VideoRotation rotation);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000055
wu@webrtc.orgcd701192014-04-24 22:10:24 +000056 int64_t first_frame_capture_time() const { return first_frame_capture_time_; }
57
andresp@webrtc.orgab654952013-09-19 12:14:03 +000058 FrameGeneratorCapturer(Clock* clock,
pbos@webrtc.org26d12102013-05-29 13:41:03 +000059 FrameGenerator* frame_generator,
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000060 int target_fps);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000061 bool Init();
sprang@webrtc.org131bea82015-02-18 12:46:06 +000062
63 private:
pbos@webrtc.org26d12102013-05-29 13:41:03 +000064 void InsertFrame();
65 static bool Run(void* obj);
66
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000067 Clock* const clock_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000068 bool sending_;
perkja49cbd32016-09-16 07:53:41 -070069 rtc::VideoSinkInterface<VideoFrame>* sink_ GUARDED_BY(&lock_);
pbos@webrtc.org26d12102013-05-29 13:41:03 +000070
kwibergbfefb032016-05-01 14:53:46 -070071 std::unique_ptr<EventTimerWrapper> tick_;
Peter Boströmf2f82832015-05-01 13:00:41 +020072 rtc::CriticalSection lock_;
Peter Boström8c38e8b2015-11-26 17:45:47 +010073 rtc::PlatformThread thread_;
kwibergbfefb032016-05-01 14:53:46 -070074 std::unique_ptr<FrameGenerator> frame_generator_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000075
76 int target_fps_;
Perba7dc722016-04-19 15:01:23 +020077 VideoRotation fake_rotation_ = kVideoRotation_0;
wu@webrtc.orgcd701192014-04-24 22:10:24 +000078
79 int64_t first_frame_capture_time_;
pbos@webrtc.org26d12102013-05-29 13:41:03 +000080};
81} // test
82} // webrtc
83
Peter Boström7623ce42015-12-09 12:13:30 +010084#endif // WEBRTC_TEST_FRAME_GENERATOR_CAPTURER_H_