Bug 1180725 - use AVFoundation for camera capture on OSX. r=jib

This commit is contained in:
Munro Mengjue Chiang 2016-05-19 22:48:55 +08:00
Родитель 9ebc499566
Коммит f71af76062
15 изменённых файлов: 1335 добавлений и 30 удалений

Просмотреть файл

@ -64,6 +64,8 @@ if CONFIG['OS_TARGET'] == 'Darwin':
'-framework CoreAudio', '-framework CoreAudio',
'-framework OpenGL', '-framework OpenGL',
'-framework QTKit', '-framework QTKit',
'-framework AVFoundation',
'-framework CoreMedia',
'-framework QuartzCore', '-framework QuartzCore',
'-framework Security', '-framework Security',
'-framework SystemConfiguration', '-framework SystemConfiguration',

Просмотреть файл

@ -101,6 +101,15 @@ if (!build_with_chromium) {
"mac/qtkit/video_capture_qtkit_objc.h", "mac/qtkit/video_capture_qtkit_objc.h",
"mac/qtkit/video_capture_qtkit_objc.mm", "mac/qtkit/video_capture_qtkit_objc.mm",
"mac/qtkit/video_capture_qtkit_utility.h", "mac/qtkit/video_capture_qtkit_utility.h",
"mac/avfoundation/video_capture_avfoundation.h",
"mac/avfoundation/video_capture_avfoundation.mm",
"mac/avfoundation/video_capture_avfoundation_info.h",
"mac/avfoundation/video_capture_avfoundation_info.mm",
"mac/avfoundation/video_capture_avfoundation_info_objc.h",
"mac/avfoundation/video_capture_avfoundation_info_objc.mm",
"mac/avfoundation/video_capture_avfoundation_objc.h",
"mac/avfoundation/video_capture_avfoundation_objc.mm",
"mac/avfoundation/video_capture_avfoundation_utility.h",
"mac/video_capture_mac.mm", "mac/video_capture_mac.mm",
] ]

Просмотреть файл

