| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #if !defined(__has_feature) || !__has_feature(objc_arc) | 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 12 #error "This file requires ARC support." | 12 #error "This file requires ARC support." |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 #include <AVFoundation/AVFoundation.h> | 15 #include <AVFoundation/AVFoundation.h> |
| 16 | 16 |
| 17 #include <string> | 17 #include <string> |
| 18 | 18 |
| 19 #include "webrtc/modules/video_capture/ios/device_info_ios.h" | 19 #include "webrtc/modules/video_capture/objc/device_info.h" |
| 20 #include "webrtc/modules/video_capture/ios/device_info_ios_objc.h" | 20 #include "webrtc/modules/video_capture/objc/device_info_objc.h" |
| 21 #include "webrtc/modules/video_capture/video_capture_impl.h" | 21 #include "webrtc/modules/video_capture/video_capture_impl.h" |
| 22 #include "webrtc/system_wrappers/include/trace.h" | 22 #include "webrtc/system_wrappers/include/trace.h" |
| 23 | 23 |
| 24 using namespace webrtc; | 24 using namespace webrtc; |
| 25 using namespace videocapturemodule; | 25 using namespace videocapturemodule; |
| 26 | 26 |
| 27 static NSArray *camera_presets = @[AVCaptureSessionPreset352x288, | 27 static NSArray* camera_presets = @[ |
| 28 AVCaptureSessionPreset640x480, | 28 AVCaptureSessionPreset352x288, AVCaptureSessionPreset640x480, |
| 29 AVCaptureSessionPreset1280x720, | 29 AVCaptureSessionPreset1280x720 |
| 30 AVCaptureSessionPreset1920x1080]; | 30 ]; |
| 31 | 31 |
| 32 | 32 #define IOS_UNSUPPORTED() \ |
| 33 #define IOS_UNSUPPORTED() \ | 33 WEBRTC_TRACE(kTraceError, kTraceVideoCapture, _id, \ |
| 34 WEBRTC_TRACE(kTraceError, \ | 34 "%s is not supported on the iOS platform.", __FUNCTION__); \ |
| 35 kTraceVideoCapture, \ | |
| 36 _id, \ | |
| 37 "%s is not supported on the iOS platform.", \ | |
| 38 __FUNCTION__); \ | |
| 39 return -1; | 35 return -1; |
| 40 | 36 |
| 41 VideoCaptureModule::DeviceInfo* VideoCaptureImpl::CreateDeviceInfo( | 37 VideoCaptureModule::DeviceInfo* VideoCaptureImpl::CreateDeviceInfo( |
| 42 const int32_t device_id) { | 38 const int32_t device_id) { |
| 43 return new DeviceInfoIos(device_id); | 39 return new DeviceInfoIos(device_id); |
| 44 } | 40 } |
| 45 | 41 |
| 46 DeviceInfoIos::DeviceInfoIos(const int32_t device_id) | 42 DeviceInfoIos::DeviceInfoIos(const int32_t device_id) |
| 47 : DeviceInfoImpl(device_id) { | 43 : DeviceInfoImpl(device_id) { |
| 48 this->Init(); | 44 this->Init(); |
| 49 } | 45 } |
| 50 | 46 |
| 51 DeviceInfoIos::~DeviceInfoIos() {} | 47 DeviceInfoIos::~DeviceInfoIos() {} |
| 52 | 48 |
| 53 int32_t DeviceInfoIos::Init() { | 49 int32_t DeviceInfoIos::Init() { |
| 54 // Fill in all device capabilities. | 50 // Fill in all device capabilities. |
| 55 | 51 |
| 56 int deviceCount = [DeviceInfoIosObjC captureDeviceCount]; | 52 int deviceCount = [DeviceInfoIosObjC captureDeviceCount]; |
| 57 | 53 |
| 58 for (int i = 0; i < deviceCount; i++) { | 54 for (int i = 0; i < deviceCount; i++) { |
| 59 AVCaptureDevice *avDevice = [DeviceInfoIosObjC captureDeviceForIndex:i]; | 55 AVCaptureDevice* avDevice = [DeviceInfoIosObjC captureDeviceForIndex:i]; |
| 60 VideoCaptureCapabilities capabilityVector; | 56 VideoCaptureCapabilities capabilityVector; |
| 61 | 57 |
| 62 for (NSString *preset in camera_presets) { | 58 for (NSString* preset in camera_presets) { |
| 63 BOOL support = [avDevice supportsAVCaptureSessionPreset:preset]; | 59 BOOL support = [avDevice supportsAVCaptureSessionPreset:preset]; |
| 64 if (support) { | 60 if (support) { |
| 65 VideoCaptureCapability capability = | 61 VideoCaptureCapability capability = |
| 66 [DeviceInfoIosObjC capabilityForPreset:preset]; | 62 [DeviceInfoIosObjC capabilityForPreset:preset]; |
| 67 capabilityVector.push_back(capability); | 63 capabilityVector.push_back(capability); |
| 68 } | 64 } |
| 69 } | 65 } |
| 70 | 66 |
| 71 char deviceNameUTF8[256]; | 67 char deviceNameUTF8[256]; |
| 72 char deviceId[256]; | 68 char deviceId[256]; |
| 73 this->GetDeviceName(i, deviceNameUTF8, 256, deviceId, 256); | 69 this->GetDeviceName(i, deviceNameUTF8, 256, deviceId, 256); |
| 74 std::string deviceIdCopy(deviceId); | 70 std::string deviceIdCopy(deviceId); |
| 75 std::pair<std::string, VideoCaptureCapabilities> mapPair = | 71 std::pair<std::string, VideoCaptureCapabilities> mapPair = |
| 76 std::pair<std::string, VideoCaptureCapabilities> | 72 std::pair<std::string, VideoCaptureCapabilities>(deviceIdCopy, |
| 77 (deviceIdCopy, capabilityVector); | 73 capabilityVector); |
| 78 _capabilitiesMap.insert(mapPair); | 74 _capabilitiesMap.insert(mapPair); |
| 79 } | 75 } |
| 80 | 76 |
| 81 return 0; | 77 return 0; |
| 82 } | 78 } |
| 83 | 79 |
| 84 uint32_t DeviceInfoIos::NumberOfDevices() { | 80 uint32_t DeviceInfoIos::NumberOfDevices() { |
| 85 return [DeviceInfoIosObjC captureDeviceCount]; | 81 return [DeviceInfoIosObjC captureDeviceCount]; |
| 86 } | 82 } |
| 87 | 83 |
| 88 int32_t DeviceInfoIos::GetDeviceName(uint32_t deviceNumber, | 84 int32_t DeviceInfoIos::GetDeviceName(uint32_t deviceNumber, |
| 89 char* deviceNameUTF8, | 85 char* deviceNameUTF8, |
| 90 uint32_t deviceNameUTF8Length, | 86 uint32_t deviceNameUTF8Length, |
| 91 char* deviceUniqueIdUTF8, | 87 char* deviceUniqueIdUTF8, |
| 92 uint32_t deviceUniqueIdUTF8Length, | 88 uint32_t deviceUniqueIdUTF8Length, |
| 93 char* productUniqueIdUTF8, | 89 char* productUniqueIdUTF8, |
| 94 uint32_t productUniqueIdUTF8Length) { | 90 uint32_t productUniqueIdUTF8Length) { |
| 95 NSString* deviceName = [DeviceInfoIosObjC deviceNameForIndex:deviceNumber]; | 91 NSString* deviceName = [DeviceInfoIosObjC deviceNameForIndex:deviceNumber]; |
| 96 | 92 |
| 97 NSString* deviceUniqueId = | 93 NSString* deviceUniqueId = |
| 98 [DeviceInfoIosObjC deviceUniqueIdForIndex:deviceNumber]; | 94 [DeviceInfoIosObjC deviceUniqueIdForIndex:deviceNumber]; |
| 99 | 95 |
| 100 strncpy(deviceNameUTF8, [deviceName UTF8String], deviceNameUTF8Length); | 96 strncpy(deviceNameUTF8, [deviceName UTF8String], deviceNameUTF8Length); |
| 101 deviceNameUTF8[deviceNameUTF8Length - 1] = '\0'; | 97 deviceNameUTF8[deviceNameUTF8Length - 1] = '\0'; |
| 102 | 98 |
| 103 strncpy(deviceUniqueIdUTF8, | 99 strncpy(deviceUniqueIdUTF8, deviceUniqueId.UTF8String, deviceUniqueIdUTF8Lengt
h); |
| 104 [deviceUniqueId UTF8String], | |
| 105 deviceUniqueIdUTF8Length); | |
| 106 deviceUniqueIdUTF8[deviceUniqueIdUTF8Length - 1] = '\0'; | 100 deviceUniqueIdUTF8[deviceUniqueIdUTF8Length - 1] = '\0'; |
| 107 | 101 |
| 108 if (productUniqueIdUTF8) { | 102 if (productUniqueIdUTF8) { |
| 109 productUniqueIdUTF8[0] = '\0'; | 103 productUniqueIdUTF8[0] = '\0'; |
| 110 } | 104 } |
| 111 | 105 |
| 112 return 0; | 106 return 0; |
| 113 } | 107 } |
| 114 | 108 |
| 115 int32_t DeviceInfoIos::NumberOfCapabilities(const char* deviceUniqueIdUTF8) { | 109 int32_t DeviceInfoIos::NumberOfCapabilities(const char* deviceUniqueIdUTF8) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 std::map<std::string, std::vector<VideoCaptureCapability>>::iterator it = | 163 std::map<std::string, std::vector<VideoCaptureCapability>>::iterator it = |
| 170 _capabilitiesMap.find(deviceName); | 164 _capabilitiesMap.find(deviceName); |
| 171 VideoCaptureCapabilities deviceCapabilities; | 165 VideoCaptureCapabilities deviceCapabilities; |
| 172 if (it != _capabilitiesMap.end()) { | 166 if (it != _capabilitiesMap.end()) { |
| 173 _captureCapabilities = it->second; | 167 _captureCapabilities = it->second; |
| 174 return 0; | 168 return 0; |
| 175 } | 169 } |
| 176 | 170 |
| 177 return -1; | 171 return -1; |
| 178 } | 172 } |
| OLD | NEW |