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