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

Side by Side Diff: device/capture/device_monitor_mac.mm

Issue 2214533002: move //media/capture to //device/capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « device/capture/device_monitor_mac.h ('k') | device/capture/device_monitor_udev.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "media/capture/device_monitor_mac.h" 5 #include "device/capture/device_monitor_mac.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/mac/bind_objc_block.h" 11 #include "base/mac/bind_objc_block.h"
12 #include "base/mac/scoped_nsobject.h" 12 #include "base/mac/scoped_nsobject.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/profiler/scoped_tracker.h" 14 #include "base/profiler/scoped_tracker.h"
15 #include "base/task_runner_util.h" 15 #include "base/task_runner_util.h"
(...skipping 22 matching lines...) Expand all
38 38
39 private: 39 private:
40 std::string unique_id_; 40 std::string unique_id_;
41 DeviceType type_; 41 DeviceType type_;
42 // Allow generated copy constructor and assignment. 42 // Allow generated copy constructor and assignment.
43 }; 43 };
44 44
45 // Base abstract class used by DeviceMonitorMac. 45 // Base abstract class used by DeviceMonitorMac.
46 class DeviceMonitorMacImpl { 46 class DeviceMonitorMacImpl {
47 public: 47 public:
48 explicit DeviceMonitorMacImpl(media::DeviceMonitorMac* monitor) 48 explicit DeviceMonitorMacImpl(device::DeviceMonitorMac* monitor)
49 : monitor_(monitor), 49 : monitor_(monitor),
50 cached_devices_(), 50 cached_devices_(),
51 device_arrival_(nil), 51 device_arrival_(nil),
52 device_removal_(nil) { 52 device_removal_(nil) {
53 DCHECK(monitor); 53 DCHECK(monitor);
54 // Initialise the devices_cache_ with a not-valid entry. For the case in 54 // Initialise the devices_cache_ with a not-valid entry. For the case in
55 // which there is one single device in the system and we get notified when 55 // which there is one single device in the system and we get notified when
56 // it gets removed, this will prevent the system from thinking that no 56 // it gets removed, this will prevent the system from thinking that no
57 // devices were added nor removed and not notifying the |monitor_|. 57 // devices were added nor removed and not notifying the |monitor_|.
58 cached_devices_.push_back(DeviceInfo("invalid", DeviceInfo::kInvalid)); 58 cached_devices_.push_back(DeviceInfo("invalid", DeviceInfo::kInvalid));
59 } 59 }
60 virtual ~DeviceMonitorMacImpl() {} 60 virtual ~DeviceMonitorMacImpl() {}
61 61
62 virtual void OnDeviceChanged() = 0; 62 virtual void OnDeviceChanged() = 0;
63 63
64 // Method called by the default notification center when a device is removed 64 // Method called by the default notification center when a device is removed
65 // or added to the system. It will compare the |cached_devices_| with the 65 // or added to the system. It will compare the |cached_devices_| with the
66 // current situation, update it, and, if there's an update, signal to 66 // current situation, update it, and, if there's an update, signal to
67 // |monitor_| with the appropriate device type. 67 // |monitor_| with the appropriate device type.
68 void ConsolidateDevicesListAndNotify( 68 void ConsolidateDevicesListAndNotify(
69 const std::vector<DeviceInfo>& snapshot_devices); 69 const std::vector<DeviceInfo>& snapshot_devices);
70 70
71 protected: 71 protected:
72 media::DeviceMonitorMac* monitor_; 72 device::DeviceMonitorMac* monitor_;
73 std::vector<DeviceInfo> cached_devices_; 73 std::vector<DeviceInfo> cached_devices_;
74 74
75 // Handles to NSNotificationCenter block observers. 75 // Handles to NSNotificationCenter block observers.
76 id device_arrival_; 76 id device_arrival_;
77 id device_removal_; 77 id device_removal_;
78 78
79 private: 79 private:
80 DISALLOW_COPY_AND_ASSIGN(DeviceMonitorMacImpl); 80 DISALLOW_COPY_AND_ASSIGN(DeviceMonitorMacImpl);
81 }; 81 };
82 82
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } 290 }
291 291
292 // AVFoundation implementation of the Mac Device Monitor, registers as a global 292 // AVFoundation implementation of the Mac Device Monitor, registers as a global
293 // device connect/disconnect observer and plugs suspend/wake up device observers 293 // device connect/disconnect observer and plugs suspend/wake up device observers
294 // per device. This class is created and lives on the main Application thread 294 // per device. This class is created and lives on the main Application thread
295 // (UI for content). Owns a SuspendObserverDelegate that notifies when a device 295 // (UI for content). Owns a SuspendObserverDelegate that notifies when a device
296 // is suspended/resumed. 296 // is suspended/resumed.
297 class AVFoundationMonitorImpl : public DeviceMonitorMacImpl { 297 class AVFoundationMonitorImpl : public DeviceMonitorMacImpl {
298 public: 298 public:
299 AVFoundationMonitorImpl( 299 AVFoundationMonitorImpl(
300 media::DeviceMonitorMac* monitor, 300 device::DeviceMonitorMac* monitor,
301 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner); 301 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner);
302 ~AVFoundationMonitorImpl() override; 302 ~AVFoundationMonitorImpl() override;
303 303
304 void OnDeviceChanged() override; 304 void OnDeviceChanged() override;
305 305
306 private: 306 private:
307 // {Video,AudioInput}DeviceManager's "Device" thread task runner used for 307 // {Video,AudioInput}DeviceManager's "Device" thread task runner used for
308 // posting tasks to |suspend_observer_delegate_|; 308 // posting tasks to |suspend_observer_delegate_|;
309 const scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_; 309 const scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_;
310 310
311 // Pegged to the "main" thread -- usually content::BrowserThread::UI. 311 // Pegged to the "main" thread -- usually content::BrowserThread::UI.
312 base::ThreadChecker main_thread_checker_; 312 base::ThreadChecker main_thread_checker_;
313 313
314 scoped_refptr<SuspendObserverDelegate> suspend_observer_delegate_; 314 scoped_refptr<SuspendObserverDelegate> suspend_observer_delegate_;
315 315
316 DISALLOW_COPY_AND_ASSIGN(AVFoundationMonitorImpl); 316 DISALLOW_COPY_AND_ASSIGN(AVFoundationMonitorImpl);
317 }; 317 };
318 318
319 AVFoundationMonitorImpl::AVFoundationMonitorImpl( 319 AVFoundationMonitorImpl::AVFoundationMonitorImpl(
320 media::DeviceMonitorMac* monitor, 320 device::DeviceMonitorMac* monitor,
321 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) 321 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner)
322 : DeviceMonitorMacImpl(monitor), 322 : DeviceMonitorMacImpl(monitor),
323 device_task_runner_(device_task_runner), 323 device_task_runner_(device_task_runner),
324 suspend_observer_delegate_(new SuspendObserverDelegate(this)) { 324 suspend_observer_delegate_(new SuspendObserverDelegate(this)) {
325 DCHECK(main_thread_checker_.CalledOnValidThread()); 325 DCHECK(main_thread_checker_.CalledOnValidThread());
326 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; 326 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
327 device_arrival_ = 327 device_arrival_ =
328 [nc addObserverForName:AVFoundationGlue:: 328 [nc addObserverForName:AVFoundationGlue::
329 AVCaptureDeviceWasConnectedNotification() 329 AVCaptureDeviceWasConnectedNotification()
330 object:nil 330 object:nil
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 context:(void*)context { 430 context:(void*)context {
431 DCHECK(mainThreadChecker_.CalledOnValidThread()); 431 DCHECK(mainThreadChecker_.CalledOnValidThread());
432 if ([keyPath isEqual:@"suspended"]) 432 if ([keyPath isEqual:@"suspended"])
433 onDeviceChangedCallback_.Run(); 433 onDeviceChangedCallback_.Run();
434 if ([keyPath isEqual:@"connected"]) 434 if ([keyPath isEqual:@"connected"])
435 [self stopObserving:static_cast<CrAVCaptureDevice*>(context)]; 435 [self stopObserving:static_cast<CrAVCaptureDevice*>(context)];
436 } 436 }
437 437
438 @end // @implementation CrAVFoundationDeviceObserver 438 @end // @implementation CrAVFoundationDeviceObserver
439 439
440 namespace media { 440 namespace device {
441 441
442 DeviceMonitorMac::DeviceMonitorMac() { 442 DeviceMonitorMac::DeviceMonitorMac() {
443 // AVFoundation do not need to be fired up until the user 443 // AVFoundation do not need to be fired up until the user
444 // exercises a GetUserMedia. Bringing up either library and enumerating the 444 // exercises a GetUserMedia. Bringing up either library and enumerating the
445 // devices in the system is an operation taking in the range of hundred of ms, 445 // devices in the system is an operation taking in the range of hundred of ms,
446 // so it is triggered explicitly from MediaStreamManager::StartMonitoring(). 446 // so it is triggered explicitly from MediaStreamManager::StartMonitoring().
447 } 447 }
448 448
449 DeviceMonitorMac::~DeviceMonitorMac() {} 449 DeviceMonitorMac::~DeviceMonitorMac() {}
450 450
(...skipping 14 matching lines...) Expand all
465 new AVFoundationMonitorImpl(this, device_task_runner)); 465 new AVFoundationMonitorImpl(this, device_task_runner));
466 } 466 }
467 467
468 void DeviceMonitorMac::NotifyDeviceChanged( 468 void DeviceMonitorMac::NotifyDeviceChanged(
469 base::SystemMonitor::DeviceType type) { 469 base::SystemMonitor::DeviceType type) {
470 DCHECK(thread_checker_.CalledOnValidThread()); 470 DCHECK(thread_checker_.CalledOnValidThread());
471 // TODO(xians): Remove the global variable for SystemMonitor. 471 // TODO(xians): Remove the global variable for SystemMonitor.
472 base::SystemMonitor::Get()->ProcessDevicesChanged(type); 472 base::SystemMonitor::Get()->ProcessDevicesChanged(type);
473 } 473 }
474 474
475 } // namespace media 475 } // namespace device
OLDNEW
« no previous file with comments | « device/capture/device_monitor_mac.h ('k') | device/capture/device_monitor_udev.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698