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 "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 12 #include "base/time/tick_clock.h" |
12 #include "cc/layers/video_frame_provider.h" | 13 #include "cc/layers/video_frame_provider.h" |
13 #include "media/base/media_export.h" | 14 #include "media/base/media_export.h" |
14 #include "media/base/video_renderer_sink.h" | 15 #include "media/base/video_renderer_sink.h" |
15 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
16 | 17 |
17 namespace media { | 18 namespace media { |
18 class VideoFrame; | 19 class VideoFrame; |
19 | 20 |
20 // VideoFrameCompositor acts as a bridge between the media and cc layers for | 21 // VideoFrameCompositor acts as a bridge between the media and cc layers for |
21 // rendering video frames. I.e. a media::VideoRenderer will talk to this class | 22 // rendering video frames. I.e. a media::VideoRenderer will talk to this class |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 scoped_refptr<VideoFrame> GetCurrentFrame() override; | 85 scoped_refptr<VideoFrame> GetCurrentFrame() override; |
85 void PutCurrentFrame() override; | 86 void PutCurrentFrame() override; |
86 | 87 |
87 // VideoRendererSink implementation. These methods must be called from the | 88 // VideoRendererSink implementation. These methods must be called from the |
88 // same thread (typically the media thread). | 89 // same thread (typically the media thread). |
89 void Start(RenderCallback* callback) override; | 90 void Start(RenderCallback* callback) override; |
90 void Stop() override; | 91 void Stop() override; |
91 void PaintFrameUsingOldRenderingPath( | 92 void PaintFrameUsingOldRenderingPath( |
92 const scoped_refptr<VideoFrame>& frame) override; | 93 const scoped_refptr<VideoFrame>& frame) override; |
93 | 94 |
| 95 void set_tick_clock_for_testing(scoped_ptr<base::TickClock> tick_clock) { |
| 96 tick_clock_ = tick_clock.Pass(); |
| 97 } |
| 98 |
| 99 base::TimeDelta get_stale_frame_threshold_for_testing() const { |
| 100 return stale_frame_threshold_; |
| 101 } |
| 102 |
| 103 void clear_current_frame_for_testing() { current_frame_ = nullptr; } |
| 104 |
94 private: | 105 private: |
95 // Called on the compositor thread to start or stop rendering if rendering was | 106 // Called on the compositor thread in response to Start() or Stop() calls; |
96 // previously started or stopped before we had a |callback_|. | 107 // must be used to change |rendering_| state. |
97 void OnRendererStateUpdate(); | 108 void OnRendererStateUpdate(bool new_state); |
| 109 |
| 110 // Handles setting of |current_frame_| and fires |natural_size_changed_cb_| |
| 111 // and |opacity_changed_cb_| when the frame properties changes. |
| 112 void ProcessNewFrame(const scoped_refptr<VideoFrame>& frame); |
98 | 113 |
99 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 114 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
| 115 scoped_ptr<base::TickClock> tick_clock_; |
100 | 116 |
101 // These callbacks are executed on the compositor thread. | 117 // These callbacks are executed on the compositor thread. |
102 base::Callback<void(gfx::Size)> natural_size_changed_cb_; | 118 const base::Callback<void(gfx::Size)> natural_size_changed_cb_; |
103 base::Callback<void(bool)> opacity_changed_cb_; | 119 const base::Callback<void(bool)> opacity_changed_cb_; |
| 120 |
| 121 base::TimeDelta stale_frame_threshold_; |
104 | 122 |
105 // These values are only set and read on the compositor thread. | 123 // These values are only set and read on the compositor thread. |
106 cc::VideoFrameProvider::Client* client_; | 124 cc::VideoFrameProvider::Client* client_; |
107 scoped_refptr<VideoFrame> current_frame_; | 125 scoped_refptr<VideoFrame> current_frame_; |
| 126 bool rendering_; |
| 127 bool rendered_last_frame_; |
108 | 128 |
109 // These values are updated and read from the media and compositor threads. | 129 // These values are updated and read from the media and compositor threads. |
110 base::Lock lock_; | 130 base::Lock lock_; |
111 bool rendering_; | |
112 VideoRendererSink::RenderCallback* callback_; | 131 VideoRendererSink::RenderCallback* callback_; |
113 | 132 |
| 133 // These values are set on the compositor thread under lock and may be read |
| 134 // from the media thread under lock. |
| 135 base::TimeTicks last_frame_update_time_; |
| 136 base::TimeDelta last_interval_; |
| 137 |
114 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositor); | 138 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositor); |
115 }; | 139 }; |
116 | 140 |
117 } // namespace media | 141 } // namespace media |
118 | 142 |
119 #endif // MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_ | 143 #endif // MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_ |
OLD | NEW |