OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CC_LAYERS_VIDEO_FRAME_PROVIDER_H_ | 5 #ifndef CC_LAYERS_VIDEO_FRAME_PROVIDER_H_ |
6 #define CC_LAYERS_VIDEO_FRAME_PROVIDER_H_ | 6 #define CC_LAYERS_VIDEO_FRAME_PROVIDER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/time/time.h" | |
9 #include "cc/base/cc_export.h" | 10 #include "cc/base/cc_export.h" |
10 | 11 |
11 namespace media { | 12 namespace media { |
12 class VideoFrame; | 13 class VideoFrame; |
13 } | 14 } |
14 | 15 |
15 namespace cc { | 16 namespace cc { |
16 | 17 |
17 // Threading notes: This class may be used in a multi threaded manner. | 18 // VideoFrameProvider and VideoFrameProvider::Client define the relationship by |
18 // Specifically, the implementation may call GetCurrentFrame() or | 19 // which video frames are exchanged between a provider and client. |
19 // PutCurrentFrame() from the compositor thread. If so, the caller is | 20 // |
20 // responsible for making sure Client::DidReceiveFrame() and | 21 // Threading notes: This class may be used in a multithreaded manner. However, |
21 // Client::DidUpdateMatrix() are only called from this same thread. | 22 // if the Client implementation calls GetCurrentFrame()/PutCurrentFrame() from |
23 // one thread, the provider must ensure that all client methods are called from | |
24 // that thread (typically the compositor thread). | |
22 class CC_EXPORT VideoFrameProvider { | 25 class CC_EXPORT VideoFrameProvider { |
23 public: | 26 public: |
24 virtual ~VideoFrameProvider() {} | |
25 | |
26 class CC_EXPORT Client { | 27 class CC_EXPORT Client { |
27 public: | 28 public: |
28 // Provider will call this method to tell the client to stop using it. | 29 // The provider will call this method to tell the client to stop using it. |
29 // StopUsingProvider() may be called from any thread. The client should | 30 // StopUsingProvider() may be called from any thread. The client should |
30 // block until it has PutCurrentFrame() any outstanding frames. | 31 // block until it has PutCurrentFrame() any outstanding frames. |
31 virtual void StopUsingProvider() = 0; | 32 virtual void StopUsingProvider() = 0; |
32 | 33 |
34 // Notifies the client that it should start or stop making regular Render() | |
35 // calls to the provider. No further calls to Render() will be made after | |
36 // StopRendering() returns. Clients should handle redundant calls. | |
37 virtual void StartRendering() = 0; | |
38 virtual void StopRendering() = 0; | |
39 | |
33 // Notifies the provider's client that a call to GetCurrentFrame() will | 40 // Notifies the provider's client that a call to GetCurrentFrame() will |
34 // return new data. | 41 // return new data. |
42 // TODO(dalecurtis): Nuke this once VideoFrameProviderClientImpl is using a | |
43 // BeginFrameObserver based approach. http://crbug.com/336733 | |
35 virtual void DidReceiveFrame() = 0; | 44 virtual void DidReceiveFrame() = 0; |
36 | 45 |
37 // Notifies the provider's client of a new UV transform matrix to be used. | 46 // Notifies the client of a new UV transform matrix to be used. |
38 virtual void DidUpdateMatrix(const float* matrix) = 0; | 47 virtual void DidUpdateMatrix(const float* matrix) = 0; |
39 | 48 |
40 protected: | 49 protected: |
41 virtual ~Client() {} | 50 virtual ~Client() {} |
42 }; | 51 }; |
43 | 52 |
44 // May be called from any thread, but there must be some external guarantee | 53 // May be called from any thread, but there must be some external guarantee |
45 // that the provider is not destroyed before this call returns. | 54 // that the provider is not destroyed before this call returns. |
46 virtual void SetVideoFrameProviderClient(Client* client) = 0; | 55 virtual void SetVideoFrameProviderClient(Client* client) = 0; |
47 | 56 |
48 // This function places a lock on the current frame and returns a pointer to | 57 // Called by the client on a regular interval. Returns true if a new frame is |
xhwang
2015/04/03 07:00:13
nit: s/is/will be/ ?
DaleCurtis
2015/04/07 00:40:51
Done.
| |
49 // it. Calls to this method should always be followed with a call to | 58 // available via GetCurrentFrame() which should be displayed within the |
50 // PutCurrentFrame(). | 59 // presentation interval [|deadline_min|, |deadline_max|]. |
xhwang
2015/04/03 07:00:13
So I assume the "interval" will be the vsync inter
DaleCurtis
2015/04/03 17:14:52
Yup, you can see what the mostly complete algorith
| |
51 // Only the current provider client should call this function. | 60 virtual bool Render(base::TimeTicks deadline_min, |
61 base::TimeTicks deadline_max) = 0; | |
xhwang
2015/04/03 07:00:13
bikeshedding on naming: This really is something l
DaleCurtis
2015/04/03 17:14:52
Yeah... I went back and forth on this: Either keep
DaleCurtis
2015/04/07 00:40:51
Done.
| |
62 | |
63 // Returns the last frame that was rendered during Render(). A call to this | |
64 // method does not ensure that the frame will be rendered. A subsequent call | |
65 // to PutCurrentFrame() will be made if the frame is rendered. | |
52 virtual scoped_refptr<media::VideoFrame> GetCurrentFrame() = 0; | 66 virtual scoped_refptr<media::VideoFrame> GetCurrentFrame() = 0; |
53 | 67 |
54 // This function releases the lock on the video frame. It should always be | 68 // Indicates that the frame returned via GetCurrentFrame() was rendered. Must |
55 // called after GetCurrentFrame(). Frames passed into this method | 69 // only occur after a previous call to GetCurrentFrame(). |
56 // should no longer be referenced after the call is made. Only the current | 70 virtual void PutCurrentFrame() = 0; |
xhwang
2015/04/03 07:00:13
Here we have GetCurrentFrame/PutCurrentFrame. Then
DaleCurtis
2015/04/03 17:14:52
The compositor is what I'd call a two-phase proces
xhwang
2015/04/03 19:18:27
Let me make sure I understand "dropped frame" coun
DaleCurtis
2015/04/03 19:59:16
Yes this is correct. I'd be okay with renaming it.
| |
57 // provider client should call this function. | 71 |
58 virtual void PutCurrentFrame( | 72 // Called by the client when the visibility of the output layer changes. The |
59 const scoped_refptr<media::VideoFrame>& frame) = 0; | 73 // client will not issue any Render() calls while the output layer has no |
74 // visibility. It will not start any Render() calls before notifying the | |
xhwang
2015/04/03 07:00:13
What about using web canvas to manipulate video? I
DaleCurtis
2015/04/03 17:14:52
Sunny, can you clarify on this? It's my expectatio
xhwang
2015/04/03 19:18:27
What if the JS app draw the video into a canvas, g
DaleCurtis
2015/04/03 19:59:16
I think if we update every say 100ms that should b
| |
75 // provider of visibility. | |
76 virtual void SetVisible(bool visible) = 0; | |
77 | |
78 protected: | |
79 virtual ~VideoFrameProvider() {} | |
60 }; | 80 }; |
61 | 81 |
62 } // namespace cc | 82 } // namespace cc |
63 | 83 |
64 #endif // CC_LAYERS_VIDEO_FRAME_PROVIDER_H_ | 84 #endif // CC_LAYERS_VIDEO_FRAME_PROVIDER_H_ |
OLD | NEW |