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 #include "content/renderer/media/video_capture_impl.h" | 5 #include "content/renderer/media/video_capture_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "content/common/child_process.h" | 9 #include "content/common/child_process.h" |
10 #include "content/common/media/video_capture_messages.h" | 10 #include "content/common/media/video_capture_messages.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 const media::VideoCaptureSessionId id, | 49 const media::VideoCaptureSessionId id, |
50 base::MessageLoopProxy* capture_message_loop_proxy, | 50 base::MessageLoopProxy* capture_message_loop_proxy, |
51 VideoCaptureMessageFilter* filter) | 51 VideoCaptureMessageFilter* filter) |
52 : VideoCapture(), | 52 : VideoCapture(), |
53 message_filter_(filter), | 53 message_filter_(filter), |
54 capture_message_loop_proxy_(capture_message_loop_proxy), | 54 capture_message_loop_proxy_(capture_message_loop_proxy), |
55 io_message_loop_proxy_(ChildProcess::current()->io_message_loop_proxy()), | 55 io_message_loop_proxy_(ChildProcess::current()->io_message_loop_proxy()), |
56 device_id_(0), | 56 device_id_(0), |
57 video_type_(media::VideoCaptureCapability::kI420), | 57 video_type_(media::VideoCaptureCapability::kI420), |
58 device_info_available_(false), | 58 device_info_available_(false), |
| 59 suspended_(false), |
59 state_(VIDEO_CAPTURE_STATE_STOPPED) { | 60 state_(VIDEO_CAPTURE_STATE_STOPPED) { |
60 DCHECK(filter); | 61 DCHECK(filter); |
61 memset(¤t_params_, 0, sizeof(current_params_)); | 62 memset(¤t_params_, 0, sizeof(current_params_)); |
62 memset(&device_info_, 0, sizeof(device_info_)); | 63 memset(&device_info_, 0, sizeof(device_info_)); |
63 current_params_.session_id = id; | 64 current_params_.session_id = id; |
64 } | 65 } |
65 | 66 |
66 VideoCaptureImpl::~VideoCaptureImpl() { | 67 VideoCaptureImpl::~VideoCaptureImpl() { |
67 STLDeleteValues(&cached_dibs_); | 68 STLDeleteValues(&cached_dibs_); |
68 } | 69 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 base::Bind(&VideoCaptureImpl::DoDeviceInfoReceivedOnCaptureThread, | 132 base::Bind(&VideoCaptureImpl::DoDeviceInfoReceivedOnCaptureThread, |
132 base::Unretained(this), device_info)); | 133 base::Unretained(this), device_info)); |
133 } | 134 } |
134 | 135 |
135 void VideoCaptureImpl::OnDelegateAdded(int32 device_id) { | 136 void VideoCaptureImpl::OnDelegateAdded(int32 device_id) { |
136 capture_message_loop_proxy_->PostTask(FROM_HERE, | 137 capture_message_loop_proxy_->PostTask(FROM_HERE, |
137 base::Bind(&VideoCaptureImpl::DoDelegateAddedOnCaptureThread, | 138 base::Bind(&VideoCaptureImpl::DoDelegateAddedOnCaptureThread, |
138 base::Unretained(this), device_id)); | 139 base::Unretained(this), device_id)); |
139 } | 140 } |
140 | 141 |
| 142 void VideoCaptureImpl::SuspendCapture(bool suspend) { |
| 143 capture_message_loop_proxy_->PostTask(FROM_HERE, |
| 144 base::Bind(&VideoCaptureImpl::DoSuspendCaptureOnCaptureThread, |
| 145 base::Unretained(this), suspend)); |
| 146 } |
| 147 |
141 void VideoCaptureImpl::DoDeInitOnCaptureThread(base::Closure task) { | 148 void VideoCaptureImpl::DoDeInitOnCaptureThread(base::Closure task) { |
142 if (state_ == VIDEO_CAPTURE_STATE_STARTED) | 149 if (state_ == VIDEO_CAPTURE_STATE_STARTED) |
143 Send(new VideoCaptureHostMsg_Stop(device_id_)); | 150 Send(new VideoCaptureHostMsg_Stop(device_id_)); |
144 | 151 |
145 io_message_loop_proxy_->PostTask(FROM_HERE, | 152 io_message_loop_proxy_->PostTask(FROM_HERE, |
146 base::Bind(&VideoCaptureImpl::RemoveDelegateOnIOThread, | 153 base::Bind(&VideoCaptureImpl::RemoveDelegateOnIOThread, |
147 base::Unretained(this), task)); | 154 base::Unretained(this), task)); |
148 } | 155 } |
149 | 156 |
150 void VideoCaptureImpl::DoStartCaptureOnCaptureThread( | 157 void VideoCaptureImpl::DoStartCaptureOnCaptureThread( |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 buffer->stride = device_info_.width; | 275 buffer->stride = device_info_.width; |
269 | 276 |
270 DIBBuffer* dib_buffer = new DIBBuffer(dib, buffer); | 277 DIBBuffer* dib_buffer = new DIBBuffer(dib, buffer); |
271 cached_dibs_[buffer_id] = dib_buffer; | 278 cached_dibs_[buffer_id] = dib_buffer; |
272 } | 279 } |
273 | 280 |
274 void VideoCaptureImpl::DoBufferReceivedOnCaptureThread( | 281 void VideoCaptureImpl::DoBufferReceivedOnCaptureThread( |
275 int buffer_id, base::Time timestamp) { | 282 int buffer_id, base::Time timestamp) { |
276 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); | 283 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |
277 | 284 |
278 if (state_ != VIDEO_CAPTURE_STATE_STARTED) { | 285 if (state_ != VIDEO_CAPTURE_STATE_STARTED || suspended_) { |
279 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id)); | 286 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id)); |
280 return; | 287 return; |
281 } | 288 } |
282 | 289 |
283 media::VideoCapture::VideoFrameBuffer* buffer; | 290 media::VideoCapture::VideoFrameBuffer* buffer; |
284 DCHECK(cached_dibs_.find(buffer_id) != cached_dibs_.end()); | 291 DCHECK(cached_dibs_.find(buffer_id) != cached_dibs_.end()); |
285 buffer = cached_dibs_[buffer_id]->mapped_memory; | 292 buffer = cached_dibs_[buffer_id]->mapped_memory; |
286 buffer->timestamp = timestamp; | 293 buffer->timestamp = timestamp; |
287 | 294 |
288 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) { | 295 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); ++it) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 device_id_ = device_id; | 364 device_id_ = device_id; |
358 for (ClientInfo::iterator it = clients_pending_on_filter_.begin(); | 365 for (ClientInfo::iterator it = clients_pending_on_filter_.begin(); |
359 it != clients_pending_on_filter_.end(); ) { | 366 it != clients_pending_on_filter_.end(); ) { |
360 media::VideoCapture::EventHandler* handler = it->first; | 367 media::VideoCapture::EventHandler* handler = it->first; |
361 const media::VideoCaptureCapability capability = it->second; | 368 const media::VideoCaptureCapability capability = it->second; |
362 clients_pending_on_filter_.erase(it++); | 369 clients_pending_on_filter_.erase(it++); |
363 StartCapture(handler, capability); | 370 StartCapture(handler, capability); |
364 } | 371 } |
365 } | 372 } |
366 | 373 |
| 374 void VideoCaptureImpl::DoSuspendCaptureOnCaptureThread(bool suspend) { |
| 375 DVLOG(1) << "DoSuspendCapture: suspend " << (suspend ? "yes" : "no"); |
| 376 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |
| 377 |
| 378 suspended_ = suspend; |
| 379 } |
| 380 |
367 void VideoCaptureImpl::StopDevice() { | 381 void VideoCaptureImpl::StopDevice() { |
368 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); | 382 DCHECK(capture_message_loop_proxy_->BelongsToCurrentThread()); |
369 | 383 |
370 device_info_available_ = false; | 384 device_info_available_ = false; |
371 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { | 385 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { |
372 state_ = VIDEO_CAPTURE_STATE_STOPPING; | 386 state_ = VIDEO_CAPTURE_STATE_STOPPING; |
373 Send(new VideoCaptureHostMsg_Stop(device_id_)); | 387 Send(new VideoCaptureHostMsg_Stop(device_id_)); |
374 current_params_.width = current_params_.height = 0; | 388 current_params_.width = current_params_.height = 0; |
375 } | 389 } |
376 } | 390 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 if (it != clients->end()) { | 459 if (it != clients->end()) { |
446 handler->OnStopped(this); | 460 handler->OnStopped(this); |
447 handler->OnRemoved(this); | 461 handler->OnRemoved(this); |
448 clients->erase(it); | 462 clients->erase(it); |
449 found = true; | 463 found = true; |
450 } | 464 } |
451 return found; | 465 return found; |
452 } | 466 } |
453 | 467 |
454 } // namespace content | 468 } // namespace content |
OLD | NEW |