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

Side by Side Diff: content/renderer/media/video_track_adapter.cc

Issue 516783002: Drop back to back frames in VideoFrameResolutionAdapter::MaybeDropFrame. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed kMinTimeInMsBetweenFrames Created 6 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/media/video_track_adapter.h" 5 #include "content/renderer/media/video_track_adapter.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/debug/trace_event.h" 12 #include "base/debug/trace_event.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "media/base/video_util.h" 15 #include "media/base/video_util.h"
16 16
17 namespace content { 17 namespace content {
18 18
19 namespace { 19 namespace {
20 20
21 // Amount of frame intervals to wait before considering the source as muted, for 21 // Amount of frame intervals to wait before considering the source as muted, for
22 // the first frame and under normal conditions, respectively. First frame might 22 // the first frame and under normal conditions, respectively. First frame might
23 // take longer to arrive due to source startup. 23 // take longer to arrive due to source startup.
24 const float kFirstFrameTimeoutInFrameIntervals = 100.0f; 24 const float kFirstFrameTimeoutInFrameIntervals = 100.0f;
25 const float kNormalFrameTimeoutInFrameIntervals = 25.0f; 25 const float kNormalFrameTimeoutInFrameIntervals = 25.0f;
26 26
27 // Min delta time between two frames allowed without being dropped if a max
28 // frame rate is specified.
29 const int kMinTimeInMsBetweenFrames = 5;
30
27 // Empty method used for keeping a reference to the original media::VideoFrame 31 // Empty method used for keeping a reference to the original media::VideoFrame
28 // in VideoFrameResolutionAdapter::DeliverFrame if cropping is needed. 32 // in VideoFrameResolutionAdapter::DeliverFrame if cropping is needed.
29 // The reference to |frame| is kept in the closure that calls this method. 33 // The reference to |frame| is kept in the closure that calls this method.
30 void ReleaseOriginalFrame( 34 void ReleaseOriginalFrame(
31 const scoped_refptr<media::VideoFrame>& frame) { 35 const scoped_refptr<media::VideoFrame>& frame) {
32 } 36 }
33 37
34 void ResetCallbackOnMainRenderThread( 38 void ResetCallbackOnMainRenderThread(
35 scoped_ptr<VideoCaptureDeliverFrameCB> callback) { 39 scoped_ptr<VideoCaptureDeliverFrameCB> callback) {
36 // |callback| will be deleted when this exits. 40 // |callback| will be deleted when this exits.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 222 }
219 DoDeliverFrame(video_frame, format, estimated_capture_time); 223 DoDeliverFrame(video_frame, format, estimated_capture_time);
220 } 224 }
221 225
222 bool VideoTrackAdapter::VideoFrameResolutionAdapter::MaybeDropFrame( 226 bool VideoTrackAdapter::VideoFrameResolutionAdapter::MaybeDropFrame(
223 const scoped_refptr<media::VideoFrame>& frame) { 227 const scoped_refptr<media::VideoFrame>& frame) {
224 if (max_frame_rate_ == 0.0f) 228 if (max_frame_rate_ == 0.0f)
225 return false; 229 return false;
226 230
227 base::TimeDelta delta = frame->timestamp() - last_time_stamp_; 231 base::TimeDelta delta = frame->timestamp() - last_time_stamp_;
232 if (delta.InMilliseconds() < kMinTimeInMsBetweenFrames) {
233 // We have seen video frames being delivered from camera devices back to
234 // back. The simple AR filter for frame rate calculation is too short to
235 // handle that. Frames rendered back to back are not visible to the eye
236 // anyway so therefore instead dropped.
tommi (sloooow) - chröme 2014/08/28 09:01:39 To be fair, when this happens, the frames were ver
237 DVLOG(3) << "Drop frame since delta time since previous frame is "
238 << delta.InMilliseconds();
mcasas 2014/08/28 08:26:40 nit: add << "ms"; after delta.InMilliseconds()
239 return true;
240 }
228 last_time_stamp_ = frame->timestamp(); 241 last_time_stamp_ = frame->timestamp();
229 if (delta.ToInternalValue() == 0 || delta == last_time_stamp_) 242 if (delta == last_time_stamp_) // First received frame.
230 return false; 243 return false;
231 // Calculate the moving average frame rate. Use a simple filter with 0.1 244 // Calculate the frame rate using a simple AR filter.
232 // weight of the current sample. 245 // Use a simple filter with 0.1 weight of the current sample.
233 frame_rate_ = 100 / delta.InMillisecondsF() + 0.9 * frame_rate_; 246 frame_rate_ = 100 / delta.InMillisecondsF() + 0.9 * frame_rate_;
234 247
235 // Prefer to not drop frames. 248 // Prefer to not drop frames.
236 if (max_frame_rate_ + 0.5f > frame_rate_) 249 if (max_frame_rate_ + 0.5f > frame_rate_)
237 return false; // Keep this frame. 250 return false; // Keep this frame.
238 251
239 // The input frame rate is higher than requested. 252 // The input frame rate is higher than requested.
240 // Decide if we should keep this frame or drop it. 253 // Decide if we should keep this frame or drop it.
241 keep_frame_counter_ += max_frame_rate_ / frame_rate_; 254 keep_frame_counter_ += max_frame_rate_ / frame_rate_;
242 if (keep_frame_counter_ >= 1) { 255 if (keep_frame_counter_ >= 1) {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 // Rearm the monitoring while there are active Tracks, i.e. as long as the 449 // Rearm the monitoring while there are active Tracks, i.e. as long as the
437 // owner MediaStreamSource is active. 450 // owner MediaStreamSource is active.
438 io_message_loop_->PostDelayedTask(FROM_HERE, 451 io_message_loop_->PostDelayedTask(FROM_HERE,
439 base::Bind(&VideoTrackAdapter::CheckFramesReceivedOnIO, this, 452 base::Bind(&VideoTrackAdapter::CheckFramesReceivedOnIO, this,
440 set_muted_state_callback, frame_counter_), 453 set_muted_state_callback, frame_counter_),
441 base::TimeDelta::FromSecondsD(kNormalFrameTimeoutInFrameIntervals / 454 base::TimeDelta::FromSecondsD(kNormalFrameTimeoutInFrameIntervals /
442 source_frame_rate_)); 455 source_frame_rate_));
443 } 456 }
444 457
445 } // namespace content 458 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698