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 (except |
| 24 // StopUsingProvider()) are called from that thread (typically the compositor |
| 25 // thread). |
22 class CC_EXPORT VideoFrameProvider { | 26 class CC_EXPORT VideoFrameProvider { |
23 public: | 27 public: |
24 virtual ~VideoFrameProvider() {} | |
25 | |
26 class CC_EXPORT Client { | 28 class CC_EXPORT Client { |
27 public: | 29 public: |
28 // Provider will call this method to tell the client to stop using it. | 30 // 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 | 31 // StopUsingProvider() may be called from any thread. The client should |
30 // block until it has PutCurrentFrame() any outstanding frames. | 32 // block until it has PutCurrentFrame() any outstanding frames. |
31 virtual void StopUsingProvider() = 0; | 33 virtual void StopUsingProvider() = 0; |
32 | 34 |
33 // Notifies the provider's client that a call to GetCurrentFrame() will | 35 // Notifies the client that it should start or stop making regular |
34 // return new data. | 36 // UpdateCurrentFrame() calls to the provider. No further calls to |
| 37 // UpdateCurrentFrame() should be made once StopRendering() returns. |
| 38 // |
| 39 // Callers should use these methods to indicate when it expects and no |
| 40 // longer expects (respectively) to have new frames for the client. Clients |
| 41 // may use this information for power conservation. |
| 42 virtual void StartRendering() = 0; |
| 43 virtual void StopRendering() = 0; |
| 44 |
| 45 // Notifies the client that GetCurrentFrame() will return new data. |
| 46 // TODO(dalecurtis): Nuke this once VideoFrameProviderClientImpl is using a |
| 47 // BeginFrameObserver based approach. http://crbug.com/336733 |
35 virtual void DidReceiveFrame() = 0; | 48 virtual void DidReceiveFrame() = 0; |
36 | 49 |
37 // Notifies the provider's client of a new UV transform matrix to be used. | 50 // Notifies the client of a new UV transform matrix to be used. |
38 virtual void DidUpdateMatrix(const float* matrix) = 0; | 51 virtual void DidUpdateMatrix(const float* matrix) = 0; |
39 | 52 |
40 protected: | 53 protected: |
41 virtual ~Client() {} | 54 virtual ~Client() {} |
42 }; | 55 }; |
43 | 56 |
44 // May be called from any thread, but there must be some external guarantee | 57 // May be called from any thread, but there must be some external guarantee |
45 // that the provider is not destroyed before this call returns. | 58 // that the provider is not destroyed before this call returns. |
46 virtual void SetVideoFrameProviderClient(Client* client) = 0; | 59 virtual void SetVideoFrameProviderClient(Client* client) = 0; |
47 | 60 |
48 // This function places a lock on the current frame and returns a pointer to | 61 // Called by the client on a regular interval. Returns true if a new frame |
49 // it. Calls to this method should always be followed with a call to | 62 // will be available via GetCurrentFrame() which should be displayed within |
50 // PutCurrentFrame(). | 63 // the presentation interval [|deadline_min|, |deadline_max|]. |
51 // Only the current provider client should call this function. | 64 // |
| 65 // Implementations may use this to drive frame acquisition from underlying |
| 66 // sources, so it must be called by clients before calling GetCurrentFrame(). |
| 67 virtual bool UpdateCurrentFrame(base::TimeTicks deadline_min, |
| 68 base::TimeTicks deadline_max) = 0; |
| 69 |
| 70 // Returns the current frame, which may have been updated by a recent call to |
| 71 // UpdateCurrentFrame(). A call to this method does not ensure that the frame |
| 72 // will be rendered. A subsequent call to PutCurrentFrame() must be made if |
| 73 // the frame is expected to be rendered. |
| 74 // |
| 75 // Clients should call this in response to UpdateCurrentFrame() returning true |
| 76 // or in response to a DidReceiveFrame() call. |
| 77 // |
| 78 // TODO(dalecurtis): Remove text about DidReceiveFrame() once the old path |
| 79 // has been removed. http://crbug.com/439548 |
52 virtual scoped_refptr<media::VideoFrame> GetCurrentFrame() = 0; | 80 virtual scoped_refptr<media::VideoFrame> GetCurrentFrame() = 0; |
53 | 81 |
54 // This function releases the lock on the video frame. It should always be | 82 // Indicates that the last frame returned via GetCurrentFrame() is expected to |
55 // called after GetCurrentFrame(). Frames passed into this method | 83 // be rendered. Must only occur after a previous call to GetCurrentFrame(). |
56 // should no longer be referenced after the call is made. Only the current | 84 virtual void PutCurrentFrame() = 0; |
57 // provider client should call this function. | 85 |
58 virtual void PutCurrentFrame( | 86 protected: |
59 const scoped_refptr<media::VideoFrame>& frame) = 0; | 87 virtual ~VideoFrameProvider() {} |
60 }; | 88 }; |
61 | 89 |
62 } // namespace cc | 90 } // namespace cc |
63 | 91 |
64 #endif // CC_LAYERS_VIDEO_FRAME_PROVIDER_H_ | 92 #endif // CC_LAYERS_VIDEO_FRAME_PROVIDER_H_ |
OLD | NEW |