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

Side by Side Diff: webrtc/media/devices/macdevicemanagermm.mm

Issue 1715883002: Remove DeviceManager and DeviceInfo. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 9 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 | « webrtc/media/devices/macdevicemanager.cc ('k') | webrtc/media/devices/mobiledevicemanager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 // support GCC compiler
12 #ifndef __has_feature
13 #define __has_feature(x) 0
14 #endif
15
16 #include "webrtc/media/devices/devicemanager.h"
17
18 #import <assert.h>
19 #ifdef __MAC_OS_X_VERSION_MAX_ALLOWED
20 #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
21 #import <AVFoundation/AVFoundation.h>
22 #endif
23 #endif
24 #import <QTKit/QTKit.h>
25
26 #include "webrtc/base/logging.h"
27
28 @interface DeviceWatcherImpl : NSObject {
29 @private
30 cricket::DeviceManagerInterface* manager_;
31 }
32 - (id)init:(cricket::DeviceManagerInterface*)manager;
33 - (void)onDevicesChanged:(NSNotification*)notification;
34 @end
35
36 @implementation DeviceWatcherImpl
37 - (id)init:(cricket::DeviceManagerInterface*)manager {
38 if ((self = [super init])) {
39 assert(manager != NULL);
40 manager_ = manager;
41 [[NSNotificationCenter defaultCenter]
42 addObserver:self
43 selector:@selector(onDevicesChanged:)
44 name:QTCaptureDeviceWasConnectedNotification
45 object:nil];
46 [[NSNotificationCenter defaultCenter]
47 addObserver:self
48 selector:@selector(onDevicesChanged:)
49 name:QTCaptureDeviceWasDisconnectedNotification
50 object:nil];
51 }
52 return self;
53 }
54
55 - (void)dealloc {
56 [[NSNotificationCenter defaultCenter] removeObserver:self];
57 #if !__has_feature(objc_arc)
58 [super dealloc];
59 #endif
60 }
61 - (void)onDevicesChanged:(NSNotification*)notification {
62 manager_->SignalDevicesChange();
63 }
64 @end
65
66 namespace cricket {
67
68 DeviceWatcherImpl* CreateDeviceWatcherCallback(
69 DeviceManagerInterface* manager) {
70 DeviceWatcherImpl* impl;
71 #if !__has_feature(objc_arc)
72 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
73 #else
74 @autoreleasepool
75 #endif
76 { impl = [[DeviceWatcherImpl alloc] init:manager]; }
77 #if !__has_feature(objc_arc)
78 [pool drain];
79 #endif
80 return impl;
81 }
82
83 void ReleaseDeviceWatcherCallback(DeviceWatcherImpl* watcher) {
84 #if !__has_feature(objc_arc)
85 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
86 [watcher release];
87 [pool drain];
88 #endif
89 }
90
91 bool GetQTKitVideoDevices(std::vector<Device>* devices) {
92 #if !__has_feature(objc_arc)
93 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
94 #else
95 @autoreleasepool
96 #endif
97 {
98 NSArray* qt_capture_devices =
99 [QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo];
100 NSUInteger count = [qt_capture_devices count];
101 LOG(LS_INFO) << count << " capture device(s) found:";
102 for (QTCaptureDevice* qt_capture_device in qt_capture_devices) {
103 static NSString* const kFormat = @"localizedDisplayName: \"%@\", "
104 @"modelUniqueID: \"%@\", uniqueID \"%@\", isConnected: %d, "
105 @"isOpen: %d, isInUseByAnotherApplication: %d";
106 NSString* info = [NSString
107 stringWithFormat:kFormat,
108 [qt_capture_device localizedDisplayName],
109 [qt_capture_device modelUniqueID],
110 [qt_capture_device uniqueID],
111 [qt_capture_device isConnected],
112 [qt_capture_device isOpen],
113 [qt_capture_device isInUseByAnotherApplication]];
114 LOG(LS_INFO) << [info UTF8String];
115
116 std::string name([[qt_capture_device localizedDisplayName] UTF8String]);
117 devices->push_back(
118 Device(name, [[qt_capture_device uniqueID] UTF8String]));
119 }
120 }
121 #if !__has_feature(objc_arc)
122 [pool drain];
123 #endif
124 return true;
125 }
126
127 bool GetAVFoundationVideoDevices(std::vector<Device>* devices) {
128 #ifdef __MAC_OS_X_VERSION_MAX_ALLOWED
129 #if __MAC_OS_X_VERSION_MAX_ALLOWED >=1070
130 if (![AVCaptureDevice class]) {
131 // Fallback to using QTKit if AVFoundation is not available
132 return GetQTKitVideoDevices(devices);
133 }
134 #if !__has_feature(objc_arc)
135 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
136 #else
137 @autoreleasepool
138 #endif
139 {
140 NSArray* capture_devices = [AVCaptureDevice devices];
141 LOG(LS_INFO) << [capture_devices count] << " capture device(s) found:";
142 for (AVCaptureDevice* capture_device in capture_devices) {
143 if ([capture_device hasMediaType:AVMediaTypeVideo] ||
144 [capture_device hasMediaType:AVMediaTypeMuxed]) {
145 static NSString* const kFormat = @"localizedName: \"%@\", "
146 @"modelID: \"%@\", uniqueID \"%@\", isConnected: %d, "
147 @"isInUseByAnotherApplication: %d";
148 NSString* info = [NSString
149 stringWithFormat:kFormat,
150 [capture_device localizedName],
151 [capture_device modelID],
152 [capture_device uniqueID],
153 [capture_device isConnected],
154 [capture_device isInUseByAnotherApplication]];
155 LOG(LS_INFO) << [info UTF8String];
156
157 std::string name([[capture_device localizedName] UTF8String]);
158 devices->push_back(
159 Device(name, [[capture_device uniqueID] UTF8String]));
160 }
161 }
162 }
163 #if !__has_feature(objc_arc)
164 [pool drain];
165 #endif
166 return true;
167 #else // __MAC_OS_X_VERSION_MAX_ALLOWED >=1070
168 return GetQTKitVideoDevices(devices);
169 #endif // __MAC_OS_X_VERSION_MAX_ALLOWED >=1070
170 #else // __MAC_OS_X_VERSION_MAX_ALLOWED
171 return GetQTKitVideoDevices(devices);
172 #endif // __MAC_OS_X_VERSION_MAX_ALLOWED
173 }
174
175 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/media/devices/macdevicemanager.cc ('k') | webrtc/media/devices/mobiledevicemanager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698