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 #ifndef MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_ | 5 #ifndef MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_ |
6 #define MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_ | 6 #define MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_ |
7 | 7 |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 // | 47 // |
48 // VideoFrameCompositor must live on the same thread as the compositor, though | 48 // VideoFrameCompositor must live on the same thread as the compositor, though |
49 // it may be constructed on any thread. | 49 // it may be constructed on any thread. |
50 class MEDIA_BLINK_EXPORT VideoFrameCompositor | 50 class MEDIA_BLINK_EXPORT VideoFrameCompositor |
51 : public VideoRendererSink, | 51 : public VideoRendererSink, |
52 NON_EXPORTED_BASE(public cc::VideoFrameProvider) { | 52 NON_EXPORTED_BASE(public cc::VideoFrameProvider) { |
53 public: | 53 public: |
54 // |compositor_task_runner| is the task runner on which this class will live, | 54 // |compositor_task_runner| is the task runner on which this class will live, |
55 // though it may be constructed on any thread. | 55 // though it may be constructed on any thread. |
56 // | 56 // |
57 // |natural_size_changed_cb| is run with the new natural size of the video | |
58 // frame whenever a change in natural size is detected. It is not called the | |
59 // first time UpdateCurrentFrame() is called. Run on the same thread as the | |
60 // caller of UpdateCurrentFrame(). | |
61 // | |
62 // |opacity_changed_cb| is run when a change in opacity is detected. It *is* | 57 // |opacity_changed_cb| is run when a change in opacity is detected. It *is* |
63 // called the first time UpdateCurrentFrame() is called. Run on the same | 58 // called the first time UpdateCurrentFrame() is called. Run on the same |
64 // thread as the caller of UpdateCurrentFrame(). | 59 // thread as the caller of UpdateCurrentFrame(). |
65 // | |
66 // TODO(dalecurtis): Investigate the inconsistency between the callbacks with | |
67 // respect to why we don't call |natural_size_changed_cb| on the first frame. | |
68 // I suspect it was for historical reasons that no longer make sense. | |
69 VideoFrameCompositor( | 60 VideoFrameCompositor( |
70 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, | 61 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, |
71 const base::Callback<void(gfx::Size)>& natural_size_changed_cb, | |
72 const base::Callback<void(bool)>& opacity_changed_cb); | 62 const base::Callback<void(bool)>& opacity_changed_cb); |
xhwang
2016/04/12 19:40:37
(not for this CL) Maybe we should move the opacity
alokp
2016/04/19 00:16:07
yeah - I plan to do that in a followup patch.
| |
73 | 63 |
74 // Destruction must happen on the compositor thread; Stop() must have been | 64 // Destruction must happen on the compositor thread; Stop() must have been |
75 // called before destruction starts. | 65 // called before destruction starts. |
76 ~VideoFrameCompositor() override; | 66 ~VideoFrameCompositor() override; |
77 | 67 |
78 // cc::VideoFrameProvider implementation. These methods must be called on the | 68 // cc::VideoFrameProvider implementation. These methods must be called on the |
79 // |compositor_task_runner_|. | 69 // |compositor_task_runner_|. |
80 void SetVideoFrameProviderClient( | 70 void SetVideoFrameProviderClient( |
81 cc::VideoFrameProvider::Client* client) override; | 71 cc::VideoFrameProvider::Client* client) override; |
82 bool UpdateCurrentFrame(base::TimeTicks deadline_min, | 72 bool UpdateCurrentFrame(base::TimeTicks deadline_min, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 // rendering call issues when a sink is started. | 113 // rendering call issues when a sink is started. |
124 void set_background_rendering_for_testing(bool enabled) { | 114 void set_background_rendering_for_testing(bool enabled) { |
125 background_rendering_enabled_ = enabled; | 115 background_rendering_enabled_ = enabled; |
126 } | 116 } |
127 | 117 |
128 private: | 118 private: |
129 // Called on the compositor thread in response to Start() or Stop() calls; | 119 // Called on the compositor thread in response to Start() or Stop() calls; |
130 // must be used to change |rendering_| state. | 120 // must be used to change |rendering_| state. |
131 void OnRendererStateUpdate(bool new_state); | 121 void OnRendererStateUpdate(bool new_state); |
132 | 122 |
133 // Handles setting of |current_frame_| and fires |natural_size_changed_cb_| | 123 // Handles setting of |current_frame_| and fires |
134 // and |opacity_changed_cb_| when the frame properties changes. | 124 // |opacity_changed_cb_| when the frame properties changes. |
xhwang
2016/04/12 19:40:37
nit: reformat
alokp
2016/04/19 00:16:07
Done.
| |
135 bool ProcessNewFrame(const scoped_refptr<VideoFrame>& frame); | 125 bool ProcessNewFrame(const scoped_refptr<VideoFrame>& frame); |
136 | 126 |
137 // Called by |background_rendering_timer_| when enough time elapses where we | 127 // Called by |background_rendering_timer_| when enough time elapses where we |
138 // haven't seen a Render() call. | 128 // haven't seen a Render() call. |
139 void BackgroundRender(); | 129 void BackgroundRender(); |
140 | 130 |
141 // If |callback_| is available, calls Render() with the provided properties. | 131 // If |callback_| is available, calls Render() with the provided properties. |
142 // Updates |is_background_rendering_|, |last_interval_|, and resets | 132 // Updates |is_background_rendering_|, |last_interval_|, and resets |
143 // |background_rendering_timer_|. Ensures that natural size and opacity | 133 // |background_rendering_timer_|. Ensures that opacity |
144 // changes are correctly fired. Returns true if there's a new frame available | 134 // changes are correctly fired. Returns true if there's a new frame available |
145 // via GetCurrentFrame(). | 135 // via GetCurrentFrame(). |
146 bool CallRender(base::TimeTicks deadline_min, | 136 bool CallRender(base::TimeTicks deadline_min, |
147 base::TimeTicks deadline_max, | 137 base::TimeTicks deadline_max, |
148 bool background_rendering); | 138 bool background_rendering); |
149 | 139 |
150 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 140 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
151 scoped_ptr<base::TickClock> tick_clock_; | 141 scoped_ptr<base::TickClock> tick_clock_; |
152 | 142 |
153 // These callbacks are executed on the compositor thread. | 143 // These callbacks are executed on the compositor thread. |
xhwang
2016/04/12 19:40:37
nit: update this comment
alokp
2016/04/19 00:16:07
Done.
| |
154 const base::Callback<void(gfx::Size)> natural_size_changed_cb_; | |
155 const base::Callback<void(bool)> opacity_changed_cb_; | 144 const base::Callback<void(bool)> opacity_changed_cb_; |
156 | 145 |
157 // Allows tests to disable the background rendering task. | 146 // Allows tests to disable the background rendering task. |
158 bool background_rendering_enabled_; | 147 bool background_rendering_enabled_; |
159 | 148 |
160 // Manages UpdateCurrentFrame() callbacks if |client_| has stopped sending | 149 // Manages UpdateCurrentFrame() callbacks if |client_| has stopped sending |
161 // them for various reasons. Runs on |compositor_task_runner_| and is reset | 150 // them for various reasons. Runs on |compositor_task_runner_| and is reset |
162 // after each successful UpdateCurrentFrame() call. | 151 // after each successful UpdateCurrentFrame() call. |
163 base::Timer background_rendering_timer_; | 152 base::Timer background_rendering_timer_; |
164 | 153 |
(...skipping 13 matching lines...) Expand all Loading... | |
178 // These values are updated and read from the media and compositor threads. | 167 // These values are updated and read from the media and compositor threads. |
179 base::Lock callback_lock_; | 168 base::Lock callback_lock_; |
180 VideoRendererSink::RenderCallback* callback_; | 169 VideoRendererSink::RenderCallback* callback_; |
181 | 170 |
182 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositor); | 171 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositor); |
183 }; | 172 }; |
184 | 173 |
185 } // namespace media | 174 } // namespace media |
186 | 175 |
187 #endif // MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_ | 176 #endif // MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_ |
OLD | NEW |