Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: content/browser/renderer_host/media/video_capture_controller.cc

Issue 2738763002: [Mojo Video Capture] Introduce abstraction BuildableVideoCaptureDevice (Closed)
Patch Set: Incorporated miu@'s suggestions from PatchSet 3 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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 BuildableDeviceCallbacks* callbacks,
502 std::unique_ptr<Ownership> context_reference) {
503 buildable_device_->CreateAndStartDeviceAsync(this, this, params, callbacks,
504 std::move(context_reference));
505 }
506
507 void VideoCaptureController::ReleaseDeviceAsync(
508 std::unique_ptr<Ownership> context_reference) {
509 buildable_device_->ReleaseDeviceAsync(this, std::move(context_reference));
510 }
511
512 bool VideoCaptureController::IsDeviceAlive() const {
513 return buildable_device_->IsDeviceAlive();
514 }
515
516 bool VideoCaptureController::CorrespondsToController(
517 const VideoCaptureController* controller) const {
518 return controller == this;
519 }
520
521 void VideoCaptureController::GetPhotoCapabilities(
522 media::VideoCaptureDevice::GetPhotoCapabilitiesCallback callback) const {
523 buildable_device_->GetPhotoCapabilities(std::move(callback));
524 }
525
526 void VideoCaptureController::SetPhotoOptions(
527 media::mojom::PhotoSettingsPtr settings,
528 media::VideoCaptureDevice::SetPhotoOptionsCallback callback) {
529 buildable_device_->SetPhotoOptions(std::move(settings), std::move(callback));
530 }
531
532 void VideoCaptureController::TakePhoto(
533 media::VideoCaptureDevice::TakePhotoCallback callback) {
534 buildable_device_->TakePhoto(std::move(callback));
535 }
536
537 void VideoCaptureController::MaybeSuspend() {
538 buildable_device_->MaybeSuspendDevice();
539 }
540
541 void VideoCaptureController::Resume() {
542 buildable_device_->ResumeDevice();
543 }
544
545 void VideoCaptureController::RequestRefreshFrame() {
546 buildable_device_->RequestRefreshFrame();
547 }
548
549 void VideoCaptureController::SetDesktopCaptureWindowIdAsync(
550 gfx::NativeViewId window_id,
551 std::unique_ptr<Ownership> context_reference) {
552 buildable_device_->SetDesktopCaptureWindowIdAsync(
553 window_id, std::move(context_reference));
554 }
555
487 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( 556 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient(
488 VideoCaptureControllerID id, 557 VideoCaptureControllerID id,
489 VideoCaptureControllerEventHandler* handler, 558 VideoCaptureControllerEventHandler* handler,
490 const ControllerClients& clients) { 559 const ControllerClients& clients) {
491 for (const auto& client : clients) { 560 for (const auto& client : clients) {
492 if (client->controller_id == id && client->event_handler == handler) 561 if (client->controller_id == id && client->event_handler == handler)
493 return client.get(); 562 return client.get();
494 } 563 }
495 return nullptr; 564 return nullptr;
496 } 565 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 EventHandlerAction action) { 629 EventHandlerAction action) {
561 DCHECK_CURRENTLY_ON(BrowserThread::IO); 630 DCHECK_CURRENTLY_ON(BrowserThread::IO);
562 for (const auto& client : controller_clients_) { 631 for (const auto& client : controller_clients_) {
563 if (client->session_closed) 632 if (client->session_closed)
564 continue; 633 continue;
565 action.Run(client->event_handler, client->controller_id); 634 action.Run(client->event_handler, client->controller_id);
566 } 635 }
567 } 636 }
568 637
569 } // namespace content 638 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698