• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_
6 #define MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_
7 
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "cc/layers/video_frame_provider.h"
11 #include "media/base/media_export.h"
12 #include "ui/gfx/size.h"
13 
14 namespace media {
15 class VideoFrame;
16 
17 // VideoFrameCompositor handles incoming frames by notifying the compositor and
18 // dispatching callbacks when detecting changes in video frames.
19 //
20 // Typical usage is to deliver ready-to-be-displayed video frames to
21 // UpdateCurrentFrame() so that VideoFrameCompositor can take care of tracking
22 // changes in video frames and firing callbacks as needed.
23 //
24 // VideoFrameCompositor must live on the same thread as the compositor.
25 class MEDIA_EXPORT VideoFrameCompositor
NON_EXPORTED_BASE(public cc::VideoFrameProvider)26     : NON_EXPORTED_BASE(public cc::VideoFrameProvider) {
27  public:
28   // |natural_size_changed_cb| is run with the new natural size of the video
29   // frame whenever a change in natural size is detected. It is not called the
30   // first time UpdateCurrentFrame() is called. Run on the same thread as the
31   // caller of UpdateCurrentFrame().
32   //
33   // |opacity_changed_cb| is run when a change in opacity is detected. It *is*
34   // called the first time UpdateCurrentFrame() is called. Run on the same
35   // thread as the caller of UpdateCurrentFrame().
36   //
37   // TODO(scherkus): Investigate the inconsistency between the callbacks with
38   // respect to why we don't call |natural_size_changed_cb| on the first frame.
39   // I suspect it was for historical reasons that no longer make sense.
40   VideoFrameCompositor(
41       const base::Callback<void(gfx::Size)>& natural_size_changed_cb,
42       const base::Callback<void(bool)>& opacity_changed_cb);
43   virtual ~VideoFrameCompositor();
44 
45   // cc::VideoFrameProvider implementation.
46   virtual void SetVideoFrameProviderClient(
47       cc::VideoFrameProvider::Client* client) OVERRIDE;
48   virtual scoped_refptr<VideoFrame> GetCurrentFrame() OVERRIDE;
49   virtual void PutCurrentFrame(
50       const scoped_refptr<VideoFrame>& frame) OVERRIDE;
51 
52   // Updates the current frame and notifies the compositor.
53   void UpdateCurrentFrame(const scoped_refptr<VideoFrame>& frame);
54 
55  private:
56   base::Callback<void(gfx::Size)> natural_size_changed_cb_;
57   base::Callback<void(bool)> opacity_changed_cb_;
58 
59   cc::VideoFrameProvider::Client* client_;
60 
61   scoped_refptr<VideoFrame> current_frame_;
62 
63   DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositor);
64 };
65 
66 }  // namespace media
67 
68 #endif  // MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_
69