| 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_STARTED), | 177 state_(VIDEO_CAPTURE_STATE_STARTED), |
| 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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 } | 484 } |
| 473 | 485 |
| 474 void VideoCaptureController::OnStarted() { | 486 void VideoCaptureController::OnStarted() { |
| 475 PerformForClientsWithOpenSession(base::Bind(&CallOnStarted)); | 487 PerformForClientsWithOpenSession(base::Bind(&CallOnStarted)); |
| 476 } | 488 } |
| 477 | 489 |
| 478 void VideoCaptureController::OnStartedUsingGpuDecode() { | 490 void VideoCaptureController::OnStartedUsingGpuDecode() { |
| 479 PerformForClientsWithOpenSession(base::Bind(&CallOnStartedUsingGpuDecode)); | 491 PerformForClientsWithOpenSession(base::Bind(&CallOnStartedUsingGpuDecode)); |
| 480 } | 492 } |
| 481 | 493 |
| 494 void VideoCaptureController::CreateAndStartDeviceAsync( |
| 495 const media::VideoCaptureParams& params, |
| 496 BuildableDeviceCallbacks* callbacks, |
| 497 std::unique_ptr<Ownership> context_reference) { |
| 498 buildable_device_->CreateAndStartDeviceAsync(this, this, params, callbacks, |
| 499 std::move(context_reference)); |
| 500 } |
| 501 |
| 502 void VideoCaptureController::ReleaseDeviceAsync( |
| 503 std::unique_ptr<Ownership> context_reference) { |
| 504 buildable_device_->ReleaseDeviceAsync(this, std::move(context_reference)); |
| 505 } |
| 506 |
| 507 bool VideoCaptureController::IsDeviceAlive() const { |
| 508 return buildable_device_->IsDeviceAlive(); |
| 509 } |
| 510 |
| 511 bool VideoCaptureController::CorrespondsToController( |
| 512 const VideoCaptureController* controller) const { |
| 513 return controller == this; |
| 514 } |
| 515 |
| 516 void VideoCaptureController::GetPhotoCapabilities( |
| 517 media::VideoCaptureDevice::GetPhotoCapabilitiesCallback callback) const { |
| 518 buildable_device_->GetPhotoCapabilities(std::move(callback)); |
| 519 } |
| 520 |
| 521 void VideoCaptureController::SetPhotoOptions( |
| 522 media::mojom::PhotoSettingsPtr settings, |
| 523 media::VideoCaptureDevice::SetPhotoOptionsCallback callback) { |
| 524 buildable_device_->SetPhotoOptions(std::move(settings), std::move(callback)); |
| 525 } |
| 526 |
| 527 void VideoCaptureController::TakePhoto( |
| 528 media::VideoCaptureDevice::TakePhotoCallback callback) { |
| 529 buildable_device_->TakePhoto(std::move(callback)); |
| 530 } |
| 531 |
| 532 void VideoCaptureController::MaybeSuspend() { |
| 533 buildable_device_->MaybeSuspendDevice(); |
| 534 } |
| 535 |
| 536 void VideoCaptureController::Resume() { |
| 537 buildable_device_->ResumeDevice(); |
| 538 } |
| 539 |
| 540 void VideoCaptureController::RequestRefreshFrame() { |
| 541 buildable_device_->RequestRefreshFrame(); |
| 542 } |
| 543 |
| 544 void VideoCaptureController::SetDesktopCaptureWindowIdAsync( |
| 545 gfx::NativeViewId window_id, |
| 546 std::unique_ptr<Ownership> context_reference) { |
| 547 buildable_device_->SetDesktopCaptureWindowIdAsync( |
| 548 window_id, std::move(context_reference)); |
| 549 } |
| 550 |
| 482 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( | 551 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( |
| 483 VideoCaptureControllerID id, | 552 VideoCaptureControllerID id, |
| 484 VideoCaptureControllerEventHandler* handler, | 553 VideoCaptureControllerEventHandler* handler, |
| 485 const ControllerClients& clients) { | 554 const ControllerClients& clients) { |
| 486 for (const auto& client : clients) { | 555 for (const auto& client : clients) { |
| 487 if (client->controller_id == id && client->event_handler == handler) | 556 if (client->controller_id == id && client->event_handler == handler) |
| 488 return client.get(); | 557 return client.get(); |
| 489 } | 558 } |
| 490 return nullptr; | 559 return nullptr; |
| 491 } | 560 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 EventHandlerAction action) { | 624 EventHandlerAction action) { |
| 556 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 625 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 557 for (const auto& client : controller_clients_) { | 626 for (const auto& client : controller_clients_) { |
| 558 if (client->session_closed) | 627 if (client->session_closed) |
| 559 continue; | 628 continue; |
| 560 action.Run(client->event_handler, client->controller_id); | 629 action.Run(client->event_handler, client->controller_id); |
| 561 } | 630 } |
| 562 } | 631 } |
| 563 | 632 |
| 564 } // namespace content | 633 } // namespace content |
| OLD | NEW |