@ -0,0 +1,80 @@
/*
* Copyright (c) 2016 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_AVFOUNDATION_VIDEO_CAPTURE_AVFOUNDATION_H_
#define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_AVFOUNDATION_VIDEO_CAPTURE_AVFOUNDATION_H_
#import <AVFoundation/AVFoundation.h>
#include <stdio.h>
#include "webrtc/modules/video_capture/device_info_impl.h"
#include "webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_utility.h"
#include "webrtc/modules/video_capture/video_capture_impl.h"
@class VideoCaptureMacAVFoundationObjC;
@class VideoCaptureMacAVFoundationInfoObjC;
namespace webrtc
{
namespace videocapturemodule
{
class VideoCaptureMacAVFoundation : public VideoCaptureImpl
{
public:
VideoCaptureMacAVFoundation(const int32_t id);
virtual ~VideoCaptureMacAVFoundation();
/*
* 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:
VideoCaptureMacAVFoundationObjC* _captureDevice;
VideoCaptureMacAVFoundationInfoObjC* _captureInfo;
bool _isCapturing;
int32_t _id;
int32_t _captureWidth;
int32_t _captureHeight;
int32_t _captureFrameRate;
RawVideoType _captureRawType;
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_AVFOUNDATION_VIDEO_CAPTURE_AVFOUNDATION_H_

Просмотреть файл

@ -0,0 +1,238 @@
/*
* Copyright (c) 2016 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/avfoundation/video_capture_avfoundation.h"
#import "webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_info_objc.h"
#import "webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_objc.h"
#include "webrtc/modules/video_capture/video_capture_config.h"
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "webrtc/system_wrappers/interface/trace.h"
class nsAutoreleasePool {
public:
nsAutoreleasePool()
{
mLocalPool = [[NSAutoreleasePool alloc] init];
}
~nsAutoreleasePool()
{
[mLocalPool release];
}
private:
NSAutoreleasePool *mLocalPool;
};
namespace webrtc
{
namespace videocapturemodule
{
VideoCaptureMacAVFoundation::VideoCaptureMacAVFoundation(const int32_t id) :
VideoCaptureImpl(id),
_captureDevice(NULL),
_captureInfo(NULL),
_isCapturing(false),
_id(id),
_captureWidth(AVFOUNDATION_DEFAULT_WIDTH),
_captureHeight(AVFOUNDATION_DEFAULT_HEIGHT),
_captureFrameRate(AVFOUNDATION_DEFAULT_FRAME_RATE),
_captureRawType(kVideoUnknown),
_frameCount(0)
{
memset(_currentDeviceNameUTF8, 0, MAX_NAME_LENGTH);
memset(_currentDeviceUniqueIdUTF8, 0, MAX_NAME_LENGTH);
memset(_currentDeviceProductUniqueIDUTF8, 0, MAX_NAME_LENGTH);
}
VideoCaptureMacAVFoundation::~VideoCaptureMacAVFoundation()
{
nsAutoreleasePool localPool;
WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, _id,
"~VideoCaptureMacAVFoundation() called");
if(_captureDevice)
{
[_captureDevice registerOwner:nil];
[_captureDevice performSelectorOnMainThread:@selector(stopCapture)
withObject:nil
waitUntilDone:NO];
[_captureDevice performSelectorOnMainThread:@selector(release)
withObject:nil
waitUntilDone:NO];
}
if(_captureInfo)
{
[_captureInfo release];
}
}
int32_t VideoCaptureMacAVFoundation::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);
nsAutoreleasePool localPool;
_captureDevice = [[VideoCaptureMacAVFoundationObjC alloc] init];
if(NULL == _captureDevice)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id,
"Failed to create an instance of "
"VideoCaptureMacAVFounationObjC");
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 = [[VideoCaptureMacAVFoundationInfoObjC alloc]init];
if(nil == _captureInfo)
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id,
"Failed to create an instance of VideoCaptureMacAVFoundationInfoObjC");
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 "
"VideoCaptureMacAVFoundationInfo", deviceNameUTF8,
iDeviceUniqueIdUTF8);
return -1;
}
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id,
"successfully Init VideoCaptureMacAVFoundation" );
return 0;
}
int32_t VideoCaptureMacAVFoundation::StartCapture(
const VideoCaptureCapability& capability)
{
nsAutoreleasePool localPool;
_captureWidth = capability.width;
_captureHeight = capability.height;
_captureFrameRate = capability.maxFPS;
_captureRawType = capability.rawType;
_captureDelay = 120;
[_captureDevice setCaptureHeight:_captureHeight
width:_captureWidth
frameRate:_captureFrameRate
rawType:&_captureRawType];
[_captureDevice startCapture];
_isCapturing = true;
return 0;
}
int32_t VideoCaptureMacAVFoundation::StopCapture()
{
nsAutoreleasePool localPool;
[_captureDevice stopCapture];
_isCapturing = false;
return 0;
}
bool VideoCaptureMacAVFoundation::CaptureStarted()
{
return _isCapturing;
}
int32_t VideoCaptureMacAVFoundation::CaptureSettings(VideoCaptureCapability& settings)
{
settings.width = _captureWidth;
settings.height = _captureHeight;
settings.maxFPS = _captureFrameRate;
settings.rawType = _captureRawType;
return 0;
}
// ********** begin functions inherited from DeviceInfoImpl **********
struct VideoCaptureCapabilityMacAVFoundation:public VideoCaptureCapability
{
VideoCaptureCapabilityMacAVFoundation()
{
}
};
} // namespace videocapturemodule
} // namespace webrtc

Просмотреть файл

@ -0,0 +1,84 @@
/*
* Copyright (c) 2016 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_AVFOUNDATION_VIDEO_CAPTURE_AVFOUNDATION_INFO_H_
#define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_AVFOUNDATION_VIDEO_CAPTURE_AVFOUNDATION_INFO_H_
#include "webrtc/modules/video_capture/device_info_impl.h"
#include "webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_utility.h"
#include "webrtc/modules/video_capture/video_capture_impl.h"
@class VideoCaptureMacAVFoundationInfoObjC;
namespace webrtc
{
namespace videocapturemodule
{
class VideoCaptureMacAVFoundationInfo: public DeviceInfoImpl
{
public:
VideoCaptureMacAVFoundationInfo(const int32_t id);
virtual ~VideoCaptureMacAVFoundationInfo();
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);
/*
* 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);
VideoCaptureMacAVFoundationInfoObjC* _captureInfo;
};
} // namespace videocapturemodule
} // namespace webrtc
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_AVFOUNDATION_VIDEO_CAPTURE_AVFOUNDATION_INFO_H_

Просмотреть файл

@ -0,0 +1,112 @@
/*
* Copyright (c) 2016 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/avfoundation/video_capture_avfoundation_info_objc.h"
#include "webrtc/modules/video_capture/include/video_capture.h"
#include "webrtc/modules/video_capture/video_capture_config.h"
#include "webrtc/system_wrappers/interface/trace.h"
#include "nsDebug.h"
namespace webrtc
{
namespace videocapturemodule
{
VideoCaptureMacAVFoundationInfo::VideoCaptureMacAVFoundationInfo(const int32_t id) :
DeviceInfoImpl(id)
{
nsAutoreleasePool localPool;
_captureInfo = [[VideoCaptureMacAVFoundationInfoObjC alloc] init];
}
VideoCaptureMacAVFoundationInfo::~VideoCaptureMacAVFoundationInfo()
{
nsAutoreleasePool localPool;
[_captureInfo release];
}
int32_t VideoCaptureMacAVFoundationInfo::Init()
{
return 0;
}
uint32_t VideoCaptureMacAVFoundationInfo::NumberOfDevices()
{
nsAutoreleasePool localPool;
uint32_t captureDeviceCount =
[[_captureInfo getCaptureDeviceCount]intValue];
return captureDeviceCount;
}
int32_t VideoCaptureMacAVFoundationInfo::GetDeviceName(
uint32_t deviceNumber, char* deviceNameUTF8,
uint32_t deviceNameLength, char* deviceUniqueIdUTF8,
uint32_t deviceUniqueIdUTF8Length, char* productUniqueIdUTF8,
uint32_t productUniqueIdUTF8Length)
{
nsAutoreleasePool localPool;
int errNum = [[_captureInfo getDeviceNamesFromIndex:deviceNumber
DefaultName:deviceNameUTF8 WithLength:deviceNameLength
AndUniqueID:deviceUniqueIdUTF8
WithLength:deviceUniqueIdUTF8Length
AndProductID:productUniqueIdUTF8
WithLength:productUniqueIdUTF8Length]intValue];
return errNum;
}
int32_t VideoCaptureMacAVFoundationInfo::NumberOfCapabilities(
const char* deviceUniqueIdUTF8)
{
nsAutoreleasePool localPool;
uint32_t captureCapabilityCount =
[[_captureInfo getCaptureCapabilityCount:deviceUniqueIdUTF8]intValue];
return captureCapabilityCount;
}
int32_t VideoCaptureMacAVFoundationInfo::GetCapability(
const char* deviceUniqueIdUTF8,
const uint32_t deviceCapabilityNumber,
VideoCaptureCapability& capability)
{
nsAutoreleasePool localPool;
uint32_t result =
[[_captureInfo getCaptureCapability:deviceUniqueIdUTF8
CapabilityId:deviceCapabilityNumber
Capability_width:&capability.width
Capability_height:&capability.height
Capability_maxFPS:&capability.maxFPS
Capability_format:&capability.rawType]intValue];
return result;
}
int32_t VideoCaptureMacAVFoundationInfo::DisplayCaptureSettingsDialogBox(
const char* deviceUniqueIdUTF8,
const char* dialogTitleUTF8, void* parentWindow,
uint32_t positionX, uint32_t positionY)
{
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id,
"API not supported on Mac OS X.");
return -1;
}
int32_t VideoCaptureMacAVFoundationInfo::CreateCapabilityMap(
const char* deviceUniqueIdUTF8)
{
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id,
"API not supported on Mac OS X.");
return -1;
}
} // namespace videocapturemodule
} // namespace webrtc

Просмотреть файл

@ -0,0 +1,75 @@
/*
* Copyright (c) 2016 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_avfoundation_info_objc.h
//
//
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_AVFOUNDATION_VIDEO_CAPTURE_AVFOUNDATION_INFO_OBJC_H_
#define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_AVFOUNDATION_VIDEO_CAPTURE_AVFOUNDATION_INFO_OBJC_H_
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#include "webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_info.h"
#include "webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_utility.h"
@interface VideoCaptureMacAVFoundationInfoObjC : NSObject{
bool _OSSupportedInfo;
NSArray* _captureDevicesInfo;
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 VideoCaptureMacAVFoundationInfo class
*
***************************************************************************/
- (NSNumber*)getCaptureDeviceCount;
- (NSNumber*)getCaptureCapabilityCount:(const char*)uniqueId;
- (NSNumber*)getCaptureCapability:(const char*)uniqueId
CapabilityId:(uint32_t)capabilityId
Capability_width:(int32_t*)width
Capability_height:(int32_t*)height
Capability_maxFPS:(int32_t*)maxFPS
Capability_format:(webrtc::RawVideoType*)rawType;
- (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_AVFOUNDATION_VIDEO_CAPTURE_AVFOUNDATION_INFO_OBJC_H_

Просмотреть файл

@ -0,0 +1,273 @@
/*
* Copyright (c) 2016 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/avfoundation/video_capture_avfoundation_info_objc.h"
#include "webrtc/system_wrappers/interface/trace.h"
using namespace webrtc;
#pragma mark **** hidden class interface
@implementation VideoCaptureMacAVFoundationInfoObjC
// ****************** 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*)getCaptureCapabilityCount:(const char*)uniqueId {
AVCaptureDevice* captureDevice = nil;
if (uniqueId == nil || !strcmp("", uniqueId)) {
WEBRTC_TRACE(kTraceInfo, kTraceVideoCapture, 0,
"Incorrect capture id argument");
return [NSNumber numberWithInt:-1];
}
for (int index = 0; index < _captureDeviceCountInfo; index++) {
captureDevice = (AVCaptureDevice*)[_captureDevicesInfo 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);
break;
}
captureDevice = nil;
}
if (!captureDevice)
return [NSNumber numberWithInt:-1];
return [NSNumber numberWithInt:[captureDevice formats].count];
}
- (NSNumber*)getCaptureCapability:(const char*)uniqueId
CapabilityId:(uint32_t)capabilityId
Capability_width:(int32_t*)width
Capability_height:(int32_t*)height
Capability_maxFPS:(int32_t*)maxFPS
Capability_format:(webrtc::RawVideoType*)rawType
{
AVCaptureDevice* captureDevice = nil;
if (uniqueId == nil || !strcmp("", uniqueId)) {
WEBRTC_TRACE(kTraceInfo, kTraceVideoCapture, 0,
"Incorrect capture id argument");
return [NSNumber numberWithInt:-1];
}
for (int index = 0; index < _captureDeviceCountInfo; index++) {
captureDevice = (AVCaptureDevice*)[_captureDevicesInfo 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);
break;
}
captureDevice = nil;
}
if (!captureDevice)
return [NSNumber numberWithInt:-1];
AVCaptureDeviceFormat* format = (AVCaptureDeviceFormat*)[[captureDevice formats]objectAtIndex:capabilityId];
CMVideoDimensions videoDimensions = CMVideoFormatDescriptionGetDimensions(format.formatDescription);
AVFrameRateRange* maxFrameRateRange = nil;
for ( AVFrameRateRange* range in format.videoSupportedFrameRateRanges ) {
if ( range.maxFrameRate > maxFrameRateRange.maxFrameRate ) {
maxFrameRateRange = range;
}
}
*width = videoDimensions.width;
*height = videoDimensions.height;
*maxFPS = maxFrameRateRange.maxFrameRate;
*rawType = [VideoCaptureMacAVFoundationUtility fourCCToRawVideoType:CMFormatDescriptionGetMediaSubType(format.formatDescription)];
return [NSNumber numberWithInt:0];
}
- (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];
}
if ([_captureDevicesInfo count] <= index)
{
return [NSNumber numberWithInt:-1];
}
AVCaptureDevice* tempCaptureDevice = (AVCaptureDevice*)[_captureDevicesInfo objectAtIndex:index];
if(!tempCaptureDevice)
{
return [NSNumber numberWithInt:-1];
}
memset(deviceName, 0, deviceNameLength);
memset(deviceUniqueID, 0, deviceUniqueIDLength);
bool successful = NO;
NSString* tempString = [tempCaptureDevice localizedName];
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];
}
_captureDeviceCountInfo = 0;
[self getCaptureDevices];
return [NSNumber numberWithInt:0];
}
// ***** Checks to see if the AVCaptureSession 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 AVFoundation framework and run on older
// ***** versions of the OS
// ***** I.E. Backwards compaitibility
// ***** Returns nothing. Sets member variable
- (void)checkOSSupported
{
Class osSupportedTest = NSClassFromString(@"AVCaptureSession");
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:[AVCaptureDevice
devicesWithMediaType:AVMediaTypeVideo]];
_captureDeviceCountInfo = _captureDevicesInfo.count;
return [NSNumber numberWithInt:0];
}
@end

Просмотреть файл

@ -0,0 +1,62 @@
/*
* Copyright (c) 2016 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_avfoundation_objc.h
//
//
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_AVFOUNDATION_VIDEO_CAPTURE_AVFOUNDATION_OBJC_H_
#define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_AVFOUNDATION_VIDEO_CAPTURE_AVFOUNDATION_OBJC_H_
#import <AppKit/AppKit.h>
#import <CoreData/CoreData.h>
#import <CoreFoundation/CoreFoundation.h>
#import <CoreVideo/CoreVideo.h>
#import <Foundation/Foundation.h>
#include "webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation.h"
@interface VideoCaptureMacAVFoundationObjC : NSObject <AVCaptureVideoDataOutputSampleBufferDelegate> {
bool _capturing;
int _frameRate;
int _frameWidth;
int _frameHeight;
webrtc::RawVideoType _rawType;
int _framesDelivered;
int _framesRendered;
bool _captureInitialized;
webrtc::videocapturemodule::VideoCaptureMacAVFoundation* _owner;
NSLock* _lock;
AVCaptureDevice* _captureDevice;
AVCaptureSession* _captureSession;
AVCaptureVideoDataOutput* _captureVideoDataOutput;
dispatch_queue_t _videoDataOutputQueue;
NSArray* _captureDevices;
int _captureDeviceCount;
char _captureDeviceNameUTF8[1024];
char _captureDeviceNameUniqueID[1024];
}
- (void)getCaptureDevices;
- (BOOL)initializeVideoCapture;
- (BOOL)initializeVariables;
- (void)registerOwner:(webrtc::videocapturemodule::VideoCaptureMacAVFoundation*)owner;
- (BOOL)setCaptureDeviceById:(char*)uniqueId;
- (void)setCaptureHeight:(int)height width:(int)width frameRate:(int)frameRate rawType:(webrtc::RawVideoType*)rawType;
- (void)startCapture;
- (void)stopCapture;
@end
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_AVFOUNDATION_VIDEO_CAPTURE_AVFOUNDATION_OBJC_H_

Просмотреть файл

@ -0,0 +1,266 @@
/*
* Copyright (c) 2016 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/avfoundation/video_capture_avfoundation_objc.h"
#include "webrtc/system_wrappers/interface/trace.h"
using namespace webrtc;
using namespace videocapturemodule;
@implementation VideoCaptureMacAVFoundationObjC
-(id)init {
self = [super init];
if (self) {
[self initializeVariables];
}
return self;
}
- (void)dealloc {
if (_captureSession)
[_captureSession stopRunning];
[_captureVideoDataOutput release];
if (_videoDataOutputQueue)
dispatch_release(_videoDataOutputQueue);
[_captureSession release];
[_captureDevices release];
[_lock release];
[super dealloc];
}
#pragma mark Public methods
- (void)registerOwner:(VideoCaptureMacAVFoundation*)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;
for(int index = 0; index < _captureDeviceCount; index++) {
_captureDevice = (AVCaptureDevice*)[_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 localizedName] getCString:_captureDeviceNameUTF8
maxLength:1024
encoding:NSUTF8StringEncoding];
[[_captureDevice uniqueID] getCString:_captureDeviceNameUniqueID
maxLength:1024
encoding:NSUTF8StringEncoding];
break;
}
_captureDevice = nil;
}
if (!_captureDevice)
return NO;
NSError* error;
AVCaptureDeviceInput *deviceInput =
[AVCaptureDeviceInput deviceInputWithDevice:_captureDevice error:&error];
if (deviceInput &&
[_captureSession canAddInput:deviceInput]) {
[_captureSession addInput:deviceInput];
} else {
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 rawType:(webrtc::RawVideoType*)rawType {
_frameWidth = width;
_frameHeight = height;
_frameRate = frameRate;
_rawType = *rawType;
AVCaptureDeviceFormat *bestFormat = nil;
AVFrameRateRange *bestFrameRateRange = nil;
for (AVCaptureDeviceFormat* format in [_captureDevice formats]) {
CMVideoDimensions videoDimensions = CMVideoFormatDescriptionGetDimensions(format.formatDescription);
if (videoDimensions.width == _frameWidth &&
videoDimensions.height == _frameHeight &&
[VideoCaptureMacAVFoundationUtility fourCCToRawVideoType:CMFormatDescriptionGetMediaSubType(format.formatDescription)] == _rawType)
{
bestFormat = format;
for (AVFrameRateRange* range in format.videoSupportedFrameRateRanges) {
if ( range.maxFrameRate <= _frameRate && range.maxFrameRate > bestFrameRateRange.maxFrameRate) {
bestFrameRateRange = range;
}
}
break;
}
}
if (bestFormat && bestFrameRateRange) {
NSDictionary* newSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithDouble:_frameWidth], (id)kCVPixelBufferWidthKey,
[NSNumber numberWithDouble:_frameHeight], (id)kCVPixelBufferHeightKey,
[NSNumber numberWithUnsignedInt:CMFormatDescriptionGetMediaSubType(bestFormat.formatDescription)], (id)kCVPixelBufferPixelFormatTypeKey,
nil];
_captureVideoDataOutput.videoSettings = newSettings;
if ([_captureDevice lockForConfiguration:NULL] == YES) {
_captureDevice.activeFormat = bestFormat;
_captureDevice.activeVideoMinFrameDuration = bestFrameRateRange.minFrameDuration;
[_captureDevice unlockForConfiguration];
}
}
}
- (void)startCapture {
if (_capturing)
return;
[_captureSession startRunning];
_capturing = YES;
}
- (void)stopCapture {
if (!_capturing)
return;
[_captureSession performSelectorOnMainThread:@selector(stopRunning)
withObject:nil
waitUntilDone:NO];
_capturing = NO;
}
#pragma mark Private methods
- (BOOL)initializeVariables {
if (NSClassFromString(@"AVCaptureSession") == 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 = [[AVCaptureSession alloc] init];
_captureVideoDataOutput = [AVCaptureVideoDataOutput new];
[_captureVideoDataOutput setAlwaysDiscardsLateVideoFrames:YES];
_videoDataOutputQueue = dispatch_queue_create("VideoDataOutputQueue", DISPATCH_QUEUE_SERIAL);
[_captureVideoDataOutput setSampleBufferDelegate:self queue:_videoDataOutputQueue];
[self getCaptureDevices];
if (![self initializeVideoCapture])
return NO;
return NO;
}
- (void)getCaptureDevices {
if (_captureDevices)
[_captureDevices release];
_captureDevices = [[NSArray alloc] initWithArray:
[AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]];
_captureDeviceCount = _captureDevices.count;
}
- (BOOL)initializeVideoCapture{
if ([_captureSession canAddOutput:_captureVideoDataOutput]) {
[_captureSession addOutput:_captureVideoDataOutput];
return YES;
} else {
return NO;
}
}
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didDropSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection {
// TODO(mflodman) Experiment more when this happens.
}
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection {
[_lock lock];
if (!_owner) {
[_lock unlock];
return;
}
// Get a CMSampleBuffer's Core Video image buffer for the media data
CVImageBufferRef videoFrame = CMSampleBufferGetImageBuffer(sampleBuffer);
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;
tempCaptureCapability.rawType = _rawType;
_owner->IncomingFrame((unsigned char*)baseAddress, frameSize,
tempCaptureCapability, 0);
CVPixelBufferUnlockBaseAddress(videoFrame, kFlags);
}
[_lock unlock];
_framesDelivered++;
_framesRendered++;
}
@end

Просмотреть файл

@ -0,0 +1,71 @@
/*
* Copyright (c) 2016 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_avfoundation_utility.h
*
*/
#ifndef WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_AVFOUNDATION_VIDEO_CAPTURE_AVFOUNDATION_UTILITY_H_
#define WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_AVFOUNDATION_VIDEO_CAPTURE_AVFOUNDATION_UTILITY_H_
#define MAX_NAME_LENGTH 1024
#define AVFOUNDATION_MIN_WIDTH 0
#define AVFOUNDATION_MAX_WIDTH 2560
#define AVFOUNDATION_DEFAULT_WIDTH 352
#define AVFOUNDATION_MIN_HEIGHT 0
#define AVFOUNDATION_MAX_HEIGHT 1440
#define AVFOUNDATION_DEFAULT_HEIGHT 288
#define AVFOUNDATION_MIN_FRAME_RATE 1
#define AVFOUNDATION_MAX_FRAME_RATE 60
#define AVFOUNDATION_DEFAULT_FRAME_RATE 30
#define RELEASE_AND_CLEAR(p) if (p) { (p) -> Release () ; (p) = NULL ; }
@interface VideoCaptureMacAVFoundationUtility : NSObject {}
+ (webrtc::RawVideoType)fourCCToRawVideoType:(FourCharCode)fourcc;
@end
@implementation VideoCaptureMacAVFoundationUtility
+ (webrtc::RawVideoType)fourCCToRawVideoType:(FourCharCode)fourcc {
switch (fourcc) {
case kCMPixelFormat_32ARGB:
return webrtc::kVideoBGRA;
case kCMPixelFormat_32BGRA:
return webrtc::kVideoARGB;
case kCMPixelFormat_24RGB:
return webrtc::kVideoRGB24;
case kCMPixelFormat_16LE565:
return webrtc::kVideoRGB565;
case kCMPixelFormat_16LE5551:
return webrtc::kVideoARGB1555;
case kCMPixelFormat_422YpCbCr8:
return webrtc::kVideoUYVY;
case kCMPixelFormat_422YpCbCr8_yuvs:
return webrtc::kVideoYUY2;
case kCMVideoCodecType_JPEG_OpenDML:
return webrtc::kVideoMJPEG;
case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange:
case kCVPixelFormatType_420YpCbCr8BiPlanarFullRange:
return webrtc::kVideoNV12;
case kCVPixelFormatType_420YpCbCr8Planar:
case kCVPixelFormatType_420YpCbCr8PlanarFullRange:
return webrtc::kVideoI420;
default:
return webrtc::kVideoUnknown;
}
}
@end
#endif // WEBRTC_MODULES_VIDEO_CAPTURE_MAIN_SOURCE_MAC_AVFOUNDATION_VIDEO_CAPTURE_AVFOUNDATION_UTILITY_H_

Просмотреть файл

@ -26,9 +26,12 @@
#if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version #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.h>
#include <QuickTime/video_capture_quick_time_info.h> #include <QuickTime/video_capture_quick_time_info.h>
#else #elseif __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_7
#include "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit.h" #include "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit.h"
#include "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit_info.h" #include "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit_info.h"
#else
#include "webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation.h"
#include "webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_info.h"
#endif #endif
namespace webrtc namespace webrtc
@ -164,7 +167,7 @@ VideoCaptureModule* VideoCaptureImpl::Create(
deviceUniqueIdUTF8); deviceUniqueIdUTF8);
return newCaptureModule; return newCaptureModule;
#else // QTKit version #elseif __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_7 // QTKit version
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id, WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id,
"Using QTKit framework to capture video", id); "Using QTKit framework to capture video", id);
@ -193,6 +196,35 @@ VideoCaptureModule* VideoCaptureImpl::Create(
"Module created for unique device %s, will use QTKit " "Module created for unique device %s, will use QTKit "
"framework",deviceUniqueIdUTF8); "framework",deviceUniqueIdUTF8);
return newCaptureModule; return newCaptureModule;
#else // AVFoundation version
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id,
"Using AVFoundation framework to capture video", id);
RefCountImpl<videocapturemodule::VideoCaptureMacAVFoundation>* newCaptureModule =
new RefCountImpl<videocapturemodule::VideoCaptureMacAVFoundation>(id);
if(!newCaptureModule)
{
WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, id,
"could not Create for unique device %s, !newCaptureModule",
deviceUniqueIdUTF8);
return NULL;
}
if(newCaptureModule->Init(id, deviceUniqueIdUTF8) != 0)
{
WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, id,
"could not Create for unique device %s, "
"newCaptureModule->Init()!=0", deviceUniqueIdUTF8);
delete newCaptureModule;
return NULL;
}
// Successfully created VideoCaptureMacQuicktime. Return it
WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id,
"Module created for unique device %s, will use AVFoundation "
"framework",deviceUniqueIdUTF8);
return newCaptureModule;
#endif #endif
} }
@ -240,7 +272,7 @@ VideoCaptureImpl::CreateDeviceInfo(const int32_t id)
"VideoCaptureModule created for id", id); "VideoCaptureModule created for id", id);
return newCaptureInfoModule; return newCaptureInfoModule;
#else // QTKit version #elseif __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_7 // QTKit version
webrtc::videocapturemodule::VideoCaptureMacQTKitInfo* newCaptureInfoModule = webrtc::videocapturemodule::VideoCaptureMacQTKitInfo* newCaptureInfoModule =
new webrtc::videocapturemodule::VideoCaptureMacQTKitInfo(id); new webrtc::videocapturemodule::VideoCaptureMacQTKitInfo(id);
@ -258,6 +290,23 @@ VideoCaptureImpl::CreateDeviceInfo(const int32_t id)
"VideoCaptureModule created for id", id); "VideoCaptureModule created for id", id);
return newCaptureInfoModule; return newCaptureInfoModule;
#else // AVFoundation version
webrtc::videocapturemodule::VideoCaptureMacAVFoundationInfo* newCaptureInfoModule =
new webrtc::videocapturemodule::VideoCaptureMacAVFoundationInfo(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 #endif
} }

