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

Side by Side Diff: media/capture/video/fake_video_capture_device.cc

Issue 1983193002: Decouple capture timestamp and reference time (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolve Comments Created 4 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/capture/video/fake_video_capture_device.h" 5 #include "media/capture/video/fake_video_capture_device.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 void FakeVideoCaptureDevice::CaptureUsingOwnBuffers( 172 void FakeVideoCaptureDevice::CaptureUsingOwnBuffers(
173 base::TimeTicks expected_execution_time) { 173 base::TimeTicks expected_execution_time) {
174 DCHECK(thread_checker_.CalledOnValidThread()); 174 DCHECK(thread_checker_.CalledOnValidThread());
175 const size_t frame_size = capture_format_.ImageAllocationSize(); 175 const size_t frame_size = capture_format_.ImageAllocationSize();
176 memset(fake_frame_.get(), 0, frame_size); 176 memset(fake_frame_.get(), 0, frame_size);
177 177
178 DrawPacman(false /* use_argb */, fake_frame_.get(), elapsed_time_, 178 DrawPacman(false /* use_argb */, fake_frame_.get(), elapsed_time_,
179 fake_capture_rate_, capture_format_.frame_size); 179 fake_capture_rate_, capture_format_.frame_size);
180 180
181 // Give the captured frame to the client. 181 // Give the captured frame to the client.
182 base::TimeTicks now = base::TimeTicks::Now();
183 if (first_ref_time_.is_null())
184 first_ref_time_ = now;
182 client_->OnIncomingCapturedData(fake_frame_.get(), frame_size, 185 client_->OnIncomingCapturedData(fake_frame_.get(), frame_size,
183 capture_format_, 0 /* rotation */, 186 capture_format_, 0 /* rotation */, now,
184 base::TimeTicks::Now()); 187 now - first_ref_time_);
185 BeepAndScheduleNextCapture( 188 BeepAndScheduleNextCapture(
186 expected_execution_time, 189 expected_execution_time,
187 base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers, 190 base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers,
188 weak_factory_.GetWeakPtr())); 191 weak_factory_.GetWeakPtr()));
189 } 192 }
190 193
191 void FakeVideoCaptureDevice::CaptureUsingClientBuffers( 194 void FakeVideoCaptureDevice::CaptureUsingClientBuffers(
192 base::TimeTicks expected_execution_time) { 195 base::TimeTicks expected_execution_time) {
193 DCHECK(thread_checker_.CalledOnValidThread()); 196 DCHECK(thread_checker_.CalledOnValidThread());
194 197
(...skipping 25 matching lines...) Expand all
220 } else { 223 } else {
221 DCHECK_EQ(capture_format_.pixel_storage, PIXEL_STORAGE_CPU); 224 DCHECK_EQ(capture_format_.pixel_storage, PIXEL_STORAGE_CPU);
222 DCHECK_EQ(capture_format_.pixel_format, PIXEL_FORMAT_ARGB); 225 DCHECK_EQ(capture_format_.pixel_format, PIXEL_FORMAT_ARGB);
223 uint8_t* data_ptr = static_cast<uint8_t*>(capture_buffer->data()); 226 uint8_t* data_ptr = static_cast<uint8_t*>(capture_buffer->data());
224 memset(data_ptr, 0, capture_buffer->mapped_size()); 227 memset(data_ptr, 0, capture_buffer->mapped_size());
225 DrawPacman(true /* use_argb */, data_ptr, elapsed_time_, fake_capture_rate_, 228 DrawPacman(true /* use_argb */, data_ptr, elapsed_time_, fake_capture_rate_,
226 capture_format_.frame_size); 229 capture_format_.frame_size);
227 } 230 }
228 231
229 // Give the captured frame to the client. 232 // Give the captured frame to the client.
233 base::TimeTicks now = base::TimeTicks::Now();
234 if (first_ref_time_.is_null())
235 first_ref_time_ = now;
230 client_->OnIncomingCapturedBuffer(std::move(capture_buffer), capture_format_, 236 client_->OnIncomingCapturedBuffer(std::move(capture_buffer), capture_format_,
231 base::TimeTicks::Now()); 237 now, now - first_ref_time_);
232 238
233 BeepAndScheduleNextCapture( 239 BeepAndScheduleNextCapture(
234 expected_execution_time, 240 expected_execution_time,
235 base::Bind(&FakeVideoCaptureDevice::CaptureUsingClientBuffers, 241 base::Bind(&FakeVideoCaptureDevice::CaptureUsingClientBuffers,
236 weak_factory_.GetWeakPtr())); 242 weak_factory_.GetWeakPtr()));
237 } 243 }
238 244
239 void FakeVideoCaptureDevice::BeepAndScheduleNextCapture( 245 void FakeVideoCaptureDevice::BeepAndScheduleNextCapture(
240 base::TimeTicks expected_execution_time, 246 base::TimeTicks expected_execution_time,
241 const base::Callback<void(base::TimeTicks)>& next_capture) { 247 const base::Callback<void(base::TimeTicks)>& next_capture) {
(...skipping 15 matching lines...) Expand all
257 // Don't accumulate any debt if we are lagging behind - just post the next 263 // Don't accumulate any debt if we are lagging behind - just post the next
258 // frame immediately and continue as normal. 264 // frame immediately and continue as normal.
259 const base::TimeTicks next_execution_time = 265 const base::TimeTicks next_execution_time =
260 std::max(current_time, expected_execution_time + frame_interval); 266 std::max(current_time, expected_execution_time + frame_interval);
261 const base::TimeDelta delay = next_execution_time - current_time; 267 const base::TimeDelta delay = next_execution_time - current_time;
262 base::MessageLoop::current()->PostDelayedTask( 268 base::MessageLoop::current()->PostDelayedTask(
263 FROM_HERE, base::Bind(next_capture, next_execution_time), delay); 269 FROM_HERE, base::Bind(next_capture, next_execution_time), delay);
264 } 270 }
265 271
266 } // namespace media 272 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/fake_video_capture_device.h ('k') | media/capture/video/fake_video_capture_device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698