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

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

Issue 1162903004: FileVideoCaptureDevice: Regulate framerate without drifting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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/file_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/file_video_capture_device.cc
diff --git a/media/video/capture/file_video_capture_device.cc b/media/video/capture/file_video_capture_device.cc
index 5584c0b20931b0d8ae10e23600627a838154cafd..5a45b4a065cb7f82a79a7c1999d8465834bd8af7 100644
--- a/media/video/capture/file_video_capture_device.cc
+++ b/media/video/capture/file_video_capture_device.cc
@@ -210,6 +210,7 @@ void FileVideoCaptureDevice::OnStopAndDeAllocate() {
current_byte_index_ = 0;
first_frame_byte_index_ = 0;
frame_size_ = 0;
+ next_frame_time_ = base::TimeTicks();
video_frame_.reset();
}
@@ -217,7 +218,6 @@ void FileVideoCaptureDevice::OnCaptureTask() {
DCHECK_EQ(capture_thread_.message_loop(), base::MessageLoop::current());
if (!client_)
return;
- const base::TimeTicks timestamp_before_reading = base::TimeTicks::Now();
int result = file_.Read(current_byte_index_,
reinterpret_cast<char*>(video_frame_.get()),
frame_size_);
@@ -236,25 +236,25 @@ void FileVideoCaptureDevice::OnCaptureTask() {
}
// Give the captured frame to the client.
+ const base::TimeTicks current_time = base::TimeTicks::Now();
client_->OnIncomingCapturedData(video_frame_.get(),
frame_size_,
capture_format_,
0,
- base::TimeTicks::Now());
+ current_time);
// Reschedule next CaptureTask.
const base::TimeDelta frame_interval =
base::TimeDelta::FromMicroseconds(1E6 / capture_format_.frame_rate);
- base::TimeDelta next_on_capture_timedelta = frame_interval -
- (base::TimeTicks::Now() - timestamp_before_reading);
- if (next_on_capture_timedelta.InMilliseconds() < 0) {
- DLOG(WARNING) << "Frame reading took longer than the frame interval.";
- next_on_capture_timedelta = frame_interval;
+ if (next_frame_time_.is_null()) {
+ next_frame_time_ = current_time + frame_interval;
+ } else {
+ next_frame_time_ += frame_interval;
}
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&FileVideoCaptureDevice::OnCaptureTask,
base::Unretained(this)),
- next_on_capture_timedelta);
+ next_frame_time_ - current_time);
}
} // namespace media
« no previous file with comments | « media/video/capture/file_video_capture_device.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698