Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: media/blink/video_frame_compositor.h

Issue 1053113002: Prime the landing pad for the new video rendering pipeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments. Revert canvas changes. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
31 // rendering; this is done by ensuring each GetCurrentFrame() is followed by a
32 // PutCurrentFrame() before the next UpdateCurrentFrame() call.
33 //
34 // Consumers of this class must call StartRendering() and StopRendering() once
35 // new frames are expected or are no longer expected to be ready; this data is
36 // 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.
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; StopRendering() and
63 // Stop() must have been called before destruction starts.
43 ~VideoFrameCompositor() override; 64 ~VideoFrameCompositor() override;
44 65
45 // cc::VideoFrameProvider implementation. 66 // cc::VideoFrameProvider implementation.
46 void SetVideoFrameProviderClient( 67 void SetVideoFrameProviderClient(
47 cc::VideoFrameProvider::Client* client) override; 68 cc::VideoFrameProvider::Client* client) override;
69 bool UpdateCurrentFrame(base::TimeTicks deadline_min,
70 base::TimeTicks deadline_max) override;
48 scoped_refptr<VideoFrame> GetCurrentFrame() override; 71 scoped_refptr<VideoFrame> GetCurrentFrame() override;
49 void PutCurrentFrame(const scoped_refptr<VideoFrame>& frame) override; 72 void PutCurrentFrame() override;
73 void SetVisible(bool visible) override;
50 74
51 // Updates the current frame and notifies the compositor. 75 // VideoRendererSink implementation.
52 void UpdateCurrentFrame(const scoped_refptr<VideoFrame>& frame); 76 void Start(RenderCallback* callback) override;
77 void Stop() override;
78 void PaintFrameUsingOldRenderingPath(
79 const scoped_refptr<VideoFrame>& frame) override;
53 80
54 private: 81 private:
82 // Called on the compositor thread to start or stop rendering if rendering was
83 // previously started or stopped before we had a |callback_|.
84 void OnRendererStateUpdate();
85
86 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
87
88 // These callbacks are executed on the compositor thread.
55 base::Callback<void(gfx::Size)> natural_size_changed_cb_; 89 base::Callback<void(gfx::Size)> natural_size_changed_cb_;
56 base::Callback<void(bool)> opacity_changed_cb_; 90 base::Callback<void(bool)> opacity_changed_cb_;
57 91
92 // These values are only set and read on the compositor thread.
58 cc::VideoFrameProvider::Client* client_; 93 cc::VideoFrameProvider::Client* client_;
59 94
95 // These values are updated and read from the media, render, and compositor
96 // threads.
97 base::Lock lock_;
98 bool rendering_;
99 VideoRendererSink::RenderCallback* callback_;
60 scoped_refptr<VideoFrame> current_frame_; 100 scoped_refptr<VideoFrame> current_frame_;
61 101
62 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositor); 102 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositor);
63 }; 103 };
64 104
65 } // namespace media 105 } // namespace media
66 106
67 #endif // MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_ 107 #endif // MEDIA_BLINK_VIDEO_FRAME_COMPOSITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698