| 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 22 matching lines...) Expand all Loading... |
| 33 #endif | 33 #endif |
| 34 | 34 |
| 35 using media::VideoCaptureFormat; | 35 using media::VideoCaptureFormat; |
| 36 using media::VideoFrame; | 36 using media::VideoFrame; |
| 37 using media::VideoFrameMetadata; | 37 using media::VideoFrameMetadata; |
| 38 | 38 |
| 39 namespace content { | 39 namespace content { |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 // Counter used for identifying a DeviceRequest to start a capture device. |
| 44 static int g_device_start_id = 0; |
| 45 |
| 43 static const int kInfiniteRatio = 99999; | 46 static const int kInfiniteRatio = 99999; |
| 44 | 47 |
| 45 #define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \ | 48 #define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \ |
| 46 UMA_HISTOGRAM_SPARSE_SLOWLY( \ | 49 UMA_HISTOGRAM_SPARSE_SLOWLY( \ |
| 47 name, (height) ? ((width)*100) / (height) : kInfiniteRatio); | 50 name, (height) ? ((width)*100) / (height) : kInfiniteRatio); |
| 48 | 51 |
| 49 void CallOnError(VideoCaptureControllerEventHandler* client, | 52 void CallOnError(VideoCaptureControllerEventHandler* client, |
| 50 VideoCaptureControllerID id) { | 53 VideoCaptureControllerID id) { |
| 51 client->OnError(id); | 54 client->OnError(id); |
| 52 } | 55 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 max_consumer_utilization_ = | 156 max_consumer_utilization_ = |
| 154 media::VideoFrameConsumerFeedbackObserver::kNoUtilizationRecorded; | 157 media::VideoFrameConsumerFeedbackObserver::kNoUtilizationRecorded; |
| 155 } | 158 } |
| 156 } | 159 } |
| 157 | 160 |
| 158 mojo::ScopedSharedBufferHandle | 161 mojo::ScopedSharedBufferHandle |
| 159 VideoCaptureController::BufferContext::CloneHandle() { | 162 VideoCaptureController::BufferContext::CloneHandle() { |
| 160 return buffer_handle_->Clone(); | 163 return buffer_handle_->Clone(); |
| 161 } | 164 } |
| 162 | 165 |
| 163 VideoCaptureController::VideoCaptureController() | 166 VideoCaptureController::VideoCaptureController( |
| 164 : consumer_feedback_observer_(nullptr), | 167 const std::string& device_id, |
| 168 MediaStreamType stream_type, |
| 169 const media::VideoCaptureParams& params, |
| 170 std::unique_ptr<BuildableVideoCaptureDevice> buildable_device) |
| 171 : serial_id_(g_device_start_id++), |
| 172 device_id_(device_id), |
| 173 stream_type_(stream_type), |
| 174 parameters_(params), |
| 175 buildable_device_(std::move(buildable_device)), |
| 176 consumer_feedback_observer_(nullptr), |
| 165 state_(VIDEO_CAPTURE_STATE_STARTING), | 177 state_(VIDEO_CAPTURE_STATE_STARTING), |
| 166 has_received_frames_(false), | 178 has_received_frames_(false), |
| 167 weak_ptr_factory_(this) { | 179 weak_ptr_factory_(this) { |
| 168 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 180 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 169 } | 181 } |
| 170 | 182 |
| 171 VideoCaptureController::~VideoCaptureController() = default; | 183 VideoCaptureController::~VideoCaptureController() = default; |
| 172 | 184 |
| 173 base::WeakPtr<VideoCaptureController> | 185 base::WeakPtr<VideoCaptureController> |
| 174 VideoCaptureController::GetWeakPtrForIOThread() { | 186 VideoCaptureController::GetWeakPtrForIOThread() { |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 void VideoCaptureController::OnStarted() { | 489 void VideoCaptureController::OnStarted() { |
| 478 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 490 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 479 state_ = VIDEO_CAPTURE_STATE_STARTED; | 491 state_ = VIDEO_CAPTURE_STATE_STARTED; |
| 480 PerformForClientsWithOpenSession(base::Bind(&CallOnStarted)); | 492 PerformForClientsWithOpenSession(base::Bind(&CallOnStarted)); |
| 481 } | 493 } |
| 482 | 494 |
| 483 void VideoCaptureController::OnStartedUsingGpuDecode() { | 495 void VideoCaptureController::OnStartedUsingGpuDecode() { |
| 484 PerformForClientsWithOpenSession(base::Bind(&CallOnStartedUsingGpuDecode)); | 496 PerformForClientsWithOpenSession(base::Bind(&CallOnStartedUsingGpuDecode)); |
| 485 } | 497 } |
| 486 | 498 |
| 499 void VideoCaptureController::CreateAndStartDeviceAsync( |
| 500 const media::VideoCaptureParams& params, |
| 501 BuildableVideoCaptureDevice::Callbacks* callbacks, |
| 502 base::OnceClosure done_cb) { |
| 503 buildable_device_->CreateAndStartDeviceAsync(this, params, callbacks, |
| 504 std::move(done_cb)); |
| 505 } |
| 506 |
| 507 void VideoCaptureController::ReleaseDeviceAsync(base::OnceClosure done_cb) { |
| 508 buildable_device_->ReleaseDeviceAsync(this, std::move(done_cb)); |
| 509 } |
| 510 |
| 511 bool VideoCaptureController::IsDeviceAlive() const { |
| 512 return buildable_device_->IsDeviceAlive(); |
| 513 } |
| 514 |
| 515 void VideoCaptureController::GetPhotoCapabilities( |
| 516 media::VideoCaptureDevice::GetPhotoCapabilitiesCallback callback) const { |
| 517 buildable_device_->GetPhotoCapabilities(std::move(callback)); |
| 518 } |
| 519 |
| 520 void VideoCaptureController::SetPhotoOptions( |
| 521 media::mojom::PhotoSettingsPtr settings, |
| 522 media::VideoCaptureDevice::SetPhotoOptionsCallback callback) { |
| 523 buildable_device_->SetPhotoOptions(std::move(settings), std::move(callback)); |
| 524 } |
| 525 |
| 526 void VideoCaptureController::TakePhoto( |
| 527 media::VideoCaptureDevice::TakePhotoCallback callback) { |
| 528 buildable_device_->TakePhoto(std::move(callback)); |
| 529 } |
| 530 |
| 531 void VideoCaptureController::MaybeSuspend() { |
| 532 buildable_device_->MaybeSuspendDevice(); |
| 533 } |
| 534 |
| 535 void VideoCaptureController::Resume() { |
| 536 buildable_device_->ResumeDevice(); |
| 537 } |
| 538 |
| 539 void VideoCaptureController::RequestRefreshFrame() { |
| 540 buildable_device_->RequestRefreshFrame(); |
| 541 } |
| 542 |
| 543 void VideoCaptureController::SetDesktopCaptureWindowIdAsync( |
| 544 gfx::NativeViewId window_id, |
| 545 base::OnceClosure done_cb) { |
| 546 buildable_device_->SetDesktopCaptureWindowIdAsync(window_id, |
| 547 std::move(done_cb)); |
| 548 } |
| 549 |
| 487 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( | 550 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( |
| 488 VideoCaptureControllerID id, | 551 VideoCaptureControllerID id, |
| 489 VideoCaptureControllerEventHandler* handler, | 552 VideoCaptureControllerEventHandler* handler, |
| 490 const ControllerClients& clients) { | 553 const ControllerClients& clients) { |
| 491 for (const auto& client : clients) { | 554 for (const auto& client : clients) { |
| 492 if (client->controller_id == id && client->event_handler == handler) | 555 if (client->controller_id == id && client->event_handler == handler) |
| 493 return client.get(); | 556 return client.get(); |
| 494 } | 557 } |
| 495 return nullptr; | 558 return nullptr; |
| 496 } | 559 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 EventHandlerAction action) { | 623 EventHandlerAction action) { |
| 561 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 624 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 562 for (const auto& client : controller_clients_) { | 625 for (const auto& client : controller_clients_) { |
| 563 if (client->session_closed) | 626 if (client->session_closed) |
| 564 continue; | 627 continue; |
| 565 action.Run(client->event_handler, client->controller_id); | 628 action.Run(client->event_handler, client->controller_id); |
| 566 } | 629 } |
| 567 } | 630 } |
| 568 | 631 |
| 569 } // namespace content | 632 } // namespace content |
| OLD | NEW |