Chromium Code Reviews| Index: content/renderer/media/video_capture_impl.cc |
| diff --git a/content/renderer/media/video_capture_impl.cc b/content/renderer/media/video_capture_impl.cc |
| index 583fb97bb9e68b9fffc02977cecb96879447632e..c4bf09fe5420e88f92c18257d37061005138bf06 100644 |
| --- a/content/renderer/media/video_capture_impl.cc |
| +++ b/content/renderer/media/video_capture_impl.cc |
| @@ -111,6 +111,7 @@ VideoCaptureImpl::VideoCaptureImpl( |
| : message_filter_(filter), |
| device_id_(0), |
| session_id_(session_id), |
| + video_capture_service_for_testing_(nullptr), |
| suspended_(false), |
| state_(VIDEO_CAPTURE_STATE_STOPPED), |
| io_task_runner_(std::move(io_task_runner)), |
| @@ -124,16 +125,16 @@ VideoCaptureImpl::VideoCaptureImpl( |
| VideoCaptureImpl::~VideoCaptureImpl() { |
| DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| if (state_ == VIDEO_CAPTURE_STATE_STARTED) |
| - Send(new VideoCaptureHostMsg_Stop(device_id_)); |
| + GetVideoCaptureService()->Stop(device_id_); |
| message_filter_->RemoveDelegate(this); |
| } |
| void VideoCaptureImpl::SuspendCapture(bool suspend) { |
| DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| - Send(suspend ? static_cast<IPC::Message*>( |
| - new VideoCaptureHostMsg_Pause(device_id_)) |
| - : static_cast<IPC::Message*>(new VideoCaptureHostMsg_Resume( |
| - device_id_, session_id_, params_))); |
| + if (suspend) |
| + GetVideoCaptureService()->Pause(device_id_); |
| + else |
| + Send(new VideoCaptureHostMsg_Resume(device_id_, session_id_, params_)); |
| } |
| void VideoCaptureImpl::StartCapture( |
| @@ -198,36 +199,38 @@ void VideoCaptureImpl::StopCapture(int client_id) { |
| } |
| } |
| - if (clients_.empty()) { |
| - DVLOG(1) << "StopCapture: No more client, stopping ..."; |
| - StopDevice(); |
| - client_buffers_.clear(); |
| - client_buffer2s_.clear(); |
| - weak_factory_.InvalidateWeakPtrs(); |
| - } |
| + if (!clients_.empty()) |
| + return; |
| + DVLOG(1) << "StopCapture: No more client, stopping ..."; |
| + StopDevice(); |
| + client_buffers_.clear(); |
| + client_buffer2s_.clear(); |
| + weak_factory_.InvalidateWeakPtrs(); |
| } |
| void VideoCaptureImpl::RequestRefreshFrame() { |
| DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| - Send(new VideoCaptureHostMsg_RequestRefreshFrame(device_id_)); |
| + GetVideoCaptureService()->RequestRefreshFrame(device_id_); |
| } |
| void VideoCaptureImpl::GetDeviceSupportedFormats( |
| const VideoCaptureDeviceFormatsCB& callback) { |
| DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| device_formats_cb_queue_.push_back(callback); |
| - if (device_formats_cb_queue_.size() == 1) |
| + if (device_formats_cb_queue_.size() == 1) { |
| Send(new VideoCaptureHostMsg_GetDeviceSupportedFormats(device_id_, |
| session_id_)); |
| + } |
| } |
| void VideoCaptureImpl::GetDeviceFormatsInUse( |
| const VideoCaptureDeviceFormatsCB& callback) { |
| DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| device_formats_in_use_cb_queue_.push_back(callback); |
| - if (device_formats_in_use_cb_queue_.size() == 1) |
| + if (device_formats_in_use_cb_queue_.size() == 1) { |
| Send( |
| new VideoCaptureHostMsg_GetDeviceFormatsInUse(device_id_, session_id_)); |
| + } |
| } |
| void VideoCaptureImpl::OnBufferCreated(base::SharedMemoryHandle handle, |
| @@ -497,12 +500,11 @@ void VideoCaptureImpl::OnDelegateAdded(int32_t device_id) { |
| void VideoCaptureImpl::StopDevice() { |
| DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| - |
| - if (state_ == VIDEO_CAPTURE_STATE_STARTED) { |
| - state_ = VIDEO_CAPTURE_STATE_STOPPING; |
| - Send(new VideoCaptureHostMsg_Stop(device_id_)); |
| - params_.requested_format.frame_size.SetSize(0, 0); |
| - } |
| + if (state_ != VIDEO_CAPTURE_STATE_STARTED) |
| + return; |
| + state_ = VIDEO_CAPTURE_STATE_STOPPING; |
| + GetVideoCaptureService()->Stop(device_id_); |
| + params_.requested_format.frame_size.SetSize(0, 0); |
| } |
| void VideoCaptureImpl::RestartCapture() { |
| @@ -552,6 +554,20 @@ bool VideoCaptureImpl::RemoveClient(int client_id, ClientInfoMap* clients) { |
| return found; |
| } |
| +mojom::VideoCaptureService* VideoCaptureImpl::GetVideoCaptureService() { |
| + DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| + if (video_capture_service_for_testing_) |
| + return video_capture_service_for_testing_; |
| + if (video_capture_service_.get()) |
|
Ken Rockot(use gerrit already)
2016/10/05 20:59:44
minor nit: a more common pattern is
if (!foo.get(
mcasas
2016/10/05 22:23:50
Done.
|
| + return video_capture_service_.get(); |
| + |
| + DCHECK(message_filter_->sender()); |
| + message_filter_->sender() |
| + ->GetAssociatedInterfaceSupport() |
| + ->GetRemoteAssociatedInterface(&video_capture_service_); |
| + return video_capture_service_.get(); |
| +}; |
| + |
| // static |
| void VideoCaptureImpl::DidFinishConsumingFrame( |
| const media::VideoFrameMetadata* metadata, |