Просмотреть файл

@ -87,6 +87,15 @@
'mac/qtkit/video_capture_qtkit_objc.h', 'mac/qtkit/video_capture_qtkit_objc.h',
'mac/qtkit/video_capture_qtkit_objc.mm', 'mac/qtkit/video_capture_qtkit_objc.mm',
'mac/qtkit/video_capture_qtkit_utility.h', 'mac/qtkit/video_capture_qtkit_utility.h',
'mac/avfoundation/video_capture_avfoundation.h',
'mac/avfoundation/video_capture_avfoundation.mm',
'mac/avfoundation/video_capture_avfoundation_info.h',
'mac/avfoundation/video_capture_avfoundation_info.mm',
'mac/avfoundation/video_capture_avfoundation_info_objc.h',
'mac/avfoundation/video_capture_avfoundation_info_objc.mm',
'mac/avfoundation/video_capture_avfoundation_objc.h',
'mac/avfoundation/video_capture_avfoundation_objc.mm',
'mac/avfoundation/video_capture_avfoundation_utility.h',
'mac/video_capture_mac.mm', 'mac/video_capture_mac.mm',
], ],
'link_settings': { 'link_settings': {

Просмотреть файл

@ -293,15 +293,6 @@ int ViECaptureImpl::NumberOfCapabilities(
const char* unique_idUTF8, const char* unique_idUTF8,
const unsigned int unique_idUTF8Length) { const unsigned int unique_idUTF8Length) {
#if defined(WEBRTC_MAC)
// TODO(mflodman) Move to capture module!
// QTKit framework handles all capabilities and capture settings
// automatically (mandatory).
// Thus this function cannot be supported on the Mac platform.
shared_data_->SetLastError(kViECaptureDeviceMacQtkitNotSupported);
LOG_F(LS_ERROR) << "API not supported on Mac OS X.";
return -1;
#endif
return shared_data_->input_manager()->NumberOfCaptureCapabilities( return shared_data_->input_manager()->NumberOfCaptureCapabilities(
unique_idUTF8); unique_idUTF8);
} }
@ -312,15 +303,6 @@ int ViECaptureImpl::GetCaptureCapability(const char* unique_idUTF8,
const unsigned int capability_number, const unsigned int capability_number,
CaptureCapability& capability) { CaptureCapability& capability) {
#if defined(WEBRTC_MAC)
// TODO(mflodman) Move to capture module!
// QTKit framework handles all capabilities and capture settings
// automatically (mandatory).
// Thus this function cannot be supported on the Mac platform.
LOG_F(LS_ERROR) << "API not supported on Mac OS X.";
shared_data_->SetLastError(kViECaptureDeviceMacQtkitNotSupported);
return -1;
#endif
if (shared_data_->input_manager()->GetCaptureCapability( if (shared_data_->input_manager()->GetCaptureCapability(
unique_idUTF8, capability_number, capability) != 0) { unique_idUTF8, capability_number, capability) != 0) {
shared_data_->SetLastError(kViECaptureDeviceUnknownError); shared_data_->SetLastError(kViECaptureDeviceUnknownError);
@ -336,15 +318,6 @@ int ViECaptureImpl::ShowCaptureSettingsDialogBox(
void* parent_window, void* parent_window,
const unsigned int x, const unsigned int x,
const unsigned int y) { const unsigned int y) {
#if defined(WEBRTC_MAC)
// TODO(mflodman) Move to capture module
// QTKit framework handles all capabilities and capture settings
// automatically (mandatory).
// Thus this function cannot be supported on the Mac platform.
shared_data_->SetLastError(kViECaptureDeviceMacQtkitNotSupported);
LOG_F(LS_ERROR) << "API not supported on Mac OS X.";
return -1;
#endif
return shared_data_->input_manager()->DisplayCaptureSettingsDialogBox( return shared_data_->input_manager()->DisplayCaptureSettingsDialogBox(
unique_idUTF8, dialog_title, unique_idUTF8, dialog_title,
parent_window, x, y); parent_window, x, y);

Просмотреть файл

@ -153,6 +153,8 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
'-framework OpenGL', '-framework OpenGL',
'-framework SystemConfiguration', '-framework SystemConfiguration',
'-framework QTKit', '-framework QTKit',
'-framework AVFoundation',
'-framework CoreMedia',
'-framework IOKit', '-framework IOKit',
'-F%s' % CONFIG['MACOS_PRIVATE_FRAMEWORKS_DIR'], '-F%s' % CONFIG['MACOS_PRIVATE_FRAMEWORKS_DIR'],
'-framework CoreUI', '-framework CoreUI',