Bug 1374938 - use our own avfoundation wrapper. r?jib
MozReview-Commit-ID: KObTvtvRk10
--- a/media/webrtc/trunk/webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation.mm
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation.mm
@@ -31,17 +31,16 @@ private:
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),
--- a/media/webrtc/trunk/webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_info.mm
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_info.mm
@@ -14,18 +14,17 @@
#include "webrtc/system_wrappers/include/trace.h"
#include "nsDebug.h"
namespace webrtc
{
namespace videocapturemodule
{
-VideoCaptureMacAVFoundationInfo::VideoCaptureMacAVFoundationInfo(const int32_t id) :
- DeviceInfoImpl(id)
+VideoCaptureMacAVFoundationInfo::VideoCaptureMacAVFoundationInfo(const int32_t id)
{
nsAutoreleasePool localPool;
_captureInfo = [[VideoCaptureMacAVFoundationInfoObjC alloc] init];
[_captureInfo registerOwner:this];
}
VideoCaptureMacAVFoundationInfo::~VideoCaptureMacAVFoundationInfo()
{
@@ -94,22 +93,22 @@ int32_t VideoCaptureMacAVFoundationInfo:
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,
+ WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, 0,
"API not supported on Mac OS X.");
return -1;
}
int32_t VideoCaptureMacAVFoundationInfo::CreateCapabilityMap(
const char* deviceUniqueIdUTF8)
{
- WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id,
+ WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, 0,
"API not supported on Mac OS X.");
return -1;
}
} // namespace videocapturemodule
} // namespace webrtc
new file mode 100644
--- /dev/null
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/mac/video_capture_mac.mm
@@ -0,0 +1,159 @@
+/*
+ * 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 "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"
+
+#include "webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation.h"
+#include "webrtc/modules/video_capture/mac/avfoundation/video_capture_avfoundation_info.h"
+
+namespace webrtc
+{
+namespace videocapturemodule
+{
+
+// static
+bool CheckOSVersion()
+{
+ // Check OSX version is at least 10.7 (min for AVFoundation)
+ int major = 0;
+ int minor = 0;
+
+ NSString* versionString = [[NSDictionary dictionaryWithContentsOfFile:
+ @"/System/Library/CoreServices/SystemVersion.plist"] objectForKey:@"ProductVersion"];
+ NSArray* versions = [versionString componentsSeparatedByString:@"."];
+ NSUInteger count = [versions count];
+ if (count > 0) {
+ major = [(NSString *)[versions objectAtIndex:0] integerValue];
+ if (count > 1) {
+ minor = [(NSString *)[versions objectAtIndex:1] integerValue];
+ }
+ }
+
+ if (major < 10)
+ {
+ return false;
+ }
+ if ((major == 10) && (minor < 7)) {
+ return false;
+ }
+
+ 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 char* deviceUniqueIdUTF8)
+{
+
+ if (webrtc::videocapturemodule::CheckOSVersion() == false)
+ {
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0,
+ "OS version is too old. Could not create video capture "
+ "module. Returning NULL");
+ return NULL;
+ }
+
+ WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, 0,
+ "Using AVFoundation framework to capture video", 0);
+
+ rtc::scoped_refptr<videocapturemodule::VideoCaptureMacAVFoundation> newCaptureModule(
+ new rtc::RefCountedObject<videocapturemodule::VideoCaptureMacAVFoundation>(0));
+
+ if(!newCaptureModule)
+ {
+ WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, 0,
+ "could not Create for unique device %s, !newCaptureModule",
+ deviceUniqueIdUTF8);
+ return NULL;
+ }
+ if(newCaptureModule->Init(0, deviceUniqueIdUTF8) != 0)
+ {
+ WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, 0,
+ "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, 0,
+ "Module created for unique device %s, will use AVFoundation "
+ "framework",deviceUniqueIdUTF8);
+ return newCaptureModule;
+}
+
+/**************************************************************************
+ *
+ * Create/Destroy a DeviceInfo
+ *
+ ***************************************************************************/
+
+VideoCaptureModule::DeviceInfo*
+VideoCaptureImpl::CreateDeviceInfo()
+{
+
+
+ if (webrtc::videocapturemodule::CheckOSVersion() == false)
+ {
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0,
+ "OS version is too old. Could not create video capture "
+ "module. Returning NULL");
+ return NULL;
+ }
+
+ webrtc::videocapturemodule::VideoCaptureMacAVFoundationInfo* newCaptureInfoModule =
+ new webrtc::videocapturemodule::VideoCaptureMacAVFoundationInfo(0);
+
+ if(!newCaptureInfoModule || newCaptureInfoModule->Init() != 0)
+ {
+ //Destroy(newCaptureInfoModule);
+ delete newCaptureInfoModule;
+ newCaptureInfoModule = NULL;
+ WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, 0,
+ "Failed to Init newCaptureInfoModule created with id %d "
+ "and device \"\" ", 0);
+ return NULL;
+ }
+ WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, 0,
+ "VideoCaptureModule created for id", 0);
+ return newCaptureInfoModule;
+
+}
+
+/**************************************************************************
+ *
+ * End Create/Destroy VideoCaptureModule
+ *
+ ***************************************************************************/
+} // namespace videocapturemodule
+} // namespace webrtc
--- a/media/webrtc/trunk/webrtc/modules/video_capture/video_capture.gypi
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/video_capture.gypi
@@ -70,16 +70,38 @@
['include_v4l2_video_capture==1', {
'sources': [
'linux/device_info_linux.cc',
'linux/device_info_linux.h',
'linux/video_capture_linux.cc',
'linux/video_capture_linux.h',
],
}],
+ ['OS=="mac"', {
+ 'sources': [
+ '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',
+ ],
+ 'link_settings': {
+ 'xcode_settings': {
+ 'OTHER_LDFLAGS': [
+ '-framework Cocoa',
+ '-framework CoreVideo',
+ ],
+ },
+ },
+ }], # mac
['OS=="win"', {
'conditions': [
['build_with_mozilla==0', {
'dependencies': [
'<(DEPTH)/third_party/winsdk_samples/winsdk_samples.gyp:directshow_baseclasses',
],
}],
],
@@ -128,17 +150,17 @@
['OS=="android"', {
'sources': [
'android/device_info_android.cc',
'android/device_info_android.h',
'android/video_capture_android.cc',
'android/video_capture_android.h',
],
}], # android
- ['OS=="ios" or OS=="mac"', {
+ ['OS=="ios"', {
'sources': [
'objc/device_info.h',
'objc/device_info.mm',
'objc/device_info_objc.h',
'objc/device_info_objc.mm',
'objc/rtc_video_capture_objc.h',
'objc/rtc_video_capture_objc.mm',
'objc/video_capture.h',