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