Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1063)

Side by Side Diff: webrtc/test/frame_generator_capturer.cc

Issue 2750473002: Reland of write frame generator capturer to use TaskQueue instead of EventTimeWrapper (Closed)
Patch Set: Do not modify QueueTask, as it will be fixed by another CL by Tommi@ Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/test/frame_generator_capturer.h ('k') | webrtc/video/full_stack_tests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/test/frame_generator_capturer.h" 11 #include "webrtc/test/frame_generator_capturer.h"
12 12
13 #include <utility>
14 #include <vector>
15
13 #include "webrtc/base/criticalsection.h" 16 #include "webrtc/base/criticalsection.h"
14 #include "webrtc/base/platform_thread.h" 17 #include "webrtc/base/platform_thread.h"
18 #include "webrtc/base/task_queue.h"
15 #include "webrtc/system_wrappers/include/clock.h" 19 #include "webrtc/system_wrappers/include/clock.h"
16 #include "webrtc/system_wrappers/include/event_wrapper.h"
17 #include "webrtc/system_wrappers/include/sleep.h" 20 #include "webrtc/system_wrappers/include/sleep.h"
18 #include "webrtc/test/frame_generator.h" 21 #include "webrtc/test/frame_generator.h"
19 #include "webrtc/video_send_stream.h" 22 #include "webrtc/video_send_stream.h"
20 23
21 namespace webrtc { 24 namespace webrtc {
22 namespace test { 25 namespace test {
23 26
27 class FrameGeneratorCapturer::InsertFrameTask : public rtc::QueuedTask {
28 public:
29 // Repeats in |repeat_interval_ms|. One-time if |repeat_interval_ms| == 0.
30 InsertFrameTask(
31 webrtc::test::FrameGeneratorCapturer* frame_generator_capturer,
32 uint32_t repeat_interval_ms)
33 : frame_generator_capturer_(frame_generator_capturer),
34 repeat_interval_ms_(repeat_interval_ms) {}
35
36 private:
37 bool Run() override {
38 if (repeat_interval_ms_ > 0) {
39 rtc::TaskQueue::Current()->PostDelayedTask(
40 std::unique_ptr<rtc::QueuedTask>(this), repeat_interval_ms_);
41 }
42 frame_generator_capturer_->InsertFrame();
43 // Task should be deleted only if it's not repeating.
44 return repeat_interval_ms_ == 0;
45 }
46
47 webrtc::test::FrameGeneratorCapturer* const frame_generator_capturer_;
48 const uint32_t repeat_interval_ms_;
49 };
50
24 FrameGeneratorCapturer* FrameGeneratorCapturer::Create(int width, 51 FrameGeneratorCapturer* FrameGeneratorCapturer::Create(int width,
25 int height, 52 int height,
26 int target_fps, 53 int target_fps,
27 Clock* clock) { 54 Clock* clock) {
28 FrameGeneratorCapturer* capturer = new FrameGeneratorCapturer( 55 FrameGeneratorCapturer* capturer = new FrameGeneratorCapturer(
29 clock, FrameGenerator::CreateSquareGenerator(width, height), target_fps); 56 clock, FrameGenerator::CreateSquareGenerator(width, height), target_fps);
30 if (!capturer->Init()) { 57 if (!capturer->Init()) {
31 delete capturer; 58 delete capturer;
32 return NULL; 59 return NULL;
33 } 60 }
(...skipping 20 matching lines...) Expand all
54 } 81 }
55 82
56 FrameGeneratorCapturer::FrameGeneratorCapturer( 83 FrameGeneratorCapturer::FrameGeneratorCapturer(
57 Clock* clock, 84 Clock* clock,
58 std::unique_ptr<FrameGenerator> frame_generator, 85 std::unique_ptr<FrameGenerator> frame_generator,
59 int target_fps) 86 int target_fps)
60 : clock_(clock), 87 : clock_(clock),
61 sending_(false), 88 sending_(false),
62 sink_(nullptr), 89 sink_(nullptr),
63 sink_wants_observer_(nullptr), 90 sink_wants_observer_(nullptr),
64 tick_(EventTimerWrapper::Create()),
65 thread_(FrameGeneratorCapturer::Run, this, "FrameGeneratorCapturer"),
66 frame_generator_(std::move(frame_generator)), 91 frame_generator_(std::move(frame_generator)),
67 target_fps_(target_fps), 92 target_fps_(target_fps),
68 first_frame_capture_time_(-1) { 93 first_frame_capture_time_(-1),
94 task_queue_("FrameGeneratorCapturerQueue",
95 rtc::TaskQueue::Priority::HIGH) {
69 RTC_DCHECK(frame_generator_); 96 RTC_DCHECK(frame_generator_);
70 RTC_DCHECK_GT(target_fps, 0); 97 RTC_DCHECK_GT(target_fps, 0);
71 } 98 }
72 99
73 FrameGeneratorCapturer::~FrameGeneratorCapturer() { 100 FrameGeneratorCapturer::~FrameGeneratorCapturer() {
74 Stop(); 101 Stop();
75
76 thread_.Stop();
77 } 102 }
78 103
79 void FrameGeneratorCapturer::SetFakeRotation(VideoRotation rotation) { 104 void FrameGeneratorCapturer::SetFakeRotation(VideoRotation rotation) {
80 rtc::CritScope cs(&lock_); 105 rtc::CritScope cs(&lock_);
81 fake_rotation_ = rotation; 106 fake_rotation_ = rotation;
82 } 107 }
83 108
84 bool FrameGeneratorCapturer::Init() { 109 bool FrameGeneratorCapturer::Init() {
85 // This check is added because frame_generator_ might be file based and should 110 // This check is added because frame_generator_ might be file based and should
86 // not crash because a file moved. 111 // not crash because a file moved.
87 if (frame_generator_.get() == NULL) 112 if (frame_generator_.get() == NULL)
88 return false; 113 return false;
89 114
90 if (!tick_->StartTimer(true, 1000 / target_fps_)) 115 task_queue_.PostDelayedTask(
91 return false; 116 std::unique_ptr<rtc::QueuedTask>(
92 thread_.Start(); 117 new InsertFrameTask(this, 1000 / target_fps_)),
93 thread_.SetPriority(rtc::kHighPriority); 118 1000 / target_fps_);
119
94 return true; 120 return true;
95 } 121 }
96 122
97 bool FrameGeneratorCapturer::Run(void* obj) {
98 static_cast<FrameGeneratorCapturer*>(obj)->InsertFrame();
99 return true;
100 }
101
102 void FrameGeneratorCapturer::InsertFrame() { 123 void FrameGeneratorCapturer::InsertFrame() {
103 { 124 {
104 rtc::CritScope cs(&lock_); 125 rtc::CritScope cs(&lock_);
105 if (sending_) { 126 if (sending_) {
106 VideoFrame* frame = frame_generator_->NextFrame(); 127 VideoFrame* frame = frame_generator_->NextFrame();
107 frame->set_ntp_time_ms(clock_->CurrentNtpInMilliseconds()); 128 frame->set_ntp_time_ms(clock_->CurrentNtpInMilliseconds());
108 frame->set_rotation(fake_rotation_); 129 frame->set_rotation(fake_rotation_);
109 if (first_frame_capture_time_ == -1) { 130 if (first_frame_capture_time_ == -1) {
110 first_frame_capture_time_ = frame->ntp_time_ms(); 131 first_frame_capture_time_ = frame->ntp_time_ms();
111 } 132 }
112 if (sink_) 133 if (sink_)
113 sink_->OnFrame(*frame); 134 sink_->OnFrame(*frame);
114 } 135 }
115 } 136 }
116 tick_->Wait(WEBRTC_EVENT_INFINITE);
117 } 137 }
118 138
119 void FrameGeneratorCapturer::Start() { 139 void FrameGeneratorCapturer::Start() {
120 rtc::CritScope cs(&lock_); 140 rtc::CritScope cs(&lock_);
121 sending_ = true; 141 sending_ = true;
122 } 142 }
123 143
124 void FrameGeneratorCapturer::Stop() { 144 void FrameGeneratorCapturer::Stop() {
125 rtc::CritScope cs(&lock_); 145 rtc::CritScope cs(&lock_);
126 sending_ = false; 146 sending_ = false;
(...skipping 21 matching lines...) Expand all
148 } 168 }
149 169
150 void FrameGeneratorCapturer::RemoveSink( 170 void FrameGeneratorCapturer::RemoveSink(
151 rtc::VideoSinkInterface<VideoFrame>* sink) { 171 rtc::VideoSinkInterface<VideoFrame>* sink) {
152 rtc::CritScope cs(&lock_); 172 rtc::CritScope cs(&lock_);
153 RTC_CHECK(sink_ == sink); 173 RTC_CHECK(sink_ == sink);
154 sink_ = nullptr; 174 sink_ = nullptr;
155 } 175 }
156 176
157 void FrameGeneratorCapturer::ForceFrame() { 177 void FrameGeneratorCapturer::ForceFrame() {
158 tick_->Set(); 178 // One-time non-repeating task,
179 // therefore repeat_interval_ms is 0 in InsertFrameTask()
180 task_queue_.PostTask(
181 std::unique_ptr<rtc::QueuedTask>(new InsertFrameTask(this, 0)));
159 } 182 }
160 } // test 183
161 } // webrtc 184 } // namespace test
185 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/test/frame_generator_capturer.h ('k') | webrtc/video/full_stack_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698