OLD | NEW |
---|---|
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_frame_compositor.h" | 5 #include "content/renderer/media/video_frame_compositor.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "cc/layers/video_frame_provider.h" | 10 #include "cc/layers/video_frame_provider.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 } | 31 } |
32 | 32 |
33 void DeleteSoon() { | 33 void DeleteSoon() { |
34 compositor_task_runner_->DeleteSoon(FROM_HERE, this); | 34 compositor_task_runner_->DeleteSoon(FROM_HERE, this); |
35 } | 35 } |
36 | 36 |
37 void UpdateCurrentFrame(const scoped_refptr<media::VideoFrame>& frame) { | 37 void UpdateCurrentFrame(const scoped_refptr<media::VideoFrame>& frame) { |
38 base::AutoLock auto_lock(lock_); | 38 base::AutoLock auto_lock(lock_); |
39 | 39 |
40 // Count frames as dropped if and only if we updated the frame but didn't | 40 // Count frames as dropped if and only if we updated the frame but didn't |
41 // finish notifying the compositor nor managed to composite the current | 41 // finish notifying the compositor for the previous frame. |
42 // frame. | 42 if (!compositor_notify_finished_ && |
43 if (!current_frame_composited_ && !compositor_notify_finished_ && | |
44 frames_dropped_before_composite_ < kuint32max) { | 43 frames_dropped_before_composite_ < kuint32max) { |
45 ++frames_dropped_before_composite_; | 44 ++frames_dropped_before_composite_; |
46 } | 45 } |
xhwang
2014/03/27 21:28:59
Merge this to l.54-55? e.g.
if (!compositor_notif
scherkus (not reviewing)
2014/03/29 00:34:14
Done.
| |
47 | 46 |
48 if (current_frame_ && | 47 if (current_frame_ && |
49 current_frame_->natural_size() != frame->natural_size()) { | 48 current_frame_->natural_size() != frame->natural_size()) { |
50 natural_size_changed_cb_.Run(frame->natural_size()); | 49 natural_size_changed_cb_.Run(frame->natural_size()); |
51 } | 50 } |
52 | 51 |
53 current_frame_ = frame; | 52 current_frame_ = frame; |
54 current_frame_composited_ = false; | 53 |
54 if (!compositor_notify_finished_) | |
xhwang
2014/03/27 21:28:59
Since we check the negative, how about renaming it
scherkus (not reviewing)
2014/03/29 00:34:14
Done.
| |
55 return; | |
xhwang
2014/03/27 21:28:59
OOC, what's the chance for this to happen? It seem
scherkus (not reviewing)
2014/03/29 00:34:14
to be honest I'm not 100% sure
I've definitely lo
| |
55 | 56 |
56 compositor_notify_finished_ = false; | 57 compositor_notify_finished_ = false; |
57 compositor_task_runner_->PostTask( | 58 compositor_task_runner_->PostTask( |
58 FROM_HERE, | 59 FROM_HERE, |
59 base::Bind(&Internal::NotifyCompositorOfNewFrame, | 60 base::Bind(&Internal::NotifyCompositorOfNewFrame, |
60 base::Unretained(this))); | 61 base::Unretained(this))); |
61 } | 62 } |
62 | 63 |
63 // If |frame_being_composited| is true the current frame will not be counted | |
64 // as being dropped the next time UpdateCurrentFrame() is called. | |
65 scoped_refptr<media::VideoFrame> GetCurrentFrame( | |
66 bool frame_being_composited) { | |
67 base::AutoLock auto_lock(lock_); | |
68 if (frame_being_composited) | |
69 current_frame_composited_ = false; | |
scherkus (not reviewing)
2014/03/27 20:58:22
this was a bug ... but unittests didn't catch it b
dshwang
2014/03/27 21:17:01
I couldn't understand.
It is possible that VideoLa
scherkus (not reviewing)
2014/03/29 00:34:14
the original intent was to increment dropped frame
| |
70 return current_frame_; | |
71 } | |
72 | |
73 uint32 GetFramesDroppedBeforeComposite() { | 64 uint32 GetFramesDroppedBeforeComposite() { |
74 base::AutoLock auto_lock(lock_); | 65 base::AutoLock auto_lock(lock_); |
75 return frames_dropped_before_composite_; | 66 return frames_dropped_before_composite_; |
76 } | 67 } |
77 | 68 |
78 void SetFramesDroppedBeforeCompositeForTesting(uint32 dropped_frames) { | 69 void SetFramesDroppedBeforeCompositeForTesting(uint32 dropped_frames) { |
79 base::AutoLock auto_lock(lock_); | 70 base::AutoLock auto_lock(lock_); |
80 frames_dropped_before_composite_ = dropped_frames; | 71 frames_dropped_before_composite_ = dropped_frames; |
81 } | 72 } |
82 | 73 |
83 private: | |
84 void NotifyCompositorOfNewFrame() { | |
85 base::AutoLock auto_lock(lock_); | |
86 compositor_notify_finished_ = true; | |
87 if (client_) | |
88 client_->DidReceiveFrame(); | |
89 } | |
90 | |
91 // cc::VideoFrameProvider implementation. | 74 // cc::VideoFrameProvider implementation. |
92 virtual void SetVideoFrameProviderClient( | 75 virtual void SetVideoFrameProviderClient( |
xhwang
2014/03/27 21:28:59
Now we are making this public, anything changed?
scherkus (not reviewing)
2014/03/29 00:34:14
nope -- it was mostly motivated by being able to c
| |
93 cc::VideoFrameProvider::Client* client) OVERRIDE { | 76 cc::VideoFrameProvider::Client* client) OVERRIDE { |
94 if (client_) | 77 if (client_) |
95 client_->StopUsingProvider(); | 78 client_->StopUsingProvider(); |
96 client_ = client; | 79 client_ = client; |
97 } | 80 } |
98 | 81 |
99 virtual scoped_refptr<media::VideoFrame> GetCurrentFrame() OVERRIDE { | 82 virtual scoped_refptr<media::VideoFrame> GetCurrentFrame() OVERRIDE { |
100 return GetCurrentFrame(true); | 83 base::AutoLock auto_lock(lock_); |
84 return current_frame_; | |
101 } | 85 } |
102 | 86 |
103 virtual void PutCurrentFrame(const scoped_refptr<media::VideoFrame>& frame) | 87 virtual void PutCurrentFrame(const scoped_refptr<media::VideoFrame>& frame) |
104 OVERRIDE {} | 88 OVERRIDE {} |
105 | 89 |
90 private: | |
91 void NotifyCompositorOfNewFrame() { | |
92 base::AutoLock auto_lock(lock_); | |
93 compositor_notify_finished_ = true; | |
94 if (client_) | |
95 client_->DidReceiveFrame(); | |
96 } | |
97 | |
106 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 98 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
107 base::Callback<void(gfx::Size)>natural_size_changed_cb_; | 99 base::Callback<void(gfx::Size)>natural_size_changed_cb_; |
108 | 100 |
109 cc::VideoFrameProvider::Client* client_; | 101 cc::VideoFrameProvider::Client* client_; |
110 | 102 |
111 base::Lock lock_; | 103 base::Lock lock_; |
112 scoped_refptr<media::VideoFrame> current_frame_; | 104 scoped_refptr<media::VideoFrame> current_frame_; |
113 bool compositor_notify_finished_; | 105 bool compositor_notify_finished_; |
114 bool current_frame_composited_; | 106 bool current_frame_composited_; |
115 uint32 frames_dropped_before_composite_; | 107 uint32 frames_dropped_before_composite_; |
(...skipping 14 matching lines...) Expand all Loading... | |
130 cc::VideoFrameProvider* VideoFrameCompositor::GetVideoFrameProvider() { | 122 cc::VideoFrameProvider* VideoFrameCompositor::GetVideoFrameProvider() { |
131 return internal_; | 123 return internal_; |
132 } | 124 } |
133 | 125 |
134 void VideoFrameCompositor::UpdateCurrentFrame( | 126 void VideoFrameCompositor::UpdateCurrentFrame( |
135 const scoped_refptr<media::VideoFrame>& frame) { | 127 const scoped_refptr<media::VideoFrame>& frame) { |
136 internal_->UpdateCurrentFrame(frame); | 128 internal_->UpdateCurrentFrame(frame); |
137 } | 129 } |
138 | 130 |
139 scoped_refptr<media::VideoFrame> VideoFrameCompositor::GetCurrentFrame() { | 131 scoped_refptr<media::VideoFrame> VideoFrameCompositor::GetCurrentFrame() { |
140 return internal_->GetCurrentFrame(false); | 132 return internal_->GetCurrentFrame(); |
141 } | 133 } |
142 | 134 |
143 uint32 VideoFrameCompositor::GetFramesDroppedBeforeComposite() { | 135 uint32 VideoFrameCompositor::GetFramesDroppedBeforeComposite() { |
144 return internal_->GetFramesDroppedBeforeComposite(); | 136 return internal_->GetFramesDroppedBeforeComposite(); |
145 } | 137 } |
146 | 138 |
147 void VideoFrameCompositor::SetFramesDroppedBeforeCompositeForTesting( | 139 void VideoFrameCompositor::SetFramesDroppedBeforeCompositeForTesting( |
148 uint32 dropped_frames) { | 140 uint32 dropped_frames) { |
149 internal_->SetFramesDroppedBeforeCompositeForTesting(dropped_frames); | 141 internal_->SetFramesDroppedBeforeCompositeForTesting(dropped_frames); |
150 } | 142 } |
151 | 143 |
152 } // namespace content | 144 } // namespace content |
OLD | NEW |