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 bool VideoCaptureController::CorrespondsToController( | |
516 const VideoCaptureController* controller) const { | |
517 return controller == this; | |
518 } | |
mcasas
2017/03/22 22:43:16
How is this method supposed to be used?
(It isn't
chfremer
2017/03/22 23:20:38
Good catch. With the merge of VideoCaptureDeviceEn
| |
519 | |
520 void VideoCaptureController::GetPhotoCapabilities( | |
521 media::VideoCaptureDevice::GetPhotoCapabilitiesCallback callback) const { | |
522 buildable_device_->GetPhotoCapabilities(std::move(callback)); | |
523 } | |
524 | |
525 void VideoCaptureController::SetPhotoOptions( | |
526 media::mojom::PhotoSettingsPtr settings, | |
527 media::VideoCaptureDevice::SetPhotoOptionsCallback callback) { | |
528 buildable_device_->SetPhotoOptions(std::move(settings), std::move(callback)); | |
529 } | |
530 | |
531 void VideoCaptureController::TakePhoto( | |
532 media::VideoCaptureDevice::TakePhotoCallback callback) { | |
533 buildable_device_->TakePhoto(std::move(callback)); | |
534 } | |
535 | |
536 void VideoCaptureController::MaybeSuspend() { | |
537 buildable_device_->MaybeSuspendDevice(); | |
538 } | |
539 | |
540 void VideoCaptureController::Resume() { | |
541 buildable_device_->ResumeDevice(); | |
542 } | |
543 | |
544 void VideoCaptureController::RequestRefreshFrame() { | |
545 buildable_device_->RequestRefreshFrame(); | |
546 } | |
547 | |
548 void VideoCaptureController::SetDesktopCaptureWindowIdAsync( | |
549 gfx::NativeViewId window_id, | |
550 base::OnceClosure done_cb) { | |
551 buildable_device_->SetDesktopCaptureWindowIdAsync(window_id, | |
552 std::move(done_cb)); | |
553 } | |
554 | |
487 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( | 555 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( |
488 VideoCaptureControllerID id, | 556 VideoCaptureControllerID id, |
489 VideoCaptureControllerEventHandler* handler, | 557 VideoCaptureControllerEventHandler* handler, |
490 const ControllerClients& clients) { | 558 const ControllerClients& clients) { |
491 for (const auto& client : clients) { | 559 for (const auto& client : clients) { |
492 if (client->controller_id == id && client->event_handler == handler) | 560 if (client->controller_id == id && client->event_handler == handler) |
493 return client.get(); | 561 return client.get(); |
494 } | 562 } |
495 return nullptr; | 563 return nullptr; |
496 } | 564 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 EventHandlerAction action) { | 628 EventHandlerAction action) { |
561 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 629 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
562 for (const auto& client : controller_clients_) { | 630 for (const auto& client : controller_clients_) { |
563 if (client->session_closed) | 631 if (client->session_closed) |
564 continue; | 632 continue; |
565 action.Run(client->event_handler, client->controller_id); | 633 action.Run(client->event_handler, client->controller_id); |
566 } | 634 } |
567 } | 635 } |
568 | 636 |
569 } // namespace content | 637 } // namespace content |
OLD | NEW |