OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2013 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 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
12 #error "This file requires ARC support." | |
13 #endif | |
14 | |
15 #include <AVFoundation/AVFoundation.h> | |
16 | |
17 #include <string> | |
18 | |
19 #include "webrtc/modules/video_capture/objc/device_info.h" | |
20 #include "webrtc/modules/video_capture/objc/device_info_objc.h" | |
21 #include "webrtc/modules/video_capture/video_capture_impl.h" | |
22 #include "webrtc/system_wrappers/include/trace.h" | |
23 | |
24 using namespace webrtc; | |
25 using namespace videocapturemodule; | |
26 | |
27 static NSArray* camera_presets = @[ | |
28 AVCaptureSessionPreset352x288, AVCaptureSessionPreset640x480, | |
29 AVCaptureSessionPreset1280x720 | |
30 ]; | |
31 | |
32 #define IOS_UNSUPPORTED() \ | |
33 WEBRTC_TRACE(kTraceError, kTraceVideoCapture, _id, \ | |
34 "%s is not supported on the iOS platform.", __FUNCTION__); \ | |
35 return -1; | |
36 | |
37 VideoCaptureModule::DeviceInfo* VideoCaptureImpl::CreateDeviceInfo( | |
38 const int32_t device_id) { | |
39 return new DeviceInfoIos(device_id); | |
40 } | |
41 | |
42 DeviceInfoIos::DeviceInfoIos(const int32_t device_id) | |
43 : DeviceInfoImpl(device_id) { | |
44 this->Init(); | |
45 } | |
46 | |
47 DeviceInfoIos::~DeviceInfoIos() {} | |
48 | |
49 int32_t DeviceInfoIos::Init() { | |
50 // Fill in all device capabilities. | |
51 | |
52 int deviceCount = [DeviceInfoIosObjC captureDeviceCount]; | |
53 | |
54 for (int i = 0; i < deviceCount; i++) { | |
55 AVCaptureDevice* avDevice = [DeviceInfoIosObjC captureDeviceForIndex:i]; | |
56 VideoCaptureCapabilities capabilityVector; | |
57 | |
58 for (NSString* preset in camera_presets) { | |
59 BOOL support = [avDevice supportsAVCaptureSessionPreset:preset]; | |
60 if (support) { | |
61 VideoCaptureCapability capability = | |
62 [DeviceInfoIosObjC capabilityForPreset:preset]; | |
63 capabilityVector.push_back(capability); | |
64 } | |
65 } | |
66 | |
67 char deviceNameUTF8[256]; | |
68 char deviceId[256]; | |
69 this->GetDeviceName(i, deviceNameUTF8, 256, deviceId, 256); | |
70 std::string deviceIdCopy(deviceId); | |
71 std::pair<std::string, VideoCaptureCapabilities> mapPair = | |
72 std::pair<std::string, VideoCaptureCapabilities>(deviceIdCopy, | |
73 capabilityVector); | |
74 _capabilitiesMap.insert(mapPair); | |
75 } | |
76 | |
77 return 0; | |
78 } | |
79 | |
80 uint32_t DeviceInfoIos::NumberOfDevices() { | |
81 return [DeviceInfoIosObjC captureDeviceCount]; | |
82 } | |
83 | |
84 int32_t DeviceInfoIos::GetDeviceName(uint32_t deviceNumber, | |
85 char* deviceNameUTF8, | |
86 uint32_t deviceNameUTF8Length, | |
87 char* deviceUniqueIdUTF8, | |
88 uint32_t deviceUniqueIdUTF8Length, | |
89 char* productUniqueIdUTF8, | |
90 uint32_t productUniqueIdUTF8Length) { | |
91 NSString* deviceName = [DeviceInfoIosObjC deviceNameForIndex:deviceNumber]; | |
92 | |
93 NSString* deviceUniqueId = | |
94 [DeviceInfoIosObjC deviceUniqueIdForIndex:deviceNumber]; | |
95 | |
96 strncpy(deviceNameUTF8, [deviceName UTF8String], deviceNameUTF8Length); | |
97 deviceNameUTF8[deviceNameUTF8Length - 1] = '\0'; | |
98 | |
99 strncpy(deviceUniqueIdUTF8, deviceUniqueId.UTF8String, deviceUniqueIdUTF8Lengt
h); | |
100 deviceUniqueIdUTF8[deviceUniqueIdUTF8Length - 1] = '\0'; | |
101 | |
102 if (productUniqueIdUTF8) { | |
103 productUniqueIdUTF8[0] = '\0'; | |
104 } | |
105 | |
106 return 0; | |
107 } | |
108 | |
109 int32_t DeviceInfoIos::NumberOfCapabilities(const char* deviceUniqueIdUTF8) { | |
110 int32_t numberOfCapabilities = 0; | |
111 std::string deviceUniqueId(deviceUniqueIdUTF8); | |
112 std::map<std::string, VideoCaptureCapabilities>::iterator it = | |
113 _capabilitiesMap.find(deviceUniqueId); | |
114 | |
115 if (it != _capabilitiesMap.end()) { | |
116 numberOfCapabilities = it->second.size(); | |
117 } | |
118 return numberOfCapabilities; | |
119 } | |
120 | |
121 int32_t DeviceInfoIos::GetCapability(const char* deviceUniqueIdUTF8, | |
122 const uint32_t deviceCapabilityNumber, | |
123 VideoCaptureCapability& capability) { | |
124 std::string deviceUniqueId(deviceUniqueIdUTF8); | |
125 std::map<std::string, VideoCaptureCapabilities>::iterator it = | |
126 _capabilitiesMap.find(deviceUniqueId); | |
127 | |
128 if (it != _capabilitiesMap.end()) { | |
129 VideoCaptureCapabilities deviceCapabilities = it->second; | |
130 | |
131 if (deviceCapabilityNumber < deviceCapabilities.size()) { | |
132 VideoCaptureCapability cap; | |
133 cap = deviceCapabilities[deviceCapabilityNumber]; | |
134 capability = cap; | |
135 return 0; | |
136 } | |
137 } | |
138 | |
139 return -1; | |
140 } | |
141 | |
142 int32_t DeviceInfoIos::DisplayCaptureSettingsDialogBox( | |
143 const char* deviceUniqueIdUTF8, | |
144 const char* dialogTitleUTF8, | |
145 void* parentWindow, | |
146 uint32_t positionX, | |
147 uint32_t positionY) { | |
148 IOS_UNSUPPORTED(); | |
149 } | |
150 | |
151 int32_t DeviceInfoIos::GetOrientation(const char* deviceUniqueIdUTF8, | |
152 VideoRotation& orientation) { | |
153 if (strcmp(deviceUniqueIdUTF8, "Front Camera") == 0) { | |
154 orientation = kVideoRotation_0; | |
155 } else { | |
156 orientation = kVideoRotation_90; | |
157 } | |
158 return orientation; | |
159 } | |
160 | |
161 int32_t DeviceInfoIos::CreateCapabilityMap(const char* deviceUniqueIdUTF8) { | |
162 std::string deviceName(deviceUniqueIdUTF8); | |
163 std::map<std::string, std::vector<VideoCaptureCapability>>::iterator it = | |
164 _capabilitiesMap.find(deviceName); | |
165 VideoCaptureCapabilities deviceCapabilities; | |
166 if (it != _capabilitiesMap.end()) { | |
167 _captureCapabilities = it->second; | |
168 return 0; | |
169 } | |
170 | |
171 return -1; | |
172 } | |
OLD | NEW |