OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_CLIENT_IMPL_H_ | 5 #ifndef CC_LAYERS_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_ |
6 #define CC_LAYERS_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_ | 6 #define CC_LAYERS_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
10 #include "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.h" |
11 #include "cc/base/cc_export.h" | |
11 #include "cc/layers/video_frame_provider.h" | 12 #include "cc/layers/video_frame_provider.h" |
12 #include "ui/gfx/transform.h" | 13 #include "ui/gfx/transform.h" |
13 | 14 |
14 namespace media { class VideoFrame; } | 15 namespace media { class VideoFrame; } |
15 | 16 |
16 namespace cc { | 17 namespace cc { |
17 class VideoLayerImpl; | 18 class VideoLayerImpl; |
18 | 19 |
19 class VideoFrameProviderClientImpl | 20 // VideoFrameProviderClientImpl liasons with the VideoFrameProvider and the |
21 // VideoLayer. It receives updates from the provider and updates the layer as a | |
22 // result. It also allows the layer to access the video frame that the provider | |
23 // has. | |
24 class CC_EXPORT VideoFrameProviderClientImpl | |
20 : public VideoFrameProvider::Client, | 25 : public VideoFrameProvider::Client, |
21 public base::RefCounted<VideoFrameProviderClientImpl> { | 26 public base::RefCounted<VideoFrameProviderClientImpl> { |
22 public: | 27 public: |
28 // Must be created on the impl thread while the main thread is blocked. | |
23 static scoped_refptr<VideoFrameProviderClientImpl> Create( | 29 static scoped_refptr<VideoFrameProviderClientImpl> Create( |
24 VideoFrameProvider* provider); | 30 VideoFrameProvider* provider); |
25 | 31 |
26 VideoLayerImpl* active_video_layer() { return active_video_layer_; } | 32 VideoLayerImpl* ActiveVideoLayer() const; |
27 void SetActiveVideoLayer(VideoLayerImpl* video_layer); | 33 void SetActiveVideoLayer(VideoLayerImpl* video_layer); |
28 | 34 |
29 void Stop(); | 35 bool Destroyed() const; |
30 bool Stopped(); | 36 // Must be called on the impl thread while the main thread is blocked. |
37 void Destroy(); | |
31 | 38 |
32 scoped_refptr<media::VideoFrame> AcquireLockAndCurrentFrame(); | 39 scoped_refptr<media::VideoFrame> AcquireLockAndCurrentFrame(); |
33 void PutCurrentFrame(const scoped_refptr<media::VideoFrame>& frame); | 40 void PutCurrentFrame(const scoped_refptr<media::VideoFrame>& frame); |
34 void ReleaseLock(); | 41 void ReleaseLock(); |
35 const gfx::Transform& stream_texture_matrix() const { | |
36 return stream_texture_matrix_; | |
37 } | |
38 | 42 |
39 // VideoFrameProvider::Client implementation. These methods are all callable | 43 const gfx::Transform& StreamTextureMatrix() const; |
40 // on any thread. | 44 |
45 // VideoFrameProvider::Client implementation. | |
46 // Called on the main thread. | |
41 void StopUsingProvider() override; | 47 void StopUsingProvider() override; |
48 // Called on the impl thread. | |
42 void DidReceiveFrame() override; | 49 void DidReceiveFrame() override; |
43 void DidUpdateMatrix(const float* matrix) override; | 50 void DidUpdateMatrix(const float* matrix) override; |
44 | 51 |
45 private: | 52 private: |
53 friend class base::RefCounted<VideoFrameProviderClientImpl>; | |
54 | |
46 explicit VideoFrameProviderClientImpl(VideoFrameProvider* provider); | 55 explicit VideoFrameProviderClientImpl(VideoFrameProvider* provider); |
47 friend class base::RefCounted<VideoFrameProviderClientImpl>; | |
48 ~VideoFrameProviderClientImpl() override; | 56 ~VideoFrameProviderClientImpl() override; |
49 | 57 |
58 VideoFrameProvider* provider_; | |
50 VideoLayerImpl* active_video_layer_; | 59 VideoLayerImpl* active_video_layer_; |
60 bool destroyed_; | |
51 | 61 |
52 // Guards the destruction of provider_ and the frame that it provides | 62 // Since the provider lives on another thread, it can be destroyed while the |
63 // frame controller are accessing it's frame. Before being destroyed the | |
danakj
2015/03/26 22:38:35
"is accessing"
sunnyps
2015/03/27 00:38:46
Done.
| |
64 // provider calls StopUsingProvider. provider_lock_ blocks StopUsingProvider | |
65 // from returning till the frame controller is done using the frame. | |
danakj
2015/03/26 22:38:35
"until"
sunnyps
2015/03/27 00:38:46
Done.
| |
53 base::Lock provider_lock_; | 66 base::Lock provider_lock_; |
54 VideoFrameProvider* provider_; | |
55 base::ThreadChecker thread_checker_; | 67 base::ThreadChecker thread_checker_; |
56 | 68 |
57 gfx::Transform stream_texture_matrix_; | 69 gfx::Transform stream_texture_matrix_; |
58 | 70 |
59 DISALLOW_COPY_AND_ASSIGN(VideoFrameProviderClientImpl); | 71 DISALLOW_COPY_AND_ASSIGN(VideoFrameProviderClientImpl); |
60 }; | 72 }; |
61 | 73 |
62 } // namespace cc | 74 } // namespace cc |
63 | 75 |
64 #endif // CC_LAYERS_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_ | 76 #endif // CC_LAYERS_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_ |
OLD | NEW |