| 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..c91e0e66c244841f3cdbc7b724b356e036671735 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_host_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_));
|
| + GetVideoCaptureHost()->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)
|
| + GetVideoCaptureHost()->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_));
|
| + GetVideoCaptureHost()->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;
|
| + GetVideoCaptureHost()->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::VideoCaptureHost* VideoCaptureImpl::GetVideoCaptureHost() {
|
| + DCHECK(io_task_runner_->BelongsToCurrentThread());
|
| + if (video_capture_host_for_testing_)
|
| + return video_capture_host_for_testing_;
|
| +
|
| + if (!video_capture_host_.get()) {
|
| + DCHECK(message_filter_->channel());
|
| + message_filter_->channel()
|
| + ->GetAssociatedInterfaceSupport()
|
| + ->GetRemoteAssociatedInterface(&video_capture_host_);
|
| + }
|
| + return video_capture_host_.get();
|
| +};
|
| +
|
| // static
|
| void VideoCaptureImpl::DidFinishConsumingFrame(
|
| const media::VideoFrameMetadata* metadata,
|
|
|