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

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

Issue 2753073006: [Mojo Video Capture] Add support to BuildableVideoCaptureDevice for aborting the device start. (Closed)
Patch Set: Incorporated mcasas@'s suggestions from PatchSet 2 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_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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 Callbacks* callbacks, 99 Callbacks* 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_EQ(State::NO_DEVICE, state_);
102 103
103 const int max_buffers = (controller->stream_type() == MEDIA_TAB_VIDEO_CAPTURE 104 const int max_buffers = (controller->stream_type() == MEDIA_TAB_VIDEO_CAPTURE
104 ? kMaxNumberOfBuffersForTabCapture 105 ? kMaxNumberOfBuffersForTabCapture
105 : kMaxNumberOfBuffers); 106 : kMaxNumberOfBuffers);
106 107
107 auto device_client = 108 auto device_client =
108 CreateDeviceClient(max_buffers, controller->GetWeakPtrForIOThread()); 109 CreateDeviceClient(max_buffers, controller->GetWeakPtrForIOThread());
109 110
110 base::Closure start_capture_closure; 111 base::Closure start_capture_closure;
111 switch (controller->stream_type()) { 112 switch (controller->stream_type()) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 std::move(after_start_capture_callback)); 172 std::move(after_start_capture_callback));
172 break; 173 break;
173 } 174 }
174 default: { 175 default: {
175 NOTIMPLEMENTED(); 176 NOTIMPLEMENTED();
176 return; 177 return;
177 } 178 }
178 } 179 }
179 180
180 device_task_runner_->PostTask(FROM_HERE, start_capture_closure); 181 device_task_runner_->PostTask(FROM_HERE, start_capture_closure);
182 state_ = State::DEVICE_START_IN_PROGRESS;
181 } 183 }
182 184
183 void InProcessBuildableVideoCaptureDevice::ReleaseDeviceAsync( 185 void InProcessBuildableVideoCaptureDevice::ReleaseDeviceAsync(
184 VideoCaptureController* controller, 186 VideoCaptureController* controller,
185 base::OnceClosure done_cb) { 187 base::OnceClosure done_cb) {
186 DCHECK_CURRENTLY_ON(BrowserThread::IO); 188 DCHECK_CURRENTLY_ON(BrowserThread::IO);
187 controller->SetConsumerFeedbackObserver(nullptr); 189 controller->SetConsumerFeedbackObserver(nullptr);
188 if (!device_) 190 switch (state_) {
189 return; 191 case State::DEVICE_START_IN_PROGRESS:
190 media::VideoCaptureDevice* device_ptr = device_.release(); 192 state_ = State::DEVICE_START_ABORTING;
191 193 return;
192 bool posting_task_succeeded = device_task_runner_->PostTask( 194 case State::NO_DEVICE:
193 FROM_HERE, 195 case State::DEVICE_START_ABORTING:
194 base::Bind(&StopAndReleaseDeviceOnDeviceThread, device_ptr, 196 return;
195 base::Bind([](scoped_refptr<base::SingleThreadTaskRunner>) {}, 197 case State::DEVICE_STARTED:
196 device_task_runner_))); 198 media::VideoCaptureDevice* device_ptr = device_.release();
197 if (posting_task_succeeded == false) { 199 bool posting_task_succeeded = device_task_runner_->PostTask(
198 // Since posting to the task runner has failed, we attempt doing it on 200 FROM_HERE,
199 // the calling thread instead. 201 base::Bind(
200 StopAndReleaseDeviceOnDeviceThread(device_ptr, base::Bind([]() {})); 202 &StopAndReleaseDeviceOnDeviceThread, device_ptr,
203 base::Bind([](scoped_refptr<base::SingleThreadTaskRunner>) {},
204 device_task_runner_)));
205 if (posting_task_succeeded == false) {
206 // Since posting to the task runner has failed, we attempt doing it on
207 // the calling thread instead.
208 StopAndReleaseDeviceOnDeviceThread(device_ptr, base::Bind([]() {}));
209 }
210 state_ = State::NO_DEVICE;
211 return;
201 } 212 }
202 base::ResetAndReturn(&done_cb).Run(); 213 base::ResetAndReturn(&done_cb).Run();
203 } 214 }
204 215
205 bool InProcessBuildableVideoCaptureDevice::IsDeviceAlive() const { 216 bool InProcessBuildableVideoCaptureDevice::IsDeviceAlive() const {
206 DCHECK_CURRENTLY_ON(BrowserThread::IO); 217 DCHECK_CURRENTLY_ON(BrowserThread::IO);
207 return device_ != nullptr; 218 return device_ != nullptr;
208 } 219 }
209 220
210 void InProcessBuildableVideoCaptureDevice::GetPhotoCapabilities( 221 void InProcessBuildableVideoCaptureDevice::GetPhotoCapabilities(
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 base::Unretained(this), device_.get(), window_id, 298 base::Unretained(this), device_.get(), window_id,
288 base::Passed(&done_cb))); 299 base::Passed(&done_cb)));
289 } 300 }
290 301
291 std::unique_ptr<media::VideoCaptureDeviceClient> 302 std::unique_ptr<media::VideoCaptureDeviceClient>
292 InProcessBuildableVideoCaptureDevice::CreateDeviceClient( 303 InProcessBuildableVideoCaptureDevice::CreateDeviceClient(
293 int buffer_pool_max_buffer_count, 304 int buffer_pool_max_buffer_count,
294 base::WeakPtr<media::VideoFrameReceiver> receiver) { 305 base::WeakPtr<media::VideoFrameReceiver> receiver) {
295 DCHECK_CURRENTLY_ON(BrowserThread::IO); 306 DCHECK_CURRENTLY_ON(BrowserThread::IO);
296 307
297 scoped_refptr<media::VideoCaptureBufferPool> buffer_pool_ = 308 return base::MakeUnique<media::VideoCaptureDeviceClient>(
309 base::MakeUnique<VideoFrameReceiverOnIOThread>(receiver),
298 new media::VideoCaptureBufferPoolImpl( 310 new media::VideoCaptureBufferPoolImpl(
299 base::MakeUnique<media::VideoCaptureBufferTrackerFactoryImpl>(), 311 base::MakeUnique<media::VideoCaptureBufferTrackerFactoryImpl>(),
300 buffer_pool_max_buffer_count); 312 buffer_pool_max_buffer_count),
301
302 return base::MakeUnique<media::VideoCaptureDeviceClient>(
303 base::MakeUnique<VideoFrameReceiverOnIOThread>(receiver), buffer_pool_,
304 base::Bind(&CreateGpuJpegDecoder, 313 base::Bind(&CreateGpuJpegDecoder,
305 base::Bind(&media::VideoFrameReceiver::OnFrameReadyInBuffer, 314 base::Bind(&media::VideoFrameReceiver::OnFrameReadyInBuffer,
306 receiver))); 315 receiver)));
307 } 316 }
308 317
309 void InProcessBuildableVideoCaptureDevice::OnDeviceStarted( 318 void InProcessBuildableVideoCaptureDevice::OnDeviceStarted(
310 VideoCaptureController* controller, 319 VideoCaptureController* controller,
311 Callbacks* callbacks, 320 Callbacks* callbacks,
312 base::OnceClosure done_cb, 321 base::OnceClosure done_cb,
313 std::unique_ptr<media::VideoCaptureDevice> device) { 322 std::unique_ptr<media::VideoCaptureDevice> device) {
314 DCHECK_CURRENTLY_ON(BrowserThread::IO); 323 DCHECK_CURRENTLY_ON(BrowserThread::IO);
315 if (!device) { 324 switch (state_) {
316 callbacks->OnDeviceStartFailed(controller); 325 case State::DEVICE_START_IN_PROGRESS:
317 base::ResetAndReturn(&done_cb).Run(); 326 if (!device) {
318 return; 327 state_ = State::NO_DEVICE;
328 callbacks->OnDeviceStartFailed(controller);
329 base::ResetAndReturn(&done_cb).Run();
330 return;
331 }
332 // Passing raw pointer |device.get()| to the controller is safe,
333 // because we take ownership of |device| and we call
334 // controller->SetConsumerFeedbackObserver(nullptr) before releasing
335 // |device|.
336 controller->SetConsumerFeedbackObserver(
337 base::MakeUnique<VideoFrameConsumerFeedbackObserverOnTaskRunner>(
338 device.get(), device_task_runner_));
339 device_ = std::move(device);
340 state_ = State::DEVICE_STARTED;
341 callbacks->DidStartDevice(controller);
342 base::ResetAndReturn(&done_cb).Run();
343 return;
344 case State::DEVICE_START_ABORTING:
345 if (device) {
346 device_ = std::move(device);
347 state_ = State::DEVICE_STARTED;
348 // We do not move our |done_cb| to this invocation, because
349 // we still need it to stay alive for the remainder of this method
350 // execution. Our implementation of ReleaseDeviceAsync() does not
351 // actually need the context while releasing the device.
352 ReleaseDeviceAsync(controller, base::Bind([]() {}));
353 }
354 state_ = State::NO_DEVICE;
355 callbacks->OnDeviceStartAborted();
356 base::ResetAndReturn(&done_cb).Run();
357 return;
358 case State::NO_DEVICE:
359 case State::DEVICE_STARTED:
360 NOTREACHED();
361 return;
319 } 362 }
320 // Passing raw pointer |device.get()| to the controller is safe,
321 // because we take ownership of |device| and we call
322 // controller->SetConsumerFeedbackObserver(nullptr) before releasing |device|.
323 controller->SetConsumerFeedbackObserver(
324 base::MakeUnique<VideoFrameConsumerFeedbackObserverOnTaskRunner>(
325 device.get(), device_task_runner_));
326 device_ = std::move(device);
327 callbacks->DidStartDevice(controller);
328 base::ResetAndReturn(&done_cb).Run();
329 } 363 }
330 364
331 void InProcessBuildableVideoCaptureDevice::DoStartDeviceCaptureOnDeviceThread( 365 void InProcessBuildableVideoCaptureDevice::DoStartDeviceCaptureOnDeviceThread(
332 const media::VideoCaptureDeviceDescriptor& descriptor, 366 const media::VideoCaptureDeviceDescriptor& descriptor,
333 const media::VideoCaptureParams& params, 367 const media::VideoCaptureParams& params,
334 std::unique_ptr<media::VideoCaptureDeviceClient> device_client, 368 std::unique_ptr<media::VideoCaptureDeviceClient> device_client,
335 ReceiveDeviceCallback result_callback) { 369 ReceiveDeviceCallback result_callback) {
336 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); 370 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime");
337 DCHECK(device_task_runner_->BelongsToCurrentThread()); 371 DCHECK(device_task_runner_->BelongsToCurrentThread());
338 372
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 !defined(OS_ANDROID) 463 !defined(OS_ANDROID)
430 DesktopCaptureDevice* desktop_device = 464 DesktopCaptureDevice* desktop_device =
431 static_cast<DesktopCaptureDevice*>(device); 465 static_cast<DesktopCaptureDevice*>(device);
432 desktop_device->SetNotificationWindowId(window_id); 466 desktop_device->SetNotificationWindowId(window_id);
433 VLOG(2) << "Screen capture notification window passed on device thread."; 467 VLOG(2) << "Screen capture notification window passed on device thread.";
434 #endif 468 #endif
435 base::ResetAndReturn(&done_cb).Run(); 469 base::ResetAndReturn(&done_cb).Run();
436 } 470 }
437 471
438 } // namespace content 472 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698