andrew@webrtc.org | a7b57da | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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 | #pragma mark **** imports/includes |
| 12 | |
| 13 | #import "video_capture_qtkit_info_objc.h" |
| 14 | |
| 15 | #include "trace.h" |
| 16 | |
| 17 | using namespace webrtc; |
| 18 | |
| 19 | #pragma mark **** hidden class interface |
| 20 | |
| 21 | @implementation VideoCaptureMacQTKitInfoObjC |
| 22 | |
| 23 | // ****************** over-written OS methods *********************** |
| 24 | #pragma mark **** over-written OS methods |
| 25 | |
| 26 | /// ***** Objective-C. Similar to C++ constructor, although invoked manually |
| 27 | /// ***** Potentially returns an instance of self |
| 28 | -(id)init{ |
| 29 | self = [super init]; |
| 30 | if(nil != self){ |
| 31 | [self checkOSSupported]; |
| 32 | [self initializeVariables]; |
| 33 | } |
| 34 | else |
| 35 | { |
| 36 | return nil; |
| 37 | } |
| 38 | return self; |
| 39 | } |
| 40 | |
| 41 | /// ***** Objective-C. Similar to C++ destructor |
| 42 | /// ***** Returns nothing |
| 43 | - (void)dealloc { |
| 44 | [super dealloc]; |
| 45 | } |
| 46 | |
| 47 | // ****************** public methods ****************** |
| 48 | #pragma mark **** public method implementations |
| 49 | |
| 50 | /// ***** Creates a message box with Cocoa framework |
| 51 | /// ***** Returns 0 on success, -1 otherwise. |
| 52 | - (NSNumber*)displayCaptureSettingsDialogBoxWithDevice:(const char*)deviceUniqueIdUTF8 |
| 53 | AndTitle:(const char*)dialogTitleUTF8 |
| 54 | AndParentWindow:(void*) parentWindow |
| 55 | AtX:(WebRtc_UWord32)positionX |
| 56 | AndY:(WebRtc_UWord32) positionY |
| 57 | { |
| 58 | NSString* strTitle = [NSString stringWithFormat:@"%s", dialogTitleUTF8]; |
| 59 | NSString* strButton = @"Alright"; |
| 60 | NSString* strMessage = [NSString stringWithFormat:@"Device %s is capturing", deviceUniqueIdUTF8]; |
| 61 | NSAlert* alert = [NSAlert alertWithMessageText:strTitle |
| 62 | defaultButton:strButton |
| 63 | alternateButton:nil otherButton:nil |
| 64 | informativeTextWithFormat:strMessage]; |
| 65 | [alert setAlertStyle:NSInformationalAlertStyle]; |
| 66 | [alert runModal]; |
| 67 | return [NSNumber numberWithInt:0]; |
| 68 | } |
| 69 | |
| 70 | - (NSNumber*)getCaptureDeviceCount{ |
| 71 | [self getCaptureDevices]; |
| 72 | return [NSNumber numberWithInt:_captureDeviceCountInfo]; |
| 73 | } |
| 74 | |
| 75 | |
| 76 | - (NSNumber*)getDeviceNamesFromIndex:(WebRtc_UWord32)index |
| 77 | DefaultName:(char*)deviceName |
| 78 | WithLength:(WebRtc_UWord32)deviceNameLength |
| 79 | AndUniqueID:(char*)deviceUniqueID |
| 80 | WithLength:(WebRtc_UWord32)deviceUniqueIDLength |
| 81 | AndProductID:(char*)deviceProductID |
| 82 | WithLength:(WebRtc_UWord32)deviceProductIDLength |
| 83 | { |
| 84 | if(NO == _OSSupportedInfo) |
| 85 | { |
| 86 | return [NSNumber numberWithInt:0]; |
| 87 | } |
| 88 | |
| 89 | if(index >= (WebRtc_UWord32)_captureDeviceCountInfo) |
| 90 | { |
| 91 | return [NSNumber numberWithInt:-1]; |
| 92 | } |
| 93 | |
| 94 | QTCaptureDevice* tempCaptureDevice = |
| 95 | (QTCaptureDevice*)[_captureDevicesInfo objectAtIndex:index]; |
| 96 | if(!tempCaptureDevice) |
| 97 | { |
| 98 | return [NSNumber numberWithInt:-1]; |
| 99 | } |
| 100 | |
| 101 | memset(deviceName, 0, deviceNameLength); |
| 102 | memset(deviceUniqueID, 0, deviceUniqueIDLength); |
| 103 | |
| 104 | bool successful = NO; |
| 105 | |
| 106 | NSString* tempString = [tempCaptureDevice localizedDisplayName]; |
| 107 | successful = [tempString getCString:(char*)deviceName |
| 108 | maxLength:deviceNameLength encoding:NSUTF8StringEncoding]; |
| 109 | if(NO == successful) |
| 110 | { |
| 111 | memset(deviceName, 0, deviceNameLength); |
| 112 | return [NSNumber numberWithInt:-1]; |
| 113 | } |
| 114 | |
| 115 | tempString = [tempCaptureDevice uniqueID]; |
| 116 | successful = [tempString getCString:(char*)deviceUniqueID |
| 117 | maxLength:deviceUniqueIDLength encoding:NSUTF8StringEncoding]; |
| 118 | if(NO == successful) |
| 119 | { |
| 120 | memset(deviceUniqueID, 0, deviceNameLength); |
| 121 | return [NSNumber numberWithInt:-1]; |
| 122 | } |
| 123 | |
| 124 | return [NSNumber numberWithInt:0]; |
| 125 | |
| 126 | } |
| 127 | |
| 128 | // ****************** "private" category functions below here ****************** |
| 129 | #pragma mark **** "private" method implementations |
| 130 | |
| 131 | - (NSNumber*)initializeVariables |
| 132 | { |
| 133 | if(NO == _OSSupportedInfo) |
| 134 | { |
| 135 | return [NSNumber numberWithInt:0]; |
| 136 | } |
| 137 | |
| 138 | _poolInfo = [[NSAutoreleasePool alloc]init]; |
| 139 | _captureDeviceCountInfo = 0; |
| 140 | [self getCaptureDevices]; |
| 141 | |
| 142 | return [NSNumber numberWithInt:0]; |
| 143 | } |
| 144 | |
| 145 | // ***** Checks to see if the QTCaptureSession framework is available in the OS |
| 146 | // ***** If it is not, isOSSupprted = NO |
| 147 | // ***** Throughout the rest of the class isOSSupprted is checked and functions |
| 148 | // ***** are/aren't called depending |
| 149 | // ***** The user can use weak linking to the QTKit framework and run on older |
| 150 | // ***** versions of the OS |
| 151 | // ***** I.E. Backwards compaitibility |
| 152 | // ***** Returns nothing. Sets member variable |
| 153 | - (void)checkOSSupported |
| 154 | { |
| 155 | Class osSupportedTest = NSClassFromString(@"QTCaptureSession"); |
| 156 | _OSSupportedInfo = NO; |
| 157 | if(nil == osSupportedTest) |
| 158 | { |
| 159 | } |
| 160 | _OSSupportedInfo = YES; |
| 161 | } |
| 162 | |
| 163 | /// ***** Retrieves the number of capture devices currently available |
| 164 | /// ***** Stores them in an NSArray instance |
| 165 | /// ***** Returns 0 on success, -1 otherwise. |
| 166 | - (NSNumber*)getCaptureDevices |
| 167 | { |
| 168 | if(NO == _OSSupportedInfo) |
| 169 | { |
| 170 | return [NSNumber numberWithInt:0]; |
| 171 | } |
| 172 | |
| 173 | if(_captureDevicesInfo) |
| 174 | { |
| 175 | [_captureDevicesInfo release]; |
| 176 | } |
| 177 | _captureDevicesInfo = [[NSArray alloc] |
| 178 | initWithArray:[QTCaptureDevice |
| 179 | inputDevicesWithMediaType:QTMediaTypeVideo]]; |
| 180 | |
| 181 | _captureDeviceCountInfo = _captureDevicesInfo.count; |
| 182 | |
| 183 | return [NSNumber numberWithInt:0]; |
| 184 | } |
| 185 | |
| 186 | @end |