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" | |
11 #include "base/synchronization/lock.h" | |
10 #include "cc/layers/video_frame_provider.h" | 12 #include "cc/layers/video_frame_provider.h" |
11 #include "media/base/media_export.h" | 13 #include "media/base/media_export.h" |
14 #include "media/base/video_renderer_sink.h" | |
12 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
13 | 16 |
14 namespace media { | 17 namespace media { |
15 class VideoFrame; | 18 class VideoFrame; |
16 | 19 |
17 // VideoFrameCompositor handles incoming frames by notifying the compositor and | 20 // VideoFrameCompositor acts as a bridge between the media and compositor for |
18 // dispatching callbacks when detecting changes in video frames. | 21 // rendering video frames. I.e. a media::VideoRenderer will talk to this class |
22 // from the media side, while a cc::VideoFrameProvider::Client will talk to it | |
23 // from the cc side. | |
19 // | 24 // |
20 // Typical usage is to deliver ready-to-be-displayed video frames to | 25 // This class is responsible for requesting new frames from the video renderer |
21 // UpdateCurrentFrame() so that VideoFrameCompositor can take care of tracking | 26 // in response to requests from the VFP::Client. It is also responsible for |
22 // changes in video frames and firing callbacks as needed. | 27 // requesting new frames when the VFP::Client stops doing so in response to |
28 // visibility changes of the output layer. | |
29 // | |
30 // This class is responsible for detected frames dropped by the compositor after | |
xhwang
2015/04/13 20:50:29
s/detected/detecting, hmm actually "signaling"?
DaleCurtis
2015/04/13 23:15:06
Done.
| |
31 // rendering; this is done by ensuring each GetCurrentFrame() is followed by a | |
32 // PutCurrentFrame() before the next UpdateCurrentFrame() call. | |
xhwang
2015/04/13 20:50:29
By doing so, we are signaling frame-not-dropped...
DaleCurtis
2015/04/13 23:15:06
Done.
| |
33 // | |
34 // VideoRenderSink::RenderCallback implementations must call Start() and Stop() | |
35 // once new frames are expected or are no longer expected to be ready; this data | |
36 // is relayed to the compositor to avoid extraneous callbacks. | |
23 // | 37 // |
24 // VideoFrameCompositor must live on the same thread as the compositor. | 38 // VideoFrameCompositor must live on the same thread as the compositor. |
25 class MEDIA_EXPORT VideoFrameCompositor | 39 class MEDIA_EXPORT VideoFrameCompositor |
26 : NON_EXPORTED_BASE(public cc::VideoFrameProvider) { | 40 : public VideoRendererSink, |
41 NON_EXPORTED_BASE(public cc::VideoFrameProvider) { | |
27 public: | 42 public: |
43 // |compositor_task_runner| is the task runner on which this class will live. | |
xhwang
2015/04/13 20:50:29
Clarify what this means. There are still methods c
DaleCurtis
2015/04/13 23:15:06
Clarified which methods are called where.
| |
44 // | |
28 // |natural_size_changed_cb| is run with the new natural size of the video | 45 // |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 | 46 // 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 | 47 // first time UpdateCurrentFrame() is called. Run on the same thread as the |
31 // caller of UpdateCurrentFrame(). | 48 // caller of UpdateCurrentFrame(). |
32 // | 49 // |
33 // |opacity_changed_cb| is run when a change in opacity is detected. It *is* | 50 // |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 | 51 // called the first time UpdateCurrentFrame() is called. Run on the same |
35 // thread as the caller of UpdateCurrentFrame(). | 52 // thread as the caller of UpdateCurrentFrame(). |
36 // | 53 // |
37 // TODO(scherkus): Investigate the inconsistency between the callbacks with | 54 // TODO(dalecurtis): Investigate the inconsistency between the callbacks with |
38 // respect to why we don't call |natural_size_changed_cb| on the first frame. | 55 // 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. | 56 // I suspect it was for historical reasons that no longer make sense. |
40 VideoFrameCompositor( | 57 VideoFrameCompositor( |
58 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, | |
41 const base::Callback<void(gfx::Size)>& natural_size_changed_cb, | 59 const base::Callback<void(gfx::Size)>& natural_size_changed_cb, |
42 const base::Callback<void(bool)>& opacity_changed_cb); | 60 const base::Callback<void(bool)>& opacity_changed_cb); |
61 | |
62 // Destruction must happen on the compositor thread; Stop() must have been | |
63 // called before destruction starts. | |
43 ~VideoFrameCompositor() override; | 64 ~VideoFrameCompositor() override; |
44 | 65 |
66 // Returns |current_frame_| if it was refreshed in the last 250ms; otherwise, | |
67 // if |callback_| is available, requests a new frame and returns that one. | |
68 scoped_refptr<VideoFrame> GetCurrentFrameAndUpdateIfStale(); | |
xhwang
2015/04/13 20:50:29
Add a comment about why we need this? e.g. canvas,
DaleCurtis
2015/04/13 23:15:06
Done.
| |
69 | |
45 // cc::VideoFrameProvider implementation. | 70 // cc::VideoFrameProvider implementation. |
46 void SetVideoFrameProviderClient( | 71 void SetVideoFrameProviderClient( |
47 cc::VideoFrameProvider::Client* client) override; | 72 cc::VideoFrameProvider::Client* client) override; |
73 bool UpdateCurrentFrame(base::TimeTicks deadline_min, | |
74 base::TimeTicks deadline_max) override; | |
48 scoped_refptr<VideoFrame> GetCurrentFrame() override; | 75 scoped_refptr<VideoFrame> GetCurrentFrame() override; |
49 void PutCurrentFrame(const scoped_refptr<VideoFrame>& frame) override; | 76 void PutCurrentFrame() override; |
50 | 77 |
51 // Updates the current frame and notifies the compositor. | 78 // VideoRendererSink implementation. |
52 void UpdateCurrentFrame(const scoped_refptr<VideoFrame>& frame); | 79 void Start(RenderCallback* callback) override; |
80 void Stop() override; | |
81 void PaintFrameUsingOldRenderingPath( | |
82 const scoped_refptr<VideoFrame>& frame) override; | |
53 | 83 |
54 private: | 84 private: |
85 // Called on the compositor thread to start or stop rendering if rendering was | |
86 // previously started or stopped before we had a |callback_|. | |
87 void OnRendererStateUpdate(); | |
88 | |
89 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | |
90 | |
91 // These callbacks are executed on the compositor thread. | |
55 base::Callback<void(gfx::Size)> natural_size_changed_cb_; | 92 base::Callback<void(gfx::Size)> natural_size_changed_cb_; |
56 base::Callback<void(bool)> opacity_changed_cb_; | 93 base::Callback<void(bool)> opacity_changed_cb_; |
57 | 94 |
95 // These values are only set and read on the compositor thread. | |
58 cc::VideoFrameProvider::Client* client_; | 96 cc::VideoFrameProvider::Client* client_; |
97 scoped_refptr<VideoFrame> current_frame_; | |
59 | 98 |
60 scoped_refptr<VideoFrame> current_frame_; | 99 // These values are updated and read from the media and compositor threads. |
100 base::Lock lock_; | |
101 bool rendering_; | |
102 VideoRendererSink::RenderCallback* callback_; | |
61 | 103 |
62 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositor); | 104 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositor); |
63 }; | 105 }; |
64 | 106 |
65 } // namespace media | 107 } // namespace media |
66 | 108 |
67 #endif // MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_ | 109 #endif // MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_ |
OLD | NEW |