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 // Notes about usage of this object by VideoCaptureImplManager. | 5 // Notes about usage of this object by VideoCaptureImplManager. |
6 // | 6 // |
7 // VideoCaptureImplManager access this object by using a Unretained() | 7 // VideoCaptureImplManager access this object by using a Unretained() |
8 // binding and tasks on the IO thread. It is then important that | 8 // binding and tasks on the IO thread. It is then important that |
9 // VideoCaptureImpl never post task to itself. All operations must be | 9 // VideoCaptureImpl never post task to itself. All operations must be |
10 // synchronous. | 10 // synchronous. |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 void VideoCaptureImpl::OnBufferReceived(int buffer_id, | 207 void VideoCaptureImpl::OnBufferReceived(int buffer_id, |
208 const media::VideoCaptureFormat& format, | 208 const media::VideoCaptureFormat& format, |
209 base::TimeTicks timestamp) { | 209 base::TimeTicks timestamp) { |
210 DCHECK(thread_checker_.CalledOnValidThread()); | 210 DCHECK(thread_checker_.CalledOnValidThread()); |
211 | 211 |
212 // The capture pipeline supports only I420 for now. | 212 // The capture pipeline supports only I420 for now. |
213 DCHECK_EQ(format.pixel_format, media::PIXEL_FORMAT_I420); | 213 DCHECK_EQ(format.pixel_format, media::PIXEL_FORMAT_I420); |
214 | 214 |
215 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { | 215 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { |
216 Send(new VideoCaptureHostMsg_BufferReady( | 216 Send(new VideoCaptureHostMsg_BufferReady( |
217 device_id_, buffer_id, std::vector<uint32>())); | 217 device_id_, buffer_id, std::map<std::string, uint32>())); |
218 return; | 218 return; |
219 } | 219 } |
220 | 220 |
221 last_frame_format_ = format; | 221 last_frame_format_ = format; |
222 if (first_frame_timestamp_.is_null()) | 222 if (first_frame_timestamp_.is_null()) |
223 first_frame_timestamp_ = timestamp; | 223 first_frame_timestamp_ = timestamp; |
224 | 224 |
225 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc | 225 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc |
226 TRACE_EVENT_INSTANT2( | 226 TRACE_EVENT_INSTANT2( |
227 "cast_perf_test", "OnBufferReceived", | 227 "cast_perf_test", "OnBufferReceived", |
(...skipping 12 matching lines...) Expand all Loading... |
240 last_frame_format_.frame_size, | 240 last_frame_format_.frame_size, |
241 reinterpret_cast<uint8*>(buffer->buffer->memory()), | 241 reinterpret_cast<uint8*>(buffer->buffer->memory()), |
242 buffer->buffer_size, | 242 buffer->buffer_size, |
243 buffer->buffer->handle(), | 243 buffer->buffer->handle(), |
244 timestamp - first_frame_timestamp_, | 244 timestamp - first_frame_timestamp_, |
245 media::BindToCurrentLoop( | 245 media::BindToCurrentLoop( |
246 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, | 246 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, |
247 weak_factory_.GetWeakPtr(), | 247 weak_factory_.GetWeakPtr(), |
248 buffer_id, | 248 buffer_id, |
249 buffer, | 249 buffer, |
250 std::vector<uint32>()))); | 250 std::map<std::string, uint32>()))); |
251 | 251 |
252 for (ClientInfoMap::iterator it = clients_.begin(); it != clients_.end(); | 252 for (ClientInfoMap::iterator it = clients_.begin(); it != clients_.end(); |
253 ++it) { | 253 ++it) { |
254 it->second.deliver_frame_cb.Run(frame, format); | 254 it->second.deliver_frame_cb.Run(frame, format); |
255 } | 255 } |
256 } | 256 } |
257 | 257 |
258 static void NullReadPixelsCB(const SkBitmap& bitmap) { NOTIMPLEMENTED(); } | 258 static void NullReadPixelsCB(const SkBitmap& bitmap) { NOTIMPLEMENTED(); } |
259 | 259 |
260 void VideoCaptureImpl::OnMailboxBufferReceived( | 260 void VideoCaptureImpl::OnMailboxBufferReceived( |
261 int buffer_id, | 261 int buffer_id, |
262 const gpu::MailboxHolder& mailbox_holder, | 262 const gpu::MailboxHolder& mailbox_holder, |
263 const media::VideoCaptureFormat& format, | 263 const media::VideoCaptureFormat& format, |
264 base::TimeTicks timestamp) { | 264 base::TimeTicks timestamp) { |
265 DCHECK(thread_checker_.CalledOnValidThread()); | 265 DCHECK(thread_checker_.CalledOnValidThread()); |
266 | 266 |
267 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { | 267 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { |
268 Send(new VideoCaptureHostMsg_BufferReady( | 268 Send(new VideoCaptureHostMsg_BufferReady( |
269 device_id_, buffer_id, std::vector<uint32>())); | 269 device_id_, buffer_id, std::map<std::string, uint32>())); |
270 return; | 270 return; |
271 } | 271 } |
272 | 272 |
273 last_frame_format_ = format; | 273 last_frame_format_ = format; |
274 if (first_frame_timestamp_.is_null()) | 274 if (first_frame_timestamp_.is_null()) |
275 first_frame_timestamp_ = timestamp; | 275 first_frame_timestamp_ = timestamp; |
276 | 276 |
277 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture( | 277 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::WrapNativeTexture( |
278 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)), | 278 make_scoped_ptr(new gpu::MailboxHolder(mailbox_holder)), |
279 media::BindToCurrentLoop( | 279 media::BindToCurrentLoop( |
280 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, | 280 base::Bind(&VideoCaptureImpl::OnClientBufferFinished, |
281 weak_factory_.GetWeakPtr(), | 281 weak_factory_.GetWeakPtr(), |
282 buffer_id, | 282 buffer_id, |
283 scoped_refptr<ClientBuffer>())), | 283 scoped_refptr<ClientBuffer>())), |
284 last_frame_format_.frame_size, | 284 last_frame_format_.frame_size, |
285 gfx::Rect(last_frame_format_.frame_size), | 285 gfx::Rect(last_frame_format_.frame_size), |
286 last_frame_format_.frame_size, | 286 last_frame_format_.frame_size, |
287 timestamp - first_frame_timestamp_, | 287 timestamp - first_frame_timestamp_, |
288 base::Bind(&NullReadPixelsCB)); | 288 base::Bind(&NullReadPixelsCB)); |
289 | 289 |
290 for (ClientInfoMap::iterator it = clients_.begin(); it != clients_.end(); | 290 for (ClientInfoMap::iterator it = clients_.begin(); it != clients_.end(); |
291 ++it) { | 291 ++it) { |
292 it->second.deliver_frame_cb.Run(frame, format); | 292 it->second.deliver_frame_cb.Run(frame, format); |
293 } | 293 } |
294 } | 294 } |
295 | 295 |
296 void VideoCaptureImpl::OnClientBufferFinished( | 296 void VideoCaptureImpl::OnClientBufferFinished( |
297 int buffer_id, | 297 int buffer_id, |
298 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, | 298 const scoped_refptr<ClientBuffer>& /* ignored_buffer */, |
299 const std::vector<uint32>& release_sync_points) { | 299 const std::map<std::string, uint32>& release_sync_points) { |
300 DCHECK(thread_checker_.CalledOnValidThread()); | 300 DCHECK(thread_checker_.CalledOnValidThread()); |
301 Send(new VideoCaptureHostMsg_BufferReady( | 301 Send(new VideoCaptureHostMsg_BufferReady( |
302 device_id_, buffer_id, release_sync_points)); | 302 device_id_, buffer_id, release_sync_points)); |
303 } | 303 } |
304 | 304 |
305 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { | 305 void VideoCaptureImpl::OnStateChanged(VideoCaptureState state) { |
306 DCHECK(thread_checker_.CalledOnValidThread()); | 306 DCHECK(thread_checker_.CalledOnValidThread()); |
307 | 307 |
308 switch (state) { | 308 switch (state) { |
309 case VIDEO_CAPTURE_STATE_STARTED: | 309 case VIDEO_CAPTURE_STATE_STARTED: |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 ClientInfoMap::iterator it = clients->find(client_id); | 435 ClientInfoMap::iterator it = clients->find(client_id); |
436 if (it != clients->end()) { | 436 if (it != clients->end()) { |
437 it->second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED); | 437 it->second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED); |
438 clients->erase(it); | 438 clients->erase(it); |
439 found = true; | 439 found = true; |
440 } | 440 } |
441 return found; | 441 return found; |
442 } | 442 } |
443 | 443 |
444 } // namespace content | 444 } // namespace content |
OLD | NEW |