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

Unified Diff: content/browser/device_monitor_mac.mm

Issue 24615005: Added AVFoundation Glue and Device Monitoring for Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/device_monitor_mac.mm
diff --git a/content/browser/device_monitor_mac.mm b/content/browser/device_monitor_mac.mm
index 7b12e91cbdf4ed8b57fc020d3b75c0579240d0ef..02247b875d63ea33a27ca9857431bd0a1e81dc8b 100644
--- a/content/browser/device_monitor_mac.mm
+++ b/content/browser/device_monitor_mac.mm
@@ -7,48 +7,57 @@
#import <QTKit/QTKit.h>
#include "base/logging.h"
+#include "media/video/capture/mac/avfoundation_glue.h"
namespace content {
-class DeviceMonitorMac::QTMonitorImpl {
+// Interface used by DeviceMonitorMac to interact with either a QTKit or an
+// AVFoundation implementation of events and notifications.
+class DeviceMonitorMac::MacMonitorInterface {
public:
- explicit QTMonitorImpl(DeviceMonitorMac* monitor);
- virtual ~QTMonitorImpl() {}
+ MacMonitorInterface() {};
+ MacMonitorInterface(DeviceMonitorMac* monitor)
Mark Mentovai 2013/09/26 17:09:10 This constructor should be explicit. http://google
mcasas 2013/09/30 17:53:50 Done.
+ : monitor_(monitor),
+ number_audio_devices_(0),
+ number_video_devices_(0),
+ device_arrival_(nil),
Mark Mentovai 2013/09/26 17:09:10 nil is an initializer for an Objective-C object po
mcasas 2013/09/30 17:53:50 Done.
+ device_removal_(nil) {};
+ virtual ~MacMonitorInterface() = 0;
+
+ protected:
+ virtual void OnDeviceChanged() = 0;
Mark Mentovai 2013/09/26 17:09:10 Weird indentation in this entire protected section
mcasas 2013/09/30 17:53:50 Done.
+
+ DeviceMonitorMac* monitor_;
Mark Mentovai 2013/09/26 17:09:10 Protected data is almost unseen, even in interface
mcasas 2013/09/30 17:53:50 Done.
+ int number_audio_devices_;
+ int number_video_devices_;
+ int device_arrival_;
+ int device_removal_;
- void Start();
- void Stop();
+};
- private:
- void OnDeviceChanged();
+DeviceMonitorMac::MacMonitorInterface::~MacMonitorInterface() { }
Mark Mentovai 2013/09/26 17:09:10 In the class declaration above, you made the destr
mcasas 2013/09/30 17:53:50 Gone.
- DeviceMonitorMac* monitor_;
- int number_audio_devices_;
- int number_video_devices_;
- id device_arrival_;
- id device_removal_;
+class DeviceMonitorMac::QTKitMonitorImpl : public MacMonitorInterface {
+ public:
+ QTKitMonitorImpl(DeviceMonitorMac* monitor);
Mark Mentovai 2013/09/26 17:09:10 explicit.
mcasas 2013/09/30 17:53:50 Done.
+ virtual ~QTKitMonitorImpl();
- DISALLOW_COPY_AND_ASSIGN(QTMonitorImpl);
+ virtual void OnDeviceChanged() OVERRIDE;
};
-DeviceMonitorMac::QTMonitorImpl::QTMonitorImpl(DeviceMonitorMac* monitor)
- : monitor_(monitor),
- number_audio_devices_(0),
- number_video_devices_(0),
- device_arrival_(nil),
- device_removal_(nil) {
+DeviceMonitorMac::QTKitMonitorImpl::QTKitMonitorImpl(DeviceMonitorMac* monitor)
+ : MacMonitorInterface(monitor) {
DCHECK(monitor);
-}
-void DeviceMonitorMac::QTMonitorImpl::Start() {
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
- device_arrival_ =
+ device_arrival_ = (int)
Mark Mentovai 2013/09/26 17:09:10 No, you definitely can’t cast id to int. I don’t k
mcasas 2013/09/30 17:53:50 Without wanting to escape my public defamation, I'
[nc addObserverForName:QTCaptureDeviceWasConnectedNotification
object:nil
queue:nil
usingBlock:^(NSNotification* notification) {
OnDeviceChanged();}];
- device_removal_ =
+ device_removal_ = (int)
[nc addObserverForName:QTCaptureDeviceWasDisconnectedNotification
object:nil
queue:nil
@@ -56,16 +65,16 @@ void DeviceMonitorMac::QTMonitorImpl::Start() {
OnDeviceChanged();}];
}
-void DeviceMonitorMac::QTMonitorImpl::Stop() {
+DeviceMonitorMac::QTKitMonitorImpl::~QTKitMonitorImpl() {
if (!monitor_)
return;
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
- [nc removeObserver:device_arrival_];
- [nc removeObserver:device_removal_];
+ [nc removeObserver:(id)device_arrival_];
+ [nc removeObserver:(id)device_removal_];
}
-void DeviceMonitorMac::QTMonitorImpl::OnDeviceChanged() {
+void DeviceMonitorMac::QTKitMonitorImpl::OnDeviceChanged() {
NSArray* devices = [QTCaptureDevice inputDevices];
int number_video_devices = 0;
int number_audio_devices = 0;
@@ -90,15 +99,80 @@ void DeviceMonitorMac::QTMonitorImpl::OnDeviceChanged() {
}
}
-DeviceMonitorMac::DeviceMonitorMac() {
- qt_monitor_.reset(new QTMonitorImpl(this));
- qt_monitor_->Start();
+class DeviceMonitorMac::AVFoundationMonitorImpl : public MacMonitorInterface {
+ public:
+ AVFoundationMonitorImpl(DeviceMonitorMac* monitor);
Mark Mentovai 2013/09/26 17:09:10 explicit
mcasas 2013/09/30 17:53:50 Done.
+ virtual ~AVFoundationMonitorImpl();
+
+ virtual void OnDeviceChanged() OVERRIDE;
+};
+
+DeviceMonitorMac::AVFoundationMonitorImpl::AVFoundationMonitorImpl(
+ DeviceMonitorMac* monitor)
Mark Mentovai 2013/09/26 17:09:10 This line would be a 4-space continuation line ind
mcasas 2013/09/30 17:53:50 Done.
+ : MacMonitorInterface(monitor) {
+ DCHECK(monitor);
+
+ NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
+ device_arrival_ = (int)
+ [nc addObserverForName:AVCaptureDeviceWasConnectedNotification
+ object:nil
+ queue:nil
+ usingBlock:^(NSNotification* notification) {
+ OnDeviceChanged();}];
+
+ device_removal_ = (int)
+ [nc addObserverForName:AVCaptureDeviceWasDisconnectedNotification
+ object:nil
+ queue:nil
+ usingBlock:^(NSNotification* notification) {
+ OnDeviceChanged();}];
}
-DeviceMonitorMac::~DeviceMonitorMac() {
- qt_monitor_->Stop();
+DeviceMonitorMac::AVFoundationMonitorImpl::~AVFoundationMonitorImpl() {
+ if (!monitor_)
+ return;
+
+ NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
+ [nc removeObserver:(id)device_arrival_];
+ [nc removeObserver:(id)device_removal_];
}
+void DeviceMonitorMac::AVFoundationMonitorImpl::OnDeviceChanged() {
+ NSArray* devices = [AVCaptureDeviceGlue devices];
+ int number_video_devices = 0;
+ int number_audio_devices = 0;
+ for (AVCaptureDeviceGlue* device in devices) {
Mark Mentovai 2013/09/26 17:09:10 Is it possible for the actual devices to change wi
mcasas 2013/09/30 17:53:50 I thought this is addressed by the "usingBlock" in
+ if ([device hasMediaType:AVMediaTypeVideo] ||
+ [device hasMediaType:AVMediaTypeMuxed])
+ ++number_video_devices;
+
+ if ([device hasMediaType:AVMediaTypeAudio] ||
+ [device hasMediaType:AVMediaTypeMuxed])
+ ++number_audio_devices;
+ }
+
+ if (number_video_devices_ != number_video_devices) {
+ number_video_devices_ = number_video_devices;
+ monitor_->NotifyDeviceChanged(base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE);
+ }
+
+ if (number_audio_devices_ != number_audio_devices) {
+ number_audio_devices_ = number_audio_devices;
+ monitor_->NotifyDeviceChanged(base::SystemMonitor::DEVTYPE_AUDIO_CAPTURE);
+ }
+}
+
+DeviceMonitorMac::DeviceMonitorMac() {
+ if ([AVFoundationGlue IsAVFoundationSupported]){
Mark Mentovai 2013/09/26 17:09:10 Method names (even class method names, what would
mcasas 2013/09/30 17:53:50 Happy to do so. I was following the style in: IsO
+ device_monitor_impl_.reset(new AVFoundationMonitorImpl(this));
+ } else {
+ DVLOG(1) << "Monitoring via QTKit";
+ device_monitor_impl_.reset(new QTKitMonitorImpl(this));
+ }
+}
+
+DeviceMonitorMac::~DeviceMonitorMac() {}
+
void DeviceMonitorMac::NotifyDeviceChanged(
base::SystemMonitor::DeviceType type) {
// TODO(xians): Remove the global variable for SystemMonitor.

Powered by Google App Engine
This is Rietveld 408576698