Implemented video device info for iOS

R=pbos@webrtc.org, tkchin@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/42189004

Patch from Yuriy Shevchuk <youwrk@gmail.com>.

Cr-Commit-Position: refs/heads/master@{#9190}
This commit is contained in:
Yuriy Shevchuk 2015-05-14 14:16:13 -07:00 committed by Zeke Chin
parent a4463b2b8a
commit 39f2b0c870
5 changed files with 135 additions and 20 deletions

View File

@ -200,15 +200,12 @@ bool WebRtcVideoCapturer::Init(const Device& device) {
}
}
factory_->DestroyDeviceInfo(info);
// TODO(fischman): Remove the following check
// when capabilities for iOS are implemented
// https://code.google.com/p/webrtc/issues/detail?id=2968
#if !defined(IOS)
if (supported.empty()) {
LOG(LS_ERROR) << "Failed to find usable formats for id: " << device.id;
return false;
}
#endif
module_ = factory_->Create(0, vcm_id);
if (!module_) {
LOG(LS_ERROR) << "Failed to create capturer for id: " << device.id;

View File

@ -13,6 +13,8 @@
#include "webrtc/modules/video_capture/device_info_impl.h"
#include <map>
namespace webrtc {
namespace videocapturemodule {
class DeviceInfoIos : public DeviceInfoImpl {
@ -37,10 +39,6 @@ class DeviceInfoIos : public DeviceInfoImpl {
const uint32_t deviceCapabilityNumber,
VideoCaptureCapability& capability) override;
int32_t GetBestMatchedCapability(const char* deviceUniqueIdUTF8,
const VideoCaptureCapability& requested,
VideoCaptureCapability& resulting) override;
int32_t DisplayCaptureSettingsDialogBox(const char* deviceUniqueIdUTF8,
const char* dialogTitleUTF8,
void* parentWindow,
@ -51,6 +49,9 @@ class DeviceInfoIos : public DeviceInfoImpl {
VideoRotation& orientation) override;
int32_t CreateCapabilityMap(const char* device_unique_id_utf8) override;
private:
std::map<std::string, VideoCaptureCapabilities> _capabilitiesMap;
};
} // namespace videocapturemodule

View File

@ -12,6 +12,10 @@
#error "This file requires ARC support."
#endif
#include <AVFoundation/AVFoundation.h>
#include <string>
#include "webrtc/modules/video_capture/ios/device_info_ios.h"
#include "webrtc/modules/video_capture/ios/device_info_ios_objc.h"
#include "webrtc/modules/video_capture/video_capture_impl.h"
@ -20,6 +24,12 @@
using namespace webrtc;
using namespace videocapturemodule;
static NSArray *camera_presets = @[AVCaptureSessionPreset352x288,
AVCaptureSessionPreset640x480,
AVCaptureSessionPreset1280x720,
AVCaptureSessionPreset1920x1080];
#define IOS_UNSUPPORTED() \
WEBRTC_TRACE(kTraceError, \
kTraceVideoCapture, \
@ -34,11 +44,42 @@ VideoCaptureModule::DeviceInfo* VideoCaptureImpl::CreateDeviceInfo(
}
DeviceInfoIos::DeviceInfoIos(const int32_t device_id)
: DeviceInfoImpl(device_id) {}
: DeviceInfoImpl(device_id) {
this->Init();
}
DeviceInfoIos::~DeviceInfoIos() {}
int32_t DeviceInfoIos::Init() { return 0; }
int32_t DeviceInfoIos::Init() {
// Fill in all device capabilities.
int deviceCount = [DeviceInfoIosObjC captureDeviceCount];
for (int i = 0; i < deviceCount; i++) {
AVCaptureDevice *avDevice = [DeviceInfoIosObjC captureDeviceForIndex:i];
VideoCaptureCapabilities capabilityVector;
for (NSString *preset in camera_presets) {
BOOL support = [avDevice supportsAVCaptureSessionPreset:preset];
if (support) {
VideoCaptureCapability capability =
[DeviceInfoIosObjC capabilityForPreset:preset];
capabilityVector.push_back(capability);
}
}
char deviceNameUTF8[256];
char deviceId[256];
this->GetDeviceName(i, deviceNameUTF8, 256, deviceId, 256);
std::string deviceIdCopy(deviceId);
std::pair<std::string, VideoCaptureCapabilities> mapPair =
std::pair<std::string, VideoCaptureCapabilities>
(deviceIdCopy, capabilityVector);
_capabilitiesMap.insert(mapPair);
}
return 0;
}
uint32_t DeviceInfoIos::NumberOfDevices() {
return [DeviceInfoIosObjC captureDeviceCount];
@ -72,20 +113,36 @@ int32_t DeviceInfoIos::GetDeviceName(uint32_t deviceNumber,
}
int32_t DeviceInfoIos::NumberOfCapabilities(const char* deviceUniqueIdUTF8) {
IOS_UNSUPPORTED();
int32_t numberOfCapabilities = 0;
std::string deviceUniqueId(deviceUniqueIdUTF8);
std::map<std::string, VideoCaptureCapabilities>::iterator it =
_capabilitiesMap.find(deviceUniqueId);
if (it != _capabilitiesMap.end()) {
numberOfCapabilities = it->second.size();
}
return numberOfCapabilities;
}
int32_t DeviceInfoIos::GetCapability(const char* deviceUniqueIdUTF8,
const uint32_t deviceCapabilityNumber,
VideoCaptureCapability& capability) {
IOS_UNSUPPORTED();
}
std::string deviceUniqueId(deviceUniqueIdUTF8);
std::map<std::string, VideoCaptureCapabilities>::iterator it =
_capabilitiesMap.find(deviceUniqueId);
int32_t DeviceInfoIos::GetBestMatchedCapability(
const char* deviceUniqueIdUTF8,
const VideoCaptureCapability& requested,
VideoCaptureCapability& resulting) {
IOS_UNSUPPORTED();
if (it != _capabilitiesMap.end()) {
VideoCaptureCapabilities deviceCapabilities = it->second;
if (deviceCapabilityNumber < deviceCapabilities.size()) {
VideoCaptureCapability cap;
cap = deviceCapabilities[deviceCapabilityNumber];
capability = cap;
return 0;
}
}
return -1;
}
int32_t DeviceInfoIos::DisplayCaptureSettingsDialogBox(
@ -108,5 +165,14 @@ int32_t DeviceInfoIos::GetOrientation(const char* deviceUniqueIdUTF8,
}
int32_t DeviceInfoIos::CreateCapabilityMap(const char* deviceUniqueIdUTF8) {
IOS_UNSUPPORTED();
std::string deviceName(deviceUniqueIdUTF8);
std::map<std::string, std::vector<VideoCaptureCapability>>::iterator it =
_capabilitiesMap.find(deviceName);
VideoCaptureCapabilities deviceCapabilities;
if (it != _capabilitiesMap.end()) {
_captureCapabilities = it->second;
return 0;
}
return -1;
}

View File

@ -13,6 +13,8 @@
#import <AVFoundation/AVFoundation.h>
#include "webrtc/modules/video_capture/include/video_capture_defines.h"
@interface DeviceInfoIosObjC : NSObject
+ (int)captureDeviceCount;
+ (AVCaptureDevice*)captureDeviceForIndex:(int)index;
@ -20,6 +22,8 @@
+ (NSString*)deviceNameForIndex:(int)index;
+ (NSString*)deviceUniqueIdForIndex:(int)index;
+ (NSString*)deviceNameForUniqueId:(NSString*)uniqueId;
+ (webrtc::VideoCaptureCapability)capabilityForPreset:(NSString*)preset;
@end
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_IOS_DEVICE_INFO_IOS_OBJC_H_

View File

@ -15,6 +15,7 @@
#import <AVFoundation/AVFoundation.h>
#import "webrtc/modules/video_capture/ios/device_info_ios_objc.h"
#include "webrtc/modules/video_capture/video_capture_config.h"
@implementation DeviceInfoIosObjC
@ -50,4 +51,50 @@
return [[AVCaptureDevice deviceWithUniqueID:uniqueId] localizedName];
}
+ (webrtc::VideoCaptureCapability)capabilityForPreset:(NSString*)preset {
webrtc::VideoCaptureCapability capability;
// TODO(tkchin): Maybe query AVCaptureDevice for supported formats, and
// then get the dimensions / frame rate from each supported format
if ([preset isEqualToString:AVCaptureSessionPreset352x288]) {
capability.width = 352;
capability.height = 288;
capability.maxFPS = 30;
capability.expectedCaptureDelay =
webrtc::videocapturemodule::kDefaultCaptureDelay;
capability.rawType = webrtc::kVideoNV12;
capability.codecType = webrtc::kVideoCodecUnknown;
capability.interlaced = false;
} else if ([preset isEqualToString:AVCaptureSessionPreset640x480]) {
capability.width = 640;
capability.height = 480;
capability.maxFPS = 30;
capability.expectedCaptureDelay =
webrtc::videocapturemodule::kDefaultCaptureDelay;
capability.rawType = webrtc::kVideoNV12;
capability.codecType = webrtc::kVideoCodecUnknown;
capability.interlaced = false;
} else if ([preset isEqualToString:AVCaptureSessionPreset1280x720]) {
capability.width = 1280;
capability.height = 720;
capability.maxFPS = 30;
capability.expectedCaptureDelay =
webrtc::videocapturemodule::kDefaultCaptureDelay;
capability.rawType = webrtc::kVideoNV12;
capability.codecType = webrtc::kVideoCodecUnknown;
capability.interlaced = false;
} else if ([preset isEqualToString:AVCaptureSessionPreset1920x1080]) {
capability.width = 1920;
capability.height = 1080;
capability.maxFPS = 30;
capability.expectedCaptureDelay =
webrtc::videocapturemodule::kDefaultCaptureDelay;
capability.rawType = webrtc::kVideoNV12;
capability.codecType = webrtc::kVideoCodecUnknown;
capability.interlaced = false;
}
return capability;
}
@end