OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 /* |
| 12 * video_capture_mac.cc |
| 13 * |
| 14 */ |
| 15 |
| 16 #include <QuickTime/QuickTime.h> |
| 17 |
| 18 #include "webrtc/base/refcount.h" |
| 19 #include "webrtc/base/scoped_ref_ptr.h" |
| 20 #include "webrtc/modules/video_capture/device_info_impl.h" |
| 21 #include "webrtc/modules/video_capture/video_capture_config.h" |
| 22 #include "webrtc/modules/video_capture/video_capture_impl.h" |
| 23 #include "webrtc/system_wrappers/include/trace.h" |
| 24 |
| 25 // 10.4 support must be decided runtime. We will just decide which framework to |
| 26 // use at compile time "work" classes. One for QTKit, one for QuickTime |
| 27 #if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version |
| 28 #include <QuickTime/video_capture_quick_time.h> |
| 29 #include <QuickTime/video_capture_quick_time_info.h> |
| 30 #else |
| 31 #include "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit.h" |
| 32 #include "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit_info.h" |
| 33 #endif |
| 34 |
| 35 namespace webrtc |
| 36 { |
| 37 namespace videocapturemodule |
| 38 { |
| 39 |
| 40 // static |
| 41 bool CheckOSVersion() |
| 42 { |
| 43 // Check OSX version |
| 44 OSErr err = noErr; |
| 45 |
| 46 SInt32 version; |
| 47 |
| 48 err = Gestalt(gestaltSystemVersion, &version); |
| 49 if (err != noErr) |
| 50 { |
| 51 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
| 52 "Could not get OS version"); |
| 53 return false; |
| 54 } |
| 55 |
| 56 if (version < 0x00001040) // Older version than Mac OSX 10.4 |
| 57 { |
| 58 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
| 59 "OS version too old: 0x%x", version); |
| 60 return false; |
| 61 } |
| 62 |
| 63 WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, 0, |
| 64 "OS version compatible: 0x%x", version); |
| 65 |
| 66 return true; |
| 67 } |
| 68 |
| 69 // static |
| 70 bool CheckQTVersion() |
| 71 { |
| 72 // Check OSX version |
| 73 OSErr err = noErr; |
| 74 |
| 75 SInt32 version; |
| 76 |
| 77 err = Gestalt(gestaltQuickTime, &version); |
| 78 if (err != noErr) |
| 79 { |
| 80 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
| 81 "Could not get QuickTime version"); |
| 82 return false; |
| 83 } |
| 84 |
| 85 if (version < 0x07000000) // QT v. 7.x or newer (QT 5.0.2 0x05020000) |
| 86 { |
| 87 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
| 88 "QuickTime version too old: 0x%x", version); |
| 89 return false; |
| 90 } |
| 91 |
| 92 WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, 0, |
| 93 "QuickTime version compatible: 0x%x", version); |
| 94 return true; |
| 95 } |
| 96 |
| 97 /************************************************************************** |
| 98 * |
| 99 * Create/Destroy a VideoCaptureModule |
| 100 * |
| 101 ***************************************************************************/ |
| 102 |
| 103 /* |
| 104 * Returns version of the module and its components |
| 105 * |
| 106 * version - buffer to which the version will be written |
| 107 * remainingBufferInBytes - remaining number of int8_t in the version |
| 108 * buffer |
| 109 * position - position of the next empty int8_t in the |
| 110 * version buffer |
| 111 */ |
| 112 |
| 113 rtc::scoped_refptr<VideoCaptureModule> VideoCaptureImpl::Create( |
| 114 const int32_t id, |
| 115 const char* deviceUniqueIdUTF8) { |
| 116 if (!CheckOSVersion()) { |
| 117 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id, |
| 118 "OS version is too old. Could not create video capture " |
| 119 "module. Returning NULL"); |
| 120 return nullptr; |
| 121 } |
| 122 |
| 123 #if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version |
| 124 if (!CheckQTVersion()) |
| 125 { |
| 126 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id, |
| 127 "QuickTime version is too old. Could not create video " |
| 128 "capture module. Returning NULL"); |
| 129 return nullptr; |
| 130 } |
| 131 |
| 132 WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id, |
| 133 "%s line %d. QTKit is not supported on this machine. Using " |
| 134 "QuickTime framework to capture video", |
| 135 __FILE__, __LINE__); |
| 136 |
| 137 rtc::scoped_refptr<VideoCaptureMacQuickTime> newCaptureModule( |
| 138 new rtc::RefCountedObject<VideoCaptureMacQuickTime>(id)); |
| 139 |
| 140 if (newCaptureModule->Init(id, deviceUniqueIdUTF8) != 0) |
| 141 { |
| 142 WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, id, |
| 143 "could not Create for unique device %s, " |
| 144 "newCaptureModule->Init()!=0", |
| 145 deviceUniqueIdUTF8); |
| 146 return nullptr; |
| 147 } |
| 148 |
| 149 // Successfully created VideoCaptureMacQuicktime. Return it |
| 150 WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id, |
| 151 "Module created for unique device %s. Will use QuickTime " |
| 152 "framework to capture", |
| 153 deviceUniqueIdUTF8); |
| 154 return newCaptureModule; |
| 155 |
| 156 #else // QTKit version |
| 157 |
| 158 WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id, |
| 159 "Using QTKit framework to capture video", id); |
| 160 |
| 161 rtc::scoped_refptr<VideoCaptureMacQTKit> newCaptureModule( |
| 162 new rtc::RefCountedObject<VideoCaptureMacQTKit>(id)); |
| 163 |
| 164 if(newCaptureModule->Init(id, deviceUniqueIdUTF8) != 0) |
| 165 { |
| 166 WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideoCapture, id, |
| 167 "could not Create for unique device %s, " |
| 168 "newCaptureModule->Init()!=0", deviceUniqueIdUTF8); |
| 169 return nullptr; |
| 170 } |
| 171 |
| 172 // Successfully created VideoCaptureMacQuicktime. Return it |
| 173 WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id, |
| 174 "Module created for unique device %s, will use QTKit " |
| 175 "framework",deviceUniqueIdUTF8); |
| 176 return newCaptureModule; |
| 177 #endif |
| 178 } |
| 179 |
| 180 /************************************************************************** |
| 181 * |
| 182 * Create/Destroy a DeviceInfo |
| 183 * |
| 184 ***************************************************************************/ |
| 185 |
| 186 VideoCaptureModule::DeviceInfo* |
| 187 VideoCaptureImpl::CreateDeviceInfo(const int32_t id) |
| 188 { |
| 189 |
| 190 |
| 191 if (webrtc::videocapturemodule::CheckOSVersion() == false) |
| 192 { |
| 193 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id, |
| 194 "OS version is too old. Could not create video capture " |
| 195 "module. Returning NULL"); |
| 196 return NULL; |
| 197 } |
| 198 |
| 199 #if __MAC_OS_X_VERSION_MIN_REQUIRED == __MAC_10_4 // QuickTime version |
| 200 if (webrtc::videocapturemodule::CheckQTVersion() == false) |
| 201 { |
| 202 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, id, |
| 203 "QuickTime version is too old. Could not create video " |
| 204 "capture module. Returning NULL"); |
| 205 return NULL; |
| 206 } |
| 207 |
| 208 webrtc::videocapturemodule::VideoCaptureMacQuickTimeInfo* newCaptureInfoModu
le = |
| 209 new webrtc::videocapturemodule::VideoCaptureMacQuickTimeInfo(id); |
| 210 |
| 211 if (!newCaptureInfoModule || newCaptureInfoModule->Init() != 0) |
| 212 { |
| 213 Destroy(newCaptureInfoModule); |
| 214 newCaptureInfoModule = NULL; |
| 215 WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id, |
| 216 "Failed to Init newCaptureInfoModule created with id %d " |
| 217 "and device \"\" ", id); |
| 218 return NULL; |
| 219 } |
| 220 WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id, |
| 221 "VideoCaptureModule created for id", id); |
| 222 return newCaptureInfoModule; |
| 223 |
| 224 #else // QTKit version |
| 225 webrtc::videocapturemodule::VideoCaptureMacQTKitInfo* newCaptureInfoModule = |
| 226 new webrtc::videocapturemodule::VideoCaptureMacQTKitInfo(id); |
| 227 |
| 228 if(!newCaptureInfoModule || newCaptureInfoModule->Init() != 0) |
| 229 { |
| 230 //Destroy(newCaptureInfoModule); |
| 231 delete newCaptureInfoModule; |
| 232 newCaptureInfoModule = NULL; |
| 233 WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id, |
| 234 "Failed to Init newCaptureInfoModule created with id %d " |
| 235 "and device \"\" ", id); |
| 236 return NULL; |
| 237 } |
| 238 WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, id, |
| 239 "VideoCaptureModule created for id", id); |
| 240 return newCaptureInfoModule; |
| 241 |
| 242 #endif |
| 243 |
| 244 } |
| 245 |
| 246 /************************************************************************** |
| 247 * |
| 248 * End Create/Destroy VideoCaptureModule |
| 249 * |
| 250 ***************************************************************************/ |
| 251 } // namespace videocapturemodule |
| 252 } // namespace webrtc |
OLD | NEW |