Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: content/renderer/media/video_capture_impl.cc

Issue 2390103002: Reland: VideoCapture: migrate VideoCapture renderer-->host messages to mojo, part 1 (Closed)
Patch Set: Sorted out tests after linker collision. Rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Notes about usage of this object by VideoCaptureImplManager. 5 // Notes about usage of this object by VideoCaptureImplManager.
6 // 6 //
7 // VideoCaptureImplManager access this object by using a Unretained() 7 // VideoCaptureImplManager access this object by using a Unretained()
8 // binding and tasks on the IO thread. It is then important that 8 // binding and tasks on the IO thread. It is then important that
9 // VideoCaptureImpl never post task to itself. All operations must be 9 // VideoCaptureImpl never post task to itself. All operations must be
10 // synchronous. 10 // synchronous.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 VideoCaptureImpl::ClientInfo::ClientInfo(const ClientInfo& other) = default; 104 VideoCaptureImpl::ClientInfo::ClientInfo(const ClientInfo& other) = default;
105 VideoCaptureImpl::ClientInfo::~ClientInfo() {} 105 VideoCaptureImpl::ClientInfo::~ClientInfo() {}
106 106
107 VideoCaptureImpl::VideoCaptureImpl( 107 VideoCaptureImpl::VideoCaptureImpl(
108 media::VideoCaptureSessionId session_id, 108 media::VideoCaptureSessionId session_id,
109 VideoCaptureMessageFilter* filter, 109 VideoCaptureMessageFilter* filter,
110 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) 110 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
111 : message_filter_(filter), 111 : message_filter_(filter),
112 device_id_(0), 112 device_id_(0),
113 session_id_(session_id), 113 session_id_(session_id),
114 video_capture_host_for_testing_(nullptr),
114 suspended_(false), 115 suspended_(false),
115 state_(VIDEO_CAPTURE_STATE_STOPPED), 116 state_(VIDEO_CAPTURE_STATE_STOPPED),
116 io_task_runner_(std::move(io_task_runner)), 117 io_task_runner_(std::move(io_task_runner)),
117 weak_factory_(this) { 118 weak_factory_(this) {
118 DCHECK(filter); 119 DCHECK(filter);
119 io_task_runner_->PostTask(FROM_HERE, 120 io_task_runner_->PostTask(FROM_HERE,
120 base::Bind(&VideoCaptureMessageFilter::AddDelegate, 121 base::Bind(&VideoCaptureMessageFilter::AddDelegate,
121 message_filter_, this)); 122 message_filter_, this));
122 } 123 }
123 124
124 VideoCaptureImpl::~VideoCaptureImpl() { 125 VideoCaptureImpl::~VideoCaptureImpl() {
125 DCHECK(io_task_runner_->BelongsToCurrentThread()); 126 DCHECK(io_task_runner_->BelongsToCurrentThread());
126 if (state_ == VIDEO_CAPTURE_STATE_STARTED) 127 if (state_ == VIDEO_CAPTURE_STATE_STARTED)
127 Send(new VideoCaptureHostMsg_Stop(device_id_)); 128 GetVideoCaptureHost()->Stop(device_id_);
128 message_filter_->RemoveDelegate(this); 129 message_filter_->RemoveDelegate(this);
129 } 130 }
130 131
131 void VideoCaptureImpl::SuspendCapture(bool suspend) { 132 void VideoCaptureImpl::SuspendCapture(bool suspend) {
132 DCHECK(io_task_runner_->BelongsToCurrentThread()); 133 DCHECK(io_task_runner_->BelongsToCurrentThread());
133 Send(suspend ? static_cast<IPC::Message*>( 134 if (suspend)
134 new VideoCaptureHostMsg_Pause(device_id_)) 135 GetVideoCaptureHost()->Pause(device_id_);
135 : static_cast<IPC::Message*>(new VideoCaptureHostMsg_Resume( 136 else
136 device_id_, session_id_, params_))); 137 Send(new VideoCaptureHostMsg_Resume(device_id_, session_id_, params_));
137 } 138 }
138 139
139 void VideoCaptureImpl::StartCapture( 140 void VideoCaptureImpl::StartCapture(
140 int client_id, 141 int client_id,
141 const media::VideoCaptureParams& params, 142 const media::VideoCaptureParams& params,
142 const VideoCaptureStateUpdateCB& state_update_cb, 143 const VideoCaptureStateUpdateCB& state_update_cb,
143 const VideoCaptureDeliverFrameCB& deliver_frame_cb) { 144 const VideoCaptureDeliverFrameCB& deliver_frame_cb) {
144 DCHECK(io_task_runner_->BelongsToCurrentThread()); 145 DCHECK(io_task_runner_->BelongsToCurrentThread());
145 ClientInfo client_info; 146 ClientInfo client_info;
146 client_info.params = params; 147 client_info.params = params;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 DCHECK(io_task_runner_->BelongsToCurrentThread()); 192 DCHECK(io_task_runner_->BelongsToCurrentThread());
192 // A client ID can be in only one client list. 193 // A client ID can be in only one client list.
193 // If this ID is in any client list, we can just remove it from 194 // If this ID is in any client list, we can just remove it from
194 // that client list and don't have to run the other following RemoveClient(). 195 // that client list and don't have to run the other following RemoveClient().
195 if (!RemoveClient(client_id, &clients_pending_on_filter_)) { 196 if (!RemoveClient(client_id, &clients_pending_on_filter_)) {
196 if (!RemoveClient(client_id, &clients_pending_on_restart_)) { 197 if (!RemoveClient(client_id, &clients_pending_on_restart_)) {
197 RemoveClient(client_id, &clients_); 198 RemoveClient(client_id, &clients_);
198 } 199 }
199 } 200 }
200 201
201 if (clients_.empty()) { 202 if (!clients_.empty())
202 DVLOG(1) << "StopCapture: No more client, stopping ..."; 203 return;
203 StopDevice(); 204 DVLOG(1) << "StopCapture: No more client, stopping ...";
204 client_buffers_.clear(); 205 StopDevice();
205 client_buffer2s_.clear(); 206 client_buffers_.clear();
206 weak_factory_.InvalidateWeakPtrs(); 207 client_buffer2s_.clear();
207 } 208 weak_factory_.InvalidateWeakPtrs();
208 } 209 }
209 210
210 void VideoCaptureImpl::RequestRefreshFrame() { 211 void VideoCaptureImpl::RequestRefreshFrame() {
211 DCHECK(io_task_runner_->BelongsToCurrentThread()); 212 DCHECK(io_task_runner_->BelongsToCurrentThread());
212 Send(new VideoCaptureHostMsg_RequestRefreshFrame(device_id_)); 213 GetVideoCaptureHost()->RequestRefreshFrame(device_id_);
213 } 214 }
214 215
215 void VideoCaptureImpl::GetDeviceSupportedFormats( 216 void VideoCaptureImpl::GetDeviceSupportedFormats(
216 const VideoCaptureDeviceFormatsCB& callback) { 217 const VideoCaptureDeviceFormatsCB& callback) {
217 DCHECK(io_task_runner_->BelongsToCurrentThread()); 218 DCHECK(io_task_runner_->BelongsToCurrentThread());
218 device_formats_cb_queue_.push_back(callback); 219 device_formats_cb_queue_.push_back(callback);
219 if (device_formats_cb_queue_.size() == 1) 220 if (device_formats_cb_queue_.size() == 1) {
220 Send(new VideoCaptureHostMsg_GetDeviceSupportedFormats(device_id_, 221 Send(new VideoCaptureHostMsg_GetDeviceSupportedFormats(device_id_,
221 session_id_)); 222 session_id_));
223 }
222 } 224 }
223 225
224 void VideoCaptureImpl::GetDeviceFormatsInUse( 226 void VideoCaptureImpl::GetDeviceFormatsInUse(
225 const VideoCaptureDeviceFormatsCB& callback) { 227 const VideoCaptureDeviceFormatsCB& callback) {
226 DCHECK(io_task_runner_->BelongsToCurrentThread()); 228 DCHECK(io_task_runner_->BelongsToCurrentThread());
227 device_formats_in_use_cb_queue_.push_back(callback); 229 device_formats_in_use_cb_queue_.push_back(callback);
228 if (device_formats_in_use_cb_queue_.size() == 1) 230 if (device_formats_in_use_cb_queue_.size() == 1) {
229 Send( 231 Send(
230 new VideoCaptureHostMsg_GetDeviceFormatsInUse(device_id_, session_id_)); 232 new VideoCaptureHostMsg_GetDeviceFormatsInUse(device_id_, session_id_));
233 }
231 } 234 }
232 235
233 void VideoCaptureImpl::OnBufferCreated(base::SharedMemoryHandle handle, 236 void VideoCaptureImpl::OnBufferCreated(base::SharedMemoryHandle handle,
234 int length, 237 int length,
235 int buffer_id) { 238 int buffer_id) {
236 DCHECK(io_task_runner_->BelongsToCurrentThread()); 239 DCHECK(io_task_runner_->BelongsToCurrentThread());
237 240
238 // In case client calls StopCapture before the arrival of created buffer, 241 // In case client calls StopCapture before the arrival of created buffer,
239 // just close this buffer and return. 242 // just close this buffer and return.
240 if (state_ != VIDEO_CAPTURE_STATE_STARTED) { 243 if (state_ != VIDEO_CAPTURE_STATE_STARTED) {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 const int client_id = it->first; 493 const int client_id = it->first;
491 const ClientInfo client_info = it->second; 494 const ClientInfo client_info = it->second;
492 clients_pending_on_filter_.erase(it++); 495 clients_pending_on_filter_.erase(it++);
493 StartCapture(client_id, client_info.params, client_info.state_update_cb, 496 StartCapture(client_id, client_info.params, client_info.state_update_cb,
494 client_info.deliver_frame_cb); 497 client_info.deliver_frame_cb);
495 } 498 }
496 } 499 }
497 500
498 void VideoCaptureImpl::StopDevice() { 501 void VideoCaptureImpl::StopDevice() {
499 DCHECK(io_task_runner_->BelongsToCurrentThread()); 502 DCHECK(io_task_runner_->BelongsToCurrentThread());
500 503 if (state_ != VIDEO_CAPTURE_STATE_STARTED)
501 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { 504 return;
502 state_ = VIDEO_CAPTURE_STATE_STOPPING; 505 state_ = VIDEO_CAPTURE_STATE_STOPPING;
503 Send(new VideoCaptureHostMsg_Stop(device_id_)); 506 GetVideoCaptureHost()->Stop(device_id_);
504 params_.requested_format.frame_size.SetSize(0, 0); 507 params_.requested_format.frame_size.SetSize(0, 0);
505 }
506 } 508 }
507 509
508 void VideoCaptureImpl::RestartCapture() { 510 void VideoCaptureImpl::RestartCapture() {
509 DCHECK(io_task_runner_->BelongsToCurrentThread()); 511 DCHECK(io_task_runner_->BelongsToCurrentThread());
510 DCHECK_EQ(state_, VIDEO_CAPTURE_STATE_STOPPED); 512 DCHECK_EQ(state_, VIDEO_CAPTURE_STATE_STOPPED);
511 513
512 int width = 0; 514 int width = 0;
513 int height = 0; 515 int height = 0;
514 clients_.insert(clients_pending_on_restart_.begin(), 516 clients_.insert(clients_pending_on_restart_.begin(),
515 clients_pending_on_restart_.end()); 517 clients_pending_on_restart_.end());
(...skipping 29 matching lines...) Expand all
545 547
546 const ClientInfoMap::iterator it = clients->find(client_id); 548 const ClientInfoMap::iterator it = clients->find(client_id);
547 if (it != clients->end()) { 549 if (it != clients->end()) {
548 it->second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED); 550 it->second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED);
549 clients->erase(it); 551 clients->erase(it);
550 found = true; 552 found = true;
551 } 553 }
552 return found; 554 return found;
553 } 555 }
554 556
557 mojom::VideoCaptureHost* VideoCaptureImpl::GetVideoCaptureHost() {
558 DCHECK(io_task_runner_->BelongsToCurrentThread());
559 if (video_capture_host_for_testing_)
560 return video_capture_host_for_testing_;
561
562 if (!video_capture_host_.get()) {
563 DCHECK(message_filter_->channel());
564 message_filter_->channel()
565 ->GetAssociatedInterfaceSupport()
566 ->GetRemoteAssociatedInterface(&video_capture_host_);
567 }
568 return video_capture_host_.get();
569 };
570
555 // static 571 // static
556 void VideoCaptureImpl::DidFinishConsumingFrame( 572 void VideoCaptureImpl::DidFinishConsumingFrame(
557 const media::VideoFrameMetadata* metadata, 573 const media::VideoFrameMetadata* metadata,
558 std::unique_ptr<gpu::SyncToken> release_sync_token, 574 std::unique_ptr<gpu::SyncToken> release_sync_token,
559 const BufferFinishedCallback& callback_to_io_thread) { 575 const BufferFinishedCallback& callback_to_io_thread) {
560 // Note: This function may be called on any thread by the VideoFrame 576 // Note: This function may be called on any thread by the VideoFrame
561 // destructor. |metadata| is still valid for read-access at this point. 577 // destructor. |metadata| is still valid for read-access at this point.
562 double consumer_resource_utilization = -1.0; 578 double consumer_resource_utilization = -1.0;
563 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, 579 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION,
564 &consumer_resource_utilization)) { 580 &consumer_resource_utilization)) {
565 consumer_resource_utilization = -1.0; 581 consumer_resource_utilization = -1.0;
566 } 582 }
567 583
568 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization); 584 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization);
569 } 585 }
570 586
571 } // namespace content 587 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/video_capture_impl.h ('k') | content/renderer/media/video_capture_impl_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698