| 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/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
| 8 #include "content/common/child_process.h" | 8 #include "content/common/child_process.h" |
| 9 #include "content/common/media/video_capture_messages.h" | 9 #include "content/common/media/video_capture_messages.h" |
| 10 | 10 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 io_message_loop_proxy->PostTask(FROM_HERE, | 65 io_message_loop_proxy->PostTask(FROM_HERE, |
| 66 NewRunnableMethod(this, &VideoCaptureImpl::AddDelegateOnIOThread)); | 66 NewRunnableMethod(this, &VideoCaptureImpl::AddDelegateOnIOThread)); |
| 67 return; | 67 return; |
| 68 } | 68 } |
| 69 | 69 |
| 70 AddDelegateOnIOThread(); | 70 AddDelegateOnIOThread(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void VideoCaptureImpl::DeInit(Task* task) { | 73 void VideoCaptureImpl::DeInit(Task* task) { |
| 74 if (state_ == kStarted) | 74 if (state_ == kStarted) |
| 75 Send(new VideoCaptureHostMsg_Stop(0, device_id_)); | 75 Send(new VideoCaptureHostMsg_Stop(device_id_)); |
| 76 | 76 |
| 77 base::MessageLoopProxy* io_message_loop_proxy = | 77 base::MessageLoopProxy* io_message_loop_proxy = |
| 78 ChildProcess::current()->io_message_loop_proxy(); | 78 ChildProcess::current()->io_message_loop_proxy(); |
| 79 | 79 |
| 80 if (!io_message_loop_proxy->BelongsToCurrentThread()) { | 80 if (!io_message_loop_proxy->BelongsToCurrentThread()) { |
| 81 io_message_loop_proxy->PostTask(FROM_HERE, | 81 io_message_loop_proxy->PostTask(FROM_HERE, |
| 82 NewRunnableMethod(this, &VideoCaptureImpl::RemoveDelegateOnIOThread, | 82 NewRunnableMethod(this, &VideoCaptureImpl::RemoveDelegateOnIOThread, |
| 83 task)); | 83 task)); |
| 84 return; | 84 return; |
| 85 } | 85 } |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 buffer->height = height_; | 285 buffer->height = height_; |
| 286 | 286 |
| 287 DIBBuffer* dib_buffer = new DIBBuffer(dib, buffer); | 287 DIBBuffer* dib_buffer = new DIBBuffer(dib, buffer); |
| 288 cached_dibs_[buffer_id] = dib_buffer; | 288 cached_dibs_[buffer_id] = dib_buffer; |
| 289 } | 289 } |
| 290 | 290 |
| 291 void VideoCaptureImpl::DoBufferReceived(int buffer_id, base::Time timestamp) { | 291 void VideoCaptureImpl::DoBufferReceived(int buffer_id, base::Time timestamp) { |
| 292 DCHECK(ml_proxy_->BelongsToCurrentThread()); | 292 DCHECK(ml_proxy_->BelongsToCurrentThread()); |
| 293 | 293 |
| 294 if (state_ != kStarted) { | 294 if (state_ != kStarted) { |
| 295 Send(new VideoCaptureHostMsg_BufferReady(0, device_id_, buffer_id)); | 295 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id)); |
| 296 return; | 296 return; |
| 297 } | 297 } |
| 298 | 298 |
| 299 media::VideoCapture::VideoFrameBuffer* buffer; | 299 media::VideoCapture::VideoFrameBuffer* buffer; |
| 300 DCHECK(cached_dibs_.find(buffer_id) != cached_dibs_.end()); | 300 DCHECK(cached_dibs_.find(buffer_id) != cached_dibs_.end()); |
| 301 buffer = cached_dibs_[buffer_id]->mapped_memory; | 301 buffer = cached_dibs_[buffer_id]->mapped_memory; |
| 302 | 302 |
| 303 // TODO(wjia): handle buffer sharing with downstream modules. | 303 // TODO(wjia): handle buffer sharing with downstream modules. |
| 304 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); it++) { | 304 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); it++) { |
| 305 it->first->OnBufferReady(this, buffer); | 305 it->first->OnBufferReady(this, buffer); |
| 306 } | 306 } |
| 307 | 307 |
| 308 Send(new VideoCaptureHostMsg_BufferReady(0, device_id_, buffer_id)); | 308 Send(new VideoCaptureHostMsg_BufferReady(device_id_, buffer_id)); |
| 309 } | 309 } |
| 310 | 310 |
| 311 void VideoCaptureImpl::DoStateChanged(const media::VideoCapture::State& state) { | 311 void VideoCaptureImpl::DoStateChanged(const media::VideoCapture::State& state) { |
| 312 DCHECK(ml_proxy_->BelongsToCurrentThread()); | 312 DCHECK(ml_proxy_->BelongsToCurrentThread()); |
| 313 | 313 |
| 314 switch (state) { | 314 switch (state) { |
| 315 case media::VideoCapture::kStarted: | 315 case media::VideoCapture::kStarted: |
| 316 for (ClientInfo::iterator it = clients_.begin(); | 316 for (ClientInfo::iterator it = clients_.begin(); |
| 317 it != clients_.end(); it++) { | 317 it != clients_.end(); it++) { |
| 318 it->first->OnStarted(this); | 318 it->first->OnStarted(this); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 367 |
| 368 void VideoCaptureImpl::StopDevice() { | 368 void VideoCaptureImpl::StopDevice() { |
| 369 if (!ml_proxy_->BelongsToCurrentThread()) { | 369 if (!ml_proxy_->BelongsToCurrentThread()) { |
| 370 ml_proxy_->PostTask(FROM_HERE, | 370 ml_proxy_->PostTask(FROM_HERE, |
| 371 NewRunnableMethod(this, &VideoCaptureImpl::StopDevice)); | 371 NewRunnableMethod(this, &VideoCaptureImpl::StopDevice)); |
| 372 return; | 372 return; |
| 373 } | 373 } |
| 374 | 374 |
| 375 if (state_ == kStarted) { | 375 if (state_ == kStarted) { |
| 376 state_ = kStopping; | 376 state_ = kStopping; |
| 377 Send(new VideoCaptureHostMsg_Stop(0, device_id_)); | 377 Send(new VideoCaptureHostMsg_Stop(device_id_)); |
| 378 width_ = height_ = 0; | 378 width_ = height_ = 0; |
| 379 STLDeleteContainerPairSecondPointers(cached_dibs_.begin(), | 379 STLDeleteContainerPairSecondPointers(cached_dibs_.begin(), |
| 380 cached_dibs_.end()); | 380 cached_dibs_.end()); |
| 381 cached_dibs_.clear(); | 381 cached_dibs_.clear(); |
| 382 } | 382 } |
| 383 } | 383 } |
| 384 | 384 |
| 385 void VideoCaptureImpl::RestartCapture() { | 385 void VideoCaptureImpl::RestartCapture() { |
| 386 DCHECK(ml_proxy_->BelongsToCurrentThread()); | 386 DCHECK(ml_proxy_->BelongsToCurrentThread()); |
| 387 DCHECK_EQ(state_, kStopped); | 387 DCHECK_EQ(state_, kStopped); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 398 void VideoCaptureImpl::StartCaptureInternal() { | 398 void VideoCaptureImpl::StartCaptureInternal() { |
| 399 DCHECK(ml_proxy_->BelongsToCurrentThread()); | 399 DCHECK(ml_proxy_->BelongsToCurrentThread()); |
| 400 DCHECK(device_id_); | 400 DCHECK(device_id_); |
| 401 | 401 |
| 402 media::VideoCaptureParams params; | 402 media::VideoCaptureParams params; |
| 403 params.width = width_; | 403 params.width = width_; |
| 404 params.height = height_; | 404 params.height = height_; |
| 405 params.frame_per_second = frame_rate_; | 405 params.frame_per_second = frame_rate_; |
| 406 params.session_id = session_id_; | 406 params.session_id = session_id_; |
| 407 | 407 |
| 408 Send(new VideoCaptureHostMsg_Start(0, device_id_, params)); | 408 Send(new VideoCaptureHostMsg_Start(device_id_, params)); |
| 409 state_ = kStarted; | 409 state_ = kStarted; |
| 410 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); it++) { | 410 for (ClientInfo::iterator it = clients_.begin(); it != clients_.end(); it++) { |
| 411 it->first->OnStarted(this); | 411 it->first->OnStarted(this); |
| 412 } | 412 } |
| 413 } | 413 } |
| 414 | 414 |
| 415 void VideoCaptureImpl::AddDelegateOnIOThread() { | 415 void VideoCaptureImpl::AddDelegateOnIOThread() { |
| 416 message_filter_->AddDelegate(this); | 416 message_filter_->AddDelegate(this); |
| 417 } | 417 } |
| 418 | 418 |
| 419 void VideoCaptureImpl::RemoveDelegateOnIOThread(Task* task) { | 419 void VideoCaptureImpl::RemoveDelegateOnIOThread(Task* task) { |
| 420 base::ScopedTaskRunner task_runner(task); | 420 base::ScopedTaskRunner task_runner(task); |
| 421 message_filter_->RemoveDelegate(this); | 421 message_filter_->RemoveDelegate(this); |
| 422 } | 422 } |
| 423 | 423 |
| 424 void VideoCaptureImpl::Send(IPC::Message* message) { | 424 void VideoCaptureImpl::Send(IPC::Message* message) { |
| 425 base::MessageLoopProxy* io_message_loop_proxy = | 425 base::MessageLoopProxy* io_message_loop_proxy = |
| 426 ChildProcess::current()->io_message_loop_proxy(); | 426 ChildProcess::current()->io_message_loop_proxy(); |
| 427 | 427 |
| 428 io_message_loop_proxy->PostTask(FROM_HERE, | 428 io_message_loop_proxy->PostTask(FROM_HERE, |
| 429 NewRunnableMethod(message_filter_.get(), | 429 NewRunnableMethod(message_filter_.get(), |
| 430 &VideoCaptureMessageFilter::Send, message)); | 430 &VideoCaptureMessageFilter::Send, message)); |
| 431 } | 431 } |
| OLD | NEW |