1 /*****************************************************************************
2 * vout.m: MacOS X video output plugin
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VideoLAN
5 * $Id: vout.m,v 1.7 2002/12/08 05:30:47 jlj Exp $
7 * Authors: Colin Delacroix <colin@zoy.org>
8 * Florian G. Pflug <fgp@phlo.org>
9 * Jon Lech Johansen <jon-vl@nanocrew.net>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
29 #include <errno.h> /* ENOMEM */
30 #include <stdlib.h> /* free() */
31 #include <string.h> /* strerror() */
38 #include <Cocoa/Cocoa.h>
39 #include <QuickTime/QuickTime.h>
44 #define QT_MAX_DIRECTBUFFERS 10
51 /* When using I420 output */
52 PlanarPixmapInfoYUV420 pixmap_i420;
55 /*****************************************************************************
57 *****************************************************************************/
58 static int vout_Init ( vout_thread_t * );
59 static void vout_End ( vout_thread_t * );
60 static int vout_Manage ( vout_thread_t * );
61 static void vout_Display ( vout_thread_t *, picture_t * );
63 static int CoSendRequest ( vout_thread_t *, SEL );
64 static int CoCreateWindow ( vout_thread_t * );
65 static int CoDestroyWindow ( vout_thread_t * );
66 static int CoToggleFullscreen ( vout_thread_t * );
68 static void QTScaleMatrix ( vout_thread_t * );
69 static int QTCreateSequence ( vout_thread_t * );
70 static void QTDestroySequence ( vout_thread_t * );
71 static int QTNewPicture ( vout_thread_t *, picture_t * );
72 static void QTFreePicture ( vout_thread_t *, picture_t * );
74 /*****************************************************************************
75 * OpenVideo: allocates MacOS X video thread output method
76 *****************************************************************************
77 * This function allocates and initializes a MacOS X vout method.
78 *****************************************************************************/
79 int E_(OpenVideo) ( vlc_object_t *p_this )
81 vout_thread_t * p_vout = (vout_thread_t *)p_this;
85 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
86 if( p_vout->p_sys == NULL )
88 msg_Err( p_vout, "out of memory" );
92 memset( p_vout->p_sys, 0, sizeof( vout_sys_t ) );
94 /* Wait for a MacOS X interface to appear. Timeout is 2 seconds. */
95 for( i_timeout = 20 ; i_timeout-- ; )
99 msleep( INTF_IDLE_SLEEP );
105 msg_Err( p_vout, "no MacOS X interface present" );
106 free( p_vout->p_sys );
110 if( [NSApp respondsToSelector: @selector(getIntf)] )
112 intf_thread_t * p_intf;
114 for( i_timeout = 10 ; i_timeout-- ; )
116 if( ( p_intf = [NSApp getIntf] ) == NULL )
118 msleep( INTF_IDLE_SLEEP );
124 msg_Err( p_vout, "MacOS X intf has getIntf, but is NULL" );
125 free( p_vout->p_sys );
130 p_vout->p_sys->h_img_descr =
131 (ImageDescriptionHandle)NewHandleClear( sizeof(ImageDescription) );
132 p_vout->p_sys->p_matrix = (MatrixRecordPtr)malloc( sizeof(MatrixRecord) );
134 p_vout->p_sys->b_mouse_pointer_visible = 1;
136 /* set window size */
137 p_vout->p_sys->s_rect.size.width = p_vout->i_window_width;
138 p_vout->p_sys->s_rect.size.height = p_vout->i_window_height;
140 if( ( err = EnterMovies() ) != noErr )
142 msg_Err( p_vout, "EnterMovies failed: %d", err );
143 free( p_vout->p_sys->p_matrix );
144 DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
145 free( p_vout->p_sys );
149 if( vout_ChromaCmp( p_vout->render.i_chroma, VLC_FOURCC('I','4','2','0') ) )
151 err = FindCodec( kYUV420CodecType, bestSpeedCodec,
152 nil, &p_vout->p_sys->img_dc );
153 if( err == noErr && p_vout->p_sys->img_dc != 0 )
155 p_vout->output.i_chroma = VLC_FOURCC('I','4','2','0');
156 p_vout->p_sys->i_codec = kYUV420CodecType;
160 msg_Err( p_vout, "failed to find an appropriate codec" );
165 msg_Err( p_vout, "chroma 0x%08x not supported",
166 p_vout->render.i_chroma );
169 if( p_vout->p_sys->img_dc == 0 )
171 free( p_vout->p_sys->p_matrix );
172 DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
173 free( p_vout->p_sys );
177 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
178 NSArray * o_screens = [NSScreen screens];
179 if ( [o_screens count] > 0 )
185 var_Destroy( p_vout, "video-device" );
186 var_Create( p_vout, "video-device",
187 VLC_VAR_STRING | VLC_VAR_HASCHOICE );
189 NSEnumerator * o_enumerator = [o_screens objectEnumerator];
191 while ( (o_screen = [o_enumerator nextObject]) != NULL )
194 NSRect s_rect = [o_screen frame];
196 snprintf( psz_temp, sizeof(psz_temp)/sizeof(psz_temp[0])-1,
197 "%s %d (%dx%d)", _("Screen"), i,
198 (int)s_rect.size.width, (int)s_rect.size.height );
200 val.psz_string = psz_temp;
201 var_Change( p_vout, "video-device", VLC_VAR_ADDCHOICE, &val );
206 var_AddCallback( p_vout, "video-device", vout_VarCallback,
209 val.b_bool = VLC_TRUE;
210 var_Set( p_vout, "intf-change", val );
214 if( CoCreateWindow( p_vout ) )
216 msg_Err( p_vout, "unable to create window" );
217 free( p_vout->p_sys->p_matrix );
218 DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
219 free( p_vout->p_sys );
223 p_vout->pf_init = vout_Init;
224 p_vout->pf_end = vout_End;
225 p_vout->pf_manage = vout_Manage;
226 p_vout->pf_render = NULL;
227 p_vout->pf_display = vout_Display;
232 /*****************************************************************************
233 * vout_Init: initialize video thread output method
234 *****************************************************************************/
235 static int vout_Init( vout_thread_t *p_vout )
240 I_OUTPUTPICTURES = 0;
242 /* Initialize the output structure; we already found a codec,
243 * and the corresponding chroma we will be using. Since we can
244 * arbitrary scale, stick to the coordinates and aspect. */
245 p_vout->output.i_width = p_vout->render.i_width;
246 p_vout->output.i_height = p_vout->render.i_height;
247 p_vout->output.i_aspect = p_vout->render.i_aspect;
249 SetPort( p_vout->p_sys->p_qdport );
250 QTScaleMatrix( p_vout );
252 if( QTCreateSequence( p_vout ) )
254 msg_Err( p_vout, "unable to create sequence" );
258 /* Try to initialize up to QT_MAX_DIRECTBUFFERS direct buffers */
259 while( I_OUTPUTPICTURES < QT_MAX_DIRECTBUFFERS )
263 /* Find an empty picture slot */
264 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
266 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
268 p_pic = p_vout->p_picture + i_index;
273 /* Allocate the picture */
274 if( p_pic == NULL || QTNewPicture( p_vout, p_pic ) )
279 p_pic->i_status = DESTROYED_PICTURE;
280 p_pic->i_type = DIRECT_PICTURE;
282 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
290 /*****************************************************************************
291 * vout_End: terminate video thread output method
292 *****************************************************************************/
293 static void vout_End( vout_thread_t *p_vout )
297 QTDestroySequence( p_vout );
299 /* Free the direct buffers we allocated */
300 for( i_index = I_OUTPUTPICTURES; i_index; )
303 QTFreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );
307 /*****************************************************************************
308 * CloseVideo: destroy video thread output method
309 *****************************************************************************/
310 void E_(CloseVideo) ( vlc_object_t *p_this )
312 vout_thread_t * p_vout = (vout_thread_t *)p_this;
314 if( CoDestroyWindow( p_vout ) )
316 msg_Err( p_vout, "unable to destroy window" );
321 free( p_vout->p_sys->p_matrix );
322 DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
324 free( p_vout->p_sys );
327 /*****************************************************************************
328 * vout_Manage: handle events
329 *****************************************************************************
330 * This function should be called regularly by video output thread. It manages
331 * console events. It returns a non null value on error.
332 *****************************************************************************/
333 static int vout_Manage( vout_thread_t *p_vout )
335 if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
337 if( CoToggleFullscreen( p_vout ) )
342 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
345 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
347 QTScaleMatrix( p_vout );
348 SetDSequenceMatrix( p_vout->p_sys->i_seq,
349 p_vout->p_sys->p_matrix );
351 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
354 /* hide/show mouse cursor */
355 if( p_vout->p_sys->b_mouse_moved ||
356 p_vout->p_sys->i_time_mouse_last_moved )
358 vlc_bool_t b_change = 0;
360 if( !p_vout->p_sys->b_mouse_pointer_visible )
362 CGDisplayShowCursor( kCGDirectMainDisplay );
366 else if( !p_vout->p_sys->b_mouse_moved &&
367 mdate() - p_vout->p_sys->i_time_mouse_last_moved > 2000000 &&
368 p_vout->p_sys->b_mouse_pointer_visible )
370 CGDisplayHideCursor( kCGDirectMainDisplay );
377 p_vout->p_sys->i_time_mouse_last_moved = 0;
378 p_vout->p_sys->b_mouse_moved = 0;
379 p_vout->p_sys->b_mouse_pointer_visible =
380 !p_vout->p_sys->b_mouse_pointer_visible;
387 /*****************************************************************************
388 * vout_Display: displays previously rendered output
389 *****************************************************************************
390 * This function sends the currently rendered image to the display.
391 *****************************************************************************/
392 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
397 if( ( err = DecompressSequenceFrameS(
398 p_vout->p_sys->i_seq,
399 p_pic->p_sys->p_info,
400 p_pic->p_sys->i_size,
401 codecFlagUseImageBuffer, &flags, nil ) != noErr ) )
403 msg_Err( p_vout, "DecompressSequenceFrameS failed: %d", err );
407 QDFlushPortBuffer( p_vout->p_sys->p_qdport, nil );
411 /*****************************************************************************
412 * CoSendRequest: send request to interface thread
413 *****************************************************************************
414 * Returns 0 on success, 1 otherwise
415 *****************************************************************************/
416 static int CoSendRequest( vout_thread_t *p_vout, SEL sel )
420 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
421 VLCVout * o_vlv = [[[VLCVout alloc] init] autorelease];
423 if( [o_vlv respondsToSelector: @selector(performSelectorOnMainThread:
424 withObject:waitUntilDone:)] )
426 [o_vlv performSelectorOnMainThread: sel
427 withObject: [NSValue valueWithPointer: p_vout]
430 else if( [NSApp respondsToSelector: @selector(getIntf)] )
434 NSPort * o_recv_port;
435 NSInvocation * o_inv;
436 NSPortMessage * o_msg;
437 intf_thread_t * p_intf;
438 NSMethodSignature * o_sig;
440 p_intf = (intf_thread_t *)[NSApp getIntf];
442 o_recv_port = [[NSPort port] retain];
443 o_value = [NSValue valueWithPointer: p_vout];
445 o_sig = [VLCVout instanceMethodSignatureForSelector: sel];
446 o_inv = [NSInvocation invocationWithMethodSignature: o_sig];
447 [o_inv setArgument: &o_value atIndex: 2];
448 [o_inv setTarget: o_vlv];
449 [o_inv setSelector: sel];
451 o_array = [NSArray arrayWithObject:
452 [NSData dataWithBytes: &o_inv length: sizeof(o_inv)]];
453 o_msg = [[NSPortMessage alloc]
454 initWithSendPort: p_intf->p_sys->o_sendport
455 receivePort: o_recv_port components: o_array];
457 p_vout->p_sys->o_lock =
458 [[NSConditionLock alloc] initWithCondition: 0];
459 [o_msg sendBeforeDate: [NSDate distantPast]];
460 [p_vout->p_sys->o_lock lockWhenCondition: 1];
461 [p_vout->p_sys->o_lock unlock];
462 [p_vout->p_sys->o_lock release];
463 p_vout->p_sys->o_lock = nil;
466 [o_recv_port release];
470 msg_Err( p_vout, "SendRequest: no way to communicate with mt" );
479 /*****************************************************************************
480 * CoCreateWindow: create new window
481 *****************************************************************************
482 * Returns 0 on success, 1 otherwise
483 *****************************************************************************/
484 static int CoCreateWindow( vout_thread_t *p_vout )
486 if( CoSendRequest( p_vout, @selector(createWindow:) ) )
488 msg_Err( p_vout, "CoSendRequest (createWindow) failed" );
495 /*****************************************************************************
496 * CoDestroyWindow: destroy window
497 *****************************************************************************
498 * Returns 0 on success, 1 otherwise
499 *****************************************************************************/
500 static int CoDestroyWindow( vout_thread_t *p_vout )
502 if( !p_vout->p_sys->b_mouse_pointer_visible )
504 CGDisplayShowCursor( kCGDirectMainDisplay );
505 p_vout->p_sys->b_mouse_pointer_visible = 1;
508 if( CoSendRequest( p_vout, @selector(destroyWindow:) ) )
510 msg_Err( p_vout, "CoSendRequest (destroyWindow) failed" );
517 /*****************************************************************************
518 * CoToggleFullscreen: toggle fullscreen
519 *****************************************************************************
520 * Returns 0 on success, 1 otherwise
521 *****************************************************************************/
522 static int CoToggleFullscreen( vout_thread_t *p_vout )
524 QTDestroySequence( p_vout );
526 if( CoDestroyWindow( p_vout ) )
528 msg_Err( p_vout, "unable to destroy window" );
532 p_vout->b_fullscreen = !p_vout->b_fullscreen;
534 if( p_vout->b_fullscreen )
543 if( CoCreateWindow( p_vout ) )
545 msg_Err( p_vout, "unable to create window" );
549 SetPort( p_vout->p_sys->p_qdport );
550 QTScaleMatrix( p_vout );
552 if( QTCreateSequence( p_vout ) )
554 msg_Err( p_vout, "unable to create sequence" );
561 /*****************************************************************************
562 * QTScaleMatrix: scale matrix
563 *****************************************************************************/
564 static void QTScaleMatrix( vout_thread_t *p_vout )
567 int i_width, i_height;
568 Fixed factor_x, factor_y;
572 GetPortBounds( p_vout->p_sys->p_qdport, &s_rect );
574 i_width = s_rect.right - s_rect.left;
575 i_height = s_rect.bottom - s_rect.top;
577 if( i_height * p_vout->output.i_aspect < i_width * VOUT_ASPECT_FACTOR )
579 int i_adj_width = i_height * p_vout->output.i_aspect /
582 factor_x = FixDiv( Long2Fix( i_adj_width ),
583 Long2Fix( p_vout->output.i_width ) );
584 factor_y = FixDiv( Long2Fix( i_height ),
585 Long2Fix( p_vout->output.i_height ) );
587 i_offset_x = (i_width - i_adj_width) / 2;
591 int i_adj_height = i_width * VOUT_ASPECT_FACTOR /
592 p_vout->output.i_aspect;
594 factor_x = FixDiv( Long2Fix( i_width ),
595 Long2Fix( p_vout->output.i_width ) );
596 factor_y = FixDiv( Long2Fix( i_adj_height ),
597 Long2Fix( p_vout->output.i_height ) );
599 i_offset_y = (i_height - i_adj_height) / 2;
602 SetIdentityMatrix( p_vout->p_sys->p_matrix );
604 ScaleMatrix( p_vout->p_sys->p_matrix,
606 Long2Fix(0), Long2Fix(0) );
608 TranslateMatrix( p_vout->p_sys->p_matrix,
609 Long2Fix(i_offset_x),
610 Long2Fix(i_offset_y) );
613 /*****************************************************************************
614 * QTCreateSequence: create a new sequence
615 *****************************************************************************
616 * Returns 0 on success, 1 otherwise
617 *****************************************************************************/
618 static int QTCreateSequence( vout_thread_t *p_vout )
621 ImageDescriptionPtr p_descr;
623 HLock( (Handle)p_vout->p_sys->h_img_descr );
624 p_descr = *p_vout->p_sys->h_img_descr;
626 p_descr->idSize = sizeof(ImageDescription);
627 p_descr->cType = p_vout->p_sys->i_codec;
628 p_descr->version = 1;
629 p_descr->revisionLevel = 0;
630 p_descr->vendor = 'appl';
631 p_descr->width = p_vout->output.i_width;
632 p_descr->height = p_vout->output.i_height;
633 p_descr->hRes = Long2Fix(72);
634 p_descr->vRes = Long2Fix(72);
635 p_descr->spatialQuality = codecLosslessQuality;
636 p_descr->frameCount = 1;
637 p_descr->clutID = -1;
638 p_descr->dataSize = 0;
641 HUnlock( (Handle)p_vout->p_sys->h_img_descr );
643 if( ( err = DecompressSequenceBeginS(
644 &p_vout->p_sys->i_seq,
645 p_vout->p_sys->h_img_descr,
647 p_vout->p_sys->p_qdport,
649 p_vout->p_sys->p_matrix,
651 codecFlagUseImageBuffer,
652 codecLosslessQuality,
653 p_vout->p_sys->img_dc ) ) )
655 msg_Err( p_vout, "DecompressSequenceBeginS failed: %d", err );
662 /*****************************************************************************
663 * QTDestroySequence: destroy sequence
664 *****************************************************************************/
665 static void QTDestroySequence( vout_thread_t *p_vout )
667 CDSequenceEnd( p_vout->p_sys->i_seq );
670 /*****************************************************************************
671 * QTNewPicture: allocate a picture
672 *****************************************************************************
673 * Returns 0 on success, 1 otherwise
674 *****************************************************************************/
675 static int QTNewPicture( vout_thread_t *p_vout, picture_t *p_pic )
677 int i_width = p_vout->output.i_width;
678 int i_height = p_vout->output.i_height;
680 /* We know the chroma, allocate a buffer which will be used
681 * directly by the decoder */
682 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
684 if( p_pic->p_sys == NULL )
689 switch( p_vout->output.i_chroma )
691 case VLC_FOURCC('I','4','2','0'):
693 p_pic->p_sys->p_info = (void *)&p_pic->p_sys->pixmap_i420;
694 p_pic->p_sys->i_size = sizeof(PlanarPixmapInfoYUV420);
696 /* Allocate the memory buffer */
697 p_pic->p_data = vlc_memalign( &p_pic->p_data_orig,
698 16, i_width * i_height * 3 / 2 );
701 p_pic->Y_PIXELS = p_pic->p_data;
702 p_pic->p[Y_PLANE].i_lines = i_height;
703 p_pic->p[Y_PLANE].i_pitch = i_width;
704 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
705 p_pic->p[Y_PLANE].i_visible_pitch = i_width;
708 p_pic->U_PIXELS = p_pic->Y_PIXELS + i_height * i_width;
709 p_pic->p[U_PLANE].i_lines = i_height / 2;
710 p_pic->p[U_PLANE].i_pitch = i_width / 2;
711 p_pic->p[U_PLANE].i_pixel_pitch = 1;
712 p_pic->p[U_PLANE].i_visible_pitch = i_width / 2;
715 p_pic->V_PIXELS = p_pic->U_PIXELS + i_height * i_width / 4;
716 p_pic->p[V_PLANE].i_lines = i_height / 2;
717 p_pic->p[V_PLANE].i_pitch = i_width / 2;
718 p_pic->p[V_PLANE].i_pixel_pitch = 1;
719 p_pic->p[V_PLANE].i_visible_pitch = i_width / 2;
721 /* We allocated 3 planes */
724 #define P p_pic->p_sys->pixmap_i420
725 P.componentInfoY.offset = (void *)p_pic->Y_PIXELS
726 - p_pic->p_sys->p_info;
727 P.componentInfoCb.offset = (void *)p_pic->U_PIXELS
728 - p_pic->p_sys->p_info;
729 P.componentInfoCr.offset = (void *)p_pic->V_PIXELS
730 - p_pic->p_sys->p_info;
732 P.componentInfoY.rowBytes = i_width;
733 P.componentInfoCb.rowBytes = i_width / 2;
734 P.componentInfoCr.rowBytes = i_width / 2;
740 /* Unknown chroma, tell the guy to get lost */
741 free( p_pic->p_sys );
742 msg_Err( p_vout, "never heard of chroma 0x%.8x (%4.4s)",
743 p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma );
751 /*****************************************************************************
752 * QTFreePicture: destroy a picture allocated with QTNewPicture
753 *****************************************************************************/
754 static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
756 switch( p_vout->output.i_chroma )
758 case VLC_FOURCC('I','4','2','0'):
759 free( p_pic->p_data_orig );
763 free( p_pic->p_sys );
766 /*****************************************************************************
767 * VLCWindow implementation
768 *****************************************************************************/
769 @implementation VLCWindow
771 - (void)setVout:(vout_thread_t *)_p_vout
776 - (vout_thread_t *)getVout
781 - (void)toggleFullscreen
783 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
788 return( p_vout->b_fullscreen );
791 - (BOOL)canBecomeKeyWindow
796 - (void)keyDown:(NSEvent *)o_event
800 if( [[o_event characters] length] )
802 key = [[o_event characters] characterAtIndex: 0];
807 case (unichar)0xf700: /* up-arrow */
809 aout_instance_t * p_aout = vlc_object_find( p_vout, VLC_OBJECT_AOUT,
811 if ( p_aout != NULL )
813 aout_VolumeUp( p_aout, 1, NULL );
814 vlc_object_release( (vlc_object_t *)p_aout );
819 case (unichar)0xf701: /* down-arrow */
821 aout_instance_t * p_aout = vlc_object_find( p_vout, VLC_OBJECT_AOUT,
823 if ( p_aout != NULL )
825 aout_VolumeDown( p_aout, 1, NULL );
826 vlc_object_release( (vlc_object_t *)p_aout );
832 [self toggleFullscreen];
835 case (unichar)0x1b: /* escape */
836 if( [self isFullscreen] )
838 [self toggleFullscreen];
843 p_vout->p_vlc->b_die = VLC_TRUE;
847 input_SetStatus( p_vout, INPUT_STATUS_PAUSE );
851 [super keyDown: o_event];
858 /*****************************************************************************
859 * VLCView implementation
860 *****************************************************************************/
861 @implementation VLCView
863 - (void)drawRect:(NSRect)rect
865 vout_thread_t * p_vout;
866 id o_window = [self window];
867 p_vout = (vout_thread_t *)[o_window getVout];
869 [[NSColor blackColor] set];
871 [super drawRect: rect];
873 p_vout->i_changes |= VOUT_SIZE_CHANGE;
876 - (BOOL)acceptsFirstResponder
881 - (BOOL)becomeFirstResponder
883 [[self window] setAcceptsMouseMovedEvents: YES];
887 - (BOOL)resignFirstResponder
889 [[self window] setAcceptsMouseMovedEvents: NO];
893 - (void)mouseUp:(NSEvent *)o_event
895 vout_thread_t * p_vout;
896 id o_window = [self window];
897 p_vout = (vout_thread_t *)[o_window getVout];
899 switch( [o_event type] )
904 val.b_bool = VLC_TRUE;
905 var_Set( p_vout, "mouse-clicked", val );
910 [super mouseUp: o_event];
915 - (void)mouseMoved:(NSEvent *)o_event
921 vout_thread_t * p_vout;
922 id o_window = [self window];
923 p_vout = (vout_thread_t *)[o_window getVout];
925 s_rect = [self bounds];
926 ml = [self convertPoint: [o_event locationInWindow] fromView: nil];
927 b_inside = [self mouse: ml inRect: s_rect];
932 int i_width, i_height, i_x, i_y;
934 vout_PlacePicture( p_vout, (unsigned int)s_rect.size.width,
935 (unsigned int)s_rect.size.height,
936 &i_x, &i_y, &i_width, &i_height );
938 val.i_int = ( ((int)ml.x) - i_x ) *
939 p_vout->render.i_width / i_width;
940 var_Set( p_vout, "mouse-x", val );
942 val.i_int = ( ((int)ml.y) - i_y ) *
943 p_vout->render.i_height / i_height;
944 var_Set( p_vout, "mouse-y", val );
946 val.b_bool = VLC_TRUE;
947 var_Set( p_vout, "mouse-moved", val );
951 [super mouseMoved: o_event];
957 /*****************************************************************************
958 * VLCVout implementation
959 *****************************************************************************/
960 @implementation VLCVout
962 - (void)createWindow:(NSValue *)o_value
967 vout_thread_t * p_vout;
969 p_vout = (vout_thread_t *)[o_value pointerValue];
971 p_vout->p_sys->o_window = [VLCWindow alloc];
972 [p_vout->p_sys->o_window setVout: p_vout];
973 [p_vout->p_sys->o_window setReleasedWhenClosed: YES];
975 if( var_Get( p_vout, "video-device", &val ) < 0 )
977 o_screen = [NSScreen mainScreen];
982 NSArray *o_screens = [NSScreen screens];
984 if( !sscanf( val.psz_string, "Screen %d", &i_index ) ||
985 [o_screens count] < i_index )
987 o_screen = [NSScreen mainScreen];
991 o_screen = [o_screens objectAtIndex: i_index - 1];
994 free( val.psz_string );
997 if( p_vout->b_fullscreen )
999 [p_vout->p_sys->o_window
1000 initWithContentRect: [o_screen frame]
1001 styleMask: NSBorderlessWindowMask
1002 backing: NSBackingStoreBuffered
1003 defer: NO screen: o_screen];
1005 [p_vout->p_sys->o_window setLevel: NSModalPanelWindowLevel];
1009 unsigned int i_stylemask = NSTitledWindowMask |
1010 NSMiniaturizableWindowMask |
1011 NSResizableWindowMask;
1013 [p_vout->p_sys->o_window
1014 initWithContentRect: p_vout->p_sys->s_rect
1015 styleMask: i_stylemask
1016 backing: NSBackingStoreBuffered
1017 defer: NO screen: o_screen];
1019 if( !p_vout->p_sys->b_pos_saved )
1021 [p_vout->p_sys->o_window center];
1025 o_view = [[VLCView alloc] init];
1026 /* FIXME: [o_view setMenu:] */
1027 [p_vout->p_sys->o_window setContentView: o_view];
1028 [o_view autorelease];
1031 p_vout->p_sys->p_qdport = [o_view qdPort];
1032 [o_view unlockFocus];
1034 [p_vout->p_sys->o_window setTitle:
1035 [NSString stringWithCString: VOUT_TITLE " (QuickTime)"]];
1036 [p_vout->p_sys->o_window makeKeyAndOrderFront: nil];
1039 - (void)destroyWindow:(NSValue *)o_value
1041 vout_thread_t * p_vout;
1043 p_vout = (vout_thread_t *)[o_value pointerValue];
1045 if( !p_vout->b_fullscreen )
1049 s_rect = [[p_vout->p_sys->o_window contentView] frame];
1050 p_vout->p_sys->s_rect.size = s_rect.size;
1052 s_rect = [p_vout->p_sys->o_window frame];
1053 p_vout->p_sys->s_rect.origin = s_rect.origin;
1055 p_vout->p_sys->b_pos_saved = 1;
1058 p_vout->p_sys->p_qdport = nil;
1059 [p_vout->p_sys->o_window close];
1060 p_vout->p_sys->o_window = nil;