OLD | NEW |
---|---|
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 bool posting_task_succeeded = device_task_runner_->PostTask( | |
47 FROM_HERE, | |
48 base::Bind(&StopAndReleaseDeviceOnDeviceThread, device_ptr, | |
49 base::Bind([](scoped_refptr<base::SingleThreadTaskRunner>) {}, | |
50 device_task_runner_))); | |
51 if (posting_task_succeeded == false) { | |
52 // Since posting to the task runner has failed, we attempt doing it on | |
53 // the calling thread instead. | |
54 StopAndReleaseDeviceOnDeviceThread(device_ptr, | |
emircan
2017/04/14 17:19:37
I don't think we can have this fallback. Consider
chfremer
2017/04/14 20:00:30
I am also skeptical as to whether or not this fall
emircan
2017/04/14 20:15:20
I think we should just remove it. As you described
chfremer
2017/04/14 21:07:12
Done.
| |
55 base::Bind(&base::DoNothing)); | |
56 } | |
93 } | 57 } |
94 | 58 |
95 void InProcessBuildableVideoCaptureDevice::CreateAndStartDeviceAsync( | 59 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 { | 60 media::VideoCaptureDevice::GetPhotoCapabilitiesCallback callback) const { |
194 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 61 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
195 // Unretained() is safe to use here because |device| would be null if it | 62 // 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 | 63 // was scheduled for shutdown and destruction, and because this task is |
197 // guaranteed to run before the task that destroys the |device|. | 64 // guaranteed to run before the task that destroys the |device|. |
198 device_task_runner_->PostTask( | 65 device_task_runner_->PostTask( |
199 FROM_HERE, | 66 FROM_HERE, |
200 base::Bind(&media::VideoCaptureDevice::GetPhotoCapabilities, | 67 base::Bind(&media::VideoCaptureDevice::GetPhotoCapabilities, |
201 base::Unretained(device_.get()), base::Passed(&callback))); | 68 base::Unretained(device_.get()), base::Passed(&callback))); |
202 } | 69 } |
203 | 70 |
204 void InProcessBuildableVideoCaptureDevice::SetPhotoOptions( | 71 void InProcessLaunchedVideoCaptureDevice::SetPhotoOptions( |
205 media::mojom::PhotoSettingsPtr settings, | 72 media::mojom::PhotoSettingsPtr settings, |
206 media::VideoCaptureDevice::SetPhotoOptionsCallback callback) { | 73 media::VideoCaptureDevice::SetPhotoOptionsCallback callback) { |
207 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 74 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
208 // Unretained() is safe to use here because |device| would be null if it | 75 // 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 | 76 // was scheduled for shutdown and destruction, and because this task is |
210 // guaranteed to run before the task that destroys the |device|. | 77 // guaranteed to run before the task that destroys the |device|. |
211 device_task_runner_->PostTask( | 78 device_task_runner_->PostTask( |
212 FROM_HERE, base::Bind(&media::VideoCaptureDevice::SetPhotoOptions, | 79 FROM_HERE, base::Bind(&media::VideoCaptureDevice::SetPhotoOptions, |
213 base::Unretained(device_.get()), | 80 base::Unretained(device_.get()), |
214 base::Passed(&settings), base::Passed(&callback))); | 81 base::Passed(&settings), base::Passed(&callback))); |
215 } | 82 } |
216 | 83 |
217 void InProcessBuildableVideoCaptureDevice::TakePhoto( | 84 void InProcessLaunchedVideoCaptureDevice::TakePhoto( |
218 media::VideoCaptureDevice::TakePhotoCallback callback) { | 85 media::VideoCaptureDevice::TakePhotoCallback callback) { |
219 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 86 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
220 // Unretained() is safe to use here because |device| would be null if it | 87 // 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 | 88 // was scheduled for shutdown and destruction, and because this task is |
222 // guaranteed to run before the task that destroys the |device|. | 89 // guaranteed to run before the task that destroys the |device|. |
223 device_task_runner_->PostTask( | 90 device_task_runner_->PostTask( |
224 FROM_HERE, | 91 FROM_HERE, |
225 base::Bind(&media::VideoCaptureDevice::TakePhoto, | 92 base::Bind(&media::VideoCaptureDevice::TakePhoto, |
226 base::Unretained(device_.get()), base::Passed(&callback))); | 93 base::Unretained(device_.get()), base::Passed(&callback))); |
227 } | 94 } |
228 | 95 |
229 void InProcessBuildableVideoCaptureDevice::MaybeSuspendDevice() { | 96 void InProcessLaunchedVideoCaptureDevice::MaybeSuspendDevice() { |
230 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 97 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
231 // Unretained() is safe to use here because |device| would be null if it | 98 // 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 | 99 // was scheduled for shutdown and destruction, and because this task is |
233 // guaranteed to run before the task that destroys the |device|. | 100 // guaranteed to run before the task that destroys the |device|. |
234 device_task_runner_->PostTask( | 101 device_task_runner_->PostTask( |
235 FROM_HERE, base::Bind(&media::VideoCaptureDevice::MaybeSuspend, | 102 FROM_HERE, base::Bind(&media::VideoCaptureDevice::MaybeSuspend, |
236 base::Unretained(device_.get()))); | 103 base::Unretained(device_.get()))); |
237 } | 104 } |
238 | 105 |
239 void InProcessBuildableVideoCaptureDevice::ResumeDevice() { | 106 void InProcessLaunchedVideoCaptureDevice::ResumeDevice() { |
240 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 107 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
241 // Unretained() is safe to use here because |device| would be null if it | 108 // 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 | 109 // was scheduled for shutdown and destruction, and because this task is |
243 // guaranteed to run before the task that destroys the |device|. | 110 // guaranteed to run before the task that destroys the |device|. |
244 device_task_runner_->PostTask(FROM_HERE, | 111 device_task_runner_->PostTask(FROM_HERE, |
245 base::Bind(&media::VideoCaptureDevice::Resume, | 112 base::Bind(&media::VideoCaptureDevice::Resume, |
246 base::Unretained(device_.get()))); | 113 base::Unretained(device_.get()))); |
247 } | 114 } |
248 | 115 |
249 void InProcessBuildableVideoCaptureDevice::RequestRefreshFrame() { | 116 void InProcessLaunchedVideoCaptureDevice::RequestRefreshFrame() { |
250 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 117 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
251 // Unretained() is safe to use here because |device| would be null if it | 118 // 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 | 119 // was scheduled for shutdown and destruction, and because this task is |
253 // guaranteed to run before the task that destroys the |device|. | 120 // guaranteed to run before the task that destroys the |device|. |
254 device_task_runner_->PostTask( | 121 device_task_runner_->PostTask( |
255 FROM_HERE, base::Bind(&media::VideoCaptureDevice::RequestRefreshFrame, | 122 FROM_HERE, base::Bind(&media::VideoCaptureDevice::RequestRefreshFrame, |
256 base::Unretained(device_.get()))); | 123 base::Unretained(device_.get()))); |
257 } | 124 } |
258 | 125 |
259 void InProcessBuildableVideoCaptureDevice::SetDesktopCaptureWindowIdAsync( | 126 void InProcessLaunchedVideoCaptureDevice::SetDesktopCaptureWindowIdAsync( |
260 gfx::NativeViewId window_id, | 127 gfx::NativeViewId window_id, |
261 base::OnceClosure done_cb) { | 128 base::OnceClosure done_cb) { |
262 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 129 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
263 // Post |device_| to the the |device_task_runner_|. This is safe since the | 130 // 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 | 131 // device is destroyed on the device_task_runner_ and |done_cb| |
265 // that |this| stays alive. | 132 // guarantees that |this| stays alive. |
266 device_task_runner_->PostTask( | 133 device_task_runner_->PostTask( |
267 FROM_HERE, base::Bind(&InProcessBuildableVideoCaptureDevice:: | 134 FROM_HERE, base::Bind(&InProcessLaunchedVideoCaptureDevice:: |
268 SetDesktopCaptureWindowIdOnDeviceThread, | 135 SetDesktopCaptureWindowIdOnDeviceThread, |
269 base::Unretained(this), device_.get(), window_id, | 136 base::Unretained(this), device_.get(), window_id, |
270 base::Passed(&done_cb))); | 137 base::Passed(&done_cb))); |
271 } | 138 } |
272 | 139 |
273 std::unique_ptr<media::VideoCaptureDeviceClient> | 140 void InProcessLaunchedVideoCaptureDevice::OnUtilizationReport( |
274 InProcessBuildableVideoCaptureDevice::CreateDeviceClient( | 141 int frame_feedback_id, |
275 int buffer_pool_max_buffer_count, | 142 double utilization) { |
276 base::WeakPtr<media::VideoFrameReceiver> receiver) { | |
277 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 143 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
278 | 144 // Unretained() is safe to use here because |device| would be null if it |
279 return base::MakeUnique<media::VideoCaptureDeviceClient>( | 145 // was scheduled for shutdown and destruction, and because this task is |
280 base::MakeUnique<media::VideoFrameReceiverOnTaskRunner>( | 146 // guaranteed to run before the task that destroys the |device|. |
281 receiver, BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)), | 147 device_task_runner_->PostTask( |
282 new media::VideoCaptureBufferPoolImpl( | 148 FROM_HERE, base::Bind(&media::VideoCaptureDevice::OnUtilizationReport, |
283 base::MakeUnique<media::VideoCaptureBufferTrackerFactoryImpl>(), | 149 base::Unretained(device_.get()), frame_feedback_id, |
284 buffer_pool_max_buffer_count), | 150 utilization)); |
285 base::Bind(&CreateGpuJpegDecoder, | |
286 base::Bind(&media::VideoFrameReceiver::OnFrameReadyInBuffer, | |
287 receiver))); | |
288 } | 151 } |
289 | 152 |
290 void InProcessBuildableVideoCaptureDevice::OnDeviceStarted( | 153 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, | 154 SetDesktopCaptureWindowIdOnDeviceThread(media::VideoCaptureDevice* device, |
431 gfx::NativeViewId window_id, | 155 gfx::NativeViewId window_id, |
432 base::OnceClosure done_cb) { | 156 base::OnceClosure done_cb) { |
433 DCHECK(device_task_runner_->BelongsToCurrentThread()); | 157 DCHECK(device_task_runner_->BelongsToCurrentThread()); |
434 #if defined(ENABLE_SCREEN_CAPTURE) && BUILDFLAG(ENABLE_WEBRTC) && \ | 158 #if defined(ENABLE_SCREEN_CAPTURE) && BUILDFLAG(ENABLE_WEBRTC) && \ |
435 !defined(OS_ANDROID) | 159 !defined(OS_ANDROID) |
436 DesktopCaptureDevice* desktop_device = | 160 DesktopCaptureDevice* desktop_device = |
437 static_cast<DesktopCaptureDevice*>(device); | 161 static_cast<DesktopCaptureDevice*>(device); |
438 desktop_device->SetNotificationWindowId(window_id); | 162 desktop_device->SetNotificationWindowId(window_id); |
439 VLOG(2) << "Screen capture notification window passed on device thread."; | 163 VLOG(2) << "Screen capture notification window passed on device thread."; |
440 #endif | 164 #endif |
441 base::ResetAndReturn(&done_cb).Run(); | 165 base::ResetAndReturn(&done_cb).Run(); |
442 } | 166 } |
443 | 167 |
444 } // namespace content | 168 } // namespace content |
OLD | NEW |