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 CONTENT_RENDERER_MEDIA_VIDEO_FRAME_COMPOSITOR_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_FRAME_COMPOSITOR_H_ |
6 #define CONTENT_RENDERER_MEDIA_VIDEO_FRAME_COMPOSITOR_H_ | 6 #define CONTENT_RENDERER_MEDIA_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/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 11 #include "cc/layers/video_frame_provider.h" |
11 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
12 #include "ui/gfx/size.h" | 13 #include "ui/gfx/size.h" |
13 | 14 |
14 namespace base { | |
15 class SingleThreadTaskRunner; | |
16 } | |
17 | |
18 namespace cc { | |
19 class VideoFrameProvider; | |
20 } | |
21 | |
22 namespace media { | 15 namespace media { |
23 class VideoFrame; | 16 class VideoFrame; |
24 } | 17 } |
25 | 18 |
26 namespace content { | 19 namespace content { |
27 | 20 |
28 // VideoFrameCompositor handles incoming frames by notifying the compositor in a | 21 // VideoFrameCompositor handles incoming frames by notifying the compositor and |
29 // thread-safe manner. | 22 // dispatching callbacks when detecting changes in video frames. |
30 // | 23 // |
31 // Typical usage is to deliver the output of VideoRendererImpl to | 24 // Typical usage is to deliver ready-to-be-displayed video frames to |
32 // UpdateCurrentFrame() so that VideoFrameCompositor can take care of tracking | 25 // UpdateCurrentFrame() so that VideoFrameCompositor can take care of tracking |
33 // dropped frames and firing callbacks as needed. | 26 // changes in video frames and firing callbacks as needed. |
34 // | 27 // |
35 // All APIs are callable from any thread. | 28 // While VideoFrameCompositor must live on the same thread as the compositor, |
36 class CONTENT_EXPORT VideoFrameCompositor { | 29 // GetCurrentFrame() is callable from any thread to let clients access the |
| 30 // current frame for non-compositing purposes. |
| 31 class CONTENT_EXPORT VideoFrameCompositor |
| 32 : NON_EXPORTED_BASE(public cc::VideoFrameProvider) { |
37 public: | 33 public: |
38 // |compositor_task_runner| is the task runner of the compositor. | |
39 // | |
40 // |natural_size_changed_cb| is run with the new natural size of the video | 34 // |natural_size_changed_cb| is run with the new natural size of the video |
41 // frame whenever a change in natural size is detected. It is not called the | 35 // frame whenever a change in natural size is detected. It is not called the |
42 // first time UpdateCurrentFrame() is called. Run on the same thread as the | 36 // first time UpdateCurrentFrame() is called. Run on the same thread as the |
43 // caller of UpdateCurrentFrame(). | 37 // caller of UpdateCurrentFrame(). |
44 // | 38 // |
45 // |opacity_changed_cb| is run when a change in opacity is detected. It *is* | 39 // |opacity_changed_cb| is run when a change in opacity is detected. It *is* |
46 // called the first time UpdateCurrentFrame() is called. Run on the same | 40 // called the first time UpdateCurrentFrame() is called. Run on the same |
47 // thread as the caller of UpdateCurrentFrame(). | 41 // thread as the caller of UpdateCurrentFrame(). |
48 // | 42 // |
49 // TODO(scherkus): Investigate the inconsistency between the callbacks with | 43 // TODO(scherkus): Investigate the inconsistency between the callbacks with |
50 // respect to why we don't call |natural_size_changed_cb| on the first frame. | 44 // respect to why we don't call |natural_size_changed_cb| on the first frame. |
51 // I suspect it was for historical reasons that no longer make sense. | 45 // I suspect it was for historical reasons that no longer make sense. |
52 VideoFrameCompositor( | 46 VideoFrameCompositor( |
53 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, | |
54 const base::Callback<void(gfx::Size)>& natural_size_changed_cb, | 47 const base::Callback<void(gfx::Size)>& natural_size_changed_cb, |
55 const base::Callback<void(bool)>& opacity_changed_cb); | 48 const base::Callback<void(bool)>& opacity_changed_cb); |
56 ~VideoFrameCompositor(); | 49 virtual ~VideoFrameCompositor(); |
57 | 50 |
58 cc::VideoFrameProvider* GetVideoFrameProvider(); | 51 // cc::VideoFrameProvider implementation. |
| 52 // |
| 53 // NOTE: GetCurrentFrame() is safe to call from any thread. |
| 54 virtual void SetVideoFrameProviderClient( |
| 55 cc::VideoFrameProvider::Client* client) OVERRIDE; |
| 56 virtual scoped_refptr<media::VideoFrame> GetCurrentFrame() OVERRIDE; |
| 57 virtual void PutCurrentFrame( |
| 58 const scoped_refptr<media::VideoFrame>& frame) OVERRIDE; |
59 | 59 |
60 // Updates the current frame and notifies the compositor. | 60 // Updates the current frame and notifies the compositor. |
61 void UpdateCurrentFrame(const scoped_refptr<media::VideoFrame>& frame); | 61 void UpdateCurrentFrame(const scoped_refptr<media::VideoFrame>& frame); |
62 | 62 |
63 // Retrieves the last frame set via UpdateCurrentFrame() for non-compositing | 63 private: |
64 // purposes (e.g., painting to a canvas). | 64 base::Callback<void(gfx::Size)> natural_size_changed_cb_; |
65 // | 65 base::Callback<void(bool)> opacity_changed_cb_; |
66 // Note that the compositor retrieves frames via the cc::VideoFrameProvider | |
67 // interface instead of using this method. | |
68 scoped_refptr<media::VideoFrame> GetCurrentFrame(); | |
69 | 66 |
70 // Returns the number of frames dropped before the compositor was notified | 67 cc::VideoFrameProvider::Client* client_; |
71 // of a new frame. | |
72 uint32 GetFramesDroppedBeforeCompositorWasNotified(); | |
73 | 68 |
74 void SetFramesDroppedBeforeCompositorWasNotifiedForTesting( | 69 base::Lock lock_; |
75 uint32 dropped_frames); | 70 scoped_refptr<media::VideoFrame> current_frame_; |
76 | |
77 private: | |
78 class Internal; | |
79 Internal* internal_; | |
80 | 71 |
81 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositor); | 72 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositor); |
82 }; | 73 }; |
83 | 74 |
84 } // namespace content | 75 } // namespace content |
85 | 76 |
86 #endif // CONTENT_RENDERER_MEDIA_VIDEO_FRAME_COMPOSITOR_H_ | 77 #endif // CONTENT_RENDERER_MEDIA_VIDEO_FRAME_COMPOSITOR_H_ |
OLD | NEW |