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

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

Issue 2400443006: VideoCapture: moar VideoCapture renderer-->host messages to mojo, part 3 (Closed)
Patch Set: minor 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 208 }
209 209
210 void VideoCaptureImpl::RequestRefreshFrame() { 210 void VideoCaptureImpl::RequestRefreshFrame() {
211 DCHECK(io_task_runner_->BelongsToCurrentThread()); 211 DCHECK(io_task_runner_->BelongsToCurrentThread());
212 GetVideoCaptureHost()->RequestRefreshFrame(device_id_); 212 GetVideoCaptureHost()->RequestRefreshFrame(device_id_);
213 } 213 }
214 214
215 void VideoCaptureImpl::GetDeviceSupportedFormats( 215 void VideoCaptureImpl::GetDeviceSupportedFormats(
216 const VideoCaptureDeviceFormatsCB& callback) { 216 const VideoCaptureDeviceFormatsCB& callback) {
217 DCHECK(io_task_runner_->BelongsToCurrentThread()); 217 DCHECK(io_task_runner_->BelongsToCurrentThread());
218 device_formats_cb_queue_.push_back(callback); 218 GetVideoCaptureHost()->GetDeviceSupportedFormats(
219 if (device_formats_cb_queue_.size() == 1) { 219 device_id_, session_id_,
220 Send(new VideoCaptureHostMsg_GetDeviceSupportedFormats(device_id_, 220 base::Bind(&VideoCaptureImpl::OnDeviceSupportedFormats,
221 session_id_)); 221 weak_factory_.GetWeakPtr(), callback));
222 }
223 } 222 }
224 223
225 void VideoCaptureImpl::GetDeviceFormatsInUse( 224 void VideoCaptureImpl::GetDeviceFormatsInUse(
226 const VideoCaptureDeviceFormatsCB& callback) { 225 const VideoCaptureDeviceFormatsCB& callback) {
227 DCHECK(io_task_runner_->BelongsToCurrentThread()); 226 DCHECK(io_task_runner_->BelongsToCurrentThread());
228 device_formats_in_use_cb_queue_.push_back(callback); 227 GetVideoCaptureHost()->GetDeviceFormatsInUse(
229 if (device_formats_in_use_cb_queue_.size() == 1) { 228 device_id_, session_id_,
230 Send( 229 base::Bind(&VideoCaptureImpl::OnDeviceFormatsInUse,
231 new VideoCaptureHostMsg_GetDeviceFormatsInUse(device_id_, session_id_)); 230 weak_factory_.GetWeakPtr(), callback));
232 }
233 } 231 }
234 232
235 void VideoCaptureImpl::OnBufferCreated(base::SharedMemoryHandle handle, 233 void VideoCaptureImpl::OnBufferCreated(base::SharedMemoryHandle handle,
236 int length, 234 int length,
237 int buffer_id) { 235 int buffer_id) {
238 DCHECK(io_task_runner_->BelongsToCurrentThread()); 236 DCHECK(io_task_runner_->BelongsToCurrentThread());
239 237
240 // In case client calls StopCapture before the arrival of created buffer, 238 // In case client calls StopCapture before the arrival of created buffer,
241 // just close this buffer and return. 239 // just close this buffer and return.
242 if (state_ != VIDEO_CAPTURE_STATE_STARTED) { 240 if (state_ != VIDEO_CAPTURE_STATE_STARTED) {
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 client.second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED); 457 client.second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED);
460 } 458 }
461 clients_.clear(); 459 clients_.clear();
462 state_ = VIDEO_CAPTURE_STATE_ENDED; 460 state_ = VIDEO_CAPTURE_STATE_ENDED;
463 break; 461 break;
464 default: 462 default:
465 break; 463 break;
466 } 464 }
467 } 465 }
468 466
469 void VideoCaptureImpl::OnDeviceSupportedFormatsEnumerated( 467 void VideoCaptureImpl::OnDelegateAdded(int32_t device_id) {
470 const media::VideoCaptureFormats& supported_formats) { 468 DVLOG(1) << __func__ << " " << device_id;
471 DCHECK(io_task_runner_->BelongsToCurrentThread()); 469 DCHECK(io_task_runner_->BelongsToCurrentThread());
472 for (size_t i = 0; i < device_formats_cb_queue_.size(); ++i)
473 device_formats_cb_queue_[i].Run(supported_formats);
474 device_formats_cb_queue_.clear();
475 }
476
477 void VideoCaptureImpl::OnDeviceFormatsInUseReceived(
478 const media::VideoCaptureFormats& formats_in_use) {
479 DCHECK(io_task_runner_->BelongsToCurrentThread());
480 for (size_t i = 0; i < device_formats_in_use_cb_queue_.size(); ++i)
481 device_formats_in_use_cb_queue_[i].Run(formats_in_use);
482 device_formats_in_use_cb_queue_.clear();
483 }
484
485 void VideoCaptureImpl::OnDelegateAdded(int32_t device_id) {
486 DCHECK(io_task_runner_->BelongsToCurrentThread());
487 DVLOG(1) << "OnDelegateAdded: device_id " << device_id;
488 470
489 device_id_ = device_id; 471 device_id_ = device_id;
490 ClientInfoMap::iterator it = clients_pending_on_filter_.begin(); 472 ClientInfoMap::iterator it = clients_pending_on_filter_.begin();
491 while (it != clients_pending_on_filter_.end()) { 473 while (it != clients_pending_on_filter_.end()) {
492 const int client_id = it->first; 474 const int client_id = it->first;
493 const ClientInfo client_info = it->second; 475 const ClientInfo client_info = it->second;
494 clients_pending_on_filter_.erase(it++); 476 clients_pending_on_filter_.erase(it++);
495 StartCapture(client_id, client_info.params, client_info.state_update_cb, 477 StartCapture(client_id, client_info.params, client_info.state_update_cb,
496 client_info.deliver_frame_cb); 478 client_info.deliver_frame_cb);
497 } 479 }
(...skipping 30 matching lines...) Expand all
528 } 510 }
529 511
530 void VideoCaptureImpl::StartCaptureInternal() { 512 void VideoCaptureImpl::StartCaptureInternal() {
531 DCHECK(io_task_runner_->BelongsToCurrentThread()); 513 DCHECK(io_task_runner_->BelongsToCurrentThread());
532 DCHECK(device_id_); 514 DCHECK(device_id_);
533 515
534 GetVideoCaptureHost()->Start(device_id_, session_id_, params_); 516 GetVideoCaptureHost()->Start(device_id_, session_id_, params_);
535 state_ = VIDEO_CAPTURE_STATE_STARTED; 517 state_ = VIDEO_CAPTURE_STATE_STARTED;
536 } 518 }
537 519
520 void VideoCaptureImpl::OnDeviceSupportedFormats(
521 const VideoCaptureDeviceFormatsCB& callback,
522 const media::VideoCaptureFormats& supported_formats) {
523 DCHECK(io_task_runner_->BelongsToCurrentThread());
524 callback.Run(supported_formats);
525 }
526
527 void VideoCaptureImpl::OnDeviceFormatsInUse(
528 const VideoCaptureDeviceFormatsCB& callback,
529 const media::VideoCaptureFormats& formats_in_use) {
530 DCHECK(io_task_runner_->BelongsToCurrentThread());
531 callback.Run(formats_in_use);
532 }
533
538 void VideoCaptureImpl::Send(IPC::Message* message) { 534 void VideoCaptureImpl::Send(IPC::Message* message) {
539 DCHECK(io_task_runner_->BelongsToCurrentThread()); 535 DCHECK(io_task_runner_->BelongsToCurrentThread());
540 message_filter_->Send(message); 536 message_filter_->Send(message);
541 } 537 }
542 538
543 bool VideoCaptureImpl::RemoveClient(int client_id, ClientInfoMap* clients) { 539 bool VideoCaptureImpl::RemoveClient(int client_id, ClientInfoMap* clients) {
544 DCHECK(io_task_runner_->BelongsToCurrentThread()); 540 DCHECK(io_task_runner_->BelongsToCurrentThread());
545 541
546 const ClientInfoMap::iterator it = clients->find(client_id); 542 const ClientInfoMap::iterator it = clients->find(client_id);
547 if (it == clients->end()) 543 if (it == clients->end())
(...skipping 30 matching lines...) Expand all
578 double consumer_resource_utilization = -1.0; 574 double consumer_resource_utilization = -1.0;
579 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION, 575 if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION,
580 &consumer_resource_utilization)) { 576 &consumer_resource_utilization)) {
581 consumer_resource_utilization = -1.0; 577 consumer_resource_utilization = -1.0;
582 } 578 }
583 579
584 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization); 580 callback_to_io_thread.Run(*release_sync_token, consumer_resource_utilization);
585 } 581 }
586 582
587 } // namespace content 583 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/video_capture_impl.h ('k') | content/renderer/media/video_capture_impl_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698