summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPer <perkj@google.com>2014-09-02 12:55:27 +0200
committerPer <perkj@google.com>2014-09-02 11:01:11 +0000
commit7206eb6036df6405e721d690c86093a9c2fbd004 (patch)
tree748396480d348a9f37772100cc21366ce5d232ca
parent31b5d07934158910dbb575fe365e335e8a6a28ee (diff)
downloadchromium_src-7206eb6036df6405e721d690c86093a9c2fbd004.zip
chromium_src-7206eb6036df6405e721d690c86093a9c2fbd004.tar.gz
chromium_src-7206eb6036df6405e721d690c86093a9c2fbd004.tar.bz2
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} (cherry picked from commit 2924f310947b5a091390a6c06b37f7796bee47e7) Review URL: https://codereview.chromium.org/534523002 Cr-Commit-Position: refs/branch-heads/2125@{#169} Cr-Branched-From: b68026d94bda36dd106a3d91a098719f952a9477-refs/heads/master@{#290040}
-rw-r--r--content/renderer/media/video_track_adapter.cc23
1 files changed, 20 insertions, 3 deletions
diff --git a/content/renderer/media/video_track_adapter.cc b/content/renderer/media/video_track_adapter.cc
index 9a9ab08..5281d63d 100644
--- a/content/renderer/media/video_track_adapter.cc
+++ b/content/renderer/media/video_track_adapter.cc
@@ -24,6 +24,10 @@ namespace {
const float kFirstFrameTimeoutInFrameIntervals = 100.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
// in VideoFrameResolutionAdapter::DeliverFrame if cropping is needed.
// The reference to |frame| is kept in the closure that calls this method.
@@ -225,11 +229,24 @@ bool VideoTrackAdapter::VideoFrameResolutionAdapter::MaybeDropFrame(
return false;
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();
- if (delta.ToInternalValue() == 0 || delta == last_time_stamp_)
+ if (delta == last_time_stamp_) // First received frame.
return false;
- // Calculate the moving average frame rate. Use a simple filter with 0.1
- // weight of the current sample.
+ // Calculate the frame rate using a simple AR filter.
+ // Use a simple filter with 0.1 weight of the current sample.
frame_rate_ = 100 / delta.InMillisecondsF() + 0.9 * frame_rate_;
// Prefer to not drop frames.