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 #include "cc/layers/video_frame_provider_client_impl.h" | 5 #include "cc/layers/video_frame_provider_client_impl.h" |
6 | 6 |
7 #include "base/trace_event/trace_event.h" | 7 #include "base/trace_event/trace_event.h" |
8 #include "cc/base/math_util.h" | 8 #include "cc/base/math_util.h" |
9 #include "cc/layers/video_layer_impl.h" | 9 #include "cc/layers/video_layer_impl.h" |
10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
11 | 11 |
12 namespace cc { | 12 namespace cc { |
13 | 13 |
14 // static | 14 // static |
15 scoped_refptr<VideoFrameProviderClientImpl> | 15 scoped_refptr<VideoFrameProviderClientImpl> |
16 VideoFrameProviderClientImpl::Create(VideoFrameProvider* provider, | 16 VideoFrameProviderClientImpl::Create(VideoFrameProvider* provider, |
17 VideoFrameControllerClient* client) { | 17 VideoFrameControllerClient* client) { |
18 return make_scoped_refptr(new VideoFrameProviderClientImpl(provider, client)); | 18 return make_scoped_refptr(new VideoFrameProviderClientImpl(provider, client)); |
19 } | 19 } |
20 | 20 |
21 VideoFrameProviderClientImpl::VideoFrameProviderClientImpl( | 21 VideoFrameProviderClientImpl::VideoFrameProviderClientImpl( |
22 VideoFrameProvider* provider, | 22 VideoFrameProvider* provider, |
23 VideoFrameControllerClient* client) | 23 VideoFrameControllerClient* client) |
24 : provider_(provider), | 24 : provider_(provider), |
25 client_(client), | 25 client_(client), |
26 active_video_layer_(nullptr), | 26 active_video_layer_(nullptr), |
27 stopped_(false) { | 27 stopped_(false), |
| 28 rendering_(false) { |
28 // This only happens during a commit on the compositor thread while the main | 29 // This only happens during a commit on the compositor thread while the main |
29 // thread is blocked. That makes this a thread-safe call to set the video | 30 // thread is blocked. That makes this a thread-safe call to set the video |
30 // frame provider client that does not require a lock. The same is true of | 31 // frame provider client that does not require a lock. The same is true of |
31 // the call to Stop(). | 32 // the call to Stop(). |
32 provider_->SetVideoFrameProviderClient(this); | 33 provider_->SetVideoFrameProviderClient(this); |
33 | 34 |
34 // This matrix is the default transformation for stream textures, and flips | 35 // This matrix is the default transformation for stream textures, and flips |
35 // on the Y axis. | 36 // on the Y axis. |
36 stream_texture_matrix_ = gfx::Transform( | 37 stream_texture_matrix_ = gfx::Transform( |
37 1.0, 0.0, 0.0, 0.0, | 38 1.0, 0.0, 0.0, 0.0, |
(...skipping 19 matching lines...) Expand all Loading... |
57 active_video_layer_ = video_layer; | 58 active_video_layer_ = video_layer; |
58 } | 59 } |
59 | 60 |
60 void VideoFrameProviderClientImpl::Stop() { | 61 void VideoFrameProviderClientImpl::Stop() { |
61 DCHECK(thread_checker_.CalledOnValidThread()); | 62 DCHECK(thread_checker_.CalledOnValidThread()); |
62 // It's called when the main thread is blocked, so lock isn't needed. | 63 // It's called when the main thread is blocked, so lock isn't needed. |
63 if (provider_) { | 64 if (provider_) { |
64 provider_->SetVideoFrameProviderClient(nullptr); | 65 provider_->SetVideoFrameProviderClient(nullptr); |
65 provider_ = nullptr; | 66 provider_ = nullptr; |
66 } | 67 } |
67 client_->RemoveVideoFrameController(this); | 68 if (rendering_) |
| 69 StopRendering(); |
68 active_video_layer_ = nullptr; | 70 active_video_layer_ = nullptr; |
69 stopped_ = true; | 71 stopped_ = true; |
70 } | 72 } |
71 | 73 |
72 bool VideoFrameProviderClientImpl::Stopped() const { | 74 bool VideoFrameProviderClientImpl::Stopped() const { |
73 DCHECK(thread_checker_.CalledOnValidThread()); | 75 DCHECK(thread_checker_.CalledOnValidThread()); |
74 return stopped_; | 76 return stopped_; |
75 } | 77 } |
76 | 78 |
77 scoped_refptr<media::VideoFrame> | 79 scoped_refptr<media::VideoFrame> |
(...skipping 25 matching lines...) Expand all Loading... |
103 } | 105 } |
104 | 106 |
105 void VideoFrameProviderClientImpl::StopUsingProvider() { | 107 void VideoFrameProviderClientImpl::StopUsingProvider() { |
106 // Block the provider from shutting down until this client is done | 108 // Block the provider from shutting down until this client is done |
107 // using the frame. | 109 // using the frame. |
108 base::AutoLock locker(provider_lock_); | 110 base::AutoLock locker(provider_lock_); |
109 provider_ = nullptr; | 111 provider_ = nullptr; |
110 } | 112 } |
111 | 113 |
112 void VideoFrameProviderClientImpl::StartRendering() { | 114 void VideoFrameProviderClientImpl::StartRendering() { |
113 // TODO(dalecurtis, sunnyps): Hook this method up to control when to start | 115 DCHECK(thread_checker_.CalledOnValidThread()); |
114 // observing vsync intervals. http://crbug.com/336733 | 116 TRACE_EVENT0("cc", "VideoFrameProviderClientImpl::StartRendering"); |
| 117 DCHECK(!rendering_); |
| 118 DCHECK(!stopped_); |
| 119 client_->AddVideoFrameController(this); |
| 120 rendering_ = true; |
115 } | 121 } |
116 | 122 |
117 void VideoFrameProviderClientImpl::StopRendering() { | 123 void VideoFrameProviderClientImpl::StopRendering() { |
118 // TODO(dalecurtis, sunnyps): Hook this method up to control when to stop | 124 DCHECK(thread_checker_.CalledOnValidThread()); |
119 // observing vsync intervals. http://crbug.com/336733 | 125 TRACE_EVENT0("cc", "VideoFrameProviderClientImpl::StopRendering"); |
| 126 DCHECK(rendering_); |
| 127 DCHECK(!stopped_); |
| 128 client_->RemoveVideoFrameController(this); |
| 129 rendering_ = false; |
120 } | 130 } |
121 | 131 |
122 void VideoFrameProviderClientImpl::DidReceiveFrame() { | 132 void VideoFrameProviderClientImpl::DidReceiveFrame() { |
123 TRACE_EVENT1("cc", | 133 TRACE_EVENT1("cc", |
124 "VideoFrameProviderClientImpl::DidReceiveFrame", | 134 "VideoFrameProviderClientImpl::DidReceiveFrame", |
125 "active_video_layer", | 135 "active_video_layer", |
126 !!active_video_layer_); | 136 !!active_video_layer_); |
127 DCHECK(thread_checker_.CalledOnValidThread()); | 137 DCHECK(thread_checker_.CalledOnValidThread()); |
128 if (active_video_layer_) | 138 if (active_video_layer_) |
129 active_video_layer_->SetNeedsRedraw(); | 139 active_video_layer_->SetNeedsRedraw(); |
130 } | 140 } |
131 | 141 |
132 void VideoFrameProviderClientImpl::DidUpdateMatrix(const float* matrix) { | 142 void VideoFrameProviderClientImpl::DidUpdateMatrix(const float* matrix) { |
133 DCHECK(thread_checker_.CalledOnValidThread()); | 143 DCHECK(thread_checker_.CalledOnValidThread()); |
134 stream_texture_matrix_ = gfx::Transform( | 144 stream_texture_matrix_ = gfx::Transform( |
135 matrix[0], matrix[4], matrix[8], matrix[12], | 145 matrix[0], matrix[4], matrix[8], matrix[12], |
136 matrix[1], matrix[5], matrix[9], matrix[13], | 146 matrix[1], matrix[5], matrix[9], matrix[13], |
137 matrix[2], matrix[6], matrix[10], matrix[14], | 147 matrix[2], matrix[6], matrix[10], matrix[14], |
138 matrix[3], matrix[7], matrix[11], matrix[15]); | 148 matrix[3], matrix[7], matrix[11], matrix[15]); |
139 if (active_video_layer_) | 149 if (active_video_layer_) |
140 active_video_layer_->SetNeedsRedraw(); | 150 active_video_layer_->SetNeedsRedraw(); |
141 } | 151 } |
142 | 152 |
143 void VideoFrameProviderClientImpl::OnBeginFrame(const BeginFrameArgs& args) { | 153 void VideoFrameProviderClientImpl::OnBeginFrame(const BeginFrameArgs& args) { |
144 DCHECK(thread_checker_.CalledOnValidThread()); | 154 DCHECK(thread_checker_.CalledOnValidThread()); |
145 NOTIMPLEMENTED(); | 155 DCHECK(rendering_); |
| 156 DCHECK(!stopped_); |
| 157 |
| 158 TRACE_EVENT0("cc", "VideoFrameProviderClientImpl::OnBeginFrame"); |
| 159 base::AutoLock locker(provider_lock_); |
| 160 |
| 161 // We use frame_time + interval here because that is the estimated time at |
| 162 // which a frame returned during this phase will end up being displayed. |
| 163 if (!provider_ || |
| 164 !provider_->UpdateCurrentFrame(args.frame_time + args.interval, |
| 165 args.frame_time + 2 * args.interval)) { |
| 166 return; |
| 167 } |
| 168 |
| 169 DidReceiveFrame(); |
146 } | 170 } |
147 | 171 |
148 } // namespace cc | 172 } // namespace cc |
OLD | NEW |