| Index: content/browser/renderer_host/media/video_capture_host.cc
|
| ===================================================================
|
| --- content/browser/renderer_host/media/video_capture_host.cc (revision 106642)
|
| +++ content/browser/renderer_host/media/video_capture_host.cc (working copy)
|
| @@ -8,6 +8,7 @@
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/stl_util.h"
|
| #include "content/browser/renderer_host/media/media_stream_manager.h"
|
| +#include "content/browser/renderer_host/media/video_capture_manager.h"
|
| #include "content/browser/resource_context.h"
|
| #include "content/common/media/video_capture_messages.h"
|
|
|
| @@ -24,11 +25,12 @@
|
| // Since the IPC channel is gone, close all requested VideCaptureDevices.
|
| for (EntryMap::iterator it = entries_.begin(); it != entries_.end(); it++) {
|
| VideoCaptureController* controller = it->second;
|
| - // Since the channel is closing we need a task to make sure VideoCaptureHost
|
| - // is not deleted before VideoCaptureController.
|
| - controller->StopCapture(
|
| - base::Bind(&VideoCaptureHost::OnReadyToDelete, this, it->first));
|
| + VideoCaptureControllerID controller_id(it->first);
|
| + controller->StopCapture(controller_id, this, true);
|
| + GetVideoCaptureManager()->RemoveController(controller, this);
|
| }
|
| + entries_.clear();
|
| + entry_state_.clear();
|
| }
|
|
|
| void VideoCaptureHost::OnDestruct() const {
|
| @@ -108,7 +110,7 @@
|
| EntryMap::iterator it = entries_.find(id);
|
| if (it != entries_.end()) {
|
| VideoCaptureController* controller = it->second;
|
| - controller->StopCapture(base::Closure());
|
| + controller->StopCapture(id, this, false);
|
| }
|
| }
|
|
|
| @@ -146,31 +148,63 @@
|
| void VideoCaptureHost::OnStartCapture(int device_id,
|
| const media::VideoCaptureParams& params) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + VideoCaptureControllerID controller_id(device_id);
|
| + DCHECK(entries_.find(controller_id) == entries_.end());
|
| + DCHECK(entry_state_.find(controller_id) == entry_state_.end());
|
|
|
| + entry_state_[controller_id] = media::VideoCapture::kStarted;
|
| + GetVideoCaptureManager()->AddController(
|
| + params, this, base::Bind(&VideoCaptureHost::OnControllerAdded, this,
|
| + device_id, params));
|
| +}
|
| +
|
| +void VideoCaptureHost::OnControllerAdded(
|
| + int device_id, const media::VideoCaptureParams& params,
|
| + VideoCaptureController* controller) {
|
| + BrowserThread::PostTask(
|
| + BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&VideoCaptureHost::DoControllerAddedOnIOThreead,
|
| + this, device_id, params, make_scoped_refptr(controller)));
|
| +}
|
| +
|
| +void VideoCaptureHost::DoControllerAddedOnIOThreead(
|
| + int device_id, const media::VideoCaptureParams params,
|
| + VideoCaptureController* controller) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| VideoCaptureControllerID controller_id(device_id);
|
| -
|
| DCHECK(entries_.find(controller_id) == entries_.end());
|
| + DCHECK(entry_state_.find(controller_id) != entry_state_.end());
|
|
|
| - scoped_refptr<VideoCaptureController> controller =
|
| - new VideoCaptureController(
|
| - controller_id, peer_handle(), this,
|
| - resource_context_->media_stream_manager()->video_capture_manager());
|
| + if (controller == NULL) {
|
| + Send(new VideoCaptureMsg_StateChanged(device_id,
|
| + media::VideoCapture::kError));
|
| + return;
|
| + }
|
| +
|
| entries_.insert(std::make_pair(controller_id, controller));
|
| - controller->StartCapture(params);
|
| + if (entry_state_[controller_id] == media::VideoCapture::kStarted) {
|
| + controller->StartCapture(controller_id, this, peer_handle(), params);
|
| + } else if (entry_state_[controller_id] == media::VideoCapture::kStopped) {
|
| + controller->StopCapture(controller_id, this, false);
|
| + }
|
| }
|
|
|
| void VideoCaptureHost::OnStopCapture(int device_id) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + VideoCaptureControllerID controller_id(device_id);
|
|
|
| - VideoCaptureControllerID controller_id(device_id);
|
| + if (entry_state_.find(controller_id) == entry_state_.end()) {
|
| + // It does not exist. So it must have been stopped already.
|
| + Send(new VideoCaptureMsg_StateChanged(device_id,
|
| + media::VideoCapture::kStopped));
|
| + }
|
| +
|
| + entry_state_[controller_id] = media::VideoCapture::kStopped;
|
| +
|
| EntryMap::iterator it = entries_.find(controller_id);
|
| if (it != entries_.end()) {
|
| scoped_refptr<VideoCaptureController> controller = it->second;
|
| - controller->StopCapture(base::Closure());
|
| - } else {
|
| - // It does not exist so it must have been stopped already.
|
| - Send(new VideoCaptureMsg_StateChanged(device_id,
|
| - media::VideoCapture::kStopped));
|
| + controller->StopCapture(controller_id, this, false);
|
| }
|
| }
|
|
|
| @@ -188,7 +222,7 @@
|
| EntryMap::iterator it = entries_.find(controller_id);
|
| if (it != entries_.end()) {
|
| scoped_refptr<VideoCaptureController> controller = it->second;
|
| - controller->ReturnBuffer(buffer_id);
|
| + controller->ReturnBuffer(controller_id, this, buffer_id);
|
| }
|
| }
|
|
|
| @@ -199,5 +233,15 @@
|
| // Report that the device have successfully been stopped.
|
| Send(new VideoCaptureMsg_StateChanged(id.device_id,
|
| media::VideoCapture::kStopped));
|
| + EntryMap::iterator it = entries_.find(id);
|
| + if (it != entries_.end()) {
|
| + GetVideoCaptureManager()->RemoveController(it->second, this);
|
| + }
|
| entries_.erase(id);
|
| + entry_state_.erase(id);
|
| }
|
| +
|
| +media_stream::VideoCaptureManager* VideoCaptureHost::GetVideoCaptureManager() {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + return resource_context_->media_stream_manager()->video_capture_manager();
|
| +}
|
|
|