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