Chromium Code Reviews| 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 // VideoFrameCompositor must live on the same thread as the compositor. |
|
xhwang
2014/04/28 06:42:59
Can you add more comments about threading? It seem
scherkus (not reviewing)
2014/04/28 16:59:47
Done.
| |
| 36 class CONTENT_EXPORT VideoFrameCompositor { | 29 class CONTENT_EXPORT VideoFrameCompositor : public cc::VideoFrameProvider { |
| 37 public: | 30 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 | 31 // |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 | 32 // 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 | 33 // first time UpdateCurrentFrame() is called. Run on the same thread as the |
| 43 // caller of UpdateCurrentFrame(). | 34 // caller of UpdateCurrentFrame(). |
| 44 // | 35 // |
| 45 // |opacity_changed_cb| is run when a change in opacity is detected. It *is* | 36 // |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 | 37 // called the first time UpdateCurrentFrame() is called. Run on the same |
| 47 // thread as the caller of UpdateCurrentFrame(). | 38 // thread as the caller of UpdateCurrentFrame(). |
| 48 // | 39 // |
| 49 // TODO(scherkus): Investigate the inconsistency between the callbacks with | 40 // 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. | 41 // 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. | 42 // I suspect it was for historical reasons that no longer make sense. |
| 52 VideoFrameCompositor( | 43 VideoFrameCompositor( |
| 53 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, | |
| 54 const base::Callback<void(gfx::Size)>& natural_size_changed_cb, | 44 const base::Callback<void(gfx::Size)>& natural_size_changed_cb, |
| 55 const base::Callback<void(bool)>& opacity_changed_cb); | 45 const base::Callback<void(bool)>& opacity_changed_cb); |
| 56 ~VideoFrameCompositor(); | 46 virtual ~VideoFrameCompositor(); |
| 57 | 47 |
| 58 cc::VideoFrameProvider* GetVideoFrameProvider(); | 48 // cc::VideoFrameProvider implementation. |
| 49 // | |
| 50 // NOTE: GetCurrentFrame() is safe to call from any thread. | |
| 51 virtual void SetVideoFrameProviderClient( | |
| 52 cc::VideoFrameProvider::Client* client) OVERRIDE; | |
| 53 virtual scoped_refptr<media::VideoFrame> GetCurrentFrame() OVERRIDE; | |
| 54 virtual void PutCurrentFrame( | |
| 55 const scoped_refptr<media::VideoFrame>& frame) OVERRIDE; | |
| 59 | 56 |
| 60 // Updates the current frame and notifies the compositor. | 57 // Updates the current frame and notifies the compositor. |
| 61 void UpdateCurrentFrame(const scoped_refptr<media::VideoFrame>& frame); | 58 void UpdateCurrentFrame(const scoped_refptr<media::VideoFrame>& frame); |
| 62 | 59 |
| 63 // Retrieves the last frame set via UpdateCurrentFrame() for non-compositing | 60 private: |
| 64 // purposes (e.g., painting to a canvas). | 61 base::Callback<void(gfx::Size)> natural_size_changed_cb_; |
| 65 // | 62 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 | 63 |
| 70 // Returns the number of frames dropped before the compositor was notified | 64 cc::VideoFrameProvider::Client* client_; |
| 71 // of a new frame. | |
| 72 uint32 GetFramesDroppedBeforeCompositorWasNotified(); | |
| 73 | 65 |
| 74 void SetFramesDroppedBeforeCompositorWasNotifiedForTesting( | 66 base::Lock lock_; |
| 75 uint32 dropped_frames); | 67 scoped_refptr<media::VideoFrame> current_frame_; |
| 76 | |
| 77 private: | |
| 78 class Internal; | |
| 79 Internal* internal_; | |
| 80 | 68 |
| 81 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositor); | 69 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositor); |
| 82 }; | 70 }; |
| 83 | 71 |
| 84 } // namespace content | 72 } // namespace content |
| 85 | 73 |
| 86 #endif // CONTENT_RENDERER_MEDIA_VIDEO_FRAME_COMPOSITOR_H_ | 74 #endif // CONTENT_RENDERER_MEDIA_VIDEO_FRAME_COMPOSITOR_H_ |
| OLD | NEW |