Chromium Code Reviews

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

Issue 2740723002: Rewrite 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.
Jump to:
View unified diff |
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"
15 #include "webrtc/system_wrappers/include/clock.h" 18 #include "webrtc/system_wrappers/include/clock.h"
16 #include "webrtc/system_wrappers/include/event_wrapper.h" 19 #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 {
(...skipping 31 matching lines...)
54 } 57 }
55 58
56 FrameGeneratorCapturer::FrameGeneratorCapturer( 59 FrameGeneratorCapturer::FrameGeneratorCapturer(
57 Clock* clock, 60 Clock* clock,
58 std::unique_ptr<FrameGenerator> frame_generator, 61 std::unique_ptr<FrameGenerator> frame_generator,
59 int target_fps) 62 int target_fps)
60 : clock_(clock), 63 : clock_(clock),
61 sending_(false), 64 sending_(false),
62 sink_(nullptr), 65 sink_(nullptr),
63 sink_wants_observer_(nullptr), 66 sink_wants_observer_(nullptr),
64 tick_(EventTimerWrapper::Create()), 67 task_queue_("FrameGeneratorQueue", rtc::TaskQueue::Priority::HIGH),
65 thread_(FrameGeneratorCapturer::Run, this, "FrameGeneratorCapturer"),
66 frame_generator_(std::move(frame_generator)), 68 frame_generator_(std::move(frame_generator)),
67 target_fps_(target_fps), 69 target_fps_(target_fps),
68 first_frame_capture_time_(-1) { 70 first_frame_capture_time_(-1) {
69 RTC_DCHECK(frame_generator_); 71 RTC_DCHECK(frame_generator_);
70 RTC_DCHECK_GT(target_fps, 0); 72 RTC_DCHECK_GT(target_fps, 0);
71 } 73 }
72 74
73 FrameGeneratorCapturer::~FrameGeneratorCapturer() { 75 FrameGeneratorCapturer::~FrameGeneratorCapturer() {
74 Stop(); 76 Stop();
75
76 thread_.Stop();
77 } 77 }
78 78
79 void FrameGeneratorCapturer::SetFakeRotation(VideoRotation rotation) { 79 void FrameGeneratorCapturer::SetFakeRotation(VideoRotation rotation) {
80 rtc::CritScope cs(&lock_); 80 rtc::CritScope cs(&lock_);
81 fake_rotation_ = rotation; 81 fake_rotation_ = rotation;
82 } 82 }
83 83
84 bool FrameGeneratorCapturer::Init() { 84 bool FrameGeneratorCapturer::Init() {
85 // 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
86 // not crash because a file moved. 86 // not crash because a file moved.
87 if (frame_generator_.get() == NULL) 87 if (frame_generator_.get() == NULL)
88 return false; 88 return false;
89 89
90 if (!tick_->StartTimer(true, 1000 / target_fps_)) 90 task_queue_.PostDelayedTask(
91 return false; 91 std::unique_ptr<rtc::QueuedTask>(new InsertFrameTask(this, true)),
92 thread_.Start(); 92 1000 / target_fps_);
93 thread_.SetPriority(rtc::kHighPriority); 93
94 return true; 94 return true;
95 } 95 }
96 96
97 bool FrameGeneratorCapturer::Run(void* obj) {
98 static_cast<FrameGeneratorCapturer*>(obj)->InsertFrame();
99 return true;
100 }
101
102 void FrameGeneratorCapturer::InsertFrame() { 97 void FrameGeneratorCapturer::InsertFrame() {
103 { 98 {
104 rtc::CritScope cs(&lock_); 99 rtc::CritScope cs(&lock_);
105 if (sending_) { 100 if (sending_) {
106 VideoFrame* frame = frame_generator_->NextFrame(); 101 VideoFrame* frame = frame_generator_->NextFrame();
107 frame->set_ntp_time_ms(clock_->CurrentNtpInMilliseconds()); 102 frame->set_ntp_time_ms(clock_->CurrentNtpInMilliseconds());
108 frame->set_rotation(fake_rotation_); 103 frame->set_rotation(fake_rotation_);
109 if (first_frame_capture_time_ == -1) { 104 if (first_frame_capture_time_ == -1) {
110 first_frame_capture_time_ = frame->ntp_time_ms(); 105 first_frame_capture_time_ = frame->ntp_time_ms();
111 } 106 }
112 if (sink_) 107 if (sink_)
113 sink_->OnFrame(*frame); 108 sink_->OnFrame(*frame);
114 } 109 }
115 } 110 }
116 tick_->Wait(WEBRTC_EVENT_INFINITE);
117 } 111 }
118 112
119 void FrameGeneratorCapturer::Start() { 113 void FrameGeneratorCapturer::Start() {
120 rtc::CritScope cs(&lock_); 114 rtc::CritScope cs(&lock_);
121 sending_ = true; 115 sending_ = true;
122 } 116 }
123 117
124 void FrameGeneratorCapturer::Stop() { 118 void FrameGeneratorCapturer::Stop() {
125 rtc::CritScope cs(&lock_); 119 rtc::CritScope cs(&lock_);
126 sending_ = false; 120 sending_ = false;
(...skipping 21 matching lines...)
148 } 142 }
149 143
150 void FrameGeneratorCapturer::RemoveSink( 144 void FrameGeneratorCapturer::RemoveSink(
151 rtc::VideoSinkInterface<VideoFrame>* sink) { 145 rtc::VideoSinkInterface<VideoFrame>* sink) {
152 rtc::CritScope cs(&lock_); 146 rtc::CritScope cs(&lock_);
153 RTC_CHECK(sink_ == sink); 147 RTC_CHECK(sink_ == sink);
154 sink_ = nullptr; 148 sink_ = nullptr;
155 } 149 }
156 150
157 void FrameGeneratorCapturer::ForceFrame() { 151 void FrameGeneratorCapturer::ForceFrame() {
158 tick_->Set(); 152 task_queue_.PostTask(
153 std::unique_ptr<rtc::QueuedTask>(new InsertFrameTask(this, false)));
159 } 154 }
160 } // test 155
161 } // webrtc 156 bool FrameGeneratorCapturer::InsertFrameTask::Run() {
157 if (repeat_) {
158 rtc::TaskQueue::Current()->PostDelayedTask(
159 std::unique_ptr<rtc::QueuedTask>(this),
160 1000 / frame_generator_capturer_->target_fps_);
161 }
162 frame_generator_capturer_->InsertFrame();
163 // If task is repeating, it should not be deleted.
164 return !repeat_;
165 }
166
167 } // namespace test
168 } // namespace webrtc
OLDNEW
« webrtc/test/frame_generator_capturer.h ('K') | « webrtc/test/frame_generator_capturer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine