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 |