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

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

Issue 2764133002: Revert of Add framerate to VideoSinkWants and ability to signal on overuse (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/test/vcm_capturer.h » ('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
(...skipping 19 matching lines...) Expand all
30 // Repeats in |repeat_interval_ms|. One-time if |repeat_interval_ms| == 0. 30 // Repeats in |repeat_interval_ms|. One-time if |repeat_interval_ms| == 0.
31 InsertFrameTask( 31 InsertFrameTask(
32 webrtc::test::FrameGeneratorCapturer* frame_generator_capturer, 32 webrtc::test::FrameGeneratorCapturer* frame_generator_capturer,
33 uint32_t repeat_interval_ms) 33 uint32_t repeat_interval_ms)
34 : frame_generator_capturer_(frame_generator_capturer), 34 : frame_generator_capturer_(frame_generator_capturer),
35 repeat_interval_ms_(repeat_interval_ms), 35 repeat_interval_ms_(repeat_interval_ms),
36 intended_run_time_ms_(-1) {} 36 intended_run_time_ms_(-1) {}
37 37
38 private: 38 private:
39 bool Run() override { 39 bool Run() override {
40 bool task_completed = true;
41 if (repeat_interval_ms_ > 0) { 40 if (repeat_interval_ms_ > 0) {
42 // This is not a one-off frame. Check if the frame interval for this 41 int64_t delay_ms;
43 // task queue is the same same as the current configured frame rate. 42 int64_t time_now_ms = rtc::TimeMillis();
44 uint32_t current_interval_ms = 43 if (intended_run_time_ms_ > 0) {
45 1000 / frame_generator_capturer_->GetCurrentConfiguredFramerate(); 44 delay_ms = time_now_ms - intended_run_time_ms_;
46 if (repeat_interval_ms_ != current_interval_ms) { 45 } else {
47 // Frame rate has changed since task was started, create a new instance. 46 delay_ms = 0;
47 intended_run_time_ms_ = time_now_ms;
48 }
49 intended_run_time_ms_ += repeat_interval_ms_;
50 if (delay_ms < repeat_interval_ms_) {
48 rtc::TaskQueue::Current()->PostDelayedTask( 51 rtc::TaskQueue::Current()->PostDelayedTask(
49 std::unique_ptr<rtc::QueuedTask>(new InsertFrameTask( 52 std::unique_ptr<rtc::QueuedTask>(this),
50 frame_generator_capturer_, current_interval_ms)), 53 repeat_interval_ms_ - delay_ms);
51 current_interval_ms);
52 } else { 54 } else {
53 // Schedule the next frame capture event to happen at approximately the 55 rtc::TaskQueue::Current()->PostDelayedTask(
54 // correct absolute time point. 56 std::unique_ptr<rtc::QueuedTask>(this), 0);
55 int64_t delay_ms; 57 LOG(LS_ERROR)
56 int64_t time_now_ms = rtc::TimeMillis(); 58 << "Frame Generator Capturer can't keep up with requested fps";
57 if (intended_run_time_ms_ > 0) {
58 delay_ms = time_now_ms - intended_run_time_ms_;
59 } else {
60 delay_ms = 0;
61 intended_run_time_ms_ = time_now_ms;
62 }
63 intended_run_time_ms_ += repeat_interval_ms_;
64 if (delay_ms < repeat_interval_ms_) {
65 rtc::TaskQueue::Current()->PostDelayedTask(
66 std::unique_ptr<rtc::QueuedTask>(this),
67 repeat_interval_ms_ - delay_ms);
68 } else {
69 rtc::TaskQueue::Current()->PostDelayedTask(
70 std::unique_ptr<rtc::QueuedTask>(this), 0);
71 LOG(LS_ERROR)
72 << "Frame Generator Capturer can't keep up with requested fps";
73 }
74 // Repost of this instance, make sure it is not deleted.
75 task_completed = false;
76 } 59 }
77 } 60 }
78 frame_generator_capturer_->InsertFrame(); 61 frame_generator_capturer_->InsertFrame();
79 // Task should be deleted only if it's not repeating. 62 // Task should be deleted only if it's not repeating.
80 return task_completed; 63 return repeat_interval_ms_ == 0;
81 } 64 }
82 65
83 webrtc::test::FrameGeneratorCapturer* const frame_generator_capturer_; 66 webrtc::test::FrameGeneratorCapturer* const frame_generator_capturer_;
84 const uint32_t repeat_interval_ms_; 67 const uint32_t repeat_interval_ms_;
85 int64_t intended_run_time_ms_; 68 int64_t intended_run_time_ms_;
86 }; 69 };
87 70
88 FrameGeneratorCapturer* FrameGeneratorCapturer::Create(int width, 71 FrameGeneratorCapturer* FrameGeneratorCapturer::Create(int width,
89 int height, 72 int height,
90 int target_fps, 73 int target_fps,
91 Clock* clock) { 74 Clock* clock) {
92 std::unique_ptr<FrameGeneratorCapturer> capturer(new FrameGeneratorCapturer( 75 FrameGeneratorCapturer* capturer = new FrameGeneratorCapturer(
93 clock, FrameGenerator::CreateSquareGenerator(width, height), target_fps)); 76 clock, FrameGenerator::CreateSquareGenerator(width, height), target_fps);
94 if (!capturer->Init()) 77 if (!capturer->Init()) {
95 return nullptr; 78 delete capturer;
79 return NULL;
80 }
96 81
97 return capturer.release(); 82 return capturer;
98 } 83 }
99 84
100 FrameGeneratorCapturer* FrameGeneratorCapturer::CreateFromYuvFile( 85 FrameGeneratorCapturer* FrameGeneratorCapturer::CreateFromYuvFile(
101 const std::string& file_name, 86 const std::string& file_name,
102 size_t width, 87 size_t width,
103 size_t height, 88 size_t height,
104 int target_fps, 89 int target_fps,
105 Clock* clock) { 90 Clock* clock) {
106 std::unique_ptr<FrameGeneratorCapturer> capturer(new FrameGeneratorCapturer( 91 FrameGeneratorCapturer* capturer = new FrameGeneratorCapturer(
107 clock, 92 clock, FrameGenerator::CreateFromYuvFile(
108 FrameGenerator::CreateFromYuvFile(std::vector<std::string>(1, file_name), 93 std::vector<std::string>(1, file_name), width, height, 1),
109 width, height, 1), 94 target_fps);
110 target_fps)); 95 if (!capturer->Init()) {
111 if (!capturer->Init()) 96 delete capturer;
112 return nullptr; 97 return NULL;
98 }
113 99
114 return capturer.release(); 100 return capturer;
115 } 101 }
116 102
117 FrameGeneratorCapturer::FrameGeneratorCapturer( 103 FrameGeneratorCapturer::FrameGeneratorCapturer(
118 Clock* clock, 104 Clock* clock,
119 std::unique_ptr<FrameGenerator> frame_generator, 105 std::unique_ptr<FrameGenerator> frame_generator,
120 int target_fps) 106 int target_fps)
121 : clock_(clock), 107 : clock_(clock),
122 sending_(false), 108 sending_(false),
123 sink_(nullptr), 109 sink_(nullptr),
124 sink_wants_observer_(nullptr), 110 sink_wants_observer_(nullptr),
(...skipping 11 matching lines...) Expand all
136 } 122 }
137 123
138 void FrameGeneratorCapturer::SetFakeRotation(VideoRotation rotation) { 124 void FrameGeneratorCapturer::SetFakeRotation(VideoRotation rotation) {
139 rtc::CritScope cs(&lock_); 125 rtc::CritScope cs(&lock_);
140 fake_rotation_ = rotation; 126 fake_rotation_ = rotation;
141 } 127 }
142 128
143 bool FrameGeneratorCapturer::Init() { 129 bool FrameGeneratorCapturer::Init() {
144 // This check is added because frame_generator_ might be file based and should 130 // This check is added because frame_generator_ might be file based and should
145 // not crash because a file moved. 131 // not crash because a file moved.
146 if (frame_generator_.get() == nullptr) 132 if (frame_generator_.get() == NULL)
147 return false; 133 return false;
148 134
149 int framerate_fps = GetCurrentConfiguredFramerate();
150 task_queue_.PostDelayedTask( 135 task_queue_.PostDelayedTask(
151 std::unique_ptr<rtc::QueuedTask>( 136 std::unique_ptr<rtc::QueuedTask>(
152 new InsertFrameTask(this, 1000 / framerate_fps)), 137 new InsertFrameTask(this, 1000 / target_fps_)),
153 1000 / framerate_fps); 138 1000 / target_fps_);
154 139
155 return true; 140 return true;
156 } 141 }
157 142
158 void FrameGeneratorCapturer::InsertFrame() { 143 void FrameGeneratorCapturer::InsertFrame() {
159 rtc::CritScope cs(&lock_); 144 {
160 if (sending_) { 145 rtc::CritScope cs(&lock_);
161 VideoFrame* frame = frame_generator_->NextFrame(); 146 if (sending_) {
162 frame->set_ntp_time_ms(clock_->CurrentNtpInMilliseconds()); 147 VideoFrame* frame = frame_generator_->NextFrame();
163 frame->set_rotation(fake_rotation_); 148 frame->set_ntp_time_ms(clock_->CurrentNtpInMilliseconds());
164 if (first_frame_capture_time_ == -1) { 149 frame->set_rotation(fake_rotation_);
165 first_frame_capture_time_ = frame->ntp_time_ms(); 150 if (first_frame_capture_time_ == -1) {
166 } 151 first_frame_capture_time_ = frame->ntp_time_ms();
167 152 }
168 if (sink_) { 153 if (sink_)
169 rtc::Optional<VideoFrame> out_frame = AdaptFrame(*frame); 154 sink_->OnFrame(*frame);
170 if (out_frame)
171 sink_->OnFrame(*out_frame);
172 } 155 }
173 } 156 }
174 } 157 }
175 158
176 void FrameGeneratorCapturer::Start() { 159 void FrameGeneratorCapturer::Start() {
177 rtc::CritScope cs(&lock_); 160 rtc::CritScope cs(&lock_);
178 sending_ = true; 161 sending_ = true;
179 } 162 }
180 163
181 void FrameGeneratorCapturer::Stop() { 164 void FrameGeneratorCapturer::Stop() {
(...skipping 13 matching lines...) Expand all
195 } 178 }
196 179
197 void FrameGeneratorCapturer::AddOrUpdateSink( 180 void FrameGeneratorCapturer::AddOrUpdateSink(
198 rtc::VideoSinkInterface<VideoFrame>* sink, 181 rtc::VideoSinkInterface<VideoFrame>* sink,
199 const rtc::VideoSinkWants& wants) { 182 const rtc::VideoSinkWants& wants) {
200 rtc::CritScope cs(&lock_); 183 rtc::CritScope cs(&lock_);
201 RTC_CHECK(!sink_ || sink_ == sink); 184 RTC_CHECK(!sink_ || sink_ == sink);
202 sink_ = sink; 185 sink_ = sink;
203 if (sink_wants_observer_) 186 if (sink_wants_observer_)
204 sink_wants_observer_->OnSinkWantsChanged(sink, wants); 187 sink_wants_observer_->OnSinkWantsChanged(sink, wants);
205
206 // Handle framerate within this class, just pass on resolution for possible
207 // adaptation.
208 rtc::VideoSinkWants resolution_wants = wants;
209 resolution_wants.max_framerate_fps = std::numeric_limits<int>::max();
210 VideoCapturer::AddOrUpdateSink(sink, resolution_wants);
211
212 // Ignore any requests for framerate higher than initially configured.
213 if (wants.max_framerate_fps < target_fps_) {
214 wanted_fps_.emplace(wants.max_framerate_fps);
215 } else {
216 wanted_fps_.reset();
217 }
218 } 188 }
219 189
220 void FrameGeneratorCapturer::RemoveSink( 190 void FrameGeneratorCapturer::RemoveSink(
221 rtc::VideoSinkInterface<VideoFrame>* sink) { 191 rtc::VideoSinkInterface<VideoFrame>* sink) {
222 rtc::CritScope cs(&lock_); 192 rtc::CritScope cs(&lock_);
223 RTC_CHECK(sink_ == sink); 193 RTC_CHECK(sink_ == sink);
224 sink_ = nullptr; 194 sink_ = nullptr;
225 } 195 }
226 196
227 void FrameGeneratorCapturer::ForceFrame() { 197 void FrameGeneratorCapturer::ForceFrame() {
228 // One-time non-repeating task, 198 // One-time non-repeating task,
229 // therefore repeat_interval_ms is 0 in InsertFrameTask() 199 // therefore repeat_interval_ms is 0 in InsertFrameTask()
230 task_queue_.PostTask( 200 task_queue_.PostTask(
231 std::unique_ptr<rtc::QueuedTask>(new InsertFrameTask(this, 0))); 201 std::unique_ptr<rtc::QueuedTask>(new InsertFrameTask(this, 0)));
232 } 202 }
233 203
234 int FrameGeneratorCapturer::GetCurrentConfiguredFramerate() {
235 rtc::CritScope cs(&lock_);
236 if (wanted_fps_ && *wanted_fps_ < target_fps_)
237 return *wanted_fps_;
238 return target_fps_;
239 }
240
241 } // namespace test 204 } // namespace test
242 } // namespace webrtc 205 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/test/frame_generator_capturer.h ('k') | webrtc/test/vcm_capturer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698