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() { |
| 104 current_frame_ = nullptr; |
| 105 } |
| 106 |
94 private: | 107 private: |
95 // Called on the compositor thread to start or stop rendering if rendering was | 108 // Called on the compositor thread to start or stop rendering if rendering was |
96 // previously started or stopped before we had a |callback_|. | 109 // previously started or stopped before we had a |client_|. Will only call |
97 void OnRendererStateUpdate(); | 110 // StopRendering() if |stop_if_not_rendering| is true. |
| 111 void OnRendererStateUpdate(bool new_state); |
98 | 112 |
99 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 113 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
| 114 scoped_ptr<base::TickClock> tick_clock_; |
100 | 115 |
101 // These callbacks are executed on the compositor thread. | 116 // These callbacks are executed on the compositor thread. |
102 base::Callback<void(gfx::Size)> natural_size_changed_cb_; | 117 base::Callback<void(gfx::Size)> natural_size_changed_cb_; |
103 base::Callback<void(bool)> opacity_changed_cb_; | 118 base::Callback<void(bool)> opacity_changed_cb_; |
104 | 119 |
105 // These values are only set and read on the compositor thread. | 120 // These values are only set and read on the compositor thread. |
106 cc::VideoFrameProvider::Client* client_; | 121 cc::VideoFrameProvider::Client* client_; |
107 scoped_refptr<VideoFrame> current_frame_; | 122 scoped_refptr<VideoFrame> current_frame_; |
| 123 base::TimeTicks last_frame_update_time_; |
| 124 base::TimeDelta last_interval_; |
| 125 base::TimeDelta stale_frame_threshold_; |
| 126 bool rendering_; |
108 | 127 |
109 // These values are updated and read from the media and compositor threads. | 128 // These values are updated and read from the media and compositor threads. |
110 base::Lock lock_; | 129 base::Lock lock_; |
111 bool rendering_; | 130 bool rendered_last_frame_; |
112 VideoRendererSink::RenderCallback* callback_; | 131 VideoRendererSink::RenderCallback* callback_; |
113 | 132 |
114 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositor); | 133 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositor); |
115 }; | 134 }; |
116 | 135 |
117 } // namespace media | 136 } // namespace media |
118 | 137 |
119 #endif // MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_ | 138 #endif // MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_ |
OLD | NEW |