Commit 2924f310 authored by perkj's avatar perkj Committed by Commit bot

Drop back to back frames in VideoFrameResolutionAdapter::MaybeDropFrame.

We have observed on some Mac that video frames are delivered back to back from the build in video capture device. This can potentially happen on all platforms. If that happen, the simple filter used for frame rate calculation get scewed. This cl fix that by dropping all frames received within 5ms of the previous frame.

BUG=394315

Review URL: https://codereview.chromium.org/516783002

Cr-Commit-Position: refs/heads/master@{#292361}
parent 53b6e7a7
...@@ -24,6 +24,10 @@ namespace { ...@@ -24,6 +24,10 @@ namespace {
const float kFirstFrameTimeoutInFrameIntervals = 100.0f; const float kFirstFrameTimeoutInFrameIntervals = 100.0f;
const float kNormalFrameTimeoutInFrameIntervals = 25.0f; const float kNormalFrameTimeoutInFrameIntervals = 25.0f;
// Min delta time between two frames allowed without being dropped if a max
// frame rate is specified.
const int kMinTimeInMsBetweenFrames = 5;
// Empty method used for keeping a reference to the original media::VideoFrame // Empty method used for keeping a reference to the original media::VideoFrame
// in VideoFrameResolutionAdapter::DeliverFrame if cropping is needed. // in VideoFrameResolutionAdapter::DeliverFrame if cropping is needed.
// The reference to |frame| is kept in the closure that calls this method. // The reference to |frame| is kept in the closure that calls this method.
...@@ -225,11 +229,24 @@ bool VideoTrackAdapter::VideoFrameResolutionAdapter::MaybeDropFrame( ...@@ -225,11 +229,24 @@ bool VideoTrackAdapter::VideoFrameResolutionAdapter::MaybeDropFrame(
return false; return false;
base::TimeDelta delta = frame->timestamp() - last_time_stamp_; base::TimeDelta delta = frame->timestamp() - last_time_stamp_;
if (delta.InMilliseconds() < kMinTimeInMsBetweenFrames) {
// We have seen video frames being delivered from camera devices back to
// back. The simple AR filter for frame rate calculation is too short to
// handle that. http://crbug/394315
// TODO(perkj): Can we come up with a way to fix the times stamps and the
// timing when frames are delivered so all frames can be used?
// The time stamps are generated by Chrome and not the actual device.
// Most likely the back to back problem is caused by software and not the
// actual camera.
DVLOG(3) << "Drop frame since delta time since previous frame is "
<< delta.InMilliseconds() << "ms.";
return true;
}
last_time_stamp_ = frame->timestamp(); last_time_stamp_ = frame->timestamp();
if (delta.ToInternalValue() == 0 || delta == last_time_stamp_) if (delta == last_time_stamp_) // First received frame.
return false; return false;
// Calculate the moving average frame rate. Use a simple filter with 0.1 // Calculate the frame rate using a simple AR filter.
// weight of the current sample. // Use a simple filter with 0.1 weight of the current sample.
frame_rate_ = 100 / delta.InMillisecondsF() + 0.9 * frame_rate_; frame_rate_ = 100 / delta.InMillisecondsF() + 0.9 * frame_rate_;
// Prefer to not drop frames. // Prefer to not drop frames.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment