Cast: Skip receiver log messages with time delta that can't be encoded.
[chromium-blink-merge.git] / media / filters / video_frame_painter.cc
blob6da252170a221badc26ddfae257f327cb7432e2a
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
3 // found in the LICENSE file.
5 #include "media/filters/video_frame_painter.h"
7 #include "media/base/video_frame.h"
9 namespace media {
11 VideoFramePainter::VideoFramePainter(
12 const base::Closure& invalidate_cb,
13 const base::Callback<void(gfx::Size)>& natural_size_changed_cb)
14 : invalidate_cb_(invalidate_cb),
15 natural_size_changed_cb_(natural_size_changed_cb),
16 invalidation_finished_(true),
17 current_frame_painted_(false),
18 frames_dropped_before_paint_(0) {}
20 VideoFramePainter::~VideoFramePainter() {}
22 void VideoFramePainter::UpdateCurrentFrame(
23 const scoped_refptr<VideoFrame>& frame) {
24 base::AutoLock auto_lock(lock_);
26 // Count frames as dropped if and only if we updated the frame but didn't
27 // finish invalidating nor managed to paint the current frame.
28 if (!current_frame_painted_ && !invalidation_finished_ &&
29 frames_dropped_before_paint_ < kuint32max) {
30 ++frames_dropped_before_paint_;
33 if (current_frame_ &&
34 current_frame_->natural_size() != frame->natural_size()) {
35 natural_size_changed_cb_.Run(frame->natural_size());
38 current_frame_ = frame;
39 current_frame_painted_ = false;
41 if (!invalidation_finished_)
42 return;
44 invalidation_finished_ = false;
45 invalidate_cb_.Run();
48 scoped_refptr<VideoFrame> VideoFramePainter::GetCurrentFrame(
49 bool frame_being_painted) {
50 base::AutoLock auto_lock(lock_);
51 if (frame_being_painted)
52 current_frame_painted_ = true;
54 return current_frame_;
57 void VideoFramePainter::DidFinishInvalidating() {
58 base::AutoLock auto_lock(lock_);
59 invalidation_finished_ = true;
62 uint32 VideoFramePainter::GetFramesDroppedBeforePaint() {
63 base::AutoLock auto_lock(lock_);
64 return frames_dropped_before_paint_;
67 void VideoFramePainter::SetFramesDroppedBeforePaintForTesting(
68 uint32 dropped_frames) {
69 base::AutoLock auto_lock(lock_);
70 frames_dropped_before_paint_ = dropped_frames;
73 } // namespace media