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 // | 60 // TODO(alokp): Move |opacity_changed_cb| to Renderer. |
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( | 61 VideoFrameCompositor( |
70 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, | 62 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); | 63 const base::Callback<void(bool)>& opacity_changed_cb); |
73 | 64 |
74 // Destruction must happen on the compositor thread; Stop() must have been | 65 // Destruction must happen on the compositor thread; Stop() must have been |
75 // called before destruction starts. | 66 // called before destruction starts. |
76 ~VideoFrameCompositor() override; | 67 ~VideoFrameCompositor() override; |
77 | 68 |
78 // cc::VideoFrameProvider implementation. These methods must be called on the | 69 // cc::VideoFrameProvider implementation. These methods must be called on the |
79 // |compositor_task_runner_|. | 70 // |compositor_task_runner_|. |
80 void SetVideoFrameProviderClient( | 71 void SetVideoFrameProviderClient( |
81 cc::VideoFrameProvider::Client* client) override; | 72 cc::VideoFrameProvider::Client* client) override; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // rendering call issues when a sink is started. | 114 // rendering call issues when a sink is started. |
124 void set_background_rendering_for_testing(bool enabled) { | 115 void set_background_rendering_for_testing(bool enabled) { |
125 background_rendering_enabled_ = enabled; | 116 background_rendering_enabled_ = enabled; |
126 } | 117 } |
127 | 118 |
128 private: | 119 private: |
129 // Called on the compositor thread in response to Start() or Stop() calls; | 120 // Called on the compositor thread in response to Start() or Stop() calls; |
130 // must be used to change |rendering_| state. | 121 // must be used to change |rendering_| state. |
131 void OnRendererStateUpdate(bool new_state); | 122 void OnRendererStateUpdate(bool new_state); |
132 | 123 |
133 // Handles setting of |current_frame_| and fires |natural_size_changed_cb_| | 124 // Handles setting of |current_frame_| and fires |opacity_changed_cb_| |
134 // and |opacity_changed_cb_| when the frame properties changes. | 125 // when the frame properties changes. |
135 bool ProcessNewFrame(const scoped_refptr<VideoFrame>& frame); | 126 bool ProcessNewFrame(const scoped_refptr<VideoFrame>& frame); |
136 | 127 |
137 // Called by |background_rendering_timer_| when enough time elapses where we | 128 // Called by |background_rendering_timer_| when enough time elapses where we |
138 // haven't seen a Render() call. | 129 // haven't seen a Render() call. |
139 void BackgroundRender(); | 130 void BackgroundRender(); |
140 | 131 |
141 // If |callback_| is available, calls Render() with the provided properties. | 132 // If |callback_| is available, calls Render() with the provided properties. |
142 // Updates |is_background_rendering_|, |last_interval_|, and resets | 133 // Updates |is_background_rendering_|, |last_interval_|, and resets |
143 // |background_rendering_timer_|. Ensures that natural size and opacity | 134 // |background_rendering_timer_|. Ensures that opacity |
144 // changes are correctly fired. Returns true if there's a new frame available | 135 // changes are correctly fired. Returns true if there's a new frame available |
145 // via GetCurrentFrame(). | 136 // via GetCurrentFrame(). |
146 bool CallRender(base::TimeTicks deadline_min, | 137 bool CallRender(base::TimeTicks deadline_min, |
147 base::TimeTicks deadline_max, | 138 base::TimeTicks deadline_max, |
148 bool background_rendering); | 139 bool background_rendering); |
149 | 140 |
150 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 141 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
151 scoped_ptr<base::TickClock> tick_clock_; | 142 scoped_ptr<base::TickClock> tick_clock_; |
152 | 143 |
153 // These callbacks are executed on the compositor thread. | 144 // This callback is executed on the compositor thread. |
154 const base::Callback<void(gfx::Size)> natural_size_changed_cb_; | |
155 const base::Callback<void(bool)> opacity_changed_cb_; | 145 const base::Callback<void(bool)> opacity_changed_cb_; |
156 | 146 |
157 // Allows tests to disable the background rendering task. | 147 // Allows tests to disable the background rendering task. |
158 bool background_rendering_enabled_; | 148 bool background_rendering_enabled_; |
159 | 149 |
160 // Manages UpdateCurrentFrame() callbacks if |client_| has stopped sending | 150 // Manages UpdateCurrentFrame() callbacks if |client_| has stopped sending |
161 // them for various reasons. Runs on |compositor_task_runner_| and is reset | 151 // them for various reasons. Runs on |compositor_task_runner_| and is reset |
162 // after each successful UpdateCurrentFrame() call. | 152 // after each successful UpdateCurrentFrame() call. |
163 base::Timer background_rendering_timer_; | 153 base::Timer background_rendering_timer_; |
164 | 154 |
(...skipping 13 matching lines...) Expand all Loading... |
178 // These values are updated and read from the media and compositor threads. | 168 // These values are updated and read from the media and compositor threads. |
179 base::Lock callback_lock_; | 169 base::Lock callback_lock_; |
180 VideoRendererSink::RenderCallback* callback_; | 170 VideoRendererSink::RenderCallback* callback_; |
181 | 171 |
182 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositor); | 172 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositor); |
183 }; | 173 }; |
184 | 174 |
185 } // namespace media | 175 } // namespace media |
186 | 176 |
187 #endif // MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_ | 177 #endif // MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_ |
OLD | NEW |