root/oggzcap/src/MyController.mm

Revision 63f5355ba2b2e52bba2f4711e90306f3bbd42a3e, 21.8 kB (checked in by Robin Gareus <rgareus@…>, 14 months ago)

oggZcap: added icecast2 username entry.

  • Property mode set to 100755
Line 
1
2//////// InOut Theora encoder example + oggfwd
3#include "encoder_example.h"
4
5extern "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// Number of reader objects used by the program at once.
18// Each reader object is designed to read and hold a
19// single screen frame buffer.
20#define kNumReaderObjects               20
21
22// This is the CoreVideo display link callback. The display link invokes
23// this callback whenever it wants you to output a frame. In our case,
24// we call our displayLinkCallback to perform readback of the screen using
25// OpenGL
26static 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// Setup notifications to let us know when application is finished
42// launching so we can use this time to create the OpenGL context
43// used to render, and to let us know when the app. is terminating
44// so  we can perform cleanup
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// Perform cleanup when the application terminates
64- (void) applicationWillTerminate:(NSNotification*)notification
65{       
66        [myController release] ;
67}
68
69// Create OpenGL context used to render
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        //Create OpenGL context used to render
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        //NSAssert( displayID != nil, @"CGMainDisplayID failure");
91        if (displayID)
92        {
93                mDisplayRect = CGDisplayBounds(displayID);
94        }
95       
96       
97        // INOUT INIT ALL
98        [self initINOUT] ;
99       
100}
101
102
103
104#pragma mark -------- Reader --------
105
106// Called from our display link callback.
107// This routine will attempt to get an available reader object
108// to initiate a screen grab operation (to fill the object's buffer).
109// It then checks to see if any reader objects have indeed been
110// filled (a screen grab operation has completed and the object's
111// buffer is filled) and if so it passes the reader object to the
112// exporter/compressor object so it can be compressed and the frame
113// added to the movie.
114
115// INOUT - OLD ONE
116- (void) readAndCompressFrames
117{
118        //InOut //NSLog(@"Read and Compress Frames\n");
119       
120        //Compute the local time
121        if(mStartTime == 0.0)
122        {
123                NSTimeInterval  time = [NSDate timeIntervalSinceReferenceDate];
124                mStartTime = time;
125        }
126
127        // Get an available reader object from the reader "free" queue
128        FrameReader *freeReaderObj = [mFrameQueueController removeOldestItemFromFreeQ];
129        if (freeReaderObj)
130        {
131                [freeReaderObj setBufferReadTime:mStartTime];
132                // pass object to FrameReader and do a read operation
133                // this call spawns a new thread to do the read
134                [freeReaderObj readScreenAsyncOnSeparateThread];
135        }
136       
137        // see if there are available frames in the "filled" queue
138        FrameReader *filledReaderObj = [mFrameQueueController removeOldestItemFromFilledQ];
139        if (filledReaderObj)
140        {
141                // get the frame and process it (processImage)         
142                [self processImage:[filledReaderObj readScreenAsyncFinish]] ;
143               
144                // Ok... next
145                QueueController *frameQController = [filledReaderObj queueController];
146                [frameQController addItemToFreeQ:filledReaderObj];
147               
148        }
149}
150
151#pragma mark -------- Display Link --------
152
153// This is called from the Display Link callback.
154// We'll use this callback to read/compress our frames.
155- (CVReturn)displayLinkCallback:(const CVTimeStamp*)timeStamp flagsOut:(CVOptionFlags*)flagsOut
156{
157        // there is no autorelease pool when this method is called because it will be called from another thread
158        // it's important to create one or you will leak objects
159        NSAutoreleasePool *pool = [NSAutoreleasePool new];
160
161        // Each iteration we will attemp to read the screen into a buffer (if
162        // one is available), compress the buffer contents, then add the
163        // compressed frame to a movie
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        //[logTextField setStringValue:[NSString stringWithFormat:@"%@\n%@",inLog,[logTextField stringValue]]] ;
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        //[logTextView insertText:inLog] ;
185}
186- (IBAction)clearLog:(id)sender
187{
188        [logTextView setString:@""] ;
189}
190-(void)initINOUT
191{
192        [self pLog:@"[OggZCap] Initialization..\n"] ;
193       
194//      NSRect srcRect = NSMakeRect(0, 0, 320, 240);
195//      inPreviewView = [[SampleCIView alloc] initWithFrame:srcRect];
196       
197        totalFrames = 0 ;
198        capturing = FALSE ;
199        captureRectChanged = FALSE ;
200        captureRectChangedCompt = 0 ;
201       
202        lockF = [NSRecursiveLock new] ;
203       
204        videOpened = FALSE ;
205       
206        // Global variables
207        inListening = FALSE ;
208        showInPreview = FALSE ;
209        showOutPreview = FALSE ;
210       
211        captureRect = NSMakeRect(0,0,320,240) ;
212       
213        // OUT Video Settings
214        outBitrate = 20000 ;
215        outQuality = 16 ;
216        outFramerate = 12 ;
217        [outFramerateDisplayed setStringValue:[NSString stringWithFormat:@"%d",outFramerate]];
218       
219        // IN Video Settings
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        // INIT myOggfwd
258        NSString *tmpIcecastIp = [outIcecastIPTF stringValue] ;
259        int tmpIcecastPort = [outIcecastPortTF intValue] ;
260//      NSString *tmpIcecastMount = [outIcecastMountTF stringValue] ;
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//      tmpIcecastMount = [tmpIcecastMount stringByReplacingOccurancesOfString:@" " withString:@"_"]; // WTF 10.5 only
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        char *cip = (char*)malloc(sizeof(char)*99);
284        char *cmount = (char*)malloc(sizeof(char)*strlen(...));
285        strcpy(cip, [tmpIcecastIp UTF8String]) ;
286        strcpy(cmount, [tmpIcecastMount UTF8String]) ;
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                // INIT encoder_example
301                // sample values = 7,20000,16 ...
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                // Start Screen Capture
311               
312                NSNumber *widthNum,*heightNum;
313               
314                widthNum = [NSNumber numberWithFloat:captureRect.size.width];
315                heightNum = [NSNumber numberWithFloat:captureRect.size.height];
316                //NSLog(@"(myController) LAUNCHING new capture with size : %d x %d \n",widthNum,heightNum);
317               
318                // make a frame queue controller, which will create and manage the
319                // underlying set of (multiple) frame reader objects
320                mFrameQueueController = [[QueueController alloc] initWithReaderObjects:
321                        kNumReaderObjects       // create this many frame reader objects
322                                                                                                                                          aContext:mGLContext
323                                                                                                                                        pixelsWide:[widthNum unsignedIntValue]
324                                                                                                                                        pixelsHigh:[heightNum unsignedIntValue] ];
325               
326                captureRectChanged = TRUE ;
327                captureRectChangedCompt = 0 ;
328               
329                //      // create display link for the main display
330                //      CVDisplayLinkCreateWithCGDisplay(kCGDirectMainDisplay, &mDisplayLink);
331                //      if (NULL != mDisplayLink)
332                //      {
333                //              // set the current display of a display link.
334                //              CVDisplayLinkSetCurrentCGDisplay(mDisplayLink, kCGDirectMainDisplay);
335                //                     
336                //              // set the renderer output callback function
337                //              CVDisplayLinkSetOutputCallback(mDisplayLink, &MyRenderCallback, self);
338                //                     
339                //              // activates a display link.
340                //              CVDisplayLinkStart(mDisplayLink);
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                //[showZoneButton setEnabled:NO];
353               
354                [outBitrateTF setEnabled:NO];
355                [outQualityTF setEnabled:NO];
356                [outIcecastIPTF setEnabled:NO];
357                [outIcecastPortTF setEnabled:NO];
358//              [outIcecastMountTF setEnabled:NO];
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        ////////////////// Stop Out Timer
382        [self stopOutTimer] ;
383       
384        ////////////////// Clear Display
385        [self clearOutDisplay] ;
386               
387        ////////////////// Stop and clean encoder & oggfwd
388        myOggfwd_close() ;
389        encoder_example_end() ;
390        totalFrames = 0 ;
391       
392        // Stop CVDisplayLink to prevent
393        // more frames from being read
394//      if (mDisplayLink)
395//      {
396//              CVDisplayLinkStop(mDisplayLink);
397//              CVDisplayLinkRelease(mDisplayLink);
398//              mDisplayLink = NULL;
399//      }
400
401        // Free our queue controller
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//      [outIcecastMountTF setEnabled:YES];
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// IN OUT LOOPS
433
434- (void)newInFrameProcess
435{
436        ////////////////////////////////
437
438        ////////////////////////////////
439        // Update Image Preview
440        //if(!showInPreview)
441        //CIImage *inImage = [CIImage imageWithCVImageBuffer:theNewImageBuffer];
442        //[inPreviewView setImage:inImage];
443}
444
445- (void)newOutFrameProcess
446{       
447        CVPixelBufferRef theNewImageBuffer ;
448       
449        totalFrames++ ;
450       
451        //NSLog(@"//////////////////////////////////////(myController) %d FRAME PROCESS BEGIN\n", totalFrames);
452               
453        ////////////////////////////////////////////////////////////////////
454        // GET IMAGE FROM SCREEN
455        ////////////////////////////////////////////////////////////////////
456        NSAutoreleasePool *pool = [NSAutoreleasePool new];
457       
458        // Get an available reader object from the reader "free" queue
459        FrameReader *freeReaderObj = [mFrameQueueController removeOldestItemFromFreeQ];
460        if (freeReaderObj)
461        {
462                // set capture position and size
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        // see if there are available frames in the "filled" queue
474        FrameReader *filledReaderObj = [mFrameQueueController removeOldestItemFromFilledQ];
475        if (filledReaderObj)
476        {
477                //[self pLog:[NSString stringWithFormat:@"Processing: %d\n",totalFrames]] ;
478
479                // get the frame and process it (processImage)
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                // Update Image Preview
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                // Encode Frame (result is forwarded to myOggfwd)
501                ////////////////////////////////////////////////////////////////////
502                int res = encoder_example_loop( theNewImageBuffer ) ;
503                //[NSThread detachNewThreadSelector:@selector(encodeFrame:) toTarget:self withObject:localBuff]; // OLD [to file] part
504       
505                // Ok... next
506                QueueController *frameQController = [filledReaderObj queueController];
507                [frameQController addItemToFreeQ:filledReaderObj];
508        }
509        [pool release];
510       
511        //NSLog(@"//////////////////////////////////////(myController) %d FRAME PROCESS DONE\n", totalFrames);
512}
513
514- (void)encodeFrame:(CVPixelBufferRef)myBuff
515{
516        CVPixelBufferRef givenBuff = (CVPixelBufferRef)myBuff ;
517        int res = encoder_example_loop( givenBuff ) ;   
518}
519
520//////// TEMP - CALLED EVERY NEW FRAME (display link callback)
521- (void)processImage:(CVPixelBufferRef)imageBuffer
522{
523        //NSLog(@"(myController) I'VE GOT NEW FRAME, that's great !!\n");
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        /// InOut - FIXED framerate
537        NSTimeInterval previewFramesInterval = 1.0/_inFramerate ;
538        //printf("FRAMETT = %s\n", previewFramesInterval) ;
539       
540    if (outPreviewTimer == nil) {
541        // Schedule an ordinary NSTimer that will invoke -advanceSlideshow: at regular intervals, each time we need to advance to the next slide.
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        //NSLog(@"(myController) STOPPING OUT TIMER\n");
552    if (outPreviewTimer != nil) {
553        // Cancel and release the slideshow advance timer.
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]; // Get the new value FR
589        [outFramerateDisplayed setStringValue:[NSString stringWithFormat:@"%d",outFramerate]];
590}
591
592- (void)toggleOutPreview:(id)sender
593{
594        showOutPreview = ([sender intValue]==1) ;
595        //NSLog(@"(myController) Changing Out Preview State : %d\n",showOutPreview);
596        if(!showOutPreview) [self clearOutDisplay] ;
597}
598
599- (IBAction)setSizeAndPosition:(id)sender
600{
601        //NSLog(@"(myController) YOU PUSHED The Set size and position.....\n");
602
603        //[captureRect release] ;
604        //captureRect = [[mCaptureTarget frame] retain] ;
605        captureRect = [mCaptureTarget frame] ;
606        captureRectChanged = TRUE ;
607        captureRectChangedCompt = 0 ;
608               
609        /// Display size and location
610        //printf("(myController) TARGET : pos = %f,%f size = %f,%f\n",captureRect.origin.x,captureRect.origin.y,captureRect.size.width,captureRect.size.height);
611       
612        [self setCaptureWindowMode:FALSE] ;
613       
614        //[mCaptureTarget close];
615}
616
617- (void)setCaptureWindowMode:(BOOL)mode
618{
619        if(mode) { // visible, movable
620               
621                [mCaptureTarget setAlphaValue:0.5];
622                [mCaptureTarget setBackgroundColor: [NSColor redColor]];
623                //[mCaptureTarget setOpaque:YES];
624                [mCaptureTarget setMovableByWindowBackground: YES] ;
625               
626                [setSizeChoicesBox setHidden:FALSE] ;
627        }
628        else { // always on top, only frame
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        /// Display size and location
671        //printf("INOUT - : pos = %d\n", rowS );
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        // show movie capture window
680        [self setCaptureWindowMode:TRUE] ;
681        [mCaptureTarget makeKeyAndOrderFront:self];
682}
683
684// Displays the capture movie window for the user
685- (IBAction)showInOutWindow:(id)sender
686{
687        // show movie capture window
688        [mMovieCaptureWindow center];
689        [mMovieCaptureWindow makeKeyAndOrderFront:self];
690}
691
692// Called if the user presses the "Cancel" button in
693// the capture movie window
694- (IBAction)closeInOutWindow:(id)sender
695{
696        // pressing cancel button in movie capture window
697        // simply closes the window
698        [mMovieCaptureWindow close];
699        [mCaptureTarget close];
700}
701
702
703
704
705
706
707
708
709@end
Note: See TracBrowser for help on using the browser.