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

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

Issue 2751063005: Revert of write frame generator capturer to use TaskQueue instead of EventTimeWrapper (Closed)
Patch Set: 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
16 #include "webrtc/base/criticalsection.h" 13 #include "webrtc/base/criticalsection.h"
17 #include "webrtc/base/platform_thread.h" 14 #include "webrtc/base/platform_thread.h"
18 #include "webrtc/base/task_queue.h"
19 #include "webrtc/system_wrappers/include/clock.h" 15 #include "webrtc/system_wrappers/include/clock.h"
16 #include "webrtc/system_wrappers/include/event_wrapper.h"
20 #include "webrtc/system_wrappers/include/sleep.h" 17 #include "webrtc/system_wrappers/include/sleep.h"
21 #include "webrtc/test/frame_generator.h" 18 #include "webrtc/test/frame_generator.h"
22 #include "webrtc/video_send_stream.h" 19 #include "webrtc/video_send_stream.h"
23 20
24 namespace webrtc { 21 namespace webrtc {
25 namespace test { 22 namespace test {
26 23
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
51 FrameGeneratorCapturer* FrameGeneratorCapturer::Create(int width, 24 FrameGeneratorCapturer* FrameGeneratorCapturer::Create(int width,
52 int height, 25 int height,
53 int target_fps, 26 int target_fps,
54 Clock* clock) { 27 Clock* clock) {
55 FrameGeneratorCapturer* capturer = new FrameGeneratorCapturer( 28 FrameGeneratorCapturer* capturer = new FrameGeneratorCapturer(
56 clock, FrameGenerator::CreateSquareGenerator(width, height), target_fps); 29 clock, FrameGenerator::CreateSquareGenerator(width, height), target_fps);
57 if (!capturer->Init()) { 30 if (!capturer->Init()) {
58 delete capturer; 31 delete capturer;
59 return NULL; 32 return NULL;
60 } 33 }
(...skipping 20 matching lines...) Expand all
81 } 54 }
82 55
83 FrameGeneratorCapturer::FrameGeneratorCapturer( 56 FrameGeneratorCapturer::FrameGeneratorCapturer(
84 Clock* clock, 57 Clock* clock,
85 std::unique_ptr<FrameGenerator> frame_generator, 58 std::unique_ptr<FrameGenerator> frame_generator,
86 int target_fps) 59 int target_fps)
87 : clock_(clock), 60 : clock_(clock),
88 sending_(false), 61 sending_(false),
89 sink_(nullptr), 62 sink_(nullptr),
90 sink_wants_observer_(nullptr), 63 sink_wants_observer_(nullptr),
64 tick_(EventTimerWrapper::Create()),
65 thread_(FrameGeneratorCapturer::Run, this, "FrameGeneratorCapturer"),
91 frame_generator_(std::move(frame_generator)), 66 frame_generator_(std::move(frame_generator)),
92 target_fps_(target_fps), 67 target_fps_(target_fps),
93 first_frame_capture_time_(-1), 68 first_frame_capture_time_(-1) {
94 task_queue_("FrameGeneratorCapturerQueue",
95 rtc::TaskQueue::Priority::HIGH) {
96 RTC_DCHECK(frame_generator_); 69 RTC_DCHECK(frame_generator_);
97 RTC_DCHECK_GT(target_fps, 0); 70 RTC_DCHECK_GT(target_fps, 0);
98 } 71 }
99 72
100 FrameGeneratorCapturer::~FrameGeneratorCapturer() { 73 FrameGeneratorCapturer::~FrameGeneratorCapturer() {
101 Stop(); 74 Stop();
75
76 thread_.Stop();
102 } 77 }
103 78
104 void FrameGeneratorCapturer::SetFakeRotation(VideoRotation rotation) { 79 void FrameGeneratorCapturer::SetFakeRotation(VideoRotation rotation) {
105 rtc::CritScope cs(&lock_); 80 rtc::CritScope cs(&lock_);
106 fake_rotation_ = rotation; 81 fake_rotation_ = rotation;
107 } 82 }
108 83
109 bool FrameGeneratorCapturer::Init() { 84 bool FrameGeneratorCapturer::Init() {
110 // This check is added because frame_generator_ might be file based and should 85 // This check is added because frame_generator_ might be file based and should
111 // not crash because a file moved. 86 // not crash because a file moved.
112 if (frame_generator_.get() == NULL) 87 if (frame_generator_.get() == NULL)
113 return false; 88 return false;
114 89
115 task_queue_.PostDelayedTask( 90 if (!tick_->StartTimer(true, 1000 / target_fps_))
116 std::unique_ptr<rtc::QueuedTask>( 91 return false;
117 new InsertFrameTask(this, 1000 / target_fps_)), 92 thread_.Start();
118 1000 / target_fps_); 93 thread_.SetPriority(rtc::kHighPriority);
119
120 return true; 94 return true;
121 } 95 }
122 96
97 bool FrameGeneratorCapturer::Run(void* obj) {
98 static_cast<FrameGeneratorCapturer*>(obj)->InsertFrame();
99 return true;
100 }
101
123 void FrameGeneratorCapturer::InsertFrame() { 102 void FrameGeneratorCapturer::InsertFrame() {
124 { 103 {
125 rtc::CritScope cs(&lock_); 104 rtc::CritScope cs(&lock_);
126 if (sending_) { 105 if (sending_) {
127 VideoFrame* frame = frame_generator_->NextFrame(); 106 VideoFrame* frame = frame_generator_->NextFrame();
128 frame->set_ntp_time_ms(clock_->CurrentNtpInMilliseconds()); 107 frame->set_ntp_time_ms(clock_->CurrentNtpInMilliseconds());
129 frame->set_rotation(fake_rotation_); 108 frame->set_rotation(fake_rotation_);
130 if (first_frame_capture_time_ == -1) { 109 if (first_frame_capture_time_ == -1) {
131 first_frame_capture_time_ = frame->ntp_time_ms(); 110 first_frame_capture_time_ = frame->ntp_time_ms();
132 } 111 }
133 if (sink_) 112 if (sink_)
134 sink_->OnFrame(*frame); 113 sink_->OnFrame(*frame);
135 } 114 }
136 } 115 }
116 tick_->Wait(WEBRTC_EVENT_INFINITE);
137 } 117 }
138 118
139 void FrameGeneratorCapturer::Start() { 119 void FrameGeneratorCapturer::Start() {
140 rtc::CritScope cs(&lock_); 120 rtc::CritScope cs(&lock_);
141 sending_ = true; 121 sending_ = true;
142 } 122 }
143 123
144 void FrameGeneratorCapturer::Stop() { 124 void FrameGeneratorCapturer::Stop() {
145 rtc::CritScope cs(&lock_); 125 rtc::CritScope cs(&lock_);
146 sending_ = false; 126 sending_ = false;
(...skipping 21 matching lines...) Expand all
168 } 148 }
169 149
170 void FrameGeneratorCapturer::RemoveSink( 150 void FrameGeneratorCapturer::RemoveSink(
171 rtc::VideoSinkInterface<VideoFrame>* sink) { 151 rtc::VideoSinkInterface<VideoFrame>* sink) {
172 rtc::CritScope cs(&lock_); 152 rtc::CritScope cs(&lock_);
173 RTC_CHECK(sink_ == sink); 153 RTC_CHECK(sink_ == sink);
174 sink_ = nullptr; 154 sink_ = nullptr;
175 } 155 }
176 156
177 void FrameGeneratorCapturer::ForceFrame() { 157 void FrameGeneratorCapturer::ForceFrame() {
178 // One-time non-repeating task, 158 tick_->Set();
179 // therefore repeat_interval_ms is 0 in InsertFrameTask()
180 task_queue_.PostTask(
181 std::unique_ptr<rtc::QueuedTask>(new InsertFrameTask(this, 0)));
182 } 159 }
183 160 } // test
184 } // namespace test 161 } // webrtc
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