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

Unified Diff: media/video/capture/fake_video_capture_device.cc

Issue 1153713006: FakeVideoCaptureDevice: Regulate framerate without drifting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/video/capture/fake_video_capture_device.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/video/capture/fake_video_capture_device.cc
diff --git a/media/video/capture/fake_video_capture_device.cc b/media/video/capture/fake_video_capture_device.cc
index 12a8a3054523ce9510f85653b19dabc7e8d32cff..902a8d07a0b7e004f857ab20fe445bab9c899a28 100644
--- a/media/video/capture/fake_video_capture_device.cc
+++ b/media/video/capture/fake_video_capture_device.cc
@@ -123,6 +123,7 @@ void FakeVideoCaptureDevice::AllocateAndStart(
void FakeVideoCaptureDevice::StopAndDeAllocate() {
DCHECK(thread_checker_.CalledOnValidThread());
+ next_frame_time_ = base::TimeTicks();
client_.reset();
}
@@ -202,8 +203,20 @@ void FakeVideoCaptureDevice::BeepAndScheduleNextCapture(
FakeAudioInputStream::BeepOnce();
// Reschedule next CaptureTask.
- base::MessageLoop::current()->PostDelayedTask(FROM_HERE, next_capture,
- base::TimeDelta::FromMilliseconds(kFakeCapturePeriodMs));
+ const base::TimeTicks current_time = base::TimeTicks::Now();
+ const base::TimeDelta frame_interval =
+ base::TimeDelta::FromMilliseconds(kFakeCapturePeriodMs);
+ if (next_frame_time_.is_null()) {
mcasas 2015/06/08 17:30:35 I'm not super happy with l.209, it feels like we'l
+ next_frame_time_ = current_time + frame_interval;
+ } else {
+ next_frame_time_ += frame_interval;
+ // Don't accumulate any debt if we are lagging behind - just post the next
+ // frame immediately and continue as normal.
+ if (next_frame_time_ < current_time)
+ next_frame_time_ = current_time;
+ }
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE, next_capture, next_frame_time_ - current_time);
}
} // namespace media
« no previous file with comments | « media/video/capture/fake_video_capture_device.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698