Revert of Unify the macOS and iOS capturer implementations (patchset #4 id:60001 of https://codereview.webrtc.org/2309253005/ )
Reason for revert: Breaks internal project Original issue's description: > Unify the macOS and iOS capturer implementations > > This removes the QTKit based capturer for mac, and removes the need > to link against deprecated system libraries on macOS. > > BUG=webrtc:3968,webrtc:6275,webrtc:6333 > > Committed: https://crrev.com/242d8bdddd77109781cbb70c59d161be7566ac98 > Cr-Commit-Position: refs/heads/master@{#14418} TBR=magjed@webrtc.org,tkchin@webrtc.org,perkj@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=webrtc:3968,webrtc:6275,webrtc:6333 Review-Url: https://codereview.webrtc.org/2381853002 Cr-Commit-Position: refs/heads/master@{#14429}
This commit is contained in:
parent
ff9793c600
commit
eddb7571d8
@ -60,7 +60,7 @@ rtc_static_library("video_capture") {
|
|||||||
|
|
||||||
if (!build_with_chromium) {
|
if (!build_with_chromium) {
|
||||||
config("video_capture_internal_impl_config") {
|
config("video_capture_internal_impl_config") {
|
||||||
if (is_ios || is_mac) {
|
if (is_ios) {
|
||||||
libs = [
|
libs = [
|
||||||
"AVFoundation.framework",
|
"AVFoundation.framework",
|
||||||
"CoreMedia.framework",
|
"CoreMedia.framework",
|
||||||
@ -104,6 +104,30 @@ if (!build_with_chromium) {
|
|||||||
]
|
]
|
||||||
deps += [ "../..:webrtc_common" ]
|
deps += [ "../..:webrtc_common" ]
|
||||||
}
|
}
|
||||||
|
if (is_mac) {
|
||||||
|
sources = [
|
||||||
|
"mac/qtkit/video_capture_qtkit.h",
|
||||||
|
"mac/qtkit/video_capture_qtkit.mm",
|
||||||
|
"mac/qtkit/video_capture_qtkit_info.h",
|
||||||
|
"mac/qtkit/video_capture_qtkit_info.mm",
|
||||||
|
"mac/qtkit/video_capture_qtkit_info_objc.h",
|
||||||
|
"mac/qtkit/video_capture_qtkit_info_objc.mm",
|
||||||
|
"mac/qtkit/video_capture_qtkit_objc.h",
|
||||||
|
"mac/qtkit/video_capture_qtkit_objc.mm",
|
||||||
|
"mac/qtkit/video_capture_qtkit_utility.h",
|
||||||
|
"mac/video_capture_mac.mm",
|
||||||
|
]
|
||||||
|
|
||||||
|
libs = [
|
||||||
|
# For NSAlert in video_capture_qtkit_info_objc.mm.
|
||||||
|
"Cocoa.framework",
|
||||||
|
|
||||||
|
# For GetGestalt in video_capture_mac.mm.
|
||||||
|
"CoreServices.framework",
|
||||||
|
"CoreVideo.framework",
|
||||||
|
"QTKit.framework",
|
||||||
|
]
|
||||||
|
}
|
||||||
if (is_win) {
|
if (is_win) {
|
||||||
sources = [
|
sources = [
|
||||||
"windows/device_info_ds.cc",
|
"windows/device_info_ds.cc",
|
||||||
@ -125,16 +149,16 @@ if (!build_with_chromium) {
|
|||||||
|
|
||||||
deps += [ "//third_party/winsdk_samples" ]
|
deps += [ "//third_party/winsdk_samples" ]
|
||||||
}
|
}
|
||||||
if (is_ios || is_mac) {
|
if (is_ios) {
|
||||||
sources = [
|
sources = [
|
||||||
"objc/device_info.h",
|
"ios/device_info_ios.h",
|
||||||
"objc/device_info.mm",
|
"ios/device_info_ios.mm",
|
||||||
"objc/device_info_objc.h",
|
"ios/device_info_ios_objc.h",
|
||||||
"objc/device_info_objc.mm",
|
"ios/device_info_ios_objc.mm",
|
||||||
"objc/rtc_video_capture_objc.h",
|
"ios/rtc_video_capture_ios_objc.h",
|
||||||
"objc/rtc_video_capture_objc.mm",
|
"ios/rtc_video_capture_ios_objc.mm",
|
||||||
"objc/video_capture.h",
|
"ios/video_capture_ios.h",
|
||||||
"objc/video_capture.mm",
|
"ios/video_capture_ios.mm",
|
||||||
]
|
]
|
||||||
|
|
||||||
cflags = [
|
cflags = [
|
||||||
@ -159,6 +183,7 @@ if (!build_with_chromium) {
|
|||||||
if (!is_android && rtc_include_tests) {
|
if (!is_android && rtc_include_tests) {
|
||||||
rtc_test("video_capture_tests") {
|
rtc_test("video_capture_tests") {
|
||||||
sources = [
|
sources = [
|
||||||
|
"test/video_capture_main_mac.mm",
|
||||||
"test/video_capture_unittest.cc",
|
"test/video_capture_unittest.cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -190,7 +215,11 @@ if (!build_with_chromium) {
|
|||||||
"../utility",
|
"../utility",
|
||||||
"//testing/gtest",
|
"//testing/gtest",
|
||||||
]
|
]
|
||||||
deps += [ "//webrtc/test:test_support_main" ]
|
if (is_mac) {
|
||||||
|
deps += [ "//webrtc/test:test_support_main_threaded_mac" ]
|
||||||
|
} else {
|
||||||
|
deps += [ "//webrtc/test:test_support_main" ]
|
||||||
|
}
|
||||||
|
|
||||||
if (is_clang) {
|
if (is_clang) {
|
||||||
# Suppress warnings from Chrome's Clang plugins.
|
# Suppress warnings from Chrome's Clang plugins.
|
||||||
|
|||||||
@ -8,13 +8,12 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_OBJC_DEVICE_INFO_H_
|
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_IOS_DEVICE_INFO_IOS_H_
|
||||||
#define WEBRTC_MODULES_VIDEO_CAPTURE_OBJC_DEVICE_INFO_H_
|
#define WEBRTC_MODULES_VIDEO_CAPTURE_IOS_DEVICE_INFO_IOS_H_
|
||||||
|
|
||||||
#include "webrtc/modules/video_capture/device_info_impl.h"
|
#include "webrtc/modules/video_capture/device_info_impl.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace videocapturemodule {
|
namespace videocapturemodule {
|
||||||
@ -58,4 +57,4 @@ class DeviceInfoIos : public DeviceInfoImpl {
|
|||||||
} // namespace videocapturemodule
|
} // namespace videocapturemodule
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_OBJC_DEVICE_INFO_H_
|
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_IOS_DEVICE_INFO_IOS_H_
|
||||||
@ -16,22 +16,26 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "webrtc/modules/video_capture/objc/device_info.h"
|
#include "webrtc/modules/video_capture/ios/device_info_ios.h"
|
||||||
#include "webrtc/modules/video_capture/objc/device_info_objc.h"
|
#include "webrtc/modules/video_capture/ios/device_info_ios_objc.h"
|
||||||
#include "webrtc/modules/video_capture/video_capture_impl.h"
|
#include "webrtc/modules/video_capture/video_capture_impl.h"
|
||||||
#include "webrtc/system_wrappers/include/trace.h"
|
#include "webrtc/system_wrappers/include/trace.h"
|
||||||
|
|
||||||
using namespace webrtc;
|
using namespace webrtc;
|
||||||
using namespace videocapturemodule;
|
using namespace videocapturemodule;
|
||||||
|
|
||||||
static NSArray* camera_presets = @[
|
static NSArray *camera_presets = @[AVCaptureSessionPreset352x288,
|
||||||
AVCaptureSessionPreset352x288, AVCaptureSessionPreset640x480,
|
AVCaptureSessionPreset640x480,
|
||||||
AVCaptureSessionPreset1280x720
|
AVCaptureSessionPreset1280x720,
|
||||||
];
|
AVCaptureSessionPreset1920x1080];
|
||||||
|
|
||||||
#define IOS_UNSUPPORTED() \
|
|
||||||
WEBRTC_TRACE(kTraceError, kTraceVideoCapture, _id, \
|
#define IOS_UNSUPPORTED() \
|
||||||
"%s is not supported on the iOS platform.", __FUNCTION__); \
|
WEBRTC_TRACE(kTraceError, \
|
||||||
|
kTraceVideoCapture, \
|
||||||
|
_id, \
|
||||||
|
"%s is not supported on the iOS platform.", \
|
||||||
|
__FUNCTION__); \
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
VideoCaptureModule::DeviceInfo* VideoCaptureImpl::CreateDeviceInfo(
|
VideoCaptureModule::DeviceInfo* VideoCaptureImpl::CreateDeviceInfo(
|
||||||
@ -52,10 +56,10 @@ int32_t DeviceInfoIos::Init() {
|
|||||||
int deviceCount = [DeviceInfoIosObjC captureDeviceCount];
|
int deviceCount = [DeviceInfoIosObjC captureDeviceCount];
|
||||||
|
|
||||||
for (int i = 0; i < deviceCount; i++) {
|
for (int i = 0; i < deviceCount; i++) {
|
||||||
AVCaptureDevice* avDevice = [DeviceInfoIosObjC captureDeviceForIndex:i];
|
AVCaptureDevice *avDevice = [DeviceInfoIosObjC captureDeviceForIndex:i];
|
||||||
VideoCaptureCapabilities capabilityVector;
|
VideoCaptureCapabilities capabilityVector;
|
||||||
|
|
||||||
for (NSString* preset in camera_presets) {
|
for (NSString *preset in camera_presets) {
|
||||||
BOOL support = [avDevice supportsAVCaptureSessionPreset:preset];
|
BOOL support = [avDevice supportsAVCaptureSessionPreset:preset];
|
||||||
if (support) {
|
if (support) {
|
||||||
VideoCaptureCapability capability =
|
VideoCaptureCapability capability =
|
||||||
@ -69,8 +73,8 @@ int32_t DeviceInfoIos::Init() {
|
|||||||
this->GetDeviceName(i, deviceNameUTF8, 256, deviceId, 256);
|
this->GetDeviceName(i, deviceNameUTF8, 256, deviceId, 256);
|
||||||
std::string deviceIdCopy(deviceId);
|
std::string deviceIdCopy(deviceId);
|
||||||
std::pair<std::string, VideoCaptureCapabilities> mapPair =
|
std::pair<std::string, VideoCaptureCapabilities> mapPair =
|
||||||
std::pair<std::string, VideoCaptureCapabilities>(deviceIdCopy,
|
std::pair<std::string, VideoCaptureCapabilities>
|
||||||
capabilityVector);
|
(deviceIdCopy, capabilityVector);
|
||||||
_capabilitiesMap.insert(mapPair);
|
_capabilitiesMap.insert(mapPair);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +100,9 @@ int32_t DeviceInfoIos::GetDeviceName(uint32_t deviceNumber,
|
|||||||
strncpy(deviceNameUTF8, [deviceName UTF8String], deviceNameUTF8Length);
|
strncpy(deviceNameUTF8, [deviceName UTF8String], deviceNameUTF8Length);
|
||||||
deviceNameUTF8[deviceNameUTF8Length - 1] = '\0';
|
deviceNameUTF8[deviceNameUTF8Length - 1] = '\0';
|
||||||
|
|
||||||
strncpy(deviceUniqueIdUTF8, deviceUniqueId.UTF8String, deviceUniqueIdUTF8Length);
|
strncpy(deviceUniqueIdUTF8,
|
||||||
|
[deviceUniqueId UTF8String],
|
||||||
|
deviceUniqueIdUTF8Length);
|
||||||
deviceUniqueIdUTF8[deviceUniqueIdUTF8Length - 1] = '\0';
|
deviceUniqueIdUTF8[deviceUniqueIdUTF8Length - 1] = '\0';
|
||||||
|
|
||||||
if (productUniqueIdUTF8) {
|
if (productUniqueIdUTF8) {
|
||||||
@ -8,8 +8,8 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_OBJC_DEVICE_INFO_OBJC_H_
|
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_IOS_DEVICE_INFO_IOS_OBJC_H_
|
||||||
#define WEBRTC_MODULES_VIDEO_CAPTURE_OBJC_DEVICE_INFO_OBJC_H_
|
#define WEBRTC_MODULES_VIDEO_CAPTURE_IOS_DEVICE_INFO_IOS_OBJC_H_
|
||||||
|
|
||||||
#import <AVFoundation/AVFoundation.h>
|
#import <AVFoundation/AVFoundation.h>
|
||||||
|
|
||||||
@ -26,4 +26,4 @@
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_OBJC_DEVICE_INFO_OBJC_H_
|
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_IOS_DEVICE_INFO_IOS_OBJC_H_
|
||||||
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#import <AVFoundation/AVFoundation.h>
|
#import <AVFoundation/AVFoundation.h>
|
||||||
|
|
||||||
#import "webrtc/modules/video_capture/objc/device_info_objc.h"
|
#import "webrtc/modules/video_capture/ios/device_info_ios_objc.h"
|
||||||
#include "webrtc/modules/video_capture/video_capture_config.h"
|
#include "webrtc/modules/video_capture/video_capture_config.h"
|
||||||
|
|
||||||
@implementation DeviceInfoIosObjC
|
@implementation DeviceInfoIosObjC
|
||||||
@ -83,6 +83,15 @@
|
|||||||
capability.rawType = webrtc::kVideoNV12;
|
capability.rawType = webrtc::kVideoNV12;
|
||||||
capability.codecType = webrtc::kVideoCodecUnknown;
|
capability.codecType = webrtc::kVideoCodecUnknown;
|
||||||
capability.interlaced = false;
|
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;
|
return capability;
|
||||||
@ -8,15 +8,13 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_OBJC_RTC_VIDEO_CAPTURE_OBJC_H_
|
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_IOS_VIDEO_CAPTURE_IOS_OBJC_H_
|
||||||
#define WEBRTC_MODULES_VIDEO_CAPTURE_OBJC_RTC_VIDEO_CAPTURE_OBJC_H_
|
#define WEBRTC_MODULES_VIDEO_CAPTURE_IOS_VIDEO_CAPTURE_IOS_OBJC_H_
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#ifdef WEBRTC_IOS
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "webrtc/modules/video_capture/objc/video_capture.h"
|
#include "webrtc/modules/video_capture/ios/video_capture_ios.h"
|
||||||
|
|
||||||
// The following class listens to a notification with name:
|
// The following class listens to a notification with name:
|
||||||
// 'StatusBarOrientationDidChange'.
|
// 'StatusBarOrientationDidChange'.
|
||||||
@ -34,8 +32,8 @@
|
|||||||
captureId:(int)captureId;
|
captureId:(int)captureId;
|
||||||
- (BOOL)setCaptureDeviceByUniqueId:(NSString*)uniqueId;
|
- (BOOL)setCaptureDeviceByUniqueId:(NSString*)uniqueId;
|
||||||
- (BOOL)startCaptureWithCapability:
|
- (BOOL)startCaptureWithCapability:
|
||||||
(const webrtc::VideoCaptureCapability&)capability;
|
(const webrtc::VideoCaptureCapability&)capability;
|
||||||
- (BOOL)stopCapture;
|
- (BOOL)stopCapture;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_OBJC_RTC_VIDEO_CAPTURE_OBJC_H_
|
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_IOS_VIDEO_CAPTURE_IOS_OBJC_H_
|
||||||
@ -12,13 +12,10 @@
|
|||||||
#error "This file requires ARC support."
|
#error "This file requires ARC support."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#import <AVFoundation/AVFoundation.h>
|
|
||||||
#ifdef WEBRTC_IOS
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#import "webrtc/modules/video_capture/objc/device_info_objc.h"
|
#import "webrtc/modules/video_capture/ios/device_info_ios_objc.h"
|
||||||
#import "webrtc/modules/video_capture/objc/rtc_video_capture_objc.h"
|
#import "webrtc/modules/video_capture/ios/rtc_video_capture_ios_objc.h"
|
||||||
|
|
||||||
#include "webrtc/system_wrappers/include/trace.h"
|
#include "webrtc/system_wrappers/include/trace.h"
|
||||||
|
|
||||||
@ -47,8 +44,7 @@ using namespace webrtc::videocapturemodule;
|
|||||||
_owner = owner;
|
_owner = owner;
|
||||||
_captureId = captureId;
|
_captureId = captureId;
|
||||||
_captureSession = [[AVCaptureSession alloc] init];
|
_captureSession = [[AVCaptureSession alloc] init];
|
||||||
#if defined(__IPHONE_7_0) && defined(__IPHONE_OS_VERSION_MAX_ALLOWED) \
|
#if defined(__IPHONE_7_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
|
||||||
&& __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0
|
|
||||||
NSString* version = [[UIDevice currentDevice] systemVersion];
|
NSString* version = [[UIDevice currentDevice] systemVersion];
|
||||||
if ([version integerValue] >= 7) {
|
if ([version integerValue] >= 7) {
|
||||||
_captureSession.usesApplicationAudioSession = NO;
|
_captureSession.usesApplicationAudioSession = NO;
|
||||||
@ -76,12 +72,15 @@ using namespace webrtc::videocapturemodule;
|
|||||||
if ([_captureSession canAddOutput:captureOutput]) {
|
if ([_captureSession canAddOutput:captureOutput]) {
|
||||||
[_captureSession addOutput:captureOutput];
|
[_captureSession addOutput:captureOutput];
|
||||||
} else {
|
} else {
|
||||||
WEBRTC_TRACE(kTraceError, kTraceVideoCapture, _captureId,
|
WEBRTC_TRACE(kTraceError,
|
||||||
|
kTraceVideoCapture,
|
||||||
|
_captureId,
|
||||||
"%s:%s:%d Could not add output to AVCaptureSession ",
|
"%s:%s:%d Could not add output to AVCaptureSession ",
|
||||||
__FILE__, __FUNCTION__, __LINE__);
|
__FILE__,
|
||||||
|
__FUNCTION__,
|
||||||
|
__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WEBRTC_IOS
|
|
||||||
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
|
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
|
||||||
|
|
||||||
NSNotificationCenter* notify = [NSNotificationCenter defaultCenter];
|
NSNotificationCenter* notify = [NSNotificationCenter defaultCenter];
|
||||||
@ -93,7 +92,6 @@ using namespace webrtc::videocapturemodule;
|
|||||||
selector:@selector(deviceOrientationDidChange:)
|
selector:@selector(deviceOrientationDidChange:)
|
||||||
name:UIDeviceOrientationDidChangeNotification
|
name:UIDeviceOrientationDidChangeNotification
|
||||||
object:nil];
|
object:nil];
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
@ -146,7 +144,12 @@ using namespace webrtc::videocapturemodule;
|
|||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([_captureSession canSetSessionPreset:AVCaptureSessionPreset1280x720]) {
|
if ([_captureSession canSetSessionPreset:AVCaptureSessionPreset1920x1080]) {
|
||||||
|
if (capability.width > 1920 || capability.height > 1080) {
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
} else if ([_captureSession
|
||||||
|
canSetSessionPreset:AVCaptureSessionPreset1280x720]) {
|
||||||
if (capability.width > 1280 || capability.height > 720) {
|
if (capability.width > 1280 || capability.height > 720) {
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
@ -174,10 +177,9 @@ using namespace webrtc::videocapturemodule;
|
|||||||
|
|
||||||
_orientationHasChanged = NO;
|
_orientationHasChanged = NO;
|
||||||
_captureChanging = YES;
|
_captureChanging = YES;
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
dispatch_async(
|
||||||
^{
|
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
||||||
[self startCaptureInBackgroundWithOutput:currentOutput];
|
^(void) { [self startCaptureInBackgroundWithOutput:currentOutput]; });
|
||||||
});
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,10 +188,13 @@ using namespace webrtc::videocapturemodule;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)startCaptureInBackgroundWithOutput:
|
- (void)startCaptureInBackgroundWithOutput:
|
||||||
(AVCaptureVideoDataOutput*)currentOutput {
|
(AVCaptureVideoDataOutput*)currentOutput {
|
||||||
NSString* captureQuality =
|
NSString* captureQuality =
|
||||||
[NSString stringWithString:AVCaptureSessionPresetLow];
|
[NSString stringWithString:AVCaptureSessionPresetLow];
|
||||||
if (_capability.width >= 1280 || _capability.height >= 720) {
|
if (_capability.width >= 1920 || _capability.height >= 1080) {
|
||||||
|
captureQuality =
|
||||||
|
[NSString stringWithString:AVCaptureSessionPreset1920x1080];
|
||||||
|
} else if (_capability.width >= 1280 || _capability.height >= 720) {
|
||||||
captureQuality = [NSString stringWithString:AVCaptureSessionPreset1280x720];
|
captureQuality = [NSString stringWithString:AVCaptureSessionPreset1280x720];
|
||||||
} else if (_capability.width >= 640 || _capability.height >= 480) {
|
} else if (_capability.width >= 640 || _capability.height >= 480) {
|
||||||
captureQuality = [NSString stringWithString:AVCaptureSessionPreset640x480];
|
captureQuality = [NSString stringWithString:AVCaptureSessionPreset640x480];
|
||||||
@ -203,6 +208,30 @@ using namespace webrtc::videocapturemodule;
|
|||||||
// picture resolution
|
// picture resolution
|
||||||
[_captureSession setSessionPreset:captureQuality];
|
[_captureSession setSessionPreset:captureQuality];
|
||||||
|
|
||||||
|
// take care of capture framerate now
|
||||||
|
NSArray* sessionInputs = _captureSession.inputs;
|
||||||
|
AVCaptureDeviceInput* deviceInput = [sessionInputs count] > 0 ?
|
||||||
|
sessionInputs[0] : nil;
|
||||||
|
AVCaptureDevice* inputDevice = deviceInput.device;
|
||||||
|
if (inputDevice) {
|
||||||
|
AVCaptureDeviceFormat* activeFormat = inputDevice.activeFormat;
|
||||||
|
NSArray* supportedRanges = activeFormat.videoSupportedFrameRateRanges;
|
||||||
|
AVFrameRateRange* targetRange = [supportedRanges count] > 0 ?
|
||||||
|
supportedRanges[0] : nil;
|
||||||
|
// Find the largest supported framerate less than capability maxFPS.
|
||||||
|
for (AVFrameRateRange* range in supportedRanges) {
|
||||||
|
if (range.maxFrameRate <= _capability.maxFPS &&
|
||||||
|
targetRange.maxFrameRate <= range.maxFrameRate) {
|
||||||
|
targetRange = range;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (targetRange && [inputDevice lockForConfiguration:NULL]) {
|
||||||
|
inputDevice.activeVideoMinFrameDuration = targetRange.minFrameDuration;
|
||||||
|
inputDevice.activeVideoMaxFrameDuration = targetRange.minFrameDuration;
|
||||||
|
[inputDevice unlockForConfiguration];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_connection = [currentOutput connectionWithMediaType:AVMediaTypeVideo];
|
_connection = [currentOutput connectionWithMediaType:AVMediaTypeVideo];
|
||||||
[self setRelativeVideoOrientation];
|
[self setRelativeVideoOrientation];
|
||||||
|
|
||||||
@ -217,47 +246,49 @@ using namespace webrtc::videocapturemodule;
|
|||||||
if (!_connection.supportsVideoOrientation) {
|
if (!_connection.supportsVideoOrientation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#ifndef WEBRTC_IOS
|
|
||||||
_connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;
|
|
||||||
return;
|
|
||||||
#else
|
|
||||||
switch ([UIDevice currentDevice].orientation) {
|
switch ([UIDevice currentDevice].orientation) {
|
||||||
case UIDeviceOrientationPortrait:
|
case UIDeviceOrientationPortrait:
|
||||||
_connection.videoOrientation = AVCaptureVideoOrientationPortrait;
|
_connection.videoOrientation =
|
||||||
|
AVCaptureVideoOrientationPortrait;
|
||||||
break;
|
break;
|
||||||
case UIDeviceOrientationPortraitUpsideDown:
|
case UIDeviceOrientationPortraitUpsideDown:
|
||||||
_connection.videoOrientation =
|
_connection.videoOrientation =
|
||||||
AVCaptureVideoOrientationPortraitUpsideDown;
|
AVCaptureVideoOrientationPortraitUpsideDown;
|
||||||
break;
|
break;
|
||||||
case UIDeviceOrientationLandscapeLeft:
|
case UIDeviceOrientationLandscapeLeft:
|
||||||
_connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight;
|
_connection.videoOrientation =
|
||||||
|
AVCaptureVideoOrientationLandscapeRight;
|
||||||
break;
|
break;
|
||||||
case UIDeviceOrientationLandscapeRight:
|
case UIDeviceOrientationLandscapeRight:
|
||||||
_connection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
|
_connection.videoOrientation =
|
||||||
|
AVCaptureVideoOrientationLandscapeLeft;
|
||||||
break;
|
break;
|
||||||
case UIDeviceOrientationFaceUp:
|
case UIDeviceOrientationFaceUp:
|
||||||
case UIDeviceOrientationFaceDown:
|
case UIDeviceOrientationFaceDown:
|
||||||
case UIDeviceOrientationUnknown:
|
case UIDeviceOrientationUnknown:
|
||||||
if (!_orientationHasChanged) {
|
if (!_orientationHasChanged) {
|
||||||
_connection.videoOrientation = AVCaptureVideoOrientationPortrait;
|
_connection.videoOrientation =
|
||||||
|
AVCaptureVideoOrientationPortrait;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)onVideoError:(NSNotification*)notification {
|
- (void)onVideoError:(NSNotification*)notification {
|
||||||
NSLog(@"onVideoError: %@", notification);
|
NSLog(@"onVideoError: %@", notification);
|
||||||
// TODO(sjlee): make the specific error handling with this notification.
|
// TODO(sjlee): make the specific error handling with this notification.
|
||||||
WEBRTC_TRACE(kTraceError, kTraceVideoCapture, _captureId,
|
WEBRTC_TRACE(kTraceError,
|
||||||
"%s:%s:%d [AVCaptureSession startRunning] error.", __FILE__,
|
kTraceVideoCapture,
|
||||||
__FUNCTION__, __LINE__);
|
_captureId,
|
||||||
|
"%s:%s:%d [AVCaptureSession startRunning] error.",
|
||||||
|
__FILE__,
|
||||||
|
__FUNCTION__,
|
||||||
|
__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)stopCapture {
|
- (BOOL)stopCapture {
|
||||||
#ifdef WEBRTC_IOS
|
|
||||||
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
|
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
|
||||||
#endif
|
|
||||||
_orientationHasChanged = NO;
|
_orientationHasChanged = NO;
|
||||||
[self waitForCaptureChangeToFinish];
|
[self waitForCaptureChangeToFinish];
|
||||||
[self directOutputToNil];
|
[self directOutputToNil];
|
||||||
@ -268,9 +299,7 @@ using namespace webrtc::videocapturemodule;
|
|||||||
|
|
||||||
_captureChanging = YES;
|
_captureChanging = YES;
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
||||||
^(void) {
|
^(void) { [self stopCaptureInBackground]; });
|
||||||
[self stopCaptureInBackground];
|
|
||||||
});
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,9 +342,14 @@ using namespace webrtc::videocapturemodule;
|
|||||||
if (!newCaptureInput) {
|
if (!newCaptureInput) {
|
||||||
const char* errorMessage = [[deviceError localizedDescription] UTF8String];
|
const char* errorMessage = [[deviceError localizedDescription] UTF8String];
|
||||||
|
|
||||||
WEBRTC_TRACE(kTraceError, kTraceVideoCapture, _captureId,
|
WEBRTC_TRACE(kTraceError,
|
||||||
"%s:%s:%d deviceInputWithDevice error:%s", __FILE__,
|
kTraceVideoCapture,
|
||||||
__FUNCTION__, __LINE__, errorMessage);
|
_captureId,
|
||||||
|
"%s:%s:%d deviceInputWithDevice error:%s",
|
||||||
|
__FILE__,
|
||||||
|
__FUNCTION__,
|
||||||
|
__LINE__,
|
||||||
|
errorMessage);
|
||||||
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
@ -8,8 +8,8 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_OBJC_VIDEO_CAPTURE_H_
|
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_IOS_VIDEO_CAPTURE_IOS_H_
|
||||||
#define WEBRTC_MODULES_VIDEO_CAPTURE_OBJC_VIDEO_CAPTURE_H_
|
#define WEBRTC_MODULES_VIDEO_CAPTURE_IOS_VIDEO_CAPTURE_IOS_H_
|
||||||
|
|
||||||
#include "webrtc/base/scoped_ref_ptr.h"
|
#include "webrtc/base/scoped_ref_ptr.h"
|
||||||
#include "webrtc/modules/video_capture/video_capture_impl.h"
|
#include "webrtc/modules/video_capture/video_capture_impl.h"
|
||||||
@ -43,4 +43,4 @@ class VideoCaptureIos : public VideoCaptureImpl {
|
|||||||
} // namespace videocapturemodule
|
} // namespace videocapturemodule
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_OBJC_VIDEO_CAPTURE_H_
|
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_IOS_VIDEO_CAPTURE_IOS_H_
|
||||||
@ -14,8 +14,8 @@
|
|||||||
|
|
||||||
#include "webrtc/base/refcount.h"
|
#include "webrtc/base/refcount.h"
|
||||||
#include "webrtc/base/scoped_ref_ptr.h"
|
#include "webrtc/base/scoped_ref_ptr.h"
|
||||||
#include "webrtc/modules/video_capture/objc/device_info_objc.h"
|
#include "webrtc/modules/video_capture/ios/device_info_ios_objc.h"
|
||||||
#include "webrtc/modules/video_capture/objc/rtc_video_capture_objc.h"
|
#include "webrtc/modules/video_capture/ios/rtc_video_capture_ios_objc.h"
|
||||||
#include "webrtc/system_wrappers/include/trace.h"
|
#include "webrtc/system_wrappers/include/trace.h"
|
||||||
|
|
||||||
using namespace webrtc;
|
using namespace webrtc;
|
||||||
@ -67,10 +67,9 @@ rtc::scoped_refptr<VideoCaptureModule> VideoCaptureIos::Create(
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (![capture_module->capture_device_
|
if (![capture_module->capture_device_ setCaptureDeviceByUniqueId:[
|
||||||
setCaptureDeviceByUniqueId:
|
[NSString alloc] initWithCString:deviceUniqueIdUTF8
|
||||||
[[NSString alloc] initWithCString:deviceUniqueIdUTF8
|
encoding:NSUTF8StringEncoding]]) {
|
||||||
encoding:NSUTF8StringEncoding]]) {
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return capture_module;
|
return capture_module;
|
||||||
@ -98,9 +97,7 @@ int32_t VideoCaptureIos::StopCapture() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VideoCaptureIos::CaptureStarted() {
|
bool VideoCaptureIos::CaptureStarted() { return is_capturing_; }
|
||||||
return is_capturing_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t VideoCaptureIos::CaptureSettings(VideoCaptureCapability& settings) {
|
int32_t VideoCaptureIos::CaptureSettings(VideoCaptureCapability& settings) {
|
||||||
settings = capability_;
|
settings = capability_;
|
||||||
79
webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit.h
Normal file
79
webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit.h
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_QTKIT_VIDEO_CAPTURE_QTKIT_H_
|
||||||
|
#define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_QTKIT_VIDEO_CAPTURE_QTKIT_H_
|
||||||
|
|
||||||
|
#import <QTKit/QTKit.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "webrtc/modules/video_capture/device_info_impl.h"
|
||||||
|
#include "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit_utility.h"
|
||||||
|
#include "webrtc/modules/video_capture/video_capture_impl.h"
|
||||||
|
|
||||||
|
@class VideoCaptureMacQTKitObjC;
|
||||||
|
@class VideoCaptureMacQTKitInfoObjC;
|
||||||
|
|
||||||
|
namespace webrtc
|
||||||
|
{
|
||||||
|
namespace videocapturemodule
|
||||||
|
{
|
||||||
|
|
||||||
|
class VideoCaptureMacQTKit : public VideoCaptureImpl
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VideoCaptureMacQTKit(const int32_t id);
|
||||||
|
virtual ~VideoCaptureMacQTKit();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a video capture module object
|
||||||
|
*
|
||||||
|
* id - unique identifier of this video capture module object
|
||||||
|
* deviceUniqueIdUTF8 - name of the device. Available names can be found
|
||||||
|
* by using GetDeviceName
|
||||||
|
* deviceUniqueIdUTF8Length - length of deviceUniqueIdUTF8
|
||||||
|
*/
|
||||||
|
static void Destroy(VideoCaptureModule* module);
|
||||||
|
|
||||||
|
int32_t Init(const int32_t id, const char* deviceUniqueIdUTF8);
|
||||||
|
|
||||||
|
|
||||||
|
// Start/Stop
|
||||||
|
virtual int32_t StartCapture(
|
||||||
|
const VideoCaptureCapability& capability);
|
||||||
|
virtual int32_t StopCapture();
|
||||||
|
|
||||||
|
// Properties of the set device
|
||||||
|
|
||||||
|
virtual bool CaptureStarted();
|
||||||
|
|
||||||
|
int32_t CaptureSettings(VideoCaptureCapability& settings);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Help functions
|
||||||
|
int32_t SetCameraOutput();
|
||||||
|
|
||||||
|
private:
|
||||||
|
VideoCaptureMacQTKitObjC* _captureDevice;
|
||||||
|
VideoCaptureMacQTKitInfoObjC* _captureInfo;
|
||||||
|
bool _isCapturing;
|
||||||
|
int32_t _id;
|
||||||
|
int32_t _captureWidth;
|
||||||
|
int32_t _captureHeight;
|
||||||
|
int32_t _captureFrameRate;
|
||||||
|
char _currentDeviceNameUTF8[MAX_NAME_LENGTH];
|
||||||
|
char _currentDeviceUniqueIdUTF8[MAX_NAME_LENGTH];
|
||||||
|
char _currentDeviceProductUniqueIDUTF8[MAX_NAME_LENGTH];
|
||||||
|
int32_t _frameCount;
|
||||||
|
};
|
||||||
|
} // namespace videocapturemodule
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_QTKIT_VIDEO_CAPTURE_QTKIT_H_
|
||||||
211
webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit.mm
Normal file
211
webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit.mm
Normal file
@ -0,0 +1,211 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit.h"
|
||||||
|
#import "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit_info_objc.h"
|
||||||
|
#import "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit_objc.h"
|
||||||
|
#include "webrtc/modules/video_capture/video_capture_config.h"
|
||||||
|
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
|
||||||
|
#include "webrtc/system_wrappers/include/trace.h"
|
||||||
|
|
||||||
|
namespace webrtc
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace videocapturemodule
|
||||||
|
{
|
||||||
|
|
||||||
|
VideoCaptureMacQTKit::VideoCaptureMacQTKit(const int32_t id) :
|
||||||
|
VideoCaptureImpl(id),
|
||||||
|
_captureDevice(NULL),
|
||||||
|
_captureInfo(NULL),
|
||||||
|
_isCapturing(false),
|
||||||
|
_id(id),
|
||||||
|
_captureWidth(QTKIT_DEFAULT_WIDTH),
|
||||||
|
_captureHeight(QTKIT_DEFAULT_HEIGHT),
|
||||||
|
_captureFrameRate(QTKIT_DEFAULT_FRAME_RATE),
|
||||||
|
_frameCount(0)
|
||||||
|
{
|
||||||
|
|
||||||
|
memset(_currentDeviceNameUTF8, 0, MAX_NAME_LENGTH);
|
||||||
|
memset(_currentDeviceUniqueIdUTF8, 0, MAX_NAME_LENGTH);
|
||||||
|
memset(_currentDeviceProductUniqueIDUTF8, 0, MAX_NAME_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
VideoCaptureMacQTKit::~VideoCaptureMacQTKit()
|
||||||
|
{
|
||||||
|
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, _id,
|
||||||
|
"~VideoCaptureMacQTKit() called");
|
||||||
|
if(_captureDevice)
|
||||||
|
{
|
||||||
|
[_captureDevice registerOwner:nil];
|
||||||
|
[_captureDevice stopCapture];
|
||||||
|
[_captureDevice release];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_captureInfo)
|
||||||
|
{
|
||||||
|
[_captureInfo release];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t VideoCaptureMacQTKit::Init(
|
||||||
|
const int32_t id, const char* iDeviceUniqueIdUTF8)
|
||||||
|
{
|
||||||
|
CriticalSectionScoped cs(&_apiCs);
|
||||||
|
|
||||||
|
|
||||||
|
const int32_t nameLength =
|
||||||
|
(int32_t) strlen((char*)iDeviceUniqueIdUTF8);
|
||||||
|
if(nameLength>kVideoCaptureUniqueNameLength)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// Store the device name
|
||||||
|
_deviceUniqueId = new char[nameLength+1];
|
||||||
|
memcpy(_deviceUniqueId, iDeviceUniqueIdUTF8,nameLength+1);
|
||||||
|
|
||||||
|
_captureDevice = [[VideoCaptureMacQTKitObjC alloc] init];
|
||||||
|
if(NULL == _captureDevice)
|
||||||
|
{
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id,
|
||||||
|
"Failed to create an instance of "
|
||||||
|
"VideoCaptureMacQTKitObjC");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
[_captureDevice registerOwner:this];
|
||||||
|
|
||||||
|
if(0 == strcmp((char*)iDeviceUniqueIdUTF8, ""))
|
||||||
|
{
|
||||||
|
// the user doesn't want to set a capture device at this time
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
_captureInfo = [[VideoCaptureMacQTKitInfoObjC alloc]init];
|
||||||
|
if(nil == _captureInfo)
|
||||||
|
{
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id,
|
||||||
|
"Failed to create an instance of VideoCaptureMacQTKitInfoObjC");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int captureDeviceCount = [[_captureInfo getCaptureDeviceCount]intValue];
|
||||||
|
if(captureDeviceCount < 0)
|
||||||
|
{
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id,
|
||||||
|
"No Capture Devices Present");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int NAME_LENGTH = 1024;
|
||||||
|
char deviceNameUTF8[1024] = "";
|
||||||
|
char deviceUniqueIdUTF8[1024] = "";
|
||||||
|
char deviceProductUniqueIDUTF8[1024] = "";
|
||||||
|
|
||||||
|
bool captureDeviceFound = false;
|
||||||
|
for(int index = 0; index < captureDeviceCount; index++){
|
||||||
|
|
||||||
|
memset(deviceNameUTF8, 0, NAME_LENGTH);
|
||||||
|
memset(deviceUniqueIdUTF8, 0, NAME_LENGTH);
|
||||||
|
memset(deviceProductUniqueIDUTF8, 0, NAME_LENGTH);
|
||||||
|
if(-1 == [[_captureInfo getDeviceNamesFromIndex:index
|
||||||
|
DefaultName:deviceNameUTF8 WithLength:NAME_LENGTH
|
||||||
|
AndUniqueID:deviceUniqueIdUTF8 WithLength:NAME_LENGTH
|
||||||
|
AndProductID:deviceProductUniqueIDUTF8
|
||||||
|
WithLength:NAME_LENGTH]intValue])
|
||||||
|
{
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id,
|
||||||
|
"GetDeviceName returned -1 for index %d", index);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(0 == strcmp((const char*)iDeviceUniqueIdUTF8,
|
||||||
|
(char*)deviceUniqueIdUTF8))
|
||||||
|
{
|
||||||
|
// we have a match
|
||||||
|
captureDeviceFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(false == captureDeviceFound)
|
||||||
|
{
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id,
|
||||||
|
"Failed to find capture device unique ID %s",
|
||||||
|
iDeviceUniqueIdUTF8);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// at this point we know that the user has passed in a valid camera. Let's
|
||||||
|
// set it as the current.
|
||||||
|
if(![_captureDevice setCaptureDeviceById:(char*)deviceUniqueIdUTF8])
|
||||||
|
{
|
||||||
|
strcpy((char*)_deviceUniqueId, (char*)deviceUniqueIdUTF8);
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id,
|
||||||
|
"Failed to set capture device %s (unique ID %s) even "
|
||||||
|
"though it was a valid return from "
|
||||||
|
"VideoCaptureMacQTKitInfo", deviceNameUTF8,
|
||||||
|
iDeviceUniqueIdUTF8);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id,
|
||||||
|
"successfully Init VideoCaptureMacQTKit" );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t VideoCaptureMacQTKit::StartCapture(
|
||||||
|
const VideoCaptureCapability& capability)
|
||||||
|
{
|
||||||
|
|
||||||
|
_captureWidth = capability.width;
|
||||||
|
_captureHeight = capability.height;
|
||||||
|
_captureFrameRate = capability.maxFPS;
|
||||||
|
_captureDelay = 120;
|
||||||
|
|
||||||
|
[_captureDevice setCaptureHeight:_captureHeight
|
||||||
|
width:_captureWidth
|
||||||
|
frameRate:_captureFrameRate];
|
||||||
|
|
||||||
|
[_captureDevice startCapture];
|
||||||
|
_isCapturing = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t VideoCaptureMacQTKit::StopCapture()
|
||||||
|
{
|
||||||
|
[_captureDevice stopCapture];
|
||||||
|
_isCapturing = false;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VideoCaptureMacQTKit::CaptureStarted()
|
||||||
|
{
|
||||||
|
return _isCapturing;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t VideoCaptureMacQTKit::CaptureSettings(VideoCaptureCapability& settings)
|
||||||
|
{
|
||||||
|
settings.width = _captureWidth;
|
||||||
|
settings.height = _captureHeight;
|
||||||
|
settings.maxFPS = _captureFrameRate;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ********** begin functions inherited from DeviceInfoImpl **********
|
||||||
|
|
||||||
|
struct VideoCaptureCapabilityMacQTKit:public VideoCaptureCapability
|
||||||
|
{
|
||||||
|
VideoCaptureCapabilityMacQTKit()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace videocapturemodule
|
||||||
|
} // namespace webrtc
|
||||||
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_QTKIT_VIDEO_CAPTURE_QTKIT_INFO_H_
|
||||||
|
#define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_QTKIT_VIDEO_CAPTURE_QTKIT_INFO_H_
|
||||||
|
|
||||||
|
#include "webrtc/modules/video_capture/device_info_impl.h"
|
||||||
|
#include "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit_utility.h"
|
||||||
|
#include "webrtc/modules/video_capture/video_capture_impl.h"
|
||||||
|
|
||||||
|
|
||||||
|
@class VideoCaptureMacQTKitInfoObjC;
|
||||||
|
|
||||||
|
namespace webrtc
|
||||||
|
{
|
||||||
|
namespace videocapturemodule
|
||||||
|
{
|
||||||
|
|
||||||
|
class VideoCaptureMacQTKitInfo: public DeviceInfoImpl
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
VideoCaptureMacQTKitInfo(const int32_t id);
|
||||||
|
virtual ~VideoCaptureMacQTKitInfo();
|
||||||
|
|
||||||
|
int32_t Init();
|
||||||
|
|
||||||
|
virtual uint32_t NumberOfDevices();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the available capture devices.
|
||||||
|
* deviceNumber -[in] index of capture device
|
||||||
|
* deviceNameUTF8 - friendly name of the capture device
|
||||||
|
* deviceUniqueIdUTF8 - unique name of the capture device if it exist.
|
||||||
|
* Otherwise same as deviceNameUTF8
|
||||||
|
* productUniqueIdUTF8 - unique product id if it exist. Null terminated
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
virtual int32_t GetDeviceName(
|
||||||
|
uint32_t deviceNumber, char* deviceNameUTF8,
|
||||||
|
uint32_t deviceNameLength, char* deviceUniqueIdUTF8,
|
||||||
|
uint32_t deviceUniqueIdUTF8Length,
|
||||||
|
char* productUniqueIdUTF8 = 0,
|
||||||
|
uint32_t productUniqueIdUTF8Length = 0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the number of capabilities for this device
|
||||||
|
*/
|
||||||
|
virtual int32_t NumberOfCapabilities(
|
||||||
|
const char* deviceUniqueIdUTF8);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Gets the capabilities of the named device
|
||||||
|
*/
|
||||||
|
virtual int32_t GetCapability(
|
||||||
|
const char* deviceUniqueIdUTF8,
|
||||||
|
const uint32_t deviceCapabilityNumber,
|
||||||
|
VideoCaptureCapability& capability);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Gets the capability that best matches the requested width, height and frame rate.
|
||||||
|
* Returns the deviceCapabilityNumber on success.
|
||||||
|
*/
|
||||||
|
virtual int32_t GetBestMatchedCapability(
|
||||||
|
const char* deviceUniqueIdUTF8,
|
||||||
|
const VideoCaptureCapability& requested,
|
||||||
|
VideoCaptureCapability& resulting);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Display OS /capture device specific settings dialog
|
||||||
|
*/
|
||||||
|
virtual int32_t DisplayCaptureSettingsDialogBox(
|
||||||
|
const char* deviceUniqueIdUTF8,
|
||||||
|
const char* dialogTitleUTF8, void* parentWindow,
|
||||||
|
uint32_t positionX, uint32_t positionY);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual int32_t CreateCapabilityMap(
|
||||||
|
const char* deviceUniqueIdUTF8);
|
||||||
|
|
||||||
|
VideoCaptureMacQTKitInfoObjC* _captureInfo;
|
||||||
|
};
|
||||||
|
} // namespace videocapturemodule
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_QTKIT_VIDEO_CAPTURE_QTKIT_INFO_H_
|
||||||
@ -0,0 +1,125 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit_info_objc.h"
|
||||||
|
#include "webrtc/modules/video_capture/video_capture.h"
|
||||||
|
#include "webrtc/modules/video_capture/video_capture_config.h"
|
||||||
|
#include "webrtc/system_wrappers/include/trace.h"
|
||||||
|
|
||||||
|
namespace webrtc
|
||||||
|
{
|
||||||
|
namespace videocapturemodule
|
||||||
|
{
|
||||||
|
|
||||||
|
VideoCaptureMacQTKitInfo::VideoCaptureMacQTKitInfo(const int32_t id) :
|
||||||
|
DeviceInfoImpl(id)
|
||||||
|
{
|
||||||
|
_captureInfo = [[VideoCaptureMacQTKitInfoObjC alloc] init];
|
||||||
|
}
|
||||||
|
|
||||||
|
VideoCaptureMacQTKitInfo::~VideoCaptureMacQTKitInfo()
|
||||||
|
{
|
||||||
|
[_captureInfo release];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t VideoCaptureMacQTKitInfo::Init()
|
||||||
|
{
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t VideoCaptureMacQTKitInfo::NumberOfDevices()
|
||||||
|
{
|
||||||
|
|
||||||
|
uint32_t captureDeviceCount =
|
||||||
|
[[_captureInfo getCaptureDeviceCount]intValue];
|
||||||
|
return captureDeviceCount;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t VideoCaptureMacQTKitInfo::GetDeviceName(
|
||||||
|
uint32_t deviceNumber, char* deviceNameUTF8,
|
||||||
|
uint32_t deviceNameLength, char* deviceUniqueIdUTF8,
|
||||||
|
uint32_t deviceUniqueIdUTF8Length, char* productUniqueIdUTF8,
|
||||||
|
uint32_t productUniqueIdUTF8Length)
|
||||||
|
{
|
||||||
|
int errNum = [[_captureInfo getDeviceNamesFromIndex:deviceNumber
|
||||||
|
DefaultName:deviceNameUTF8 WithLength:deviceNameLength
|
||||||
|
AndUniqueID:deviceUniqueIdUTF8
|
||||||
|
WithLength:deviceUniqueIdUTF8Length
|
||||||
|
AndProductID:productUniqueIdUTF8
|
||||||
|
WithLength:productUniqueIdUTF8Length]intValue];
|
||||||
|
return errNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t VideoCaptureMacQTKitInfo::NumberOfCapabilities(
|
||||||
|
const char* deviceUniqueIdUTF8)
|
||||||
|
{
|
||||||
|
// Not implemented. Mac doesn't use discrete steps in capabilities, rather
|
||||||
|
// "analog". QTKit will do it's best to convert frames to what ever format
|
||||||
|
// you ask for.
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id,
|
||||||
|
"NumberOfCapabilities is not supported on the Mac platform.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32_t VideoCaptureMacQTKitInfo::GetCapability(
|
||||||
|
const char* deviceUniqueIdUTF8,
|
||||||
|
const uint32_t deviceCapabilityNumber,
|
||||||
|
VideoCaptureCapability& capability)
|
||||||
|
{
|
||||||
|
// Not implemented. Mac doesn't use discrete steps in capabilities, rather
|
||||||
|
// "analog". QTKit will do it's best to convert frames to what ever format
|
||||||
|
// you ask for.
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id,
|
||||||
|
"NumberOfCapabilities is not supported on the Mac platform.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32_t VideoCaptureMacQTKitInfo::GetBestMatchedCapability(
|
||||||
|
const char*deviceUniqueIdUTF8,
|
||||||
|
const VideoCaptureCapability& requested, VideoCaptureCapability& resulting)
|
||||||
|
{
|
||||||
|
// Not implemented. Mac doesn't use discrete steps in capabilities, rather
|
||||||
|
// "analog". QTKit will do it's best to convert frames to what ever format
|
||||||
|
// you ask for.
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id,
|
||||||
|
"NumberOfCapabilities is not supported on the Mac platform.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t VideoCaptureMacQTKitInfo::DisplayCaptureSettingsDialogBox(
|
||||||
|
const char* deviceUniqueIdUTF8,
|
||||||
|
const char* dialogTitleUTF8, void* parentWindow,
|
||||||
|
uint32_t positionX, uint32_t positionY)
|
||||||
|
{
|
||||||
|
|
||||||
|
return [[_captureInfo
|
||||||
|
displayCaptureSettingsDialogBoxWithDevice:deviceUniqueIdUTF8
|
||||||
|
AndTitle:dialogTitleUTF8
|
||||||
|
AndParentWindow:parentWindow AtX:positionX AndY:positionY]
|
||||||
|
intValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t VideoCaptureMacQTKitInfo::CreateCapabilityMap(
|
||||||
|
const char* deviceUniqueIdUTF8)
|
||||||
|
{
|
||||||
|
// Not implemented. Mac doesn't use discrete steps in capabilities, rather
|
||||||
|
// "analog". QTKit will do it's best to convert frames to what ever format
|
||||||
|
// you ask for.
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id,
|
||||||
|
"NumberOfCapabilities is not supported on the Mac platform.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} // namespace videocapturemodule
|
||||||
|
} // namespace webrtc
|
||||||
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//
|
||||||
|
// video_capture_qtkit_info_objc.h
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_QTKIT_VIDEO_CAPTURE_QTKIT_INFO_OBJC_H_
|
||||||
|
#define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_QTKIT_VIDEO_CAPTURE_QTKIT_INFO_OBJC_H_
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <QTKit/QTKit.h>
|
||||||
|
|
||||||
|
#include "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit_info.h"
|
||||||
|
#include "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit_utility.h"
|
||||||
|
|
||||||
|
@interface VideoCaptureMacQTKitInfoObjC : NSObject{
|
||||||
|
bool _OSSupportedInfo;
|
||||||
|
NSArray* _captureDevicesInfo;
|
||||||
|
NSAutoreleasePool* _poolInfo;
|
||||||
|
int _captureDeviceCountInfo;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
*
|
||||||
|
* The following functions are considered to be private
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
- (NSNumber*)getCaptureDevices;
|
||||||
|
- (NSNumber*)initializeVariables;
|
||||||
|
- (void)checkOSSupported;
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
*
|
||||||
|
* The following functions are considered to be public and called by VideoCaptureMacQTKitInfo class
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
- (NSNumber*)getCaptureDeviceCount;
|
||||||
|
|
||||||
|
- (NSNumber*)getDeviceNamesFromIndex:(uint32_t)index
|
||||||
|
DefaultName:(char*)deviceName
|
||||||
|
WithLength:(uint32_t)deviceNameLength
|
||||||
|
AndUniqueID:(char*)deviceUniqueID
|
||||||
|
WithLength:(uint32_t)deviceUniqueIDLength
|
||||||
|
AndProductID:(char*)deviceProductID
|
||||||
|
WithLength:(uint32_t)deviceProductIDLength;
|
||||||
|
|
||||||
|
- (NSNumber*)displayCaptureSettingsDialogBoxWithDevice:
|
||||||
|
(const char*)deviceUniqueIdUTF8
|
||||||
|
AndTitle:(const char*)dialogTitleUTF8
|
||||||
|
AndParentWindow:(void*) parentWindow AtX:(uint32_t)positionX
|
||||||
|
AndY:(uint32_t) positionY;
|
||||||
|
@end
|
||||||
|
|
||||||
|
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_QTKIT_VIDEO_CAPTURE_QTKIT_INFO_OBJC_H_
|
||||||
@ -0,0 +1,191 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma mark **** imports/includes
|
||||||
|
|
||||||
|
#import "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit_info_objc.h"
|
||||||
|
|
||||||
|
#include "webrtc/system_wrappers/include/trace.h"
|
||||||
|
|
||||||
|
using namespace webrtc;
|
||||||
|
|
||||||
|
#pragma mark **** hidden class interface
|
||||||
|
|
||||||
|
@implementation VideoCaptureMacQTKitInfoObjC
|
||||||
|
|
||||||
|
// ****************** over-written OS methods ***********************
|
||||||
|
#pragma mark **** over-written OS methods
|
||||||
|
|
||||||
|
/// ***** Objective-C. Similar to C++ constructor, although invoked manually
|
||||||
|
/// ***** Potentially returns an instance of self
|
||||||
|
-(id)init{
|
||||||
|
self = [super init];
|
||||||
|
if(nil != self){
|
||||||
|
[self checkOSSupported];
|
||||||
|
[self initializeVariables];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ***** Objective-C. Similar to C++ destructor
|
||||||
|
/// ***** Returns nothing
|
||||||
|
- (void)dealloc {
|
||||||
|
|
||||||
|
[_captureDevicesInfo release];
|
||||||
|
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ****************** public methods ******************
|
||||||
|
#pragma mark **** public method implementations
|
||||||
|
|
||||||
|
/// ***** Creates a message box with Cocoa framework
|
||||||
|
/// ***** Returns 0 on success, -1 otherwise.
|
||||||
|
- (NSNumber*)displayCaptureSettingsDialogBoxWithDevice:(const char*)deviceUniqueIdUTF8
|
||||||
|
AndTitle:(const char*)dialogTitleUTF8
|
||||||
|
AndParentWindow:(void*) parentWindow
|
||||||
|
AtX:(uint32_t)positionX
|
||||||
|
AndY:(uint32_t) positionY
|
||||||
|
{
|
||||||
|
NSString* strTitle = [NSString stringWithFormat:@"%s", dialogTitleUTF8];
|
||||||
|
NSString* strButton = @"Alright";
|
||||||
|
NSAlert* alert = [NSAlert alertWithMessageText:strTitle
|
||||||
|
defaultButton:strButton
|
||||||
|
alternateButton:nil otherButton:nil
|
||||||
|
informativeTextWithFormat:@"Device %s is capturing", deviceUniqueIdUTF8];
|
||||||
|
[alert setAlertStyle:NSInformationalAlertStyle];
|
||||||
|
[alert runModal];
|
||||||
|
return [NSNumber numberWithInt:0];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSNumber*)getCaptureDeviceCount{
|
||||||
|
[self getCaptureDevices];
|
||||||
|
return [NSNumber numberWithInt:_captureDeviceCountInfo];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (NSNumber*)getDeviceNamesFromIndex:(uint32_t)index
|
||||||
|
DefaultName:(char*)deviceName
|
||||||
|
WithLength:(uint32_t)deviceNameLength
|
||||||
|
AndUniqueID:(char*)deviceUniqueID
|
||||||
|
WithLength:(uint32_t)deviceUniqueIDLength
|
||||||
|
AndProductID:(char*)deviceProductID
|
||||||
|
WithLength:(uint32_t)deviceProductIDLength
|
||||||
|
{
|
||||||
|
if(NO == _OSSupportedInfo)
|
||||||
|
{
|
||||||
|
return [NSNumber numberWithInt:0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(index >= (uint32_t)_captureDeviceCountInfo)
|
||||||
|
{
|
||||||
|
return [NSNumber numberWithInt:-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
QTCaptureDevice* tempCaptureDevice =
|
||||||
|
(QTCaptureDevice*)[_captureDevicesInfo objectAtIndex:index];
|
||||||
|
if(!tempCaptureDevice)
|
||||||
|
{
|
||||||
|
return [NSNumber numberWithInt:-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(deviceName, 0, deviceNameLength);
|
||||||
|
memset(deviceUniqueID, 0, deviceUniqueIDLength);
|
||||||
|
|
||||||
|
bool successful = NO;
|
||||||
|
|
||||||
|
NSString* tempString = [tempCaptureDevice localizedDisplayName];
|
||||||
|
successful = [tempString getCString:(char*)deviceName
|
||||||
|
maxLength:deviceNameLength encoding:NSUTF8StringEncoding];
|
||||||
|
if(NO == successful)
|
||||||
|
{
|
||||||
|
memset(deviceName, 0, deviceNameLength);
|
||||||
|
return [NSNumber numberWithInt:-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
tempString = [tempCaptureDevice uniqueID];
|
||||||
|
successful = [tempString getCString:(char*)deviceUniqueID
|
||||||
|
maxLength:deviceUniqueIDLength encoding:NSUTF8StringEncoding];
|
||||||
|
if(NO == successful)
|
||||||
|
{
|
||||||
|
memset(deviceUniqueID, 0, deviceNameLength);
|
||||||
|
return [NSNumber numberWithInt:-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [NSNumber numberWithInt:0];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// ****************** "private" category functions below here ******************
|
||||||
|
#pragma mark **** "private" method implementations
|
||||||
|
|
||||||
|
- (NSNumber*)initializeVariables
|
||||||
|
{
|
||||||
|
if(NO == _OSSupportedInfo)
|
||||||
|
{
|
||||||
|
return [NSNumber numberWithInt:0];
|
||||||
|
}
|
||||||
|
|
||||||
|
_poolInfo = [[NSAutoreleasePool alloc]init];
|
||||||
|
_captureDeviceCountInfo = 0;
|
||||||
|
[self getCaptureDevices];
|
||||||
|
|
||||||
|
return [NSNumber numberWithInt:0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ***** Checks to see if the QTCaptureSession framework is available in the OS
|
||||||
|
// ***** If it is not, isOSSupprted = NO
|
||||||
|
// ***** Throughout the rest of the class isOSSupprted is checked and functions
|
||||||
|
// ***** are/aren't called depending
|
||||||
|
// ***** The user can use weak linking to the QTKit framework and run on older
|
||||||
|
// ***** versions of the OS
|
||||||
|
// ***** I.E. Backwards compaitibility
|
||||||
|
// ***** Returns nothing. Sets member variable
|
||||||
|
- (void)checkOSSupported
|
||||||
|
{
|
||||||
|
Class osSupportedTest = NSClassFromString(@"QTCaptureSession");
|
||||||
|
if(nil == osSupportedTest)
|
||||||
|
{
|
||||||
|
_OSSupportedInfo = NO;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_OSSupportedInfo = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ***** Retrieves the number of capture devices currently available
|
||||||
|
/// ***** Stores them in an NSArray instance
|
||||||
|
/// ***** Returns 0 on success, -1 otherwise.
|
||||||
|
- (NSNumber*)getCaptureDevices
|
||||||
|
{
|
||||||
|
if(NO == _OSSupportedInfo)
|
||||||
|
{
|
||||||
|
return [NSNumber numberWithInt:0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_captureDevicesInfo)
|
||||||
|
{
|
||||||
|
[_captureDevicesInfo release];
|
||||||
|
}
|
||||||
|
_captureDevicesInfo = [[NSArray alloc]
|
||||||
|
initWithArray:[QTCaptureDevice
|
||||||
|
inputDevicesWithMediaType:QTMediaTypeVideo]];
|
||||||
|
|
||||||
|
_captureDeviceCountInfo = _captureDevicesInfo.count;
|
||||||
|
|
||||||
|
return [NSNumber numberWithInt:0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//
|
||||||
|
// video_capture_qtkit_objc.h
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_QTKIT_VIDEO_CAPTURE_QTKIT_OBJC_H_
|
||||||
|
#define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_QTKIT_VIDEO_CAPTURE_QTKIT_OBJC_H_
|
||||||
|
|
||||||
|
#import <AppKit/AppKit.h>
|
||||||
|
#import <CoreData/CoreData.h>
|
||||||
|
#import <CoreFoundation/CoreFoundation.h>
|
||||||
|
#import <CoreVideo/CoreVideo.h>
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <QTKit/QTKit.h>
|
||||||
|
|
||||||
|
#include "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit.h"
|
||||||
|
|
||||||
|
@interface VideoCaptureMacQTKitObjC : NSObject {
|
||||||
|
bool _capturing;
|
||||||
|
int _frameRate;
|
||||||
|
int _frameWidth;
|
||||||
|
int _frameHeight;
|
||||||
|
int _framesDelivered;
|
||||||
|
int _framesRendered;
|
||||||
|
bool _captureInitialized;
|
||||||
|
|
||||||
|
webrtc::videocapturemodule::VideoCaptureMacQTKit* _owner;
|
||||||
|
NSLock* _lock;
|
||||||
|
|
||||||
|
QTCaptureSession* _captureSession;
|
||||||
|
QTCaptureDeviceInput* _captureVideoDeviceInput;
|
||||||
|
QTCaptureDecompressedVideoOutput* _captureDecompressedVideoOutput;
|
||||||
|
NSArray* _captureDevices;
|
||||||
|
int _captureDeviceCount;
|
||||||
|
char _captureDeviceNameUTF8[1024];
|
||||||
|
char _captureDeviceNameUniqueID[1024];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)getCaptureDevices;
|
||||||
|
- (BOOL)initializeVideoCapture;
|
||||||
|
- (BOOL)initializeVariables;
|
||||||
|
|
||||||
|
- (void)registerOwner:(webrtc::videocapturemodule::VideoCaptureMacQTKit*)owner;
|
||||||
|
- (BOOL)setCaptureDeviceById:(char*)uniqueId;
|
||||||
|
- (void)setCaptureHeight:(int)height width:(int)width frameRate:(int)frameRate;
|
||||||
|
- (void)startCapture;
|
||||||
|
- (void)stopCapture;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_QTKIT_VIDEO_CAPTURE_QTKIT_OBJC_H_
|
||||||
@ -0,0 +1,259 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define DEFAULT_CAPTURE_DEVICE_INDEX 1
|
||||||
|
#define DEFAULT_FRAME_RATE 30
|
||||||
|
#define DEFAULT_FRAME_WIDTH 352
|
||||||
|
#define DEFAULT_FRAME_HEIGHT 288
|
||||||
|
#define ROTATE_CAPTURED_FRAME 1
|
||||||
|
#define LOW_QUALITY 1
|
||||||
|
|
||||||
|
#import "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit_objc.h"
|
||||||
|
|
||||||
|
#include "webrtc/system_wrappers/include/trace.h"
|
||||||
|
|
||||||
|
using namespace webrtc;
|
||||||
|
using namespace videocapturemodule;
|
||||||
|
|
||||||
|
@implementation VideoCaptureMacQTKitObjC
|
||||||
|
|
||||||
|
-(id)init {
|
||||||
|
self = [super init];
|
||||||
|
if (self) {
|
||||||
|
[self initializeVariables];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)dealloc {
|
||||||
|
if (_captureSession)
|
||||||
|
[_captureSession stopRunning];
|
||||||
|
|
||||||
|
if (_captureVideoDeviceInput) {
|
||||||
|
if ([[_captureVideoDeviceInput device] isOpen])
|
||||||
|
[[_captureVideoDeviceInput device] close];
|
||||||
|
|
||||||
|
[_captureVideoDeviceInput release];
|
||||||
|
}
|
||||||
|
|
||||||
|
[_captureDecompressedVideoOutput release];
|
||||||
|
[_captureSession release];
|
||||||
|
[_captureDevices release];
|
||||||
|
[_lock release];
|
||||||
|
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark Public methods
|
||||||
|
|
||||||
|
- (void)registerOwner:(VideoCaptureMacQTKit*)owner {
|
||||||
|
[_lock lock];
|
||||||
|
_owner = owner;
|
||||||
|
[_lock unlock];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)setCaptureDeviceById:(char*)uniqueId {
|
||||||
|
if (uniqueId == nil || !strcmp("", uniqueId)) {
|
||||||
|
WEBRTC_TRACE(kTraceInfo, kTraceVideoCapture, 0,
|
||||||
|
"Incorrect capture id argument");
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(uniqueId, _captureDeviceNameUniqueID))
|
||||||
|
return YES;
|
||||||
|
|
||||||
|
QTCaptureDevice* captureDevice;
|
||||||
|
for(int index = 0; index < _captureDeviceCount; index++) {
|
||||||
|
captureDevice = (QTCaptureDevice*)[_captureDevices objectAtIndex:index];
|
||||||
|
char captureDeviceId[1024] = "";
|
||||||
|
[[captureDevice uniqueID] getCString:captureDeviceId
|
||||||
|
maxLength:1024
|
||||||
|
encoding:NSUTF8StringEncoding];
|
||||||
|
if (strcmp(uniqueId, captureDeviceId) == 0) {
|
||||||
|
WEBRTC_TRACE(kTraceInfo, kTraceVideoCapture, 0,
|
||||||
|
"%s:%d Found capture device id %s as index %d",
|
||||||
|
__FUNCTION__, __LINE__, captureDeviceId, index);
|
||||||
|
[[captureDevice localizedDisplayName] getCString:_captureDeviceNameUTF8
|
||||||
|
maxLength:1024
|
||||||
|
encoding:NSUTF8StringEncoding];
|
||||||
|
[[captureDevice uniqueID] getCString:_captureDeviceNameUniqueID
|
||||||
|
maxLength:1024
|
||||||
|
encoding:NSUTF8StringEncoding];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
captureDevice = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!captureDevice)
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
NSError* error;
|
||||||
|
if (![captureDevice open:&error]) {
|
||||||
|
WEBRTC_TRACE(kTraceError, kTraceVideoCapture, 0,
|
||||||
|
"Failed to open capture device: %s", _captureDeviceNameUTF8);
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_captureVideoDeviceInput) {
|
||||||
|
[_captureVideoDeviceInput release];
|
||||||
|
}
|
||||||
|
_captureVideoDeviceInput =
|
||||||
|
[[QTCaptureDeviceInput alloc] initWithDevice:captureDevice];
|
||||||
|
|
||||||
|
if (![_captureSession addInput:_captureVideoDeviceInput error:&error]) {
|
||||||
|
WEBRTC_TRACE(kTraceError, kTraceVideoCapture, 0,
|
||||||
|
"Failed to add input from %s to the capture session",
|
||||||
|
_captureDeviceNameUTF8);
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
WEBRTC_TRACE(kTraceInfo, kTraceVideoCapture, 0,
|
||||||
|
"%s:%d successfully added capture device: %s", __FUNCTION__,
|
||||||
|
__LINE__, _captureDeviceNameUTF8);
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setCaptureHeight:(int)height width:(int)width frameRate:(int)frameRate {
|
||||||
|
_frameWidth = width;
|
||||||
|
_frameHeight = height;
|
||||||
|
_frameRate = frameRate;
|
||||||
|
|
||||||
|
NSDictionary* captureDictionary =
|
||||||
|
[NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
|
[NSNumber numberWithDouble:_frameWidth],
|
||||||
|
(id)kCVPixelBufferWidthKey,
|
||||||
|
[NSNumber numberWithDouble:_frameHeight],
|
||||||
|
(id)kCVPixelBufferHeightKey,
|
||||||
|
[NSNumber numberWithUnsignedInt:kCVPixelFormatType_32ARGB],
|
||||||
|
(id)kCVPixelBufferPixelFormatTypeKey,
|
||||||
|
nil];
|
||||||
|
[_captureDecompressedVideoOutput
|
||||||
|
performSelectorOnMainThread:@selector(setPixelBufferAttributes:)
|
||||||
|
withObject:captureDictionary
|
||||||
|
waitUntilDone:YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)startCapture {
|
||||||
|
if (_capturing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
[_captureSession startRunning];
|
||||||
|
_capturing = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)stopCapture {
|
||||||
|
if (!_capturing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
[_captureSession stopRunning];
|
||||||
|
_capturing = NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark Private methods
|
||||||
|
|
||||||
|
- (BOOL)initializeVariables {
|
||||||
|
if (NSClassFromString(@"QTCaptureSession") == nil)
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
memset(_captureDeviceNameUTF8, 0, 1024);
|
||||||
|
_framesDelivered = 0;
|
||||||
|
_framesRendered = 0;
|
||||||
|
_captureDeviceCount = 0;
|
||||||
|
_capturing = NO;
|
||||||
|
_captureInitialized = NO;
|
||||||
|
_frameRate = DEFAULT_FRAME_RATE;
|
||||||
|
_frameWidth = DEFAULT_FRAME_WIDTH;
|
||||||
|
_frameHeight = DEFAULT_FRAME_HEIGHT;
|
||||||
|
_lock = [[NSLock alloc] init];
|
||||||
|
_captureSession = [[QTCaptureSession alloc] init];
|
||||||
|
_captureDecompressedVideoOutput =
|
||||||
|
[[QTCaptureDecompressedVideoOutput alloc] init];
|
||||||
|
[_captureDecompressedVideoOutput setDelegate:self];
|
||||||
|
|
||||||
|
[self getCaptureDevices];
|
||||||
|
if (![self initializeVideoCapture])
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)getCaptureDevices {
|
||||||
|
if (_captureDevices)
|
||||||
|
[_captureDevices release];
|
||||||
|
|
||||||
|
_captureDevices = [[NSArray alloc] initWithArray:
|
||||||
|
[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo]];
|
||||||
|
|
||||||
|
_captureDeviceCount = _captureDevices.count;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)initializeVideoCapture{
|
||||||
|
NSDictionary *captureDictionary =
|
||||||
|
[NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
|
[NSNumber numberWithDouble:_frameWidth],
|
||||||
|
(id)kCVPixelBufferWidthKey,
|
||||||
|
[NSNumber numberWithDouble:_frameHeight],
|
||||||
|
(id)kCVPixelBufferHeightKey,
|
||||||
|
[NSNumber numberWithUnsignedInt:kCVPixelFormatType_32ARGB],
|
||||||
|
(id)kCVPixelBufferPixelFormatTypeKey,
|
||||||
|
nil];
|
||||||
|
|
||||||
|
[_captureDecompressedVideoOutput setPixelBufferAttributes:captureDictionary];
|
||||||
|
[_captureDecompressedVideoOutput setAutomaticallyDropsLateVideoFrames:YES];
|
||||||
|
[_captureDecompressedVideoOutput
|
||||||
|
setMinimumVideoFrameInterval:(NSTimeInterval)1/(float)_frameRate];
|
||||||
|
|
||||||
|
NSError *error;
|
||||||
|
if (![_captureSession addOutput:_captureDecompressedVideoOutput error:&error])
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)captureOutput:(QTCaptureOutput *)captureOutput
|
||||||
|
didDropVideoFrameWithSampleBuffer:(QTSampleBuffer *)sampleBuffer
|
||||||
|
fromConnection:(QTCaptureConnection *)connection {
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)captureOutput:(QTCaptureOutput *)captureOutput
|
||||||
|
didOutputVideoFrame:(CVImageBufferRef)videoFrame
|
||||||
|
withSampleBuffer:(QTSampleBuffer *)sampleBuffer
|
||||||
|
fromConnection:(QTCaptureConnection *)connection {
|
||||||
|
|
||||||
|
[_lock lock];
|
||||||
|
if (!_owner) {
|
||||||
|
[_lock unlock];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int kFlags = 0;
|
||||||
|
if (CVPixelBufferLockBaseAddress(videoFrame, kFlags) == kCVReturnSuccess) {
|
||||||
|
void *baseAddress = CVPixelBufferGetBaseAddress(videoFrame);
|
||||||
|
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(videoFrame);
|
||||||
|
size_t frameHeight = CVPixelBufferGetHeight(videoFrame);
|
||||||
|
size_t frameSize = bytesPerRow * frameHeight;
|
||||||
|
|
||||||
|
VideoCaptureCapability tempCaptureCapability;
|
||||||
|
tempCaptureCapability.width = _frameWidth;
|
||||||
|
tempCaptureCapability.height = _frameHeight;
|
||||||
|
tempCaptureCapability.maxFPS = _frameRate;
|
||||||
|
// TODO(wu) : Update actual type and not hard-coded value.
|
||||||
|
tempCaptureCapability.rawType = kVideoBGRA;
|
||||||
|
|
||||||
|
_owner->IncomingFrame((unsigned char*)baseAddress, frameSize,
|
||||||
|
tempCaptureCapability, 0);
|
||||||
|
CVPixelBufferUnlockBaseAddress(videoFrame, kFlags);
|
||||||
|
}
|
||||||
|
[_lock unlock];
|
||||||
|
_framesDelivered++;
|
||||||
|
_framesRendered++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* video_capture_qtkit_utility.h
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_QTKIT_VIDEO_CAPTURE_QTKIT_UTILITY_H_
|
||||||
|
#define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_QTKIT_VIDEO_CAPTURE_QTKIT_UTILITY_H_
|
||||||
|
|
||||||
|
#define MAX_NAME_LENGTH 1024
|
||||||
|
|
||||||
|
#define QTKIT_MIN_WIDTH 0
|
||||||
|
#define QTKIT_MAX_WIDTH 2560
|
||||||
|
#define QTKIT_DEFAULT_WIDTH 352
|
||||||
|
|
||||||
|
#define QTKIT_MIN_HEIGHT 0
|
||||||
|
#define QTKIT_MAX_HEIGHT 1440
|
||||||
|
#define QTKIT_DEFAULT_HEIGHT 288
|
||||||
|
|
||||||
|
#define QTKIT_MIN_FRAME_RATE 1
|
||||||
|
#define QTKIT_MAX_FRAME_RATE 60
|
||||||
|
#define QTKIT_DEFAULT_FRAME_RATE 30
|
||||||
|
|
||||||
|
#define RELEASE_AND_CLEAR(p) if (p) { (p) -> Release () ; (p) = NULL ; }
|
||||||
|
|
||||||
|
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_QTKIT_VIDEO_CAPTURE_QTKIT_UTILITY_H_
|
||||||
252
webrtc/modules/video_capture/mac/video_capture_mac.mm
Normal file
252
webrtc/modules/video_capture/mac/video_capture_mac.mm
Normal file
@ -0,0 +1,252 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* video_capture_mac.cc
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QuickTime/QuickTime.h>
|
||||||
|
|
||||||
|
#include "webrtc/base/refcount.h"
|
||||||
|
#include "webrtc/base/scoped_ref_ptr.h"
|
||||||
|
#include "webrtc/modules/video_capture/device_info_impl.h"
|
||||||
|
#include "webrtc/modules/video_capture/video_capture_config.h"
|
||||||
|
#include "webrtc/modules/video_capture/video_capture_impl.h"
|
||||||
|
#include "webrtc/system_wrappers/include/trace.h"
|
||||||
|
|
||||||
|
// 10.4 support must be decided runtime. We will just decide which framework to
|
||||||
|
// use at compile time "work" classes. One for QTKit, one for QuickTime
|
||||||
|
#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version
|
||||||
|
#include <QuickTime/video_capture_quick_time.h>
|
||||||
|
#include <QuickTime/video_capture_quick_time_info.h>
|
||||||
|
#else
|
||||||
|
#include "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit.h"
|
||||||
|
#include "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit_info.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace webrtc
|
||||||
|
{
|
||||||
|
namespace videocapturemodule
|
||||||
|
{
|
||||||
|
|
||||||
|
// static
|
||||||
|
bool CheckOSVersion()
|
||||||
|
{
|
||||||
|
// Check OSX version
|
||||||
|
OSErr err = noErr;
|
||||||
|
|
||||||
|
SInt32 version;
|
||||||
|
|
||||||
|
err = Gestalt(gestaltSystemVersion, &version);
|
||||||
|
if (err != noErr)
|
||||||
|
{
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0,
|
||||||
|
"Could not get OS version");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version < 0x00001040) // Older version than Mac OSX 10.4
|
||||||
|
{
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0,
|
||||||
|
"OS version too old: 0x%x", version);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, 0,
|
||||||
|
"OS version compatible: 0x%x", version);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
bool CheckQTVersion()
|
||||||
|
{
|
||||||
|
// Check OSX version
|
||||||
|
OSErr err = noErr;
|
||||||
|
|
||||||
|
SInt32 version;
|
||||||
|
|
||||||
|
err = Gestalt(gestaltQuickTime, &version);
|
||||||
|
if (err != noErr)
|
||||||
|
{
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0,
|
||||||
|
"Could not get QuickTime version");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version < 0x07000000) // QT v. 7.x or newer (QT 5.0.2 0x05020000)
|
||||||
|
{
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0,
|
||||||
|
"QuickTime version too old: 0x%x", version);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, 0,
|
||||||
|
"QuickTime version compatible: 0x%x", version);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
*
|
||||||
|
* Create/Destroy a VideoCaptureModule
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns version of the module and its components
|
||||||
|
*
|
||||||
|
* version - buffer to which the version will be written
|
||||||
|
* remainingBufferInBytes - remaining number of int8_t in the version
|
||||||
|
* buffer
|
||||||
|
* position - position of the next empty int8_t in the
|
||||||
|
* version buffer
|
||||||
|
*/
|
||||||
|
|
||||||
|
rtc::scoped_refptr<VideoCaptureModule> VideoCaptureImpl::Create(
|
||||||
|
const int32_t id,
|
||||||
|
const char* deviceUniqueIdUTF8) {
|
||||||
|
if (!CheckOSVersion()) {
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id,
|
||||||
|
"OS version is too old. Could not create video capture "
|
||||||
|
"module. Returning NULL");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version
|
||||||
|
if (!CheckQTVersion())
|
||||||
|
{
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id,
|
||||||
|
"QuickTime version is too old. Could not create video "
|
||||||
|
"capture module. Returning NULL");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id,
|
||||||
|
"%s line %d. QTKit is not supported on this machine. Using "
|
||||||
|
"QuickTime framework to capture video",
|
||||||
|
__FILE__, __LINE__);
|
||||||
|
|
||||||
|
rtc::scoped_refptr<VideoCaptureMacQuickTime> newCaptureModule(
|
||||||
|
new rtc::RefCountedObject<VideoCaptureMacQuickTime>(id));
|
||||||
|
|
||||||
|
if (newCaptureModule->Init(id, deviceUniqueIdUTF8) != 0)
|
||||||
|
{
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, id,
|
||||||
|
"could not Create for unique device %s, "
|
||||||
|
"newCaptureModule->Init()!=0",
|
||||||
|
deviceUniqueIdUTF8);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Successfully created VideoCaptureMacQuicktime. Return it
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id,
|
||||||
|
"Module created for unique device %s. Will use QuickTime "
|
||||||
|
"framework to capture",
|
||||||
|
deviceUniqueIdUTF8);
|
||||||
|
return newCaptureModule;
|
||||||
|
|
||||||
|
#else // QTKit version
|
||||||
|
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id,
|
||||||
|
"Using QTKit framework to capture video", id);
|
||||||
|
|
||||||
|
rtc::scoped_refptr<VideoCaptureMacQTKit> newCaptureModule(
|
||||||
|
new rtc::RefCountedObject<VideoCaptureMacQTKit>(id));
|
||||||
|
|
||||||
|
if(newCaptureModule->Init(id, deviceUniqueIdUTF8) != 0)
|
||||||
|
{
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, id,
|
||||||
|
"could not Create for unique device %s, "
|
||||||
|
"newCaptureModule->Init()!=0", deviceUniqueIdUTF8);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Successfully created VideoCaptureMacQuicktime. Return it
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id,
|
||||||
|
"Module created for unique device %s, will use QTKit "
|
||||||
|
"framework",deviceUniqueIdUTF8);
|
||||||
|
return newCaptureModule;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
*
|
||||||
|
* Create/Destroy a DeviceInfo
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
VideoCaptureModule::DeviceInfo*
|
||||||
|
VideoCaptureImpl::CreateDeviceInfo(const int32_t id)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
if (webrtc::videocapturemodule::CheckOSVersion() == false)
|
||||||
|
{
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id,
|
||||||
|
"OS version is too old. Could not create video capture "
|
||||||
|
"module. Returning NULL");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version
|
||||||
|
if (webrtc::videocapturemodule::CheckQTVersion() == false)
|
||||||
|
{
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id,
|
||||||
|
"QuickTime version is too old. Could not create video "
|
||||||
|
"capture module. Returning NULL");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
webrtc::videocapturemodule::VideoCaptureMacQuickTimeInfo* newCaptureInfoModule =
|
||||||
|
new webrtc::videocapturemodule::VideoCaptureMacQuickTimeInfo(id);
|
||||||
|
|
||||||
|
if (!newCaptureInfoModule || newCaptureInfoModule->Init() != 0)
|
||||||
|
{
|
||||||
|
Destroy(newCaptureInfoModule);
|
||||||
|
newCaptureInfoModule = NULL;
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id,
|
||||||
|
"Failed to Init newCaptureInfoModule created with id %d "
|
||||||
|
"and device \"\" ", id);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id,
|
||||||
|
"VideoCaptureModule created for id", id);
|
||||||
|
return newCaptureInfoModule;
|
||||||
|
|
||||||
|
#else // QTKit version
|
||||||
|
webrtc::videocapturemodule::VideoCaptureMacQTKitInfo* newCaptureInfoModule =
|
||||||
|
new webrtc::videocapturemodule::VideoCaptureMacQTKitInfo(id);
|
||||||
|
|
||||||
|
if(!newCaptureInfoModule || newCaptureInfoModule->Init() != 0)
|
||||||
|
{
|
||||||
|
//Destroy(newCaptureInfoModule);
|
||||||
|
delete newCaptureInfoModule;
|
||||||
|
newCaptureInfoModule = NULL;
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id,
|
||||||
|
"Failed to Init newCaptureInfoModule created with id %d "
|
||||||
|
"and device \"\" ", id);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id,
|
||||||
|
"VideoCaptureModule created for id", id);
|
||||||
|
return newCaptureInfoModule;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
*
|
||||||
|
* End Create/Destroy VideoCaptureModule
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
} // namespace videocapturemodule
|
||||||
|
} // namespace webrtc
|
||||||
@ -68,6 +68,29 @@
|
|||||||
'linux/video_capture_linux.h',
|
'linux/video_capture_linux.h',
|
||||||
],
|
],
|
||||||
}], # linux
|
}], # linux
|
||||||
|
['OS=="mac"', {
|
||||||
|
'sources': [
|
||||||
|
'mac/qtkit/video_capture_qtkit.h',
|
||||||
|
'mac/qtkit/video_capture_qtkit.mm',
|
||||||
|
'mac/qtkit/video_capture_qtkit_info.h',
|
||||||
|
'mac/qtkit/video_capture_qtkit_info.mm',
|
||||||
|
'mac/qtkit/video_capture_qtkit_info_objc.h',
|
||||||
|
'mac/qtkit/video_capture_qtkit_info_objc.mm',
|
||||||
|
'mac/qtkit/video_capture_qtkit_objc.h',
|
||||||
|
'mac/qtkit/video_capture_qtkit_objc.mm',
|
||||||
|
'mac/qtkit/video_capture_qtkit_utility.h',
|
||||||
|
'mac/video_capture_mac.mm',
|
||||||
|
],
|
||||||
|
'link_settings': {
|
||||||
|
'xcode_settings': {
|
||||||
|
'OTHER_LDFLAGS': [
|
||||||
|
'-framework Cocoa',
|
||||||
|
'-framework CoreVideo',
|
||||||
|
'-framework QTKit',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}], # mac
|
||||||
['OS=="win"', {
|
['OS=="win"', {
|
||||||
'dependencies': [
|
'dependencies': [
|
||||||
'<(DEPTH)/third_party/winsdk_samples/winsdk_samples.gyp:directshow_baseclasses',
|
'<(DEPTH)/third_party/winsdk_samples/winsdk_samples.gyp:directshow_baseclasses',
|
||||||
@ -110,16 +133,16 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}],
|
}],
|
||||||
['OS=="ios" or OS=="mac"', {
|
['OS=="ios"', {
|
||||||
'sources': [
|
'sources': [
|
||||||
'apple/device_info.h',
|
'ios/device_info_ios.h',
|
||||||
'apple/device_info.mm',
|
'ios/device_info_ios.mm',
|
||||||
'apple/device_info_objc.h',
|
'ios/device_info_ios_objc.h',
|
||||||
'apple/device_info_objc.mm',
|
'ios/device_info_ios_objc.mm',
|
||||||
'apple/rtc_video_capture_objc.h',
|
'ios/rtc_video_capture_ios_objc.h',
|
||||||
'apple/rtc_video_capture_objc.mm',
|
'ios/rtc_video_capture_ios_objc.mm',
|
||||||
'apple/video_capture.h',
|
'ios/video_capture_ios.h',
|
||||||
'apple/video_capture.mm',
|
'ios/video_capture_ios.mm',
|
||||||
],
|
],
|
||||||
'xcode_settings': {
|
'xcode_settings': {
|
||||||
'CLANG_ENABLE_OBJC_ARC': 'YES',
|
'CLANG_ENABLE_OBJC_ARC': 'YES',
|
||||||
@ -130,14 +153,6 @@
|
|||||||
'-framework AVFoundation',
|
'-framework AVFoundation',
|
||||||
'-framework CoreMedia',
|
'-framework CoreMedia',
|
||||||
'-framework CoreVideo',
|
'-framework CoreVideo',
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}], # ios
|
|
||||||
['OS=="ios"', {
|
|
||||||
'all_dependent_settings': {
|
|
||||||
'xcode_settings': {
|
|
||||||
'OTHER_LDFLAGS': [
|
|
||||||
'-framework UIKit',
|
'-framework UIKit',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user