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_(true) { |
sunnyps
2015/04/24 23:18:11
Let's not use the stopped_ variable for keeping tr
| |
28 // This only happens during a commit on the compositor thread while the main | 28 // 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 | 29 // 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 | 30 // frame provider client that does not require a lock. The same is true of |
31 // the call to Stop(). | 31 // the call to Stop(). |
32 provider_->SetVideoFrameProviderClient(this); | 32 provider_->SetVideoFrameProviderClient(this); |
33 | 33 |
34 // This matrix is the default transformation for stream textures, and flips | 34 // This matrix is the default transformation for stream textures, and flips |
35 // on the Y axis. | 35 // on the Y axis. |
36 stream_texture_matrix_ = gfx::Transform( | 36 stream_texture_matrix_ = gfx::Transform( |
37 1.0, 0.0, 0.0, 0.0, | 37 1.0, 0.0, 0.0, 0.0, |
(...skipping 19 matching lines...) Expand all Loading... | |
57 active_video_layer_ = video_layer; | 57 active_video_layer_ = video_layer; |
58 } | 58 } |
59 | 59 |
60 void VideoFrameProviderClientImpl::Stop() { | 60 void VideoFrameProviderClientImpl::Stop() { |
61 DCHECK(thread_checker_.CalledOnValidThread()); | 61 DCHECK(thread_checker_.CalledOnValidThread()); |
62 // It's called when the main thread is blocked, so lock isn't needed. | 62 // It's called when the main thread is blocked, so lock isn't needed. |
63 if (provider_) { | 63 if (provider_) { |
64 provider_->SetVideoFrameProviderClient(nullptr); | 64 provider_->SetVideoFrameProviderClient(nullptr); |
65 provider_ = nullptr; | 65 provider_ = nullptr; |
66 } | 66 } |
67 client_->RemoveVideoFrameController(this); | 67 if (!stopped_) |
68 client_->RemoveVideoFrameController(this); | |
68 active_video_layer_ = nullptr; | 69 active_video_layer_ = nullptr; |
69 stopped_ = true; | 70 stopped_ = true; |
70 } | 71 } |
71 | 72 |
72 bool VideoFrameProviderClientImpl::Stopped() const { | 73 bool VideoFrameProviderClientImpl::Stopped() const { |
73 DCHECK(thread_checker_.CalledOnValidThread()); | 74 DCHECK(thread_checker_.CalledOnValidThread()); |
74 return stopped_; | 75 return stopped_; |
75 } | 76 } |
76 | 77 |
77 scoped_refptr<media::VideoFrame> | 78 scoped_refptr<media::VideoFrame> |
(...skipping 25 matching lines...) Expand all Loading... | |
103 } | 104 } |
104 | 105 |
105 void VideoFrameProviderClientImpl::StopUsingProvider() { | 106 void VideoFrameProviderClientImpl::StopUsingProvider() { |
106 // Block the provider from shutting down until this client is done | 107 // Block the provider from shutting down until this client is done |
107 // using the frame. | 108 // using the frame. |
108 base::AutoLock locker(provider_lock_); | 109 base::AutoLock locker(provider_lock_); |
109 provider_ = nullptr; | 110 provider_ = nullptr; |
110 } | 111 } |
111 | 112 |
112 void VideoFrameProviderClientImpl::StartRendering() { | 113 void VideoFrameProviderClientImpl::StartRendering() { |
113 // TODO(dalecurtis, sunnyps): Hook this method up to control when to start | 114 DCHECK(thread_checker_.CalledOnValidThread()); |
114 // observing vsync intervals. http://crbug.com/336733 | 115 TRACE_EVENT0("cc", "VideoFrameProviderClientImpl::StartRendering"); |
sunnyps
2015/04/24 23:18:11
Might want to do a DCHECK(stopped_) here.
| |
116 if (stopped_) | |
117 client_->AddVideoFrameController(this); | |
118 stopped_ = false; | |
115 } | 119 } |
116 | 120 |
117 void VideoFrameProviderClientImpl::StopRendering() { | 121 void VideoFrameProviderClientImpl::StopRendering() { |
118 // TODO(dalecurtis, sunnyps): Hook this method up to control when to stop | 122 DCHECK(thread_checker_.CalledOnValidThread()); |
119 // observing vsync intervals. http://crbug.com/336733 | 123 TRACE_EVENT0("cc", "VideoFrameProviderClientImpl::StopRendering"); |
124 if (!stopped_) | |
125 client_->RemoveVideoFrameController(this); | |
126 stopped_ = true; | |
120 } | 127 } |
121 | 128 |
122 void VideoFrameProviderClientImpl::DidReceiveFrame() { | 129 void VideoFrameProviderClientImpl::DidReceiveFrame() { |
123 TRACE_EVENT1("cc", | 130 TRACE_EVENT1("cc", |
124 "VideoFrameProviderClientImpl::DidReceiveFrame", | 131 "VideoFrameProviderClientImpl::DidReceiveFrame", |
125 "active_video_layer", | 132 "active_video_layer", |
126 !!active_video_layer_); | 133 !!active_video_layer_); |
127 DCHECK(thread_checker_.CalledOnValidThread()); | 134 DCHECK(thread_checker_.CalledOnValidThread()); |
128 if (active_video_layer_) | 135 if (active_video_layer_) |
129 active_video_layer_->SetNeedsRedraw(); | 136 active_video_layer_->SetNeedsRedraw(); |
130 } | 137 } |
131 | 138 |
132 void VideoFrameProviderClientImpl::DidUpdateMatrix(const float* matrix) { | 139 void VideoFrameProviderClientImpl::DidUpdateMatrix(const float* matrix) { |
133 DCHECK(thread_checker_.CalledOnValidThread()); | 140 DCHECK(thread_checker_.CalledOnValidThread()); |
134 stream_texture_matrix_ = gfx::Transform( | 141 stream_texture_matrix_ = gfx::Transform( |
135 matrix[0], matrix[4], matrix[8], matrix[12], | 142 matrix[0], matrix[4], matrix[8], matrix[12], |
136 matrix[1], matrix[5], matrix[9], matrix[13], | 143 matrix[1], matrix[5], matrix[9], matrix[13], |
137 matrix[2], matrix[6], matrix[10], matrix[14], | 144 matrix[2], matrix[6], matrix[10], matrix[14], |
138 matrix[3], matrix[7], matrix[11], matrix[15]); | 145 matrix[3], matrix[7], matrix[11], matrix[15]); |
139 if (active_video_layer_) | 146 if (active_video_layer_) |
140 active_video_layer_->SetNeedsRedraw(); | 147 active_video_layer_->SetNeedsRedraw(); |
141 } | 148 } |
142 | 149 |
143 void VideoFrameProviderClientImpl::OnBeginFrame(const BeginFrameArgs& args) { | 150 void VideoFrameProviderClientImpl::OnBeginFrame(const BeginFrameArgs& args) { |
144 DCHECK(thread_checker_.CalledOnValidThread()); | 151 DCHECK(thread_checker_.CalledOnValidThread()); |
145 NOTIMPLEMENTED(); | 152 DCHECK(!stopped_); |
153 | |
154 TRACE_EVENT0("cc", "VideoFrameProviderClientImpl::OnBeginFrame"); | |
155 base::AutoLock locker(provider_lock_); | |
156 | |
157 // TODO(dalecurtis): Triple check these time arguments. | |
158 // Is frame_time + interval the time at which this frame would be displayed? | |
159 if (!provider_ || | |
160 !provider_->UpdateCurrentFrame(args.frame_time + args.interval, | |
miu
2015/04/24 22:35:34
Looks like this math is saying the frame will be d
DaleCurtis
2015/04/24 22:43:18
No, provided these values are when the frame is di
sunnyps
2015/04/24 23:18:11
frame_time + interval is the time the frame would
DaleCurtis
2015/04/24 23:35:01
Can you elaborate? It sounds like you're saying mu
| |
161 args.frame_time + 2 * args.interval)) { | |
162 return; | |
163 } | |
164 | |
165 DidReceiveFrame(); | |
146 } | 166 } |
147 | 167 |
148 } // namespace cc | 168 } // namespace cc |
OLD | NEW |