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

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

Issue 2803483003: [Mojo Video Capture] Split interface BuildableVideoCaptureDevice (Closed)
Patch Set: Remove fallback mechanism. Created 3 years, 8 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_launched_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"
9 #include "content/browser/media/capture/desktop_capture_device_uma_types.h"
10 #include "content/browser/media/capture/web_contents_video_capture_device.h"
11 #include "content/browser/renderer_host/media/video_capture_controller.h"
12 #include "content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.h"
13 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/desktop_media_id.h"
15 #include "content/public/common/media_stream_request.h"
16 #include "media/base/bind_to_current_loop.h"
17 #include "media/capture/video/video_capture_buffer_pool_impl.h"
18 #include "media/capture/video/video_capture_buffer_tracker_factory_impl.h"
19 #include "media/capture/video/video_capture_device_client.h"
20 #include "media/capture/video/video_frame_receiver_on_task_runner.h"
21 9
22 #if defined(ENABLE_SCREEN_CAPTURE) && !defined(OS_ANDROID) 10 #if defined(ENABLE_SCREEN_CAPTURE) && !defined(OS_ANDROID)
23 #include "content/browser/media/capture/desktop_capture_device.h" 11 #include "content/browser/media/capture/desktop_capture_device.h"
24 #if defined(USE_AURA) 12 #if defined(USE_AURA)
25 #include "content/browser/media/capture/desktop_capture_device_aura.h" 13 #include "content/browser/media/capture/desktop_capture_device_aura.h"
26 #endif 14 #endif
27 #endif 15 #endif
28 16
29 #if defined(ENABLE_SCREEN_CAPTURE) && defined(OS_ANDROID) 17 #if defined(ENABLE_SCREEN_CAPTURE) && defined(OS_ANDROID)
30 #include "content/browser/media/capture/screen_capture_device_android.h" 18 #include "content/browser/media/capture/screen_capture_device_android.h"
31 #endif 19 #endif
32 20
33 namespace { 21 namespace {
34 22
35 class VideoFrameConsumerFeedbackObserverOnTaskRunner
36 : public media::VideoFrameConsumerFeedbackObserver {
37 public:
38 VideoFrameConsumerFeedbackObserverOnTaskRunner(
39 media::VideoFrameConsumerFeedbackObserver* observer,
40 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
41 : observer_(observer), task_runner_(std::move(task_runner)) {}
42
43 void OnUtilizationReport(int frame_feedback_id, double utilization) override {
44 task_runner_->PostTask(
45 FROM_HERE,
46 base::Bind(
47 &media::VideoFrameConsumerFeedbackObserver::OnUtilizationReport,
48 base::Unretained(observer_), frame_feedback_id, utilization));
49 }
50
51 private:
52 media::VideoFrameConsumerFeedbackObserver* const observer_;
53 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
54 };
55
56 std::unique_ptr<media::VideoCaptureJpegDecoder> CreateGpuJpegDecoder(
57 const media::VideoCaptureJpegDecoder::DecodeDoneCB& decode_done_cb) {
58 return base::MakeUnique<content::VideoCaptureGpuJpegDecoder>(decode_done_cb);
59 }
60
61 void StopAndReleaseDeviceOnDeviceThread(media::VideoCaptureDevice* device, 23 void StopAndReleaseDeviceOnDeviceThread(media::VideoCaptureDevice* device,
62 base::OnceClosure done_cb) { 24 base::OnceClosure done_cb) {
63 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime"); 25 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime");
64 device->StopAndDeAllocate(); 26 device->StopAndDeAllocate();
65 DVLOG(3) << "StopAndReleaseDeviceOnDeviceThread"; 27 DVLOG(3) << "StopAndReleaseDeviceOnDeviceThread";
66 delete device; 28 delete device;
67 base::ResetAndReturn(&done_cb).Run(); 29 base::ResetAndReturn(&done_cb).Run();
68 } 30 }
69 31
70 // The maximum number of video frame buffers in-flight at any one time. This
71 // value should be based on the logical capacity of the capture pipeline, and
72 // not on hardware performance. For example, tab capture requires more buffers
73 // than webcam capture because the pipeline is longer (it includes read-backs
74 // pending in the GPU pipeline).
75 const int kMaxNumberOfBuffers = 3;
76 // TODO(miu): The value for tab capture should be determined programmatically.
77 // http://crbug.com/460318
78 const int kMaxNumberOfBuffersForTabCapture = 10;
79
80 } // anonymous namespace 32 } // anonymous namespace
81 33
82 namespace content { 34 namespace content {
83 35
84 InProcessBuildableVideoCaptureDevice::InProcessBuildableVideoCaptureDevice( 36 InProcessLaunchedVideoCaptureDevice::InProcessLaunchedVideoCaptureDevice(
85 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner, 37 std::unique_ptr<media::VideoCaptureDevice> device,
86 media::VideoCaptureSystem* video_capture_system) 38 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner)
87 : device_task_runner_(std::move(device_task_runner)), 39 : device_(std::move(device)),
88 video_capture_system_(video_capture_system) {} 40 device_task_runner_(std::move(device_task_runner)) {}
89 41
90 InProcessBuildableVideoCaptureDevice::~InProcessBuildableVideoCaptureDevice() { 42 InProcessLaunchedVideoCaptureDevice::~InProcessLaunchedVideoCaptureDevice() {
91 DCHECK_CURRENTLY_ON(BrowserThread::IO); 43 DCHECK_CURRENTLY_ON(BrowserThread::IO);
92 DCHECK(!device_); 44 DCHECK(device_);
45 media::VideoCaptureDevice* device_ptr = device_.release();
46 device_task_runner_->PostTask(
47 FROM_HERE,
48 base::Bind(&StopAndReleaseDeviceOnDeviceThread, device_ptr,
49 base::Bind([](scoped_refptr<base::SingleThreadTaskRunner>) {},
50 device_task_runner_)));
93 } 51 }
94 52
95 void InProcessBuildableVideoCaptureDevice::CreateAndStartDeviceAsync( 53 void InProcessLaunchedVideoCaptureDevice::GetPhotoCapabilities(
96 VideoCaptureController* controller,
97 const media::VideoCaptureParams& params,
98 Callbacks* callbacks,
99 base::OnceClosure done_cb) {
100 DCHECK_CURRENTLY_ON(BrowserThread::IO);
101 DCHECK_EQ(State::NO_DEVICE, state_);
102
103 const int max_buffers = (controller->stream_type() == MEDIA_TAB_VIDEO_CAPTURE
104 ? kMaxNumberOfBuffersForTabCapture
105 : kMaxNumberOfBuffers);
106
107 auto device_client =
108 CreateDeviceClient(max_buffers, controller->GetWeakPtrForIOThread());
109
110 base::Closure start_capture_closure;
111 // Use of Unretained() is safe, because |done_cb| guarantees that
112 // |this| stays alive.
113 ReceiveDeviceCallback after_start_capture_callback = media::BindToCurrentLoop(
114 base::Bind(&InProcessBuildableVideoCaptureDevice::OnDeviceStarted,
115 base::Unretained(this), controller, callbacks,
116 base::Passed(&done_cb)));
117
118 switch (controller->stream_type()) {
119 case MEDIA_DEVICE_VIDEO_CAPTURE: {
120 start_capture_closure =
121 base::Bind(&InProcessBuildableVideoCaptureDevice::
122 DoStartDeviceCaptureOnDeviceThread,
123 base::Unretained(this), controller->device_id(), params,
124 base::Passed(std::move(device_client)),
125 std::move(after_start_capture_callback));
126 break;
127 }
128 case MEDIA_TAB_VIDEO_CAPTURE:
129 start_capture_closure =
130 base::Bind(&InProcessBuildableVideoCaptureDevice::
131 DoStartTabCaptureOnDeviceThread,
132 base::Unretained(this), controller->device_id(), params,
133 base::Passed(std::move(device_client)),
134 std::move(after_start_capture_callback));
135 break;
136
137 case MEDIA_DESKTOP_VIDEO_CAPTURE:
138 start_capture_closure =
139 base::Bind(&InProcessBuildableVideoCaptureDevice::
140 DoStartDesktopCaptureOnDeviceThread,
141 base::Unretained(this), controller->device_id(), params,
142 base::Passed(std::move(device_client)),
143 std::move(after_start_capture_callback));
144 break;
145
146 default: {
147 NOTIMPLEMENTED();
148 return;
149 }
150 }
151
152 device_task_runner_->PostTask(FROM_HERE, start_capture_closure);
153 state_ = State::DEVICE_START_IN_PROGRESS;
154 }
155
156 void InProcessBuildableVideoCaptureDevice::ReleaseDeviceAsync(
157 VideoCaptureController* controller,
158 base::OnceClosure done_cb) {
159 DCHECK_CURRENTLY_ON(BrowserThread::IO);
160 controller->SetConsumerFeedbackObserver(nullptr);
161 switch (state_) {
162 case State::DEVICE_START_IN_PROGRESS:
163 state_ = State::DEVICE_START_ABORTING;
164 return;
165 case State::NO_DEVICE:
166 case State::DEVICE_START_ABORTING:
167 return;
168 case State::DEVICE_STARTED:
169 media::VideoCaptureDevice* device_ptr = device_.release();
170 bool posting_task_succeeded = device_task_runner_->PostTask(
171 FROM_HERE,
172 base::Bind(
173 &StopAndReleaseDeviceOnDeviceThread, device_ptr,
174 base::Bind([](scoped_refptr<base::SingleThreadTaskRunner>) {},
175 device_task_runner_)));
176 if (posting_task_succeeded == false) {
177 // Since posting to the task runner has failed, we attempt doing it on
178 // the calling thread instead.
179 StopAndReleaseDeviceOnDeviceThread(device_ptr, base::Bind([]() {}));
180 }
181 state_ = State::NO_DEVICE;
182 return;
183 }
184 base::ResetAndReturn(&done_cb).Run();
185 }
186
187 bool InProcessBuildableVideoCaptureDevice::IsDeviceAlive() const {
188 DCHECK_CURRENTLY_ON(BrowserThread::IO);
189 return device_ != nullptr;
190 }
191
192 void InProcessBuildableVideoCaptureDevice::GetPhotoCapabilities(
193 media::VideoCaptureDevice::GetPhotoCapabilitiesCallback callback) const { 54 media::VideoCaptureDevice::GetPhotoCapabilitiesCallback callback) const {
194 DCHECK_CURRENTLY_ON(BrowserThread::IO); 55 DCHECK_CURRENTLY_ON(BrowserThread::IO);
195 // Unretained() is safe to use here because |device| would be null if it 56 // Unretained() is safe to use here because |device| would be null if it
196 // was scheduled for shutdown and destruction, and because this task is 57 // was scheduled for shutdown and destruction, and because this task is
197 // guaranteed to run before the task that destroys the |device|. 58 // guaranteed to run before the task that destroys the |device|.
198 device_task_runner_->PostTask( 59 device_task_runner_->PostTask(
199 FROM_HERE, 60 FROM_HERE,
200 base::Bind(&media::VideoCaptureDevice::GetPhotoCapabilities, 61 base::Bind(&media::VideoCaptureDevice::GetPhotoCapabilities,
201 base::Unretained(device_.get()), base::Passed(&callback))); 62 base::Unretained(device_.get()), base::Passed(&callback)));
202 } 63 }
203 64
204 void InProcessBuildableVideoCaptureDevice::SetPhotoOptions( 65 void InProcessLaunchedVideoCaptureDevice::SetPhotoOptions(
205 media::mojom::PhotoSettingsPtr settings, 66 media::mojom::PhotoSettingsPtr settings,
206 media::VideoCaptureDevice::SetPhotoOptionsCallback callback) { 67 media::VideoCaptureDevice::SetPhotoOptionsCallback callback) {
207 DCHECK_CURRENTLY_ON(BrowserThread::IO); 68 DCHECK_CURRENTLY_ON(BrowserThread::IO);
208 // Unretained() is safe to use here because |device| would be null if it 69 // Unretained() is safe to use here because |device| would be null if it
209 // was scheduled for shutdown and destruction, and because this task is 70 // was scheduled for shutdown and destruction, and because this task is
210 // guaranteed to run before the task that destroys the |device|. 71 // guaranteed to run before the task that destroys the |device|.
211 device_task_runner_->PostTask( 72 device_task_runner_->PostTask(
212 FROM_HERE, base::Bind(&media::VideoCaptureDevice::SetPhotoOptions, 73 FROM_HERE, base::Bind(&media::VideoCaptureDevice::SetPhotoOptions,
213 base::Unretained(device_.get()), 74 base::Unretained(device_.get()),
214 base::Passed(&settings), base::Passed(&callback))); 75 base::Passed(&settings), base::Passed(&callback)));
215 } 76 }
216 77
217 void InProcessBuildableVideoCaptureDevice::TakePhoto( 78 void InProcessLaunchedVideoCaptureDevice::TakePhoto(
218 media::VideoCaptureDevice::TakePhotoCallback callback) { 79 media::VideoCaptureDevice::TakePhotoCallback callback) {
219 DCHECK_CURRENTLY_ON(BrowserThread::IO); 80 DCHECK_CURRENTLY_ON(BrowserThread::IO);
220 // Unretained() is safe to use here because |device| would be null if it 81 // Unretained() is safe to use here because |device| would be null if it
221 // was scheduled for shutdown and destruction, and because this task is 82 // was scheduled for shutdown and destruction, and because this task is
222 // guaranteed to run before the task that destroys the |device|. 83 // guaranteed to run before the task that destroys the |device|.
223 device_task_runner_->PostTask( 84 device_task_runner_->PostTask(
224 FROM_HERE, 85 FROM_HERE,
225 base::Bind(&media::VideoCaptureDevice::TakePhoto, 86 base::Bind(&media::VideoCaptureDevice::TakePhoto,
226 base::Unretained(device_.get()), base::Passed(&callback))); 87 base::Unretained(device_.get()), base::Passed(&callback)));
227 } 88 }
228 89
229 void InProcessBuildableVideoCaptureDevice::MaybeSuspendDevice() { 90 void InProcessLaunchedVideoCaptureDevice::MaybeSuspendDevice() {
230 DCHECK_CURRENTLY_ON(BrowserThread::IO); 91 DCHECK_CURRENTLY_ON(BrowserThread::IO);
231 // Unretained() is safe to use here because |device| would be null if it 92 // Unretained() is safe to use here because |device| would be null if it
232 // was scheduled for shutdown and destruction, and because this task is 93 // was scheduled for shutdown and destruction, and because this task is
233 // guaranteed to run before the task that destroys the |device|. 94 // guaranteed to run before the task that destroys the |device|.
234 device_task_runner_->PostTask( 95 device_task_runner_->PostTask(
235 FROM_HERE, base::Bind(&media::VideoCaptureDevice::MaybeSuspend, 96 FROM_HERE, base::Bind(&media::VideoCaptureDevice::MaybeSuspend,
236 base::Unretained(device_.get()))); 97 base::Unretained(device_.get())));
237 } 98 }
238 99
239 void InProcessBuildableVideoCaptureDevice::ResumeDevice() { 100 void InProcessLaunchedVideoCaptureDevice::ResumeDevice() {
240 DCHECK_CURRENTLY_ON(BrowserThread::IO); 101 DCHECK_CURRENTLY_ON(BrowserThread::IO);
241 // Unretained() is safe to use here because |device| would be null if it 102 // Unretained() is safe to use here because |device| would be null if it
242 // was scheduled for shutdown and destruction, and because this task is 103 // was scheduled for shutdown and destruction, and because this task is
243 // guaranteed to run before the task that destroys the |device|. 104 // guaranteed to run before the task that destroys the |device|.
244 device_task_runner_->PostTask(FROM_HERE, 105 device_task_runner_->PostTask(FROM_HERE,
245 base::Bind(&media::VideoCaptureDevice::Resume, 106 base::Bind(&media::VideoCaptureDevice::Resume,
246 base::Unretained(device_.get()))); 107 base::Unretained(device_.get())));
247 } 108 }
248 109
249 void InProcessBuildableVideoCaptureDevice::RequestRefreshFrame() { 110 void InProcessLaunchedVideoCaptureDevice::RequestRefreshFrame() {
250 DCHECK_CURRENTLY_ON(BrowserThread::IO); 111 DCHECK_CURRENTLY_ON(BrowserThread::IO);
251 // Unretained() is safe to use here because |device| would be null if it 112 // Unretained() is safe to use here because |device| would be null if it
252 // was scheduled for shutdown and destruction, and because this task is 113 // was scheduled for shutdown and destruction, and because this task is
253 // guaranteed to run before the task that destroys the |device|. 114 // guaranteed to run before the task that destroys the |device|.
254 device_task_runner_->PostTask( 115 device_task_runner_->PostTask(
255 FROM_HERE, base::Bind(&media::VideoCaptureDevice::RequestRefreshFrame, 116 FROM_HERE, base::Bind(&media::VideoCaptureDevice::RequestRefreshFrame,
256 base::Unretained(device_.get()))); 117 base::Unretained(device_.get())));
257 } 118 }
258 119
259 void InProcessBuildableVideoCaptureDevice::SetDesktopCaptureWindowIdAsync( 120 void InProcessLaunchedVideoCaptureDevice::SetDesktopCaptureWindowIdAsync(
260 gfx::NativeViewId window_id, 121 gfx::NativeViewId window_id,
261 base::OnceClosure done_cb) { 122 base::OnceClosure done_cb) {
262 DCHECK_CURRENTLY_ON(BrowserThread::IO); 123 DCHECK_CURRENTLY_ON(BrowserThread::IO);
263 // Post |device_| to the the |device_task_runner_|. This is safe since the 124 // Post |device_| to the the device_task_runner_. This is safe since the
264 // device is destroyed on the |device_task_runner_| and |done_cb| guarantees 125 // device is destroyed on the device_task_runner_ and |done_cb|
265 // that |this| stays alive. 126 // guarantees that |this| stays alive.
266 device_task_runner_->PostTask( 127 device_task_runner_->PostTask(
267 FROM_HERE, base::Bind(&InProcessBuildableVideoCaptureDevice:: 128 FROM_HERE, base::Bind(&InProcessLaunchedVideoCaptureDevice::
268 SetDesktopCaptureWindowIdOnDeviceThread, 129 SetDesktopCaptureWindowIdOnDeviceThread,
269 base::Unretained(this), device_.get(), window_id, 130 base::Unretained(this), device_.get(), window_id,
270 base::Passed(&done_cb))); 131 base::Passed(&done_cb)));
271 } 132 }
272 133
273 std::unique_ptr<media::VideoCaptureDeviceClient> 134 void InProcessLaunchedVideoCaptureDevice::OnUtilizationReport(
274 InProcessBuildableVideoCaptureDevice::CreateDeviceClient( 135 int frame_feedback_id,
275 int buffer_pool_max_buffer_count, 136 double utilization) {
276 base::WeakPtr<media::VideoFrameReceiver> receiver) {
277 DCHECK_CURRENTLY_ON(BrowserThread::IO); 137 DCHECK_CURRENTLY_ON(BrowserThread::IO);
278 138 // Unretained() is safe to use here because |device| would be null if it
279 return base::MakeUnique<media::VideoCaptureDeviceClient>( 139 // was scheduled for shutdown and destruction, and because this task is
280 base::MakeUnique<media::VideoFrameReceiverOnTaskRunner>( 140 // guaranteed to run before the task that destroys the |device|.
281 receiver, BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)), 141 device_task_runner_->PostTask(
282 new media::VideoCaptureBufferPoolImpl( 142 FROM_HERE, base::Bind(&media::VideoCaptureDevice::OnUtilizationReport,
283 base::MakeUnique<media::VideoCaptureBufferTrackerFactoryImpl>(), 143 base::Unretained(device_.get()), frame_feedback_id,
284 buffer_pool_max_buffer_count), 144 utilization));
285 base::Bind(&CreateGpuJpegDecoder,
286 base::Bind(&media::VideoFrameReceiver::OnFrameReadyInBuffer,
287 receiver)));
288 } 145 }
289 146
290 void InProcessBuildableVideoCaptureDevice::OnDeviceStarted( 147 void InProcessLaunchedVideoCaptureDevice::
291 VideoCaptureController* controller,
292 Callbacks* callbacks,
293 base::OnceClosure done_cb,
294 std::unique_ptr<media::VideoCaptureDevice> device) {
295 DCHECK_CURRENTLY_ON(BrowserThread::IO);
296 switch (state_) {
297 case State::DEVICE_START_IN_PROGRESS:
298 if (!device) {
299 state_ = State::NO_DEVICE;
300 callbacks->OnDeviceStartFailed(controller);
301 base::ResetAndReturn(&done_cb).Run();
302 return;
303 }
304 // Passing raw pointer |device.get()| to the controller is safe,
305 // because we take ownership of |device| and we call
306 // controller->SetConsumerFeedbackObserver(nullptr) before releasing
307 // |device|.
308 controller->SetConsumerFeedbackObserver(
309 base::MakeUnique<VideoFrameConsumerFeedbackObserverOnTaskRunner>(
310 device.get(), device_task_runner_));
311 device_ = std::move(device);
312 state_ = State::DEVICE_STARTED;
313 callbacks->OnDeviceStarted(controller);
314 base::ResetAndReturn(&done_cb).Run();
315 return;
316 case State::DEVICE_START_ABORTING:
317 if (device) {
318 device_ = std::move(device);
319 state_ = State::DEVICE_STARTED;
320 // We do not move our |done_cb| to this invocation, because
321 // we still need it to stay alive for the remainder of this method
322 // execution. Our implementation of ReleaseDeviceAsync() does not
323 // actually need the context while releasing the device.
324 ReleaseDeviceAsync(controller, base::Bind([]() {}));
325 }
326 state_ = State::NO_DEVICE;
327 callbacks->OnDeviceStartAborted();
328 base::ResetAndReturn(&done_cb).Run();
329 return;
330 case State::NO_DEVICE:
331 case State::DEVICE_STARTED:
332 NOTREACHED();
333 return;
334 }
335 }
336
337 void InProcessBuildableVideoCaptureDevice::DoStartDeviceCaptureOnDeviceThread(
338 const std::string& device_id,
339 const media::VideoCaptureParams& params,
340 std::unique_ptr<media::VideoCaptureDeviceClient> device_client,
341 ReceiveDeviceCallback result_callback) {
342 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime");
343 DCHECK(device_task_runner_->BelongsToCurrentThread());
344
345 std::unique_ptr<media::VideoCaptureDevice> video_capture_device =
346 video_capture_system_->CreateDevice(device_id);
347
348 if (!video_capture_device) {
349 result_callback.Run(nullptr);
350 return;
351 }
352
353 video_capture_device->AllocateAndStart(params, std::move(device_client));
354 result_callback.Run(std::move(video_capture_device));
355 }
356
357 void InProcessBuildableVideoCaptureDevice::DoStartTabCaptureOnDeviceThread(
358 const std::string& id,
359 const media::VideoCaptureParams& params,
360 std::unique_ptr<media::VideoCaptureDeviceClient> device_client,
361 ReceiveDeviceCallback result_callback) {
362 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime");
363 DCHECK(device_task_runner_->BelongsToCurrentThread());
364
365 std::unique_ptr<media::VideoCaptureDevice> video_capture_device;
366 #if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN)
367 video_capture_device = WebContentsVideoCaptureDevice::Create(id);
368 #endif
369
370 if (!video_capture_device) {
371 result_callback.Run(nullptr);
372 return;
373 }
374
375 video_capture_device->AllocateAndStart(params, std::move(device_client));
376 result_callback.Run(std::move(video_capture_device));
377 }
378
379 void InProcessBuildableVideoCaptureDevice::DoStartDesktopCaptureOnDeviceThread(
380 const std::string& id,
381 const media::VideoCaptureParams& params,
382 std::unique_ptr<media::VideoCaptureDeviceClient> device_client,
383 ReceiveDeviceCallback result_callback) {
384 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime");
385 DCHECK(device_task_runner_->BelongsToCurrentThread());
386
387 std::unique_ptr<media::VideoCaptureDevice> video_capture_device;
388 #if defined(ENABLE_SCREEN_CAPTURE)
389 DesktopMediaID desktop_id = DesktopMediaID::Parse(id);
390 if (desktop_id.is_null()) {
391 DLOG(ERROR) << "Desktop media ID is null";
392 result_callback.Run(nullptr);
393 return;
394 }
395
396 if (desktop_id.type == DesktopMediaID::TYPE_WEB_CONTENTS) {
397 #if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN)
398 video_capture_device = WebContentsVideoCaptureDevice::Create(id);
399 IncrementDesktopCaptureCounter(TAB_VIDEO_CAPTURER_CREATED);
400 if (desktop_id.audio_share)
401 IncrementDesktopCaptureCounter(TAB_VIDEO_CAPTURER_CREATED_WITH_AUDIO);
402 else
403 IncrementDesktopCaptureCounter(TAB_VIDEO_CAPTURER_CREATED_WITHOUT_AUDIO);
404 #endif
405 } else {
406 #if defined(OS_ANDROID)
407 video_capture_device = base::MakeUnique<ScreenCaptureDeviceAndroid>();
408 #else
409 #if defined(USE_AURA)
410 video_capture_device = DesktopCaptureDeviceAura::Create(desktop_id);
411 #endif // defined(USE_AURA)
412 #if BUILDFLAG(ENABLE_WEBRTC)
413 if (!video_capture_device)
414 video_capture_device = DesktopCaptureDevice::Create(desktop_id);
415 #endif // BUILDFLAG(ENABLE_WEBRTC)
416 #endif // defined (OS_ANDROID)
417 }
418 #endif // defined(ENABLE_SCREEN_CAPTURE)
419
420 if (!video_capture_device) {
421 result_callback.Run(nullptr);
422 return;
423 }
424
425 video_capture_device->AllocateAndStart(params, std::move(device_client));
426 result_callback.Run(std::move(video_capture_device));
427 }
428
429 void InProcessBuildableVideoCaptureDevice::
430 SetDesktopCaptureWindowIdOnDeviceThread(media::VideoCaptureDevice* device, 148 SetDesktopCaptureWindowIdOnDeviceThread(media::VideoCaptureDevice* device,
431 gfx::NativeViewId window_id, 149 gfx::NativeViewId window_id,
432 base::OnceClosure done_cb) { 150 base::OnceClosure done_cb) {
433 DCHECK(device_task_runner_->BelongsToCurrentThread()); 151 DCHECK(device_task_runner_->BelongsToCurrentThread());
434 #if defined(ENABLE_SCREEN_CAPTURE) && BUILDFLAG(ENABLE_WEBRTC) && \ 152 #if defined(ENABLE_SCREEN_CAPTURE) && BUILDFLAG(ENABLE_WEBRTC) && \
435 !defined(OS_ANDROID) 153 !defined(OS_ANDROID)
436 DesktopCaptureDevice* desktop_device = 154 DesktopCaptureDevice* desktop_device =
437 static_cast<DesktopCaptureDevice*>(device); 155 static_cast<DesktopCaptureDevice*>(device);
438 desktop_device->SetNotificationWindowId(window_id); 156 desktop_device->SetNotificationWindowId(window_id);
439 VLOG(2) << "Screen capture notification window passed on device thread."; 157 VLOG(2) << "Screen capture notification window passed on device thread.";
440 #endif 158 #endif
441 base::ResetAndReturn(&done_cb).Run(); 159 base::ResetAndReturn(&done_cb).Run();
442 } 160 }
443 161
444 } // namespace content 162 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698