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

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

Issue 2769543002: [Mojo Video Capture] Introduce abstraction VideoCaptureSystem (Closed)
Patch Set: 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/in_process_buildable_video_capture _device.h" 5 #include "content/browser/renderer_host/media/in_process_buildable_video_capture _device.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" 9 #include "content/browser/media/capture/desktop_capture_device_uma_types.h"
10 #include "content/browser/media/capture/web_contents_video_capture_device.h" 10 #include "content/browser/media/capture/web_contents_video_capture_device.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // TODO(miu): The value for tab capture should be determined programmatically. 77 // TODO(miu): The value for tab capture should be determined programmatically.
78 // http://crbug.com/460318 78 // http://crbug.com/460318
79 const int kMaxNumberOfBuffersForTabCapture = 10; 79 const int kMaxNumberOfBuffersForTabCapture = 10;
80 80
81 } // anonymous namespace 81 } // anonymous namespace
82 82
83 namespace content { 83 namespace content {
84 84
85 InProcessBuildableVideoCaptureDevice::InProcessBuildableVideoCaptureDevice( 85 InProcessBuildableVideoCaptureDevice::InProcessBuildableVideoCaptureDevice(
86 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner, 86 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner,
87 media::VideoCaptureDeviceFactory* device_factory) 87 media::VideoCaptureSystem* device_factory)
88 : device_task_runner_(std::move(device_task_runner)), 88 : device_task_runner_(std::move(device_task_runner)),
89 device_factory_(device_factory) {} 89 device_factory_(device_factory) {}
90 90
91 InProcessBuildableVideoCaptureDevice::~InProcessBuildableVideoCaptureDevice() { 91 InProcessBuildableVideoCaptureDevice::~InProcessBuildableVideoCaptureDevice() {
92 DCHECK_CURRENTLY_ON(BrowserThread::IO); 92 DCHECK_CURRENTLY_ON(BrowserThread::IO);
93 DCHECK(!device_); 93 DCHECK(!device_);
94 } 94 }
95 95
96 void InProcessBuildableVideoCaptureDevice::CreateAndStartDeviceAsync( 96 void InProcessBuildableVideoCaptureDevice::CreateAndStartDeviceAsync(
97 VideoCaptureController* controller, 97 VideoCaptureController* controller,
98 const media::VideoCaptureParams& params, 98 const media::VideoCaptureParams& params,
99 BuildableDeviceCallbacks* callbacks, 99 BuildableDeviceCallbacks* callbacks,
100 base::OnceClosure done_cb) { 100 base::OnceClosure done_cb) {
101 DCHECK_CURRENTLY_ON(BrowserThread::IO); 101 DCHECK_CURRENTLY_ON(BrowserThread::IO);
102 DCHECK(state_ == State::NO_DEVICE); 102 DCHECK(state_ == State::NO_DEVICE);
103 103
104 const int max_buffers = (controller->stream_type() == MEDIA_TAB_VIDEO_CAPTURE 104 const int max_buffers = (controller->stream_type() == MEDIA_TAB_VIDEO_CAPTURE
105 ? kMaxNumberOfBuffersForTabCapture 105 ? kMaxNumberOfBuffersForTabCapture
106 : kMaxNumberOfBuffers); 106 : kMaxNumberOfBuffers);
107 107
108 auto device_client = 108 auto device_client =
109 CreateDeviceClient(max_buffers, controller->GetWeakPtrForIOThread()); 109 CreateDeviceClient(max_buffers, controller->GetWeakPtrForIOThread());
110 110
111 base::Closure start_capture_closure; 111 base::Closure start_capture_closure;
112 // Use of Unretained() is safe, because |context_reference| guarantees that
113 // |this| stays alive.
114 ReceiveDeviceCallback after_start_capture_callback = media::BindToCurrentLoop(
115 base::Bind(&InProcessBuildableVideoCaptureDevice::OnDeviceStarted,
116 base::Unretained(this), controller, callbacks,
117 base::Passed(&done_cb)));
118
112 switch (controller->stream_type()) { 119 switch (controller->stream_type()) {
113 case MEDIA_DEVICE_VIDEO_CAPTURE: { 120 case MEDIA_DEVICE_VIDEO_CAPTURE: {
114 const media::VideoCaptureDeviceDescriptor* descriptor = 121 start_capture_closure =
115 callbacks->LookupDeviceDescriptor(controller->device_id()); 122 base::Bind(&InProcessBuildableVideoCaptureDevice::
116 if (descriptor) { 123 DoStartDeviceCaptureOnDeviceThread,
117 controller->OnLog( 124 base::Unretained(this), controller->device_id(), params,
118 base::StringPrintf("Starting device: id: %s, name: %s, api: %s", 125 base::Passed(std::move(device_client)),
119 descriptor->device_id.c_str(), 126 std::move(after_start_capture_callback));
120 descriptor->GetNameAndModel().c_str(),
121 descriptor->GetCaptureApiTypeString()));
122
123 callbacks->WillStartDevice(descriptor->facing);
124
125 // Use of Unretained() is safe, because |context_reference| guarantees
126 // that |this| stays alive.
127 ReceiveDeviceCallback after_start_capture_callback =
128 media::BindToCurrentLoop(base::Bind(
129 &InProcessBuildableVideoCaptureDevice::OnDeviceStarted,
130 base::Unretained(this), controller, callbacks,
131 base::Passed(&done_cb)));
132 start_capture_closure =
133 base::Bind(&InProcessBuildableVideoCaptureDevice::
134 DoStartDeviceCaptureOnDeviceThread,
135 base::Unretained(this), *descriptor, params,
136 base::Passed(std::move(device_client)),
137 std::move(after_start_capture_callback));
138 } else {
139 callbacks->OnDeviceStartFailed(controller);
140 std::move(done_cb).Run();
141 return;
142 }
143 break; 127 break;
144 } 128 }
145 case MEDIA_TAB_VIDEO_CAPTURE: { 129 case MEDIA_TAB_VIDEO_CAPTURE:
146 // Use of Unretained() is safe, because |context_reference| guarantees
147 // that |this| stays alive.
148 ReceiveDeviceCallback after_start_capture_callback =
149 media::BindToCurrentLoop(
150 base::Bind(&InProcessBuildableVideoCaptureDevice::OnDeviceStarted,
151 base::Unretained(this), controller, callbacks,
152 base::Passed(&done_cb)));
153 start_capture_closure = 130 start_capture_closure =
154 base::Bind(&InProcessBuildableVideoCaptureDevice:: 131 base::Bind(&InProcessBuildableVideoCaptureDevice::
155 DoStartTabCaptureOnDeviceThread, 132 DoStartTabCaptureOnDeviceThread,
156 base::Unretained(this), controller->device_id(), params, 133 base::Unretained(this), controller->device_id(), params,
157 base::Passed(std::move(device_client)), 134 base::Passed(std::move(device_client)),
158 std::move(after_start_capture_callback)); 135 std::move(after_start_capture_callback));
159 break; 136 break;
160 } 137
161 case MEDIA_DESKTOP_VIDEO_CAPTURE: { 138 case MEDIA_DESKTOP_VIDEO_CAPTURE:
162 // Use of Unretained() is safe, because |context_reference| guarantees
163 // that |this| stays alive.
164 ReceiveDeviceCallback after_start_capture_callback =
165 media::BindToCurrentLoop(
166 base::Bind(&InProcessBuildableVideoCaptureDevice::OnDeviceStarted,
167 base::Unretained(this), controller, callbacks,
168 base::Passed(&done_cb)));
169 start_capture_closure = 139 start_capture_closure =
170 base::Bind(&InProcessBuildableVideoCaptureDevice:: 140 base::Bind(&InProcessBuildableVideoCaptureDevice::
171 DoStartDesktopCaptureOnDeviceThread, 141 DoStartDesktopCaptureOnDeviceThread,
172 base::Unretained(this), controller->device_id(), params, 142 base::Unretained(this), controller->device_id(), params,
173 base::Passed(std::move(device_client)), 143 base::Passed(std::move(device_client)),
174 std::move(after_start_capture_callback)); 144 std::move(after_start_capture_callback));
175 break; 145 break;
176 } 146
177 default: { 147 default: {
178 NOTIMPLEMENTED(); 148 NOTIMPLEMENTED();
179 return; 149 return;
180 } 150 }
181 } 151 }
182 152
183 device_task_runner_->PostTask(FROM_HERE, start_capture_closure); 153 device_task_runner_->PostTask(FROM_HERE, start_capture_closure);
184 state_ = State::DEVICE_START_IN_PROGRESS; 154 state_ = State::DEVICE_START_IN_PROGRESS;
185 } 155 }
186 156
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 VideoCaptureController* controller, 291 VideoCaptureController* controller,
322 BuildableDeviceCallbacks* callbacks, 292 BuildableDeviceCallbacks* callbacks,
323 base::OnceClosure done_cb, 293 base::OnceClosure done_cb,
324 std::unique_ptr<media::VideoCaptureDevice> device) { 294 std::unique_ptr<media::VideoCaptureDevice> device) {
325 DCHECK_CURRENTLY_ON(BrowserThread::IO); 295 DCHECK_CURRENTLY_ON(BrowserThread::IO);
326 switch (state_) { 296 switch (state_) {
327 case State::DEVICE_START_IN_PROGRESS: 297 case State::DEVICE_START_IN_PROGRESS:
328 if (!device) { 298 if (!device) {
329 state_ = State::NO_DEVICE; 299 state_ = State::NO_DEVICE;
330 callbacks->OnDeviceStartFailed(controller); 300 callbacks->OnDeviceStartFailed(controller);
331 std::move(done_cb).Run();
332 return; 301 return;
333 } 302 }
334 // Passing raw pointer |device.get()| to the controller is safe, 303 // Passing raw pointer |device.get()| to the controller is safe,
335 // because we take ownership of |device| and we call 304 // because we take ownership of |device| and we call
336 // controller->SetConsumerFeedbackObserver(nullptr) before releasing 305 // controller->SetConsumerFeedbackObserver(nullptr) before releasing
337 // |device|. 306 // |device|.
338 controller->SetConsumerFeedbackObserver( 307 controller->SetConsumerFeedbackObserver(
339 base::MakeUnique<VideoFrameConsumerFeedbackObserverOnTaskRunner>( 308 base::MakeUnique<VideoFrameConsumerFeedbackObserverOnTaskRunner>(
340 device.get(), device_task_runner_)); 309 device.get(), device_task_runner_));
341 device_ = std::move(device); 310 device_ = std::move(device);
342 state_ = State::DEVICE_STARTED; 311 state_ = State::DEVICE_STARTED;
343 callbacks->DidStartDevice(controller); 312 callbacks->OnDeviceStarted(controller);
344 std::move(done_cb).Run(); 313 std::move(done_cb).Run();
345 return; 314 return;
346 case State::DEVICE_START_ABORTING: 315 case State::DEVICE_START_ABORTING:
347 if (device) { 316 if (device) {
348 device_ = std::move(device); 317 device_ = std::move(device);
349 state_ = State::DEVICE_STARTED; 318 state_ = State::DEVICE_STARTED;
350 // We do not move our |done_cb| to this invocation, because 319 // We do not move our |done_cb| to this invocation, because
351 // we still need it to stay alive for the remainder of this method 320 // we still need it to stay alive for the remainder of this method
352 // execution. Our implementation of ReleaseDeviceAsync() does not 321 // execution. Our implementation of ReleaseDeviceAsync() does not
353 // actually need the context while releasing the device. 322 // actually need the context while releasing the device.
354 ReleaseDeviceAsync(controller, base::Bind([]() {})); 323 ReleaseDeviceAsync(controller, base::Bind([]() {}));
355 } 324 }
356 state_ = State::NO_DEVICE; 325 state_ = State::NO_DEVICE;
357 callbacks->OnDeviceStartAborted(); 326 callbacks->OnDeviceStartAborted();
358 std::move(done_cb).Run(); 327 std::move(done_cb).Run();
359 return; 328 return;
360 case State::NO_DEVICE: 329 case State::NO_DEVICE:
361 case State::DEVICE_STARTED: 330 case State::DEVICE_STARTED:
362 NOTREACHED(); 331 NOTREACHED();
363 return; 332 return;
364 } 333 }
365 } 334 }
366 335
367 void InProcessBuildableVideoCaptureDevice::DoStartDeviceCaptureOnDeviceThread( 336 void InProcessBuildableVideoCaptureDevice::DoStartDeviceCaptureOnDeviceThread(
368 const media::VideoCaptureDeviceDescriptor& descriptor, 337 const std::string& device_id,
369 const media::VideoCaptureParams& params, 338 const media::VideoCaptureParams& params,
370 std::unique_ptr<media::VideoCaptureDeviceClient> device_client, 339 std::unique_ptr<media::VideoCaptureDeviceClient> device_client,
371 ReceiveDeviceCallback result_callback) { 340 ReceiveDeviceCallback result_callback) {
372 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); 341 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime");
373 DCHECK(device_task_runner_->BelongsToCurrentThread()); 342 DCHECK(device_task_runner_->BelongsToCurrentThread());
374 343
375 std::unique_ptr<media::VideoCaptureDevice> video_capture_device = 344 std::unique_ptr<media::VideoCaptureDevice> video_capture_device =
376 device_factory_->CreateDevice(descriptor); 345 device_factory_->CreateDevice(device_id);
377 346
378 if (!video_capture_device) { 347 if (!video_capture_device) {
379 result_callback.Run(nullptr); 348 result_callback.Run(nullptr);
380 return; 349 return;
381 } 350 }
382 351
383 video_capture_device->AllocateAndStart(params, std::move(device_client)); 352 video_capture_device->AllocateAndStart(params, std::move(device_client));
384 result_callback.Run(std::move(video_capture_device)); 353 result_callback.Run(std::move(video_capture_device));
385 } 354 }
386 355
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 !defined(OS_ANDROID) 435 !defined(OS_ANDROID)
467 DesktopCaptureDevice* desktop_device = 436 DesktopCaptureDevice* desktop_device =
468 static_cast<DesktopCaptureDevice*>(device); 437 static_cast<DesktopCaptureDevice*>(device);
469 desktop_device->SetNotificationWindowId(window_id); 438 desktop_device->SetNotificationWindowId(window_id);
470 VLOG(2) << "Screen capture notification window passed on device thread."; 439 VLOG(2) << "Screen capture notification window passed on device thread.";
471 #endif 440 #endif
472 std::move(done_cb).Run(); 441 std::move(done_cb).Run();
473 } 442 }
474 443
475 } // namespace content 444 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698