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

Side by Side Diff: content/browser/renderer_host/media/video_capture_manager.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 (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_manager.h" 5 #include "content/browser/renderer_host/media/video_capture_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/stl_util.h" 19 #include "base/stl_util.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "base/task_runner_util.h" 21 #include "base/task_runner_util.h"
22 #include "base/threading/sequenced_worker_pool.h" 22 #include "base/threading/sequenced_worker_pool.h"
23 #include "base/threading/thread_task_runner_handle.h" 23 #include "base/threading/thread_task_runner_handle.h"
24 #include "build/build_config.h" 24 #include "build/build_config.h"
25 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" 25 #include "content/browser/media/capture/desktop_capture_device_uma_types.h"
26 #include "content/browser/media/capture/web_contents_video_capture_device.h" 26 #include "content/browser/media/capture/web_contents_video_capture_device.h"
27 #include "content/browser/media/media_internals.h" 27 #include "content/browser/media/media_internals.h"
28 #include "content/browser/renderer_host/media/video_capture_controller.h" 28 #include "content/browser/renderer_host/media/video_capture_controller.h"
29 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h"
30 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
31 #include "content/public/browser/desktop_media_id.h" 30 #include "content/public/browser/desktop_media_id.h"
32 #include "content/public/common/media_stream_request.h" 31 #include "content/public/common/media_stream_request.h"
33 #include "media/base/bind_to_current_loop.h" 32 #include "media/base/bind_to_current_loop.h"
34 #include "media/base/media_switches.h" 33 #include "media/base/media_switches.h"
35 #include "media/base/video_facing.h" 34 #include "media/base/video_facing.h"
36 #include "media/capture/video/video_capture_buffer_pool_impl.h" 35 #include "media/capture/video/video_capture_buffer_pool_impl.h"
37 #include "media/capture/video/video_capture_buffer_tracker_factory_impl.h" 36 #include "media/capture/video/video_capture_buffer_tracker_factory_impl.h"
38 #include "media/capture/video/video_capture_device.h" 37 #include "media/capture/video/video_capture_device.h"
39 #include "media/capture/video/video_capture_device_client.h" 38 #include "media/capture/video/video_capture_device_client.h"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 // requesting a device with a bogus id). Note, that since other types of 279 // requesting a device with a bogus id). Note, that since other types of
281 // failure during startup of the device are allowed to be reported 280 // failure during startup of the device are allowed to be reported
282 // asynchronously, this requirement is questionable. 281 // asynchronously, this requirement is questionable.
283 // TODO(chfremer): Check if any production code actually depends on this 282 // TODO(chfremer): Check if any production code actually depends on this
284 // requirement. If not, relax the requirement in the test and remove the below 283 // requirement. If not, relax the requirement in the test and remove the below
285 // if block. See crbug.com/708251 284 // if block. See crbug.com/708251
286 if (controller->stream_type() == MEDIA_DEVICE_VIDEO_CAPTURE) { 285 if (controller->stream_type() == MEDIA_DEVICE_VIDEO_CAPTURE) {
287 const media::VideoCaptureDeviceInfo* device_info = 286 const media::VideoCaptureDeviceInfo* device_info =
288 GetDeviceInfoById(controller->device_id()); 287 GetDeviceInfoById(controller->device_id());
289 if (!device_info) { 288 if (!device_info) {
290 OnDeviceStartFailed(controller); 289 OnDeviceLaunchFailed(controller);
291 return; 290 return;
292 } 291 }
293 for (auto& observer : capture_observers_) 292 for (auto& observer : capture_observers_)
294 observer.OnVideoCaptureStarted(device_info->descriptor.facing); 293 observer.OnVideoCaptureStarted(device_info->descriptor.facing);
295 } 294 }
296 295
297 // The method CreateAndStartDeviceAsync() is going to run asynchronously. 296 // The method CreateAndStartDeviceAsync() is going to run asynchronously.
298 // Since we may be removing the controller while it is executing, we need to 297 // Since we may be removing the controller while it is executing, we need to
299 // pass it shared ownership to itself so that it stays alive while executing. 298 // pass it shared ownership to itself so that it stays alive while executing.
300 // And since the execution may make callbacks into |this|, we also need 299 // And since the execution may make callbacks into |this|, we also need
301 // to pass it shared ownership to |this|. 300 // to pass it shared ownership to |this|.
302 // TODO(chfremer): Check if request->params() can actually be different from 301 // TODO(chfremer): Check if request->params() can actually be different from
303 // controller->parameters, and simplify if this is not the case. 302 // controller->parameters, and simplify if this is not the case.
304 controller->CreateAndStartDeviceAsync( 303 controller->CreateAndStartDeviceAsync(
305 request->params(), 304 request->params(), static_cast<VideoCaptureDeviceLaunchObserver*>(this),
306 static_cast<BuildableVideoCaptureDevice::Callbacks*>(this),
307 base::Bind([](scoped_refptr<VideoCaptureManager>, 305 base::Bind([](scoped_refptr<VideoCaptureManager>,
308 scoped_refptr<VideoCaptureController>) {}, 306 scoped_refptr<VideoCaptureController>) {},
309 scoped_refptr<VideoCaptureManager>(this), 307 scoped_refptr<VideoCaptureManager>(this),
310 GetControllerSharedRef(controller))); 308 GetControllerSharedRef(controller)));
311 } 309 }
312 310
313 void VideoCaptureManager::OnDeviceStarted(VideoCaptureController* controller) { 311 void VideoCaptureManager::OnDeviceLaunched(VideoCaptureController* controller) {
314 DVLOG(3) << __func__; 312 DVLOG(3) << __func__;
315 DCHECK_CURRENTLY_ON(BrowserThread::IO); 313 DCHECK_CURRENTLY_ON(BrowserThread::IO);
316 DCHECK(!device_start_request_queue_.empty()); 314 DCHECK(!device_start_request_queue_.empty());
317 DCHECK_EQ(controller, device_start_request_queue_.begin()->controller()); 315 DCHECK_EQ(controller, device_start_request_queue_.begin()->controller());
318 DCHECK(controller); 316 DCHECK(controller);
319 317
320 if (controller->stream_type() == MEDIA_DESKTOP_VIDEO_CAPTURE) { 318 if (controller->stream_type() == MEDIA_DESKTOP_VIDEO_CAPTURE) {
321 const media::VideoCaptureSessionId session_id = 319 const media::VideoCaptureSessionId session_id =
322 device_start_request_queue_.front().session_id(); 320 device_start_request_queue_.front().session_id();
323 DCHECK(session_id != kFakeSessionId); 321 DCHECK(session_id != kFakeSessionId);
324 MaybePostDesktopCaptureWindowId(session_id); 322 MaybePostDesktopCaptureWindowId(session_id);
325 } 323 }
326 324
327 auto it = photo_request_queue_.begin(); 325 auto it = photo_request_queue_.begin();
328 while (it != photo_request_queue_.end()) { 326 while (it != photo_request_queue_.end()) {
329 auto request = it++; 327 auto request = it++;
330 VideoCaptureController* maybe_entry = 328 VideoCaptureController* maybe_entry =
331 LookupControllerBySessionId(request->first); 329 LookupControllerBySessionId(request->first);
332 if (maybe_entry && maybe_entry->IsDeviceAlive()) { 330 if (maybe_entry && maybe_entry->IsDeviceAlive()) {
333 request->second.Run(); 331 request->second.Run();
334 photo_request_queue_.erase(request); 332 photo_request_queue_.erase(request);
335 } 333 }
336 } 334 }
337 335
338 device_start_request_queue_.pop_front(); 336 device_start_request_queue_.pop_front();
339 ProcessDeviceStartRequestQueue(); 337 ProcessDeviceStartRequestQueue();
340 } 338 }
341 339
342 void VideoCaptureManager::OnDeviceStartFailed( 340 void VideoCaptureManager::OnDeviceLaunchFailed(
343 VideoCaptureController* controller) { 341 VideoCaptureController* controller) {
344 const std::string log_message = base::StringPrintf( 342 const std::string log_message = base::StringPrintf(
345 "Starting device %s has failed. Maybe recently disconnected?", 343 "Starting device %s has failed. Maybe recently disconnected?",
346 controller->device_id().c_str()); 344 controller->device_id().c_str());
347 DLOG(ERROR) << log_message; 345 DLOG(ERROR) << log_message;
348 controller->OnLog(log_message); 346 controller->OnLog(log_message);
349 controller->OnError(); 347 controller->OnError();
350 348
351 device_start_request_queue_.pop_front(); 349 device_start_request_queue_.pop_front();
352 ProcessDeviceStartRequestQueue(); 350 ProcessDeviceStartRequestQueue();
353 } 351 }
354 352
355 void VideoCaptureManager::OnDeviceStartAborted() { 353 void VideoCaptureManager::OnDeviceLaunchAborted() {
356 device_start_request_queue_.pop_front(); 354 device_start_request_queue_.pop_front();
357 ProcessDeviceStartRequestQueue(); 355 ProcessDeviceStartRequestQueue();
358 } 356 }
359 357
360 void VideoCaptureManager::ConnectClient( 358 void VideoCaptureManager::ConnectClient(
361 media::VideoCaptureSessionId session_id, 359 media::VideoCaptureSessionId session_id,
362 const media::VideoCaptureParams& params, 360 const media::VideoCaptureParams& params,
363 VideoCaptureControllerID client_id, 361 VideoCaptureControllerID client_id,
364 VideoCaptureControllerEventHandler* client_handler, 362 VideoCaptureControllerEventHandler* client_handler,
365 const DoneCB& done_cb) { 363 const DoneCB& done_cb) {
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 777
780 // Check if another session has already opened this device. If so, just 778 // Check if another session has already opened this device. If so, just
781 // use that opened device. 779 // use that opened device.
782 VideoCaptureController* const existing_device = 780 VideoCaptureController* const existing_device =
783 LookupControllerByMediaTypeAndDeviceId(device_info.type, device_info.id); 781 LookupControllerByMediaTypeAndDeviceId(device_info.type, device_info.id);
784 if (existing_device) { 782 if (existing_device) {
785 DCHECK_EQ(device_info.type, existing_device->stream_type()); 783 DCHECK_EQ(device_info.type, existing_device->stream_type());
786 return existing_device; 784 return existing_device;
787 } 785 }
788 786
789 VideoCaptureController* new_controller = 787 VideoCaptureController* new_controller = new VideoCaptureController(
790 new VideoCaptureController(device_info.id, device_info.type, params, 788 device_info.id, device_info.type, params,
791 video_capture_provider_->CreateBuildableDevice( 789 video_capture_provider_->CreateDeviceLauncher());
792 device_info.id, device_info.type));
793 controllers_.emplace_back(new_controller); 790 controllers_.emplace_back(new_controller);
794 return new_controller; 791 return new_controller;
795 } 792 }
796 793
797 base::Optional<CameraCalibration> VideoCaptureManager::GetCameraCalibration( 794 base::Optional<CameraCalibration> VideoCaptureManager::GetCameraCalibration(
798 const std::string& device_id) { 795 const std::string& device_id) {
799 media::VideoCaptureDeviceInfo* info = GetDeviceInfoById(device_id); 796 media::VideoCaptureDeviceInfo* info = GetDeviceInfoById(device_id);
800 if (!info) 797 if (!info)
801 return base::Optional<CameraCalibration>(); 798 return base::Optional<CameraCalibration>();
802 return info->descriptor.camera_calibration; 799 return info->descriptor.camera_calibration;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 // Session ID is only valid for Screen capture. So we can fake it to 851 // Session ID is only valid for Screen capture. So we can fake it to
855 // resume video capture devices here. 852 // resume video capture devices here.
856 QueueStartDevice(kFakeSessionId, controller.get(), 853 QueueStartDevice(kFakeSessionId, controller.get(),
857 controller->parameters()); 854 controller->parameters());
858 } 855 }
859 } 856 }
860 } 857 }
861 #endif // defined(OS_ANDROID) 858 #endif // defined(OS_ANDROID)
862 859
863 } // namespace content 860 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698