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 22 matching lines...) Expand all Loading... |
100 const { | 102 const { |
101 DCHECK(thread_checker_.CalledOnValidThread()); | 103 DCHECK(thread_checker_.CalledOnValidThread()); |
102 return stream_texture_matrix_; | 104 return stream_texture_matrix_; |
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; |
| 112 if (rendering_) |
| 113 StopRendering(); |
110 } | 114 } |
111 | 115 |
112 void VideoFrameProviderClientImpl::StartRendering() { | 116 void VideoFrameProviderClientImpl::StartRendering() { |
113 // TODO(dalecurtis, sunnyps): Hook this method up to control when to start | 117 DCHECK(thread_checker_.CalledOnValidThread()); |
114 // observing vsync intervals. http://crbug.com/336733 | 118 TRACE_EVENT0("cc", "VideoFrameProviderClientImpl::StartRendering"); |
| 119 DCHECK(!rendering_); |
| 120 DCHECK(!stopped_); |
| 121 client_->AddVideoFrameController(this); |
| 122 rendering_ = true; |
115 } | 123 } |
116 | 124 |
117 void VideoFrameProviderClientImpl::StopRendering() { | 125 void VideoFrameProviderClientImpl::StopRendering() { |
118 // TODO(dalecurtis, sunnyps): Hook this method up to control when to stop | 126 DCHECK(thread_checker_.CalledOnValidThread()); |
119 // observing vsync intervals. http://crbug.com/336733 | 127 TRACE_EVENT0("cc", "VideoFrameProviderClientImpl::StopRendering"); |
| 128 DCHECK(rendering_); |
| 129 DCHECK(!stopped_); |
| 130 client_->RemoveVideoFrameController(this); |
| 131 rendering_ = false; |
120 } | 132 } |
121 | 133 |
122 void VideoFrameProviderClientImpl::DidReceiveFrame() { | 134 void VideoFrameProviderClientImpl::DidReceiveFrame() { |
123 TRACE_EVENT1("cc", | 135 TRACE_EVENT1("cc", |
124 "VideoFrameProviderClientImpl::DidReceiveFrame", | 136 "VideoFrameProviderClientImpl::DidReceiveFrame", |
125 "active_video_layer", | 137 "active_video_layer", |
126 !!active_video_layer_); | 138 !!active_video_layer_); |
127 DCHECK(thread_checker_.CalledOnValidThread()); | 139 DCHECK(thread_checker_.CalledOnValidThread()); |
128 if (active_video_layer_) | 140 if (active_video_layer_) |
129 active_video_layer_->SetNeedsRedraw(); | 141 active_video_layer_->SetNeedsRedraw(); |
130 } | 142 } |
131 | 143 |
132 void VideoFrameProviderClientImpl::DidUpdateMatrix(const float* matrix) { | 144 void VideoFrameProviderClientImpl::DidUpdateMatrix(const float* matrix) { |
133 DCHECK(thread_checker_.CalledOnValidThread()); | 145 DCHECK(thread_checker_.CalledOnValidThread()); |
134 stream_texture_matrix_ = gfx::Transform( | 146 stream_texture_matrix_ = gfx::Transform( |
135 matrix[0], matrix[4], matrix[8], matrix[12], | 147 matrix[0], matrix[4], matrix[8], matrix[12], |
136 matrix[1], matrix[5], matrix[9], matrix[13], | 148 matrix[1], matrix[5], matrix[9], matrix[13], |
137 matrix[2], matrix[6], matrix[10], matrix[14], | 149 matrix[2], matrix[6], matrix[10], matrix[14], |
138 matrix[3], matrix[7], matrix[11], matrix[15]); | 150 matrix[3], matrix[7], matrix[11], matrix[15]); |
139 if (active_video_layer_) | 151 if (active_video_layer_) |
140 active_video_layer_->SetNeedsRedraw(); | 152 active_video_layer_->SetNeedsRedraw(); |
141 } | 153 } |
142 | 154 |
143 void VideoFrameProviderClientImpl::OnBeginFrame(const BeginFrameArgs& args) { | 155 void VideoFrameProviderClientImpl::OnBeginFrame(const BeginFrameArgs& args) { |
144 DCHECK(thread_checker_.CalledOnValidThread()); | 156 DCHECK(thread_checker_.CalledOnValidThread()); |
145 NOTIMPLEMENTED(); | 157 DCHECK(rendering_); |
| 158 DCHECK(!stopped_); |
| 159 |
| 160 TRACE_EVENT0("cc", "VideoFrameProviderClientImpl::OnBeginFrame"); |
| 161 base::AutoLock locker(provider_lock_); |
| 162 |
| 163 // We use frame_time + interval here because that is the estimated time at |
| 164 // which a frame returned during this phase will end up being displayed. |
| 165 if (!provider_ || |
| 166 !provider_->UpdateCurrentFrame(args.frame_time + args.interval, |
| 167 args.frame_time + 2 * args.interval)) { |
| 168 return; |
| 169 } |
| 170 |
| 171 DidReceiveFrame(); |
146 } | 172 } |
147 | 173 |
148 } // namespace cc | 174 } // namespace cc |
OLD | NEW |