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