| OLD | NEW |
| 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 #include "content/browser/renderer_host/media/video_capture_controller.h" | 5 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 160 |
| 161 mojo::ScopedSharedBufferHandle | 161 mojo::ScopedSharedBufferHandle |
| 162 VideoCaptureController::BufferContext::CloneHandle() { | 162 VideoCaptureController::BufferContext::CloneHandle() { |
| 163 return buffer_handle_->Clone(); | 163 return buffer_handle_->Clone(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 VideoCaptureController::VideoCaptureController( | 166 VideoCaptureController::VideoCaptureController( |
| 167 const std::string& device_id, | 167 const std::string& device_id, |
| 168 MediaStreamType stream_type, | 168 MediaStreamType stream_type, |
| 169 const media::VideoCaptureParams& params, | 169 const media::VideoCaptureParams& params, |
| 170 std::unique_ptr<BuildableVideoCaptureDevice> buildable_device) | 170 std::unique_ptr<VideoCaptureDeviceLauncher> device_launcher) |
| 171 : serial_id_(g_device_start_id++), | 171 : serial_id_(g_device_start_id++), |
| 172 device_id_(device_id), | 172 device_id_(device_id), |
| 173 stream_type_(stream_type), | 173 stream_type_(stream_type), |
| 174 parameters_(params), | 174 parameters_(params), |
| 175 buildable_device_(std::move(buildable_device)), | 175 device_launcher_(std::move(device_launcher)), |
| 176 consumer_feedback_observer_(nullptr), | 176 device_launch_observer_(nullptr), |
| 177 state_(VIDEO_CAPTURE_STATE_STARTING), | 177 state_(VIDEO_CAPTURE_STATE_STARTING), |
| 178 has_received_frames_(false), | 178 has_received_frames_(false), |
| 179 weak_ptr_factory_(this) { | 179 weak_ptr_factory_(this) { |
| 180 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 180 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 181 } | 181 } |
| 182 | 182 |
| 183 VideoCaptureController::~VideoCaptureController() = default; | 183 VideoCaptureController::~VideoCaptureController() = default; |
| 184 | 184 |
| 185 base::WeakPtr<VideoCaptureController> | 185 base::WeakPtr<VideoCaptureController> |
| 186 VideoCaptureController::GetWeakPtrForIOThread() { | 186 VideoCaptureController::GetWeakPtrForIOThread() { |
| 187 return weak_ptr_factory_.GetWeakPtr(); | 187 return weak_ptr_factory_.GetWeakPtr(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 void VideoCaptureController::SetConsumerFeedbackObserver( | |
| 191 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> | |
| 192 consumer_feedback_observer) { | |
| 193 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 194 consumer_feedback_observer_ = std::move(consumer_feedback_observer); | |
| 195 // Update existing BufferContext entries. | |
| 196 for (auto& entry : buffer_contexts_) | |
| 197 entry.set_consumer_feedback_observer(consumer_feedback_observer_.get()); | |
| 198 } | |
| 199 | |
| 200 void VideoCaptureController::AddClient( | 190 void VideoCaptureController::AddClient( |
| 201 VideoCaptureControllerID id, | 191 VideoCaptureControllerID id, |
| 202 VideoCaptureControllerEventHandler* event_handler, | 192 VideoCaptureControllerEventHandler* event_handler, |
| 203 media::VideoCaptureSessionId session_id, | 193 media::VideoCaptureSessionId session_id, |
| 204 const media::VideoCaptureParams& params) { | 194 const media::VideoCaptureParams& params) { |
| 205 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 195 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 206 DVLOG(1) << "VideoCaptureController::AddClient() -- id=" << id | 196 DVLOG(1) << "VideoCaptureController::AddClient() -- id=" << id |
| 207 << ", session_id=" << session_id << ", params.requested_format=" | 197 << ", session_id=" << session_id << ", params.requested_format=" |
| 208 << media::VideoCaptureFormat::ToString(params.requested_format); | 198 << media::VideoCaptureFormat::ToString(params.requested_format); |
| 209 | 199 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 } | 368 } |
| 379 | 369 |
| 380 void VideoCaptureController::OnNewBufferHandle( | 370 void VideoCaptureController::OnNewBufferHandle( |
| 381 int buffer_id, | 371 int buffer_id, |
| 382 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer::HandleProvider> | 372 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer::HandleProvider> |
| 383 handle_provider) { | 373 handle_provider) { |
| 384 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 374 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 385 DCHECK(FindUnretiredBufferContextFromBufferId(buffer_id) == | 375 DCHECK(FindUnretiredBufferContextFromBufferId(buffer_id) == |
| 386 buffer_contexts_.end()); | 376 buffer_contexts_.end()); |
| 387 buffer_contexts_.emplace_back( | 377 buffer_contexts_.emplace_back( |
| 388 next_buffer_context_id_++, buffer_id, consumer_feedback_observer_.get(), | 378 next_buffer_context_id_++, buffer_id, launched_device_.get(), |
| 389 handle_provider->GetHandleForInterProcessTransit()); | 379 handle_provider->GetHandleForInterProcessTransit()); |
| 390 } | 380 } |
| 391 | 381 |
| 392 void VideoCaptureController::OnFrameReadyInBuffer( | 382 void VideoCaptureController::OnFrameReadyInBuffer( |
| 393 int buffer_id, | 383 int buffer_id, |
| 394 int frame_feedback_id, | 384 int frame_feedback_id, |
| 395 std::unique_ptr< | 385 std::unique_ptr< |
| 396 media::VideoCaptureDevice::Client::Buffer::ScopedAccessPermission> | 386 media::VideoCaptureDevice::Client::Buffer::ScopedAccessPermission> |
| 397 buffer_read_permission, | 387 buffer_read_permission, |
| 398 media::mojom::VideoFrameInfoPtr frame_info) { | 388 media::mojom::VideoFrameInfoPtr frame_info) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 void VideoCaptureController::OnStarted() { | 480 void VideoCaptureController::OnStarted() { |
| 491 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 481 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 492 state_ = VIDEO_CAPTURE_STATE_STARTED; | 482 state_ = VIDEO_CAPTURE_STATE_STARTED; |
| 493 PerformForClientsWithOpenSession(base::Bind(&CallOnStarted)); | 483 PerformForClientsWithOpenSession(base::Bind(&CallOnStarted)); |
| 494 } | 484 } |
| 495 | 485 |
| 496 void VideoCaptureController::OnStartedUsingGpuDecode() { | 486 void VideoCaptureController::OnStartedUsingGpuDecode() { |
| 497 PerformForClientsWithOpenSession(base::Bind(&CallOnStartedUsingGpuDecode)); | 487 PerformForClientsWithOpenSession(base::Bind(&CallOnStartedUsingGpuDecode)); |
| 498 } | 488 } |
| 499 | 489 |
| 490 void VideoCaptureController::OnDeviceLaunched( |
| 491 std::unique_ptr<LaunchedVideoCaptureDevice> device) { |
| 492 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 493 launched_device_ = std::move(device); |
| 494 for (auto& entry : buffer_contexts_) |
| 495 entry.set_consumer_feedback_observer(launched_device_.get()); |
| 496 if (device_launch_observer_) { |
| 497 device_launch_observer_->OnDeviceLaunched(this); |
| 498 device_launch_observer_ = nullptr; |
| 499 } |
| 500 } |
| 501 |
| 502 void VideoCaptureController::OnDeviceLaunchFailed() { |
| 503 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 504 if (device_launch_observer_) { |
| 505 device_launch_observer_->OnDeviceLaunchFailed(this); |
| 506 device_launch_observer_ = nullptr; |
| 507 } |
| 508 } |
| 509 |
| 510 void VideoCaptureController::OnDeviceLaunchAborted() { |
| 511 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 512 if (device_launch_observer_) { |
| 513 device_launch_observer_->OnDeviceLaunchAborted(); |
| 514 device_launch_observer_ = nullptr; |
| 515 } |
| 516 } |
| 517 |
| 500 void VideoCaptureController::CreateAndStartDeviceAsync( | 518 void VideoCaptureController::CreateAndStartDeviceAsync( |
| 501 const media::VideoCaptureParams& params, | 519 const media::VideoCaptureParams& params, |
| 502 BuildableVideoCaptureDevice::Callbacks* callbacks, | 520 VideoCaptureDeviceLaunchObserver* observer, |
| 503 base::OnceClosure done_cb) { | 521 base::OnceClosure done_cb) { |
| 504 buildable_device_->CreateAndStartDeviceAsync(this, params, callbacks, | 522 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 505 std::move(done_cb)); | 523 device_launch_observer_ = observer; |
| 524 device_launcher_->LaunchDeviceAsync(device_id_, stream_type_, params, |
| 525 GetWeakPtrForIOThread(), this, |
| 526 std::move(done_cb)); |
| 506 } | 527 } |
| 507 | 528 |
| 508 void VideoCaptureController::ReleaseDeviceAsync(base::OnceClosure done_cb) { | 529 void VideoCaptureController::ReleaseDeviceAsync(base::OnceClosure done_cb) { |
| 509 buildable_device_->ReleaseDeviceAsync(this, std::move(done_cb)); | 530 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 531 if (!launched_device_) { |
| 532 device_launcher_->AbortLaunch(); |
| 533 return; |
| 534 } |
| 535 launched_device_.reset(); |
| 510 } | 536 } |
| 511 | 537 |
| 512 bool VideoCaptureController::IsDeviceAlive() const { | 538 bool VideoCaptureController::IsDeviceAlive() const { |
| 513 return buildable_device_->IsDeviceAlive(); | 539 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 540 return launched_device_ != nullptr; |
| 514 } | 541 } |
| 515 | 542 |
| 516 void VideoCaptureController::GetPhotoCapabilities( | 543 void VideoCaptureController::GetPhotoCapabilities( |
| 517 media::VideoCaptureDevice::GetPhotoCapabilitiesCallback callback) const { | 544 media::VideoCaptureDevice::GetPhotoCapabilitiesCallback callback) const { |
| 518 buildable_device_->GetPhotoCapabilities(std::move(callback)); | 545 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 546 DCHECK(launched_device_); |
| 547 launched_device_->GetPhotoCapabilities(std::move(callback)); |
| 519 } | 548 } |
| 520 | 549 |
| 521 void VideoCaptureController::SetPhotoOptions( | 550 void VideoCaptureController::SetPhotoOptions( |
| 522 media::mojom::PhotoSettingsPtr settings, | 551 media::mojom::PhotoSettingsPtr settings, |
| 523 media::VideoCaptureDevice::SetPhotoOptionsCallback callback) { | 552 media::VideoCaptureDevice::SetPhotoOptionsCallback callback) { |
| 524 buildable_device_->SetPhotoOptions(std::move(settings), std::move(callback)); | 553 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 554 DCHECK(launched_device_); |
| 555 launched_device_->SetPhotoOptions(std::move(settings), std::move(callback)); |
| 525 } | 556 } |
| 526 | 557 |
| 527 void VideoCaptureController::TakePhoto( | 558 void VideoCaptureController::TakePhoto( |
| 528 media::VideoCaptureDevice::TakePhotoCallback callback) { | 559 media::VideoCaptureDevice::TakePhotoCallback callback) { |
| 529 buildable_device_->TakePhoto(std::move(callback)); | 560 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 561 DCHECK(launched_device_); |
| 562 launched_device_->TakePhoto(std::move(callback)); |
| 530 } | 563 } |
| 531 | 564 |
| 532 void VideoCaptureController::MaybeSuspend() { | 565 void VideoCaptureController::MaybeSuspend() { |
| 533 buildable_device_->MaybeSuspendDevice(); | 566 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 567 DCHECK(launched_device_); |
| 568 launched_device_->MaybeSuspendDevice(); |
| 534 } | 569 } |
| 535 | 570 |
| 536 void VideoCaptureController::Resume() { | 571 void VideoCaptureController::Resume() { |
| 537 buildable_device_->ResumeDevice(); | 572 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 573 DCHECK(launched_device_); |
| 574 launched_device_->ResumeDevice(); |
| 538 } | 575 } |
| 539 | 576 |
| 540 void VideoCaptureController::RequestRefreshFrame() { | 577 void VideoCaptureController::RequestRefreshFrame() { |
| 541 buildable_device_->RequestRefreshFrame(); | 578 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 579 DCHECK(launched_device_); |
| 580 launched_device_->RequestRefreshFrame(); |
| 542 } | 581 } |
| 543 | 582 |
| 544 void VideoCaptureController::SetDesktopCaptureWindowIdAsync( | 583 void VideoCaptureController::SetDesktopCaptureWindowIdAsync( |
| 545 gfx::NativeViewId window_id, | 584 gfx::NativeViewId window_id, |
| 546 base::OnceClosure done_cb) { | 585 base::OnceClosure done_cb) { |
| 547 buildable_device_->SetDesktopCaptureWindowIdAsync(window_id, | 586 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 548 std::move(done_cb)); | 587 DCHECK(launched_device_); |
| 588 launched_device_->SetDesktopCaptureWindowIdAsync(window_id, |
| 589 std::move(done_cb)); |
| 549 } | 590 } |
| 550 | 591 |
| 551 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( | 592 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( |
| 552 VideoCaptureControllerID id, | 593 VideoCaptureControllerID id, |
| 553 VideoCaptureControllerEventHandler* handler, | 594 VideoCaptureControllerEventHandler* handler, |
| 554 const ControllerClients& clients) { | 595 const ControllerClients& clients) { |
| 555 for (const auto& client : clients) { | 596 for (const auto& client : clients) { |
| 556 if (client->controller_id == id && client->event_handler == handler) | 597 if (client->controller_id == id && client->event_handler == handler) |
| 557 return client.get(); | 598 return client.get(); |
| 558 } | 599 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 EventHandlerAction action) { | 665 EventHandlerAction action) { |
| 625 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 666 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 626 for (const auto& client : controller_clients_) { | 667 for (const auto& client : controller_clients_) { |
| 627 if (client->session_closed) | 668 if (client->session_closed) |
| 628 continue; | 669 continue; |
| 629 action.Run(client->event_handler, client->controller_id); | 670 action.Run(client->event_handler, client->controller_id); |
| 630 } | 671 } |
| 631 } | 672 } |
| 632 | 673 |
| 633 } // namespace content | 674 } // namespace content |
| OLD | NEW |