OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 io_message_loop_proxy->PostTask(FROM_HERE, | 72 io_message_loop_proxy->PostTask(FROM_HERE, |
73 base::Bind(&VideoCaptureImpl::AddDelegateOnIOThread, | 73 base::Bind(&VideoCaptureImpl::AddDelegateOnIOThread, |
74 base::Unretained(this))); | 74 base::Unretained(this))); |
75 return; | 75 return; |
76 } | 76 } |
77 | 77 |
78 AddDelegateOnIOThread(); | 78 AddDelegateOnIOThread(); |
79 } | 79 } |
80 | 80 |
81 void VideoCaptureImpl::DeInit(base::Closure task) { | 81 void VideoCaptureImpl::DeInit(base::Closure task) { |
| 82 ml_proxy_->PostTask(FROM_HERE, |
| 83 base::Bind(&VideoCaptureImpl::DoDeInit, |
| 84 base::Unretained(this), task)); |
| 85 } |
| 86 |
| 87 void VideoCaptureImpl::DoDeInit(base::Closure task) { |
82 if (state_ == kStarted) | 88 if (state_ == kStarted) |
83 Send(new VideoCaptureHostMsg_Stop(device_id_)); | 89 Send(new VideoCaptureHostMsg_Stop(device_id_)); |
84 | 90 |
85 base::MessageLoopProxy* io_message_loop_proxy = | 91 base::MessageLoopProxy* io_message_loop_proxy = |
86 ChildProcess::current()->io_message_loop_proxy(); | 92 ChildProcess::current()->io_message_loop_proxy(); |
87 | 93 |
88 if (!io_message_loop_proxy->BelongsToCurrentThread()) { | 94 io_message_loop_proxy->PostTask(FROM_HERE, |
89 io_message_loop_proxy->PostTask(FROM_HERE, | 95 base::Bind(&VideoCaptureImpl::RemoveDelegateOnIOThread, |
90 base::Bind(&VideoCaptureImpl::RemoveDelegateOnIOThread, | 96 base::Unretained(this), task)); |
91 base::Unretained(this), task)); | |
92 return; | |
93 } | |
94 | |
95 RemoveDelegateOnIOThread(task); | |
96 } | 97 } |
97 | 98 |
98 void VideoCaptureImpl::StartCapture( | 99 void VideoCaptureImpl::StartCapture( |
99 media::VideoCapture::EventHandler* handler, | 100 media::VideoCapture::EventHandler* handler, |
100 const VideoCaptureCapability& capability) { | 101 const VideoCaptureCapability& capability) { |
101 DCHECK_EQ(capability.raw_type, media::VideoFrame::I420); | 102 DCHECK_EQ(capability.raw_type, media::VideoFrame::I420); |
102 | 103 |
103 ml_proxy_->PostTask(FROM_HERE, | 104 ml_proxy_->PostTask(FROM_HERE, |
104 base::Bind(&VideoCaptureImpl::DoStartCapture, | 105 base::Bind(&VideoCaptureImpl::DoStartCapture, |
105 base::Unretained(this), handler, capability)); | 106 base::Unretained(this), handler, capability)); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 if (it != clients_pending_on_restart_.end()) { | 231 if (it != clients_pending_on_restart_.end()) { |
231 handler->OnStopped(this); | 232 handler->OnStopped(this); |
232 handler->OnRemoved(this); | 233 handler->OnRemoved(this); |
233 clients_pending_on_filter_.erase(it); | 234 clients_pending_on_filter_.erase(it); |
234 return; | 235 return; |
235 } | 236 } |
236 | 237 |
237 if (clients_.find(handler) == clients_.end()) | 238 if (clients_.find(handler) == clients_.end()) |
238 return; | 239 return; |
239 | 240 |
240 handler->OnStopped(this); | |
241 handler->OnRemoved(this); | |
242 clients_.erase(handler); | 241 clients_.erase(handler); |
243 | 242 |
244 if (clients_.empty()) { | 243 if (clients_.empty()) { |
245 DVLOG(1) << "StopCapture: No more client, stopping ..."; | 244 DVLOG(1) << "StopCapture: No more client, stopping ..."; |
246 StopDevice(); | 245 StopDevice(); |
247 } | 246 } |
| 247 handler->OnStopped(this); |
| 248 handler->OnRemoved(this); |
248 } | 249 } |
249 | 250 |
250 void VideoCaptureImpl::DoFeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) { | 251 void VideoCaptureImpl::DoFeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) { |
251 DCHECK(ml_proxy_->BelongsToCurrentThread()); | 252 DCHECK(ml_proxy_->BelongsToCurrentThread()); |
252 | 253 |
253 CachedDIB::iterator it; | 254 CachedDIB::iterator it; |
254 for (it = cached_dibs_.begin(); it != cached_dibs_.end(); it++) { | 255 for (it = cached_dibs_.begin(); it != cached_dibs_.end(); it++) { |
255 if (buffer == it->second->mapped_memory) | 256 if (buffer == it->second->mapped_memory) |
256 break; | 257 break; |
257 } | 258 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 | 414 |
414 Send(new VideoCaptureHostMsg_Start(device_id_, current_params_)); | 415 Send(new VideoCaptureHostMsg_Start(device_id_, current_params_)); |
415 state_ = kStarted; | 416 state_ = kStarted; |
416 } | 417 } |
417 | 418 |
418 void VideoCaptureImpl::AddDelegateOnIOThread() { | 419 void VideoCaptureImpl::AddDelegateOnIOThread() { |
419 message_filter_->AddDelegate(this); | 420 message_filter_->AddDelegate(this); |
420 } | 421 } |
421 | 422 |
422 void VideoCaptureImpl::RemoveDelegateOnIOThread(base::Closure task) { | 423 void VideoCaptureImpl::RemoveDelegateOnIOThread(base::Closure task) { |
423 base::ScopedClosureRunner task_runner(task); | |
424 message_filter_->RemoveDelegate(this); | 424 message_filter_->RemoveDelegate(this); |
| 425 ml_proxy_->PostTask(FROM_HERE, task); |
425 } | 426 } |
426 | 427 |
427 void VideoCaptureImpl::Send(IPC::Message* message) { | 428 void VideoCaptureImpl::Send(IPC::Message* message) { |
428 base::MessageLoopProxy* io_message_loop_proxy = | 429 base::MessageLoopProxy* io_message_loop_proxy = |
429 ChildProcess::current()->io_message_loop_proxy(); | 430 ChildProcess::current()->io_message_loop_proxy(); |
430 | 431 |
431 io_message_loop_proxy->PostTask(FROM_HERE, | 432 io_message_loop_proxy->PostTask(FROM_HERE, |
432 base::IgnoreReturn<bool>(base::Bind(&VideoCaptureMessageFilter::Send, | 433 base::IgnoreReturn<bool>(base::Bind(&VideoCaptureMessageFilter::Send, |
433 message_filter_.get(), message))); | 434 message_filter_.get(), message))); |
434 } | 435 } |
435 | 436 |
436 bool VideoCaptureImpl::ClientHasDIB() { | 437 bool VideoCaptureImpl::ClientHasDIB() { |
437 CachedDIB::iterator it; | 438 CachedDIB::iterator it; |
438 for (it = cached_dibs_.begin(); it != cached_dibs_.end(); it++) { | 439 for (it = cached_dibs_.begin(); it != cached_dibs_.end(); it++) { |
439 if (it->second->references > 0) | 440 if (it->second->references > 0) |
440 return true; | 441 return true; |
441 } | 442 } |
442 return false; | 443 return false; |
443 } | 444 } |
OLD | NEW |