| 1 | |
|---|
| 2 | |
|---|
| 3 | #include "encoder_example.h" |
|---|
| 4 | |
|---|
| 5 | extern "C" { |
|---|
| 6 | int myOggfwd_init( const char* outIceIp, int outIcePort, |
|---|
| 7 | const char *outUsername, const char *outPassword, const char *outIceMount, |
|---|
| 8 | const char *description, const char *genre, const char *name, const char *url ); |
|---|
| 9 | void myOggfwd_close() ; |
|---|
| 10 | void encoder_example_init(int inW, int inH, int inFramerate, int in_video_r, int in_video_q) ; |
|---|
| 11 | int encoder_example_loop( CVPixelBufferRef imBuffRef ) ; |
|---|
| 12 | int encoder_example_end() ; |
|---|
| 13 | }; |
|---|
| 14 | |
|---|
| 15 | #import "MyController.h" |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #define kNumReaderObjects 20 |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | static CVReturn MyRenderCallback(CVDisplayLinkRef displayLink, |
|---|
| 27 | const CVTimeStamp *inNow, |
|---|
| 28 | const CVTimeStamp *inOutputTime, |
|---|
| 29 | CVOptionFlags flagsIn, |
|---|
| 30 | CVOptionFlags *flagsOut, |
|---|
| 31 | void *displayLinkContext) |
|---|
| 32 | { |
|---|
| 33 | return [(MyController *)displayLinkContext displayLinkCallback:inOutputTime flagsOut:flagsOut]; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | @implementation MyController |
|---|
| 38 | |
|---|
| 39 | #pragma mark ---------- Initialization/Termination ---------- |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | -(id)init |
|---|
| 46 | { |
|---|
| 47 | if (self = [super init]) |
|---|
| 48 | { |
|---|
| 49 | mGLContext = nil; |
|---|
| 50 | |
|---|
| 51 | [[NSNotificationCenter defaultCenter] addObserver:self |
|---|
| 52 | selector:@selector(applicationDidFinishLaunching:) |
|---|
| 53 | name:@"NSApplicationDidFinishLaunchingNotification" object:NSApp]; |
|---|
| 54 | |
|---|
| 55 | [[NSNotificationCenter defaultCenter] addObserver:self |
|---|
| 56 | selector:@selector(applicationWillTerminate:) |
|---|
| 57 | name:@"NSApplicationWillTerminateNotification" object:NSApp]; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | return self; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | - (void) applicationWillTerminate:(NSNotification*)notification |
|---|
| 65 | { |
|---|
| 66 | [myController release] ; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | - (void) applicationDidFinishLaunching:(NSNotification*)notification |
|---|
| 71 | { |
|---|
| 72 | NSOpenGLPixelFormatAttribute attributes[] = { |
|---|
| 73 | NSOpenGLPFAFullScreen, |
|---|
| 74 | NSOpenGLPFAScreenMask, |
|---|
| 75 | (NSOpenGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay), |
|---|
| 76 | (NSOpenGLPixelFormatAttribute) 0 |
|---|
| 77 | }; |
|---|
| 78 | |
|---|
| 79 | mGLPixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; |
|---|
| 80 | NSAssert( mGLPixelFormat != nil, @"No Full-Screen Renderer"); |
|---|
| 81 | if (!mGLPixelFormat) return; |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | mGLContext = [[NSOpenGLContext alloc] initWithFormat:mGLPixelFormat shareContext:nil]; |
|---|
| 85 | NSAssert( mGLContext != nil, @"NSOpenGLContext initialization failure"); |
|---|
| 86 | [mGLContext makeCurrentContext]; |
|---|
| 87 | [mGLContext setFullScreen]; |
|---|
| 88 | |
|---|
| 89 | CGDirectDisplayID displayID = CGMainDisplayID(); |
|---|
| 90 | |
|---|
| 91 | if (displayID) |
|---|
| 92 | { |
|---|
| 93 | mDisplayRect = CGDisplayBounds(displayID); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | [self initINOUT] ; |
|---|
| 99 | |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | #pragma mark -------- Reader -------- |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | - (void) readAndCompressFrames |
|---|
| 117 | { |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | if(mStartTime == 0.0) |
|---|
| 122 | { |
|---|
| 123 | NSTimeInterval time = [NSDate timeIntervalSinceReferenceDate]; |
|---|
| 124 | mStartTime = time; |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | FrameReader *freeReaderObj = [mFrameQueueController removeOldestItemFromFreeQ]; |
|---|
| 129 | if (freeReaderObj) |
|---|
| 130 | { |
|---|
| 131 | [freeReaderObj setBufferReadTime:mStartTime]; |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | [freeReaderObj readScreenAsyncOnSeparateThread]; |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | FrameReader *filledReaderObj = [mFrameQueueController removeOldestItemFromFilledQ]; |
|---|
| 139 | if (filledReaderObj) |
|---|
| 140 | { |
|---|
| 141 | |
|---|
| 142 | [self processImage:[filledReaderObj readScreenAsyncFinish]] ; |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | QueueController *frameQController = [filledReaderObj queueController]; |
|---|
| 146 | [frameQController addItemToFreeQ:filledReaderObj]; |
|---|
| 147 | |
|---|
| 148 | } |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | #pragma mark -------- Display Link -------- |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | - (CVReturn)displayLinkCallback:(const CVTimeStamp*)timeStamp flagsOut:(CVOptionFlags*)flagsOut |
|---|
| 156 | { |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | NSAutoreleasePool *pool = [NSAutoreleasePool new]; |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | [self readAndCompressFrames]; |
|---|
| 165 | |
|---|
| 166 | [pool release]; |
|---|
| 167 | |
|---|
| 168 | return kCVReturnSuccess; |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | #pragma mark ---------- Action Methods ---------- |
|---|
| 172 | |
|---|
| 173 | -(void)pLog:(NSString*)inLog |
|---|
| 174 | { |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | NSRange endRange; |
|---|
| 178 | endRange.location = [[logTextView textStorage] length]; |
|---|
| 179 | endRange.length = 0; |
|---|
| 180 | [logTextView replaceCharactersInRange:endRange withString:inLog]; |
|---|
| 181 | endRange.length = [inLog length]; |
|---|
| 182 | [logTextView scrollRangeToVisible:endRange]; |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | } |
|---|
| 186 | - (IBAction)clearLog:(id)sender |
|---|
| 187 | { |
|---|
| 188 | [logTextView setString:@""] ; |
|---|
| 189 | } |
|---|
| 190 | -(void)initINOUT |
|---|
| 191 | { |
|---|
| 192 | [self pLog:@"[OggZCap] Initialization..\n"] ; |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | totalFrames = 0 ; |
|---|
| 198 | capturing = FALSE ; |
|---|
| 199 | captureRectChanged = FALSE ; |
|---|
| 200 | captureRectChangedCompt = 0 ; |
|---|
| 201 | |
|---|
| 202 | lockF = [NSRecursiveLock new] ; |
|---|
| 203 | |
|---|
| 204 | videOpened = FALSE ; |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | inListening = FALSE ; |
|---|
| 208 | showInPreview = FALSE ; |
|---|
| 209 | showOutPreview = FALSE ; |
|---|
| 210 | |
|---|
| 211 | captureRect = NSMakeRect(0,0,320,240) ; |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | outBitrate = 20000 ; |
|---|
| 215 | outQuality = 16 ; |
|---|
| 216 | outFramerate = 12 ; |
|---|
| 217 | [outFramerateDisplayed setStringValue:[NSString stringWithFormat:@"%d",outFramerate]]; |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | inFramerate = 2 ; |
|---|
| 221 | [inFramerateDisplayed setStringValue:[NSString stringWithFormat:@"%d",inFramerate]]; |
|---|
| 222 | |
|---|
| 223 | [self clearInDisplay] ; |
|---|
| 224 | [self clearOutDisplay] ; |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | [logTextView setSelectable:TRUE] ; |
|---|
| 228 | [logTextView setEditable:FALSE] ; |
|---|
| 229 | |
|---|
| 230 | } |
|---|
| 231 | - (void)clearInDisplay |
|---|
| 232 | { |
|---|
| 233 | CIImage *newI = [CIImage imageWithContentsOfURL: [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource: @"in" ofType: @"png"]]]; |
|---|
| 234 | [inPreviewView setImage:newI] ; |
|---|
| 235 | |
|---|
| 236 | CGRect mmR = CGRectMake(0,0,320,240) ; |
|---|
| 237 | [inPreviewView setCleanRect:(CGRect)mmR]; |
|---|
| 238 | NSRect tmpR = NSMakeRect(0,0,320,240) ; |
|---|
| 239 | [inPreviewView setDisplaySize:*(CGSize *)&tmpR.size]; |
|---|
| 240 | [inPreviewView setNeedsDisplay:YES]; |
|---|
| 241 | } |
|---|
| 242 | - (void)clearOutDisplay |
|---|
| 243 | { |
|---|
| 244 | CIImage *newI = [CIImage imageWithContentsOfURL: [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource: @"out" ofType: @"png"]]]; |
|---|
| 245 | [outPreviewView setImage:newI] ; |
|---|
| 246 | |
|---|
| 247 | CGRect mmR = CGRectMake(0,0,320,240) ; |
|---|
| 248 | [outPreviewView setCleanRect:(CGRect)mmR]; |
|---|
| 249 | NSRect tmpR = NSMakeRect(0,0,320,240) ; |
|---|
| 250 | [outPreviewView setDisplaySize:*(CGSize *)&tmpR.size]; |
|---|
| 251 | [outPreviewView setNeedsDisplay:YES]; |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | -(void)startOut |
|---|
| 255 | { |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | NSString *tmpIcecastIp = [outIcecastIPTF stringValue] ; |
|---|
| 259 | int tmpIcecastPort = [outIcecastPortTF intValue] ; |
|---|
| 260 | |
|---|
| 261 | NSString *tmpStrPassword = [outIcecastPassword stringValue] ; |
|---|
| 262 | NSString *tmpStrUsername = [outIcecastUsername stringValue] ; |
|---|
| 263 | |
|---|
| 264 | NSString *tmpStrName = [projectName stringValue] ; |
|---|
| 265 | NSString *tmpStrAuthor = [projectAuthor stringValue] ; |
|---|
| 266 | NSString *tmpStrDescr = [projectDescr stringValue] ; |
|---|
| 267 | NSString *tmpStrTags = [projectLocation stringValue] ; |
|---|
| 268 | NSString *tmpStrAuthorURL = [NSString stringWithFormat:@"http://wiki.citu.info/users/%@",tmpStrAuthor]; |
|---|
| 269 | NSString *tmpIcecastMount = [NSString stringWithFormat:@"%@.ogg",tmpStrName]; |
|---|
| 270 | #if 0 |
|---|
| 271 | |
|---|
| 272 | const char* cmount = [tmpIcecastMount UTF8String]; |
|---|
| 273 | #else |
|---|
| 274 | char* cmount = strdup([tmpIcecastMount UTF8String]); |
|---|
| 275 | char* tmp; |
|---|
| 276 | while (tmp=strchr(cmount, ' ')) { |
|---|
| 277 | *tmp='_'; |
|---|
| 278 | } |
|---|
| 279 | #endif |
|---|
| 280 | |
|---|
| 281 | [self pLog:[NSString stringWithFormat:@"Starting Video Out to Icecast2 server:\n http://%@:%d/%@\n",tmpIcecastIp,tmpIcecastPort,tmpIcecastMount]] ; |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | const char* cip = [tmpIcecastIp UTF8String]; |
|---|
| 289 | const char* cname = [tmpStrName UTF8String]; |
|---|
| 290 | const char* cdesc = [tmpStrDescr UTF8String]; |
|---|
| 291 | const char* ctags = [tmpStrTags UTF8String]; |
|---|
| 292 | const char* curl = [tmpStrAuthorURL UTF8String]; |
|---|
| 293 | const char* cpass = [tmpStrPassword UTF8String]; |
|---|
| 294 | const char* user = [tmpStrUsername UTF8String]; |
|---|
| 295 | |
|---|
| 296 | int iceConnect = myOggfwd_init(cip, tmpIcecastPort, strlen(user)?user:NULL, cpass, (const char*) cmount, cdesc, ctags, cname, curl) ; |
|---|
| 297 | |
|---|
| 298 | if(iceConnect==1) { |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | outBitrate = [outBitrateTF intValue] ; |
|---|
| 303 | outQuality = [outQualityTF intValue] ; |
|---|
| 304 | int vidW = (int)captureRect.size.width ; |
|---|
| 305 | int vidH = (int)captureRect.size.height ; |
|---|
| 306 | |
|---|
| 307 | encoder_example_init(vidW, vidH, outFramerate, outBitrate, outQuality) ; |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | NSNumber *widthNum,*heightNum; |
|---|
| 313 | |
|---|
| 314 | widthNum = [NSNumber numberWithFloat:captureRect.size.width]; |
|---|
| 315 | heightNum = [NSNumber numberWithFloat:captureRect.size.height]; |
|---|
| 316 | |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | mFrameQueueController = [[QueueController alloc] initWithReaderObjects: |
|---|
| 321 | kNumReaderObjects |
|---|
| 322 | aContext:mGLContext |
|---|
| 323 | pixelsWide:[widthNum unsignedIntValue] |
|---|
| 324 | pixelsHigh:[heightNum unsignedIntValue] ]; |
|---|
| 325 | |
|---|
| 326 | captureRectChanged = TRUE ; |
|---|
| 327 | captureRectChangedCompt = 0 ; |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | |
|---|
| 333 | |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | |
|---|
| 341 | |
|---|
| 342 | |
|---|
| 343 | mStartTime = 0.0 ; |
|---|
| 344 | |
|---|
| 345 | [self startOutTimer:outFramerate] ; |
|---|
| 346 | |
|---|
| 347 | capturing = TRUE ; |
|---|
| 348 | |
|---|
| 349 | [startOutButton setEnabled:NO]; |
|---|
| 350 | [stopOutButton setEnabled:YES]; |
|---|
| 351 | [resizeRadio setEnabled:NO]; |
|---|
| 352 | |
|---|
| 353 | |
|---|
| 354 | [outBitrateTF setEnabled:NO]; |
|---|
| 355 | [outQualityTF setEnabled:NO]; |
|---|
| 356 | [outIcecastIPTF setEnabled:NO]; |
|---|
| 357 | [outIcecastPortTF setEnabled:NO]; |
|---|
| 358 | |
|---|
| 359 | [outIcecastPassword setEnabled:NO]; |
|---|
| 360 | [outIcecastUsername setEnabled:NO]; |
|---|
| 361 | [projectName setEnabled:NO]; |
|---|
| 362 | [projectAuthor setEnabled:NO]; |
|---|
| 363 | [projectLocation setEnabled:NO]; |
|---|
| 364 | [projectDescr setEnabled:NO]; |
|---|
| 365 | |
|---|
| 366 | [self setCaptureWindowMode:TRUE] ; |
|---|
| 367 | [mCaptureTarget makeKeyAndOrderFront:self]; |
|---|
| 368 | [self setCaptureWindowMode:FALSE] ; |
|---|
| 369 | } |
|---|
| 370 | else { |
|---|
| 371 | [self pLog:@"Icecast Server Problem : Video Out stopped...\n"] ; |
|---|
| 372 | } |
|---|
| 373 | } |
|---|
| 374 | |
|---|
| 375 | -(void)stopOut |
|---|
| 376 | { |
|---|
| 377 | [self pLog:@"Stopping Video Out...\n"] ; |
|---|
| 378 | |
|---|
| 379 | capturing = FALSE ; |
|---|
| 380 | |
|---|
| 381 | |
|---|
| 382 | [self stopOutTimer] ; |
|---|
| 383 | |
|---|
| 384 | |
|---|
| 385 | [self clearOutDisplay] ; |
|---|
| 386 | |
|---|
| 387 | |
|---|
| 388 | myOggfwd_close() ; |
|---|
| 389 | encoder_example_end() ; |
|---|
| 390 | totalFrames = 0 ; |
|---|
| 391 | |
|---|
| 392 | |
|---|
| 393 | |
|---|
| 394 | |
|---|
| 395 | |
|---|
| 396 | |
|---|
| 397 | |
|---|
| 398 | |
|---|
| 399 | |
|---|
| 400 | |
|---|
| 401 | |
|---|
| 402 | if (mFrameQueueController) |
|---|
| 403 | { |
|---|
| 404 | [mFrameQueueController release]; |
|---|
| 405 | mFrameQueueController = nil; |
|---|
| 406 | } |
|---|
| 407 | |
|---|
| 408 | [startOutButton setEnabled:YES]; |
|---|
| 409 | [stopOutButton setEnabled:NO]; |
|---|
| 410 | [showZoneButton setEnabled:YES]; |
|---|
| 411 | [resizeRadio setEnabled:YES]; |
|---|
| 412 | |
|---|
| 413 | [outBitrateTF setEnabled:YES]; |
|---|
| 414 | [outQualityTF setEnabled:YES]; |
|---|
| 415 | [outIcecastIPTF setEnabled:YES]; |
|---|
| 416 | [outIcecastPortTF setEnabled:YES]; |
|---|
| 417 | [outIcecastPassword setEnabled:YES]; |
|---|
| 418 | [outIcecastUsername setEnabled:YES]; |
|---|
| 419 | |
|---|
| 420 | [projectName setEnabled:YES]; |
|---|
| 421 | [projectAuthor setEnabled:YES]; |
|---|
| 422 | [projectLocation setEnabled:YES]; |
|---|
| 423 | [projectDescr setEnabled:YES]; |
|---|
| 424 | |
|---|
| 425 | [mCaptureTarget close]; |
|---|
| 426 | } |
|---|
| 427 | |
|---|
| 428 | #pragma mark ---------- Action Loop Methods ---------- |
|---|
| 429 | |
|---|
| 430 | |
|---|
| 431 | |
|---|
| 432 | |
|---|
| 433 | |
|---|
| 434 | - (void)newInFrameProcess |
|---|
| 435 | { |
|---|
| 436 | |
|---|
| 437 | |
|---|
| 438 | |
|---|
| 439 | |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | |
|---|
| 443 | } |
|---|
| 444 | |
|---|
| 445 | - (void)newOutFrameProcess |
|---|
| 446 | { |
|---|
| 447 | CVPixelBufferRef theNewImageBuffer ; |
|---|
| 448 | |
|---|
| 449 | totalFrames++ ; |
|---|
| 450 | |
|---|
| 451 | |
|---|
| 452 | |
|---|
| 453 | |
|---|
| 454 | |
|---|
| 455 | |
|---|
| 456 | NSAutoreleasePool *pool = [NSAutoreleasePool new]; |
|---|
| 457 | |
|---|
| 458 | |
|---|
| 459 | FrameReader *freeReaderObj = [mFrameQueueController removeOldestItemFromFreeQ]; |
|---|
| 460 | if (freeReaderObj) |
|---|
| 461 | { |
|---|
| 462 | |
|---|
| 463 | if(captureRectChanged) { |
|---|
| 464 | captureRectChangedCompt++ ; |
|---|
| 465 | [freeReaderObj setCaptureRect:captureRect] ; |
|---|
| 466 | if(captureRectChangedCompt > kNumReaderObjects*2 ) captureRectChanged = FALSE ; |
|---|
| 467 | } |
|---|
| 468 | |
|---|
| 469 | [freeReaderObj setBufferReadTime:mStartTime]; |
|---|
| 470 | [freeReaderObj readScreenAsyncOnSeparateThread]; |
|---|
| 471 | } |
|---|
| 472 | |
|---|
| 473 | |
|---|
| 474 | FrameReader *filledReaderObj = [mFrameQueueController removeOldestItemFromFilledQ]; |
|---|
| 475 | if (filledReaderObj) |
|---|
| 476 | { |
|---|
| 477 | |
|---|
| 478 | |
|---|
| 479 | |
|---|
| 480 | theNewImageBuffer = [filledReaderObj readScreenAsyncFinish] ; |
|---|
| 481 | #if 0 |
|---|
| 482 | if (theNewImageBuffer != NULL) { |
|---|
| 483 | [self pLog:[NSString stringWithFormat:@"frame %d\n", CVPixelBufferGetWidth(theNewImageBuffer) ]] ; |
|---|
| 484 | } |
|---|
| 485 | #endif |
|---|
| 486 | |
|---|
| 487 | |
|---|
| 488 | |
|---|
| 489 | if(showOutPreview) { |
|---|
| 490 | CIImage *youpImage = [CIImage imageWithCVImageBuffer:theNewImageBuffer]; |
|---|
| 491 | [outPreviewView setImage:youpImage]; |
|---|
| 492 | CGRect mmR = CGRectMake(0,0,captureRect.size.width,captureRect.size.height) ; |
|---|
| 493 | [outPreviewView setCleanRect:(CGRect)mmR]; |
|---|
| 494 | NSRect tmpR = NSMakeRect(0,0,captureRect.size.width,captureRect.size.height) ; |
|---|
| 495 | [outPreviewView setDisplaySize:*(CGSize *)&tmpR.size]; |
|---|
| 496 | [outPreviewView setNeedsDisplay:YES]; |
|---|
| 497 | } |
|---|
| 498 | |
|---|
| 499 | |
|---|
| 500 | |
|---|
| 501 | |
|---|
| 502 | int res = encoder_example_loop( theNewImageBuffer ) ; |
|---|
| 503 | |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | QueueController *frameQController = [filledReaderObj queueController]; |
|---|
| 507 | [frameQController addItemToFreeQ:filledReaderObj]; |
|---|
| 508 | } |
|---|
| 509 | [pool release]; |
|---|
| 510 | |
|---|
| 511 | |
|---|
| 512 | } |
|---|
| 513 | |
|---|
| 514 | - (void)encodeFrame:(CVPixelBufferRef)myBuff |
|---|
| 515 | { |
|---|
| 516 | CVPixelBufferRef givenBuff = (CVPixelBufferRef)myBuff ; |
|---|
| 517 | int res = encoder_example_loop( givenBuff ) ; |
|---|
| 518 | } |
|---|
| 519 | |
|---|
| 520 | |
|---|
| 521 | - (void)processImage:(CVPixelBufferRef)imageBuffer |
|---|
| 522 | { |
|---|
| 523 | |
|---|
| 524 | [lockF lock] ; |
|---|
| 525 | if(imageBuffer) localBuff = imageBuffer ; |
|---|
| 526 | else NSLog(@"(myController) BIG PROBLEM : processImage AREGARDER !!!!!!!!!!!!!!!!!\n"); |
|---|
| 527 | [lockF unlock] ; |
|---|
| 528 | } |
|---|
| 529 | |
|---|
| 530 | |
|---|
| 531 | |
|---|
| 532 | #pragma mark ---------- Timers Methods ---------- |
|---|
| 533 | |
|---|
| 534 | - (void)startOutTimer:(int)_inFramerate |
|---|
| 535 | { |
|---|
| 536 | |
|---|
| 537 | NSTimeInterval previewFramesInterval = 1.0/_inFramerate ; |
|---|
| 538 | |
|---|
| 539 | |
|---|
| 540 | if (outPreviewTimer == nil) { |
|---|
| 541 | |
|---|
| 542 | outPreviewTimer = [[NSTimer scheduledTimerWithTimeInterval:previewFramesInterval target:self selector:@selector(nextOut:) userInfo:nil repeats:YES] retain]; |
|---|
| 543 | } |
|---|
| 544 | } |
|---|
| 545 | - (void)nextOut:(NSTimer *)timer |
|---|
| 546 | { |
|---|
| 547 | [self newOutFrameProcess] ; |
|---|
| 548 | } |
|---|
| 549 | - (void)stopOutTimer |
|---|
| 550 | { |
|---|
| 551 | |
|---|
| 552 | if (outPreviewTimer != nil) { |
|---|
| 553 | |
|---|
| 554 | [outPreviewTimer invalidate]; |
|---|
| 555 | [outPreviewTimer release]; |
|---|
| 556 | outPreviewTimer = nil; |
|---|
| 557 | } |
|---|
| 558 | } |
|---|
| 559 | |
|---|
| 560 | |
|---|
| 561 | |
|---|
| 562 | #pragma mark ---------- GUI Buttons Methods (InOutController) ---------- |
|---|
| 563 | |
|---|
| 564 | - (void)updateServerIP:(NSString*)inStr |
|---|
| 565 | { |
|---|
| 566 | [serverTF setStringValue:inStr] ; |
|---|
| 567 | } |
|---|
| 568 | |
|---|
| 569 | |
|---|
| 570 | |
|---|
| 571 | |
|---|
| 572 | #pragma mark ---------- GUI Buttons Methods (InOutController) ---------- |
|---|
| 573 | - (IBAction)startOutAction:(id)sender |
|---|
| 574 | { |
|---|
| 575 | [self startOut]; |
|---|
| 576 | } |
|---|
| 577 | |
|---|
| 578 | - (IBAction)stopOutAction:(id)sender |
|---|
| 579 | { |
|---|
| 580 | [self stopOut]; |
|---|
| 581 | } |
|---|
| 582 | |
|---|
| 583 | |
|---|
| 584 | #pragma mark ---------- Buttons Methods ---------- |
|---|
| 585 | |
|---|
| 586 | - (IBAction)outFramerateStepper:(id)sender |
|---|
| 587 | { |
|---|
| 588 | outFramerate = [sender intValue]; |
|---|
| 589 | [outFramerateDisplayed setStringValue:[NSString stringWithFormat:@"%d",outFramerate]]; |
|---|
| 590 | } |
|---|
| 591 | |
|---|
| 592 | - (void)toggleOutPreview:(id)sender |
|---|
| 593 | { |
|---|
| 594 | showOutPreview = ([sender intValue]==1) ; |
|---|
| 595 | |
|---|
| 596 | if(!showOutPreview) [self clearOutDisplay] ; |
|---|
| 597 | } |
|---|
| 598 | |
|---|
| 599 | - (IBAction)setSizeAndPosition:(id)sender |
|---|
| 600 | { |
|---|
| 601 | |
|---|
| 602 | |
|---|
| 603 | |
|---|
| 604 | |
|---|
| 605 | captureRect = [mCaptureTarget frame] ; |
|---|
| 606 | captureRectChanged = TRUE ; |
|---|
| 607 | captureRectChangedCompt = 0 ; |
|---|
| 608 | |
|---|
| 609 | |
|---|
| 610 | |
|---|
| 611 | |
|---|
| 612 | [self setCaptureWindowMode:FALSE] ; |
|---|
| 613 | |
|---|
| 614 | |
|---|
| 615 | } |
|---|
| 616 | |
|---|
| 617 | - (void)setCaptureWindowMode:(BOOL)mode |
|---|
| 618 | { |
|---|
| 619 | if(mode) { |
|---|
| 620 | |
|---|
| 621 | [mCaptureTarget setAlphaValue:0.5]; |
|---|
| 622 | [mCaptureTarget setBackgroundColor: [NSColor redColor]]; |
|---|
| 623 | |
|---|
| 624 | [mCaptureTarget setMovableByWindowBackground: YES] ; |
|---|
| 625 | |
|---|
| 626 | [setSizeChoicesBox setHidden:FALSE] ; |
|---|
| 627 | } |
|---|
| 628 | else { |
|---|
| 629 | |
|---|
| 630 | [mCaptureTarget setAlphaValue:1]; |
|---|
| 631 | [mCaptureTarget setBackgroundColor:[NSColor clearColor]]; |
|---|
| 632 | [mCaptureTarget setOpaque:NO]; |
|---|
| 633 | [mCaptureTarget setMovableByWindowBackground: NO] ; |
|---|
| 634 | |
|---|
| 635 | [setSizeChoicesBox setHidden:TRUE] ; |
|---|
| 636 | } |
|---|
| 637 | [mCaptureTarget display] ; |
|---|
| 638 | } |
|---|
| 639 | |
|---|
| 640 | - (IBAction)setCaptureSize:(id)sender |
|---|
| 641 | { |
|---|
| 642 | int rowS =[sender selectedRow] ; |
|---|
| 643 | int colS =[sender selectedColumn] ; |
|---|
| 644 | int newW,newH ; |
|---|
| 645 | NSRect oldFrame, newFrame ; |
|---|
| 646 | int newX, newY ; |
|---|
| 647 | |
|---|
| 648 | switch(rowS) { |
|---|
| 649 | case 0: |
|---|
| 650 | if(colS==0) {newW=160; newH=128;} |
|---|
| 651 | else {newW=400; newH=304;} |
|---|
| 652 | break; |
|---|
| 653 | case 1: |
|---|
| 654 | if(colS==0) {newW=208; newH=160;} |
|---|
| 655 | else {newW=640; newH=480;} |
|---|
| 656 | break; |
|---|
| 657 | case 2: |
|---|
| 658 | if(colS==0) {newW=320; newH=240;} |
|---|
| 659 | else {newW=800; newH=608;} |
|---|
| 660 | break; |
|---|
| 661 | } |
|---|
| 662 | |
|---|
| 663 | oldFrame = [mCaptureTarget frame] ; |
|---|
| 664 | newX = oldFrame.origin.x + oldFrame.size.width/2 - newW/2 ; |
|---|
| 665 | newY = oldFrame.origin.y + (oldFrame.size.height)/2 - newH/2 ; |
|---|
| 666 | |
|---|
| 667 | newFrame = NSMakeRect(newX,newY,newW,newH) ; |
|---|
| 668 | [mCaptureTarget setFrame:newFrame display:YES] ; |
|---|
| 669 | |
|---|
| 670 | |
|---|
| 671 | |
|---|
| 672 | [self pLog:[NSString stringWithFormat:@"Capture Size: %d:%d\n", newW, newH]] ; |
|---|
| 673 | } |
|---|
| 674 | |
|---|
| 675 | #pragma mark ---------- Windows ---------- |
|---|
| 676 | |
|---|
| 677 | - (IBAction)showInOutCaptureTarget:(id)sender |
|---|
| 678 | { |
|---|
| 679 | |
|---|
| 680 | [self setCaptureWindowMode:TRUE] ; |
|---|
| 681 | [mCaptureTarget makeKeyAndOrderFront:self]; |
|---|
| 682 | } |
|---|
| 683 | |
|---|
| 684 | |
|---|
| 685 | - (IBAction)showInOutWindow:(id)sender |
|---|
| 686 | { |
|---|
| 687 | |
|---|
| 688 | [mMovieCaptureWindow center]; |
|---|
| 689 | [mMovieCaptureWindow makeKeyAndOrderFront:self]; |
|---|
| 690 | } |
|---|
| 691 | |
|---|
| 692 | |
|---|
| 693 | |
|---|
| 694 | - (IBAction)closeInOutWindow:(id)sender |
|---|
| 695 | { |
|---|
| 696 | |
|---|
| 697 | |
|---|
| 698 | [mMovieCaptureWindow close]; |
|---|
| 699 | [mCaptureTarget close]; |
|---|
| 700 | } |
|---|
| 701 | |
|---|
| 702 | |
|---|
| 703 | |
|---|
| 704 | |
|---|
| 705 | |
|---|
| 706 | |
|---|
| 707 | |
|---|
| 708 | |
|---|
| 709 | @end |
|---|