2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #pragma mark **** imports/includes
13 #import "webrtc/modules/video_capture/mac/qtkit/video_capture_qtkit_info_objc.h"
15 #include "webrtc/system_wrappers/interface/trace.h"
17 using namespace webrtc;
19 #pragma mark **** hidden class interface
21 @implementation VideoCaptureMacQTKitInfoObjC
23 // ****************** over-written OS methods ***********************
24 #pragma mark **** over-written OS methods
26 /// ***** Objective-C. Similar to C++ constructor, although invoked manually
27 /// ***** Potentially returns an instance of self
31 [self checkOSSupported];
32 [self initializeVariables];
41 /// ***** Objective-C. Similar to C++ destructor
42 /// ***** Returns nothing
45 [_captureDevicesInfo release];
50 // ****************** public methods ******************
51 #pragma mark **** public method implementations
53 /// ***** Creates a message box with Cocoa framework
54 /// ***** Returns 0 on success, -1 otherwise.
55 - (NSNumber*)displayCaptureSettingsDialogBoxWithDevice:(const char*)deviceUniqueIdUTF8
56 AndTitle:(const char*)dialogTitleUTF8
57 AndParentWindow:(void*) parentWindow
58 AtX:(uint32_t)positionX
59 AndY:(uint32_t) positionY
61 NSString* strTitle = [NSString stringWithFormat:@"%s", dialogTitleUTF8];
62 NSString* strButton = @"Alright";
63 NSAlert* alert = [NSAlert alertWithMessageText:strTitle
64 defaultButton:strButton
65 alternateButton:nil otherButton:nil
66 informativeTextWithFormat:@"Device %s is capturing", deviceUniqueIdUTF8];
67 [alert setAlertStyle:NSInformationalAlertStyle];
69 return [NSNumber numberWithInt:0];
72 - (NSNumber*)getCaptureDeviceCount{
73 [self getCaptureDevices];
74 return [NSNumber numberWithInt:_captureDeviceCountInfo];
78 - (NSNumber*)getDeviceNamesFromIndex:(uint32_t)index
79 DefaultName:(char*)deviceName
80 WithLength:(uint32_t)deviceNameLength
81 AndUniqueID:(char*)deviceUniqueID
82 WithLength:(uint32_t)deviceUniqueIDLength
83 AndProductID:(char*)deviceProductID
84 WithLength:(uint32_t)deviceProductIDLength
86 if(NO == _OSSupportedInfo)
88 return [NSNumber numberWithInt:0];
91 if(index >= (uint32_t)_captureDeviceCountInfo)
93 return [NSNumber numberWithInt:-1];
96 QTCaptureDevice* tempCaptureDevice =
97 (QTCaptureDevice*)[_captureDevicesInfo objectAtIndex:index];
98 if(!tempCaptureDevice)
100 return [NSNumber numberWithInt:-1];
103 memset(deviceName, 0, deviceNameLength);
104 memset(deviceUniqueID, 0, deviceUniqueIDLength);
106 bool successful = NO;
108 NSString* tempString = [tempCaptureDevice localizedDisplayName];
109 successful = [tempString getCString:(char*)deviceName
110 maxLength:deviceNameLength encoding:NSUTF8StringEncoding];
113 memset(deviceName, 0, deviceNameLength);
114 return [NSNumber numberWithInt:-1];
117 tempString = [tempCaptureDevice uniqueID];
118 successful = [tempString getCString:(char*)deviceUniqueID
119 maxLength:deviceUniqueIDLength encoding:NSUTF8StringEncoding];
122 memset(deviceUniqueID, 0, deviceNameLength);
123 return [NSNumber numberWithInt:-1];
126 return [NSNumber numberWithInt:0];
130 // ****************** "private" category functions below here ******************
131 #pragma mark **** "private" method implementations
133 - (NSNumber*)initializeVariables
135 if(NO == _OSSupportedInfo)
137 return [NSNumber numberWithInt:0];
140 _poolInfo = [[NSAutoreleasePool alloc]init];
141 _captureDeviceCountInfo = 0;
142 [self getCaptureDevices];
144 return [NSNumber numberWithInt:0];
147 // ***** Checks to see if the QTCaptureSession framework is available in the OS
148 // ***** If it is not, isOSSupprted = NO
149 // ***** Throughout the rest of the class isOSSupprted is checked and functions
150 // ***** are/aren't called depending
151 // ***** The user can use weak linking to the QTKit framework and run on older
152 // ***** versions of the OS
153 // ***** I.E. Backwards compaitibility
154 // ***** Returns nothing. Sets member variable
155 - (void)checkOSSupported
157 Class osSupportedTest = NSClassFromString(@"QTCaptureSession");
158 if(nil == osSupportedTest)
160 _OSSupportedInfo = NO;
164 _OSSupportedInfo = YES;
168 /// ***** Retrieves the number of capture devices currently available
169 /// ***** Stores them in an NSArray instance
170 /// ***** Returns 0 on success, -1 otherwise.
171 - (NSNumber*)getCaptureDevices
173 if(NO == _OSSupportedInfo)
175 return [NSNumber numberWithInt:0];
178 if(_captureDevicesInfo)
180 [_captureDevicesInfo release];
182 _captureDevicesInfo = [[NSArray alloc]
183 initWithArray:[QTCaptureDevice
184 inputDevicesWithMediaType:QTMediaTypeVideo]];
186 _captureDeviceCountInfo = _captureDevicesInfo.count;
188 return [NSNumber numberWithInt:0];