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
3 // found in the LICENSE file.
5 #include "content/browser/device_monitor_mac.h"
7 #import <QTKit/QTKit.h>
9 #include "base/logging.h"
13 class DeviceMonitorMac::QTMonitorImpl {
15 explicit QTMonitorImpl(DeviceMonitorMac* monitor);
16 virtual ~QTMonitorImpl() {}
22 void OnDeviceChanged();
24 DeviceMonitorMac* monitor_;
25 int number_audio_devices_;
26 int number_video_devices_;
30 DISALLOW_COPY_AND_ASSIGN(QTMonitorImpl);
33 DeviceMonitorMac::QTMonitorImpl::QTMonitorImpl(DeviceMonitorMac* monitor)
35 number_audio_devices_(0),
36 number_video_devices_(0),
38 device_removal_(nil) {
42 void DeviceMonitorMac::QTMonitorImpl::Start() {
43 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
45 [nc addObserverForName:QTCaptureDeviceWasConnectedNotification
48 usingBlock:^(NSNotification* notification) {
52 [nc addObserverForName:QTCaptureDeviceWasDisconnectedNotification
55 usingBlock:^(NSNotification* notification) {
59 void DeviceMonitorMac::QTMonitorImpl::Stop() {
63 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
64 [nc removeObserver:device_arrival_];
65 [nc removeObserver:device_removal_];
68 void DeviceMonitorMac::QTMonitorImpl::OnDeviceChanged() {
69 NSArray* devices = [QTCaptureDevice inputDevices];
70 int number_video_devices = 0;
71 int number_audio_devices = 0;
72 for (QTCaptureDevice* device in devices) {
73 if ([device hasMediaType:QTMediaTypeVideo] ||
74 [device hasMediaType:QTMediaTypeMuxed])
75 ++number_video_devices;
77 if ([device hasMediaType:QTMediaTypeSound] ||
78 [device hasMediaType:QTMediaTypeMuxed])
79 ++number_audio_devices;
82 if (number_video_devices_ != number_video_devices) {
83 number_video_devices_ = number_video_devices;
84 monitor_->NotifyDeviceChanged(base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE);
87 if (number_audio_devices_ != number_audio_devices) {
88 number_audio_devices_ = number_audio_devices;
89 monitor_->NotifyDeviceChanged(base::SystemMonitor::DEVTYPE_AUDIO_CAPTURE);
93 DeviceMonitorMac::DeviceMonitorMac() {
94 qt_monitor_.reset(new QTMonitorImpl(this));
98 DeviceMonitorMac::~DeviceMonitorMac() {
102 void DeviceMonitorMac::NotifyDeviceChanged(
103 base::SystemMonitor::DeviceType type) {
104 // TODO(xians): Remove the global variable for SystemMonitor.
105 base::SystemMonitor::Get()->ProcessDevicesChanged(type);
108 } // namespace content