1 /*****************************************************************************
2 * vout.m: MacOS X video output module
3 *****************************************************************************
4 * Copyright (C) 2001-2004 VideoLAN
5 * $Id: vout.m 8351 2004-08-02 13:06:38Z hartman $
7 * Authors: Colin Delacroix <colin@zoy.org>
8 * Florian G. Pflug <fgp@phlo.org>
9 * Jon Lech Johansen <jon-vl@nanocrew.net>
10 * Derk-Jan Hartman <hartman at videolan dot org>
11 * Eric Petit <titer@m0k.org>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
26 *****************************************************************************/
28 /*****************************************************************************
30 *****************************************************************************/
31 #include <errno.h> /* ENOMEM */
32 #include <stdlib.h> /* free() */
33 #include <string.h> /* strerror() */
35 #include <QuickTime/QuickTime.h>
42 #define QT_MAX_DIRECTBUFFERS 10
43 #define VL_MAX_DISPLAYS 16
45 /*****************************************************************************
47 *****************************************************************************/
48 @interface VLCQTView : NSQuickDrawView
50 vout_thread_t * p_vout;
53 - (id) initWithVout:(vout_thread_t *)p_vout;
59 NSAutoreleasePool *o_pool;
63 vlc_bool_t b_saved_frame;
70 MatrixRecordPtr p_matrix;
71 DecompressorComponent img_dc;
72 ImageDescriptionHandle h_img_descr;
74 /* Mozilla plugin-related variables */
75 vlc_bool_t b_embedded;
85 /* When using I420 output */
86 PlanarPixmapInfoYUV420 pixmap_i420;
89 /*****************************************************************************
91 *****************************************************************************/
93 static int InitVideo ( vout_thread_t * );
94 static void EndVideo ( vout_thread_t * );
95 static int ManageVideo ( vout_thread_t * );
96 static void DisplayVideo ( vout_thread_t *, picture_t * );
97 static int ControlVideo ( vout_thread_t *, int, va_list );
99 static int CoToggleFullscreen( vout_thread_t *p_vout );
100 static void QTScaleMatrix ( vout_thread_t * );
101 static int QTCreateSequence ( vout_thread_t * );
102 static void QTDestroySequence ( vout_thread_t * );
103 static int QTNewPicture ( vout_thread_t *, picture_t * );
104 static void QTFreePicture ( vout_thread_t *, picture_t * );
106 /*****************************************************************************
107 * OpenVideo: allocates MacOS X video thread output method
108 *****************************************************************************
109 * This function allocates and initializes a MacOS X vout method.
110 *****************************************************************************/
111 int E_(OpenVideoQT) ( vlc_object_t *p_this )
113 vout_thread_t * p_vout = (vout_thread_t *)p_this;
115 vlc_value_t value_drawable;
117 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
118 if( p_vout->p_sys == NULL )
120 msg_Err( p_vout, "out of memory" );
124 memset( p_vout->p_sys, 0, sizeof( vout_sys_t ) );
126 p_vout->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
128 p_vout->pf_init = InitVideo;
129 p_vout->pf_end = EndVideo;
130 p_vout->pf_manage = ManageVideo;
131 p_vout->pf_render = NULL;
132 p_vout->pf_display = DisplayVideo;
133 p_vout->pf_control = ControlVideo;
135 /* Are we embedded? If so, the drawable value will be a pointer to a
136 * CGrafPtr that we're expected to use */
137 var_Get( p_vout->p_vlc, "drawable", &value_drawable );
138 if( value_drawable.i_int != 0 )
139 p_vout->p_sys->b_embedded = VLC_TRUE;
141 p_vout->p_sys->b_embedded = VLC_FALSE;
143 if( p_vout->p_sys->b_embedded )
145 /* Zero the clipping rectangle */
146 p_vout->p_sys->clipping_rect.left = 0;
147 p_vout->p_sys->clipping_rect.right = 0;
148 p_vout->p_sys->clipping_rect.top = 0;
149 p_vout->p_sys->clipping_rect.bottom = 0;
154 p_vout->p_sys->o_window =
155 [[VLCWindow alloc] initWithVout: p_vout frame: nil];
156 if( !p_vout->p_sys->o_window )
162 p_vout->p_sys->b_altivec = p_vout->p_libvlc->i_cpu & CPU_CAPABILITY_ALTIVEC;
163 msg_Dbg( p_vout, "We do%s have Altivec", p_vout->p_sys->b_altivec ? "" : "n't" );
165 /* Initialize QuickTime */
166 p_vout->p_sys->h_img_descr =
167 (ImageDescriptionHandle)NewHandleClear( sizeof(ImageDescription) );
168 p_vout->p_sys->p_matrix =
169 (MatrixRecordPtr)malloc( sizeof(MatrixRecord) );
171 if( ( err = EnterMovies() ) != noErr )
173 msg_Err( p_vout, "EnterMovies failed: %d", err );
174 free( p_vout->p_sys->p_matrix );
175 DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
176 free( p_vout->p_sys );
180 /* Damn QT isn't thread safe. so keep a lock in the p_vlc object */
181 vlc_mutex_lock( &p_vout->p_vlc->quicktime_lock );
183 /* Can we find the right chroma ? */
184 if( p_vout->p_sys->b_altivec )
186 err = FindCodec( kYUVSPixelFormat, bestSpeedCodec,
187 nil, &p_vout->p_sys->img_dc );
191 err = FindCodec( kYUV420CodecType, bestSpeedCodec,
192 nil, &p_vout->p_sys->img_dc );
194 vlc_mutex_unlock( &p_vout->p_vlc->quicktime_lock );
196 if( err == noErr && p_vout->p_sys->img_dc != 0 )
198 if( p_vout->p_sys->b_altivec )
200 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
201 p_vout->p_sys->i_codec = kYUVSPixelFormat;
205 p_vout->output.i_chroma = VLC_FOURCC('I','4','2','0');
206 p_vout->p_sys->i_codec = kYUV420CodecType;
211 msg_Err( p_vout, "failed to find an appropriate codec" );
214 if( p_vout->p_sys->img_dc == 0 )
216 free( p_vout->p_sys->p_matrix );
217 DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
218 free( p_vout->p_sys );
222 #define o_qtview p_vout->p_sys->o_qtview
223 o_qtview = [[VLCQTView alloc] initWithVout: p_vout];
224 [p_vout->p_sys->o_window setContentView: o_qtview];
225 [o_qtview autorelease];
227 /* Retrieve the QuickDraw port */
228 if( p_vout->p_sys->b_embedded )
230 /* Don't need (nor want) to lock the focus, since otherwise we crash
231 * (presumably because we don't own the window, but I'm not sure
232 * if this is the exact reason) -andrep */
233 p_vout->p_sys->p_qdport = [o_qtview qdPort];
237 [o_qtview lockFocus];
238 p_vout->p_sys->p_qdport = [o_qtview qdPort];
239 [o_qtview unlockFocus];
246 /*****************************************************************************
247 * CloseVideo: destroy video thread output method
248 *****************************************************************************/
249 void E_(CloseVideoQT) ( vlc_object_t *p_this )
251 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
252 vout_thread_t * p_vout = (vout_thread_t *)p_this;
254 if( !p_vout->p_sys->b_embedded )
255 [p_vout->p_sys->o_window close];
257 /* Clean Up Quicktime environment */
259 free( p_vout->p_sys->p_matrix );
260 DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
263 free( p_vout->p_sys );
266 /*****************************************************************************
267 * InitVideo: initialize video thread output method
268 *****************************************************************************/
269 static int InitVideo ( vout_thread_t *p_vout )
274 I_OUTPUTPICTURES = 0;
276 /* Initialize the output structure; we already found a codec,
277 * and the corresponding chroma we will be using. Since we can
278 * arbitrary scale, stick to the coordinates and aspect. */
279 p_vout->output.i_width = p_vout->render.i_width;
280 p_vout->output.i_height = p_vout->render.i_height;
281 p_vout->output.i_aspect = p_vout->render.i_aspect;
283 /* If we are embedded (e.g. running as a Mozilla plugin), use the pointer
284 * stored in the "drawable" value as the CGrafPtr for the QuickDraw
286 if( p_vout->p_sys->b_embedded )
289 var_Get( p_vout->p_vlc, "drawable", &val );
290 p_vout->p_sys->p_qdport = (CGrafPtr) val.i_int;
293 SetPort( p_vout->p_sys->p_qdport );
294 QTScaleMatrix( p_vout );
296 if( QTCreateSequence( p_vout ) )
298 msg_Err( p_vout, "unable to create sequence" );
302 /* Try to initialize up to QT_MAX_DIRECTBUFFERS direct buffers */
303 while( I_OUTPUTPICTURES < QT_MAX_DIRECTBUFFERS )
307 /* Find an empty picture slot */
308 for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
310 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
312 p_pic = p_vout->p_picture + i_index;
317 /* Allocate the picture */
318 if( p_pic == NULL || QTNewPicture( p_vout, p_pic ) )
323 p_pic->i_status = DESTROYED_PICTURE;
324 p_pic->i_type = DIRECT_PICTURE;
326 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
332 /*****************************************************************************
333 * EndVideo: terminate video thread output method
334 *****************************************************************************/
335 static void EndVideo( vout_thread_t *p_vout )
339 QTDestroySequence( p_vout );
341 /* Free the direct buffers we allocated */
342 for( i_index = I_OUTPUTPICTURES; i_index; )
345 QTFreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );
349 /*****************************************************************************
350 * ManageVideo: handle events
351 *****************************************************************************
352 * This function should be called regularly by video output thread. It manages
353 * console events. It returns a non null value on error.
354 *****************************************************************************/
355 static int ManageVideo( vout_thread_t *p_vout )
358 var_Get( p_vout->p_vlc, "drawableredraw", &val );
360 if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
362 if( CoToggleFullscreen( p_vout ) )
367 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
370 if( p_vout->p_sys->b_embedded && val.i_int == 1 )
372 /* If we're embedded, the application is expected to indicate a
373 * window change (move/resize/etc) via the "drawableredraw" value.
374 * If that's the case, set the VOUT_SIZE_CHANGE flag so we do
375 * actually handle the window change. */
377 var_Set( p_vout->p_vlc, "drawableredraw", val );
379 p_vout->i_changes |= VOUT_SIZE_CHANGE;
382 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
384 QTScaleMatrix( p_vout );
385 SetDSequenceMatrix( p_vout->p_sys->i_seq,
386 p_vout->p_sys->p_matrix );
387 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
390 [p_vout->p_sys->o_window manage];
395 /*****************************************************************************
396 * vout_Display: displays previously rendered output
397 *****************************************************************************
398 * This function sends the currently rendered image to the display.
399 *****************************************************************************/
400 static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic )
406 RgnHandle saved_clip;
408 saved_clip = NewRgn();
410 if( p_vout->p_sys->b_embedded )
412 /* In the Mozilla plugin, the browser also draws things in the windows.
413 * So, we have to update the origin and clipping rectangle for each
414 * picture. FIXME: The vout should probably lock something ... */
416 /* Save the origin and clipping rectangle used by the host application
417 * (e.g. Mozilla), so we can restore it later */
418 GetPortBounds( p_vout->p_sys->p_qdport, &saved_rect );
419 GetClip( saved_clip );
421 /* The port gets unlocked at the end of this function */
422 LockPortBits( p_vout->p_sys->p_qdport );
424 /* Change the origin and clipping to the coordinates that the embedded
425 * window wants to draw at */
426 SetPort( p_vout->p_sys->p_qdport );
427 SetOrigin( p_vout->p_sys->portx , p_vout->p_sys->porty );
428 ClipRect( &p_vout->p_sys->clipping_rect );
431 if( ( err = DecompressSequenceFrameWhen(
432 p_vout->p_sys->i_seq,
433 p_pic->p_sys->p_data,
434 p_pic->p_sys->i_size,
435 codecFlagUseImageBuffer, &flags, NULL, NULL ) != noErr ) )
437 msg_Warn( p_vout, "DecompressSequenceFrameWhen failed: %d", err );
441 if( !p_vout->p_sys->b_embedded )
442 QDFlushPortBuffer( p_vout->p_sys->p_qdport, nil );
445 if( p_vout->p_sys->b_embedded )
447 /* Restore the origin and clipping rectangle to the settings used
448 * by the host application */
449 SetOrigin( saved_rect.left, saved_rect.top );
450 SetClip( saved_clip );
452 UnlockPortBits( p_vout->p_sys->p_qdport );
456 /*****************************************************************************
457 * ControlVideo: control facility for the vout
458 *****************************************************************************/
459 static int ControlVideo( vout_thread_t *p_vout, int i_query, va_list args )
465 case VOUT_SET_STAY_ON_TOP:
466 b_arg = va_arg( args, vlc_bool_t );
467 [p_vout->p_sys->o_window setOnTop: b_arg];
473 return vout_vaControlDefault( p_vout, i_query, args );
477 /*****************************************************************************
478 * CoToggleFullscreen: toggle fullscreen
479 *****************************************************************************
480 * Returns 0 on success, 1 otherwise
481 *****************************************************************************/
482 static int CoToggleFullscreen( vout_thread_t *p_vout )
484 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
486 QTDestroySequence( p_vout );
488 if( !p_vout->b_fullscreen )
490 /* Save window size and position */
491 p_vout->p_sys->s_frame.size =
492 [[p_vout->p_sys->o_window contentView] frame].size;
493 p_vout->p_sys->s_frame.origin =
494 [p_vout->p_sys->o_window frame].origin;
495 p_vout->p_sys->b_saved_frame = VLC_TRUE;
497 [p_vout->p_sys->o_window close];
499 p_vout->b_fullscreen = !p_vout->b_fullscreen;
501 if( p_vout->p_sys->b_saved_frame )
503 p_vout->p_sys->o_window = [[VLCWindow alloc]
504 initWithVout: p_vout frame: &p_vout->p_sys->s_frame];
508 p_vout->p_sys->o_window = [[VLCWindow alloc]
509 initWithVout: p_vout frame: nil];
512 #define o_qtview p_vout->p_sys->o_qtview
513 o_qtview = [[VLCQTView alloc] initWithVout: p_vout];
514 [p_vout->p_sys->o_window setContentView: o_qtview];
515 [o_qtview autorelease];
517 /* Retrieve the QuickDraw port */
518 [o_qtview lockFocus];
519 p_vout->p_sys->p_qdport = [o_qtview qdPort];
520 [o_qtview unlockFocus];
523 SetPort( p_vout->p_sys->p_qdport );
524 QTScaleMatrix( p_vout );
526 if( QTCreateSequence( p_vout ) )
528 msg_Err( p_vout, "unable to create sequence" );
536 /*****************************************************************************
537 * QTScaleMatrix: scale matrix
538 *****************************************************************************/
539 static void QTScaleMatrix( vout_thread_t *p_vout )
543 unsigned int i_width, i_height;
544 Fixed factor_x, factor_y;
545 unsigned int i_offset_x = 0;
546 unsigned int i_offset_y = 0;
548 GetPortBounds( p_vout->p_sys->p_qdport, &s_rect );
550 i_width = s_rect.right - s_rect.left;
551 i_height = s_rect.bottom - s_rect.top;
553 if( p_vout->p_sys->b_embedded )
555 /* Embedded video get their drawing region from the host application
556 * by the drawable values here. Read those variables, and store them
557 * in the p_vout->p_sys structure so that other functions (such as
558 * DisplayVideo and ManageVideo) can use them later. */
559 vlc_value_t valt, vall, valb, valr, valx, valy, valw, valh,
562 var_Get( p_vout->p_vlc, "drawable", &val );
563 var_Get( p_vout->p_vlc, "drawablet", &valt );
564 var_Get( p_vout->p_vlc, "drawablel", &vall );
565 var_Get( p_vout->p_vlc, "drawableb", &valb );
566 var_Get( p_vout->p_vlc, "drawabler", &valr );
567 var_Get( p_vout->p_vlc, "drawablex", &valx );
568 var_Get( p_vout->p_vlc, "drawabley", &valy );
569 var_Get( p_vout->p_vlc, "drawablew", &valw );
570 var_Get( p_vout->p_vlc, "drawableh", &valh );
571 var_Get( p_vout->p_vlc, "drawableportx", &valportx );
572 var_Get( p_vout->p_vlc, "drawableporty", &valporty );
574 p_vout->p_sys->portx = valportx.i_int;
575 p_vout->p_sys->porty = valporty.i_int;
576 p_vout->p_sys->p_qdport = (CGrafPtr) val.i_int;
577 i_width = valw.i_int;
578 i_height = valh.i_int;
580 p_vout->p_sys->clipping_rect.top = 0;
581 p_vout->p_sys->clipping_rect.left = 0;
582 p_vout->p_sys->clipping_rect.bottom = valb.i_int - valt.i_int;
583 p_vout->p_sys->clipping_rect.right = valr.i_int - vall.i_int;
586 var_Get( p_vout, "macosx-stretch", &val );
589 factor_x = FixDiv( Long2Fix( i_width ),
590 Long2Fix( p_vout->output.i_width ) );
591 factor_y = FixDiv( Long2Fix( i_height ),
592 Long2Fix( p_vout->output.i_height ) );
595 else if( i_height * p_vout->output.i_aspect < i_width * VOUT_ASPECT_FACTOR )
597 int i_adj_width = i_height * p_vout->output.i_aspect /
600 factor_x = FixDiv( Long2Fix( i_adj_width ),
601 Long2Fix( p_vout->output.i_width ) );
602 factor_y = FixDiv( Long2Fix( i_height ),
603 Long2Fix( p_vout->output.i_height ) );
605 i_offset_x = (i_width - i_adj_width) / 2;
609 int i_adj_height = i_width * VOUT_ASPECT_FACTOR /
610 p_vout->output.i_aspect;
612 factor_x = FixDiv( Long2Fix( i_width ),
613 Long2Fix( p_vout->output.i_width ) );
614 factor_y = FixDiv( Long2Fix( i_adj_height ),
615 Long2Fix( p_vout->output.i_height ) );
617 i_offset_y = (i_height - i_adj_height) / 2;
620 SetIdentityMatrix( p_vout->p_sys->p_matrix );
622 ScaleMatrix( p_vout->p_sys->p_matrix,
624 Long2Fix(0), Long2Fix(0) );
626 TranslateMatrix( p_vout->p_sys->p_matrix,
627 Long2Fix(i_offset_x), Long2Fix(i_offset_y) );
630 /*****************************************************************************
631 * QTCreateSequence: create a new sequence
632 *****************************************************************************
633 * Returns 0 on success, 1 otherwise
634 *****************************************************************************/
635 static int QTCreateSequence( vout_thread_t *p_vout )
638 ImageDescriptionPtr p_descr;
640 HLock( (Handle)p_vout->p_sys->h_img_descr );
641 p_descr = *p_vout->p_sys->h_img_descr;
643 p_descr->idSize = sizeof(ImageDescription);
644 p_descr->cType = p_vout->p_sys->i_codec;
645 p_descr->version = 2;
646 p_descr->revisionLevel = 0;
647 p_descr->vendor = 'mpla';
648 p_descr->width = p_vout->output.i_width;
649 p_descr->height = p_vout->output.i_height;
650 p_descr->hRes = Long2Fix(72);
651 p_descr->vRes = Long2Fix(72);
652 p_descr->spatialQuality = codecLosslessQuality;
653 p_descr->frameCount = 1;
654 p_descr->clutID = -1;
655 p_descr->dataSize = 0;
658 HUnlock( (Handle)p_vout->p_sys->h_img_descr );
660 if( ( err = DecompressSequenceBeginS(
661 &p_vout->p_sys->i_seq,
662 p_vout->p_sys->h_img_descr,
664 (p_descr->width * p_descr->height * 16) / 8,
665 p_vout->p_sys->p_qdport,
667 p_vout->p_sys->p_matrix,
669 codecFlagUseImageBuffer,
670 codecLosslessQuality,
673 msg_Err( p_vout, "DecompressSequenceBeginS failed: %d", err );
680 /*****************************************************************************
681 * QTDestroySequence: destroy sequence
682 *****************************************************************************/
683 static void QTDestroySequence( vout_thread_t *p_vout )
685 CDSequenceEnd( p_vout->p_sys->i_seq );
688 /*****************************************************************************
689 * QTNewPicture: allocate a picture
690 *****************************************************************************
691 * Returns 0 on success, 1 otherwise
692 *****************************************************************************/
693 static int QTNewPicture( vout_thread_t *p_vout, picture_t *p_pic )
695 /* We know the chroma, allocate a buffer which will be used
696 * directly by the decoder */
697 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
699 if( p_pic->p_sys == NULL )
704 vout_InitPicture( VLC_OBJECT( p_vout), p_pic, p_vout->output.i_chroma,
705 p_vout->output.i_width, p_vout->output.i_height,
706 p_vout->output.i_aspect );
708 switch( p_vout->output.i_chroma )
710 case VLC_FOURCC('Y','U','Y','2'):
711 p_pic->p_sys->i_size = p_vout->output.i_width * p_vout->output.i_height * 2;
713 /* Allocate the memory buffer */
714 p_pic->p_data = vlc_memalign( &p_pic->p_data_orig,
715 16, p_pic->p_sys->i_size );
717 p_pic->p[0].p_pixels = p_pic->p_data;
718 p_pic->p[0].i_lines = p_vout->output.i_height;
719 p_pic->p[0].i_visible_lines = p_vout->output.i_height;
720 p_pic->p[0].i_pitch = p_vout->output.i_width * 2;
721 p_pic->p[0].i_pixel_pitch = 1;
722 p_pic->p[0].i_visible_pitch = p_vout->output.i_width * 2;
725 p_pic->p_sys->p_data = (void *)p_pic->p[0].p_pixels;
729 case VLC_FOURCC('I','4','2','0'):
730 p_pic->p_sys->p_data = (void *)&p_pic->p_sys->pixmap_i420;
731 p_pic->p_sys->i_size = sizeof(PlanarPixmapInfoYUV420);
733 /* Allocate the memory buffer */
734 p_pic->p_data = vlc_memalign( &p_pic->p_data_orig,
735 16, p_vout->output.i_width * p_vout->output.i_height * 3 / 2 );
738 p_pic->Y_PIXELS = p_pic->p_data;
739 p_pic->p[Y_PLANE].i_lines = p_vout->output.i_height;
740 p_pic->p[Y_PLANE].i_visible_lines = p_vout->output.i_height;
741 p_pic->p[Y_PLANE].i_pitch = p_vout->output.i_width;
742 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
743 p_pic->p[Y_PLANE].i_visible_pitch = p_vout->output.i_width;
746 p_pic->U_PIXELS = p_pic->Y_PIXELS + p_vout->output.i_height * p_vout->output.i_width;
747 p_pic->p[U_PLANE].i_lines = p_vout->output.i_height / 2;
748 p_pic->p[U_PLANE].i_visible_lines = p_vout->output.i_height / 2;
749 p_pic->p[U_PLANE].i_pitch = p_vout->output.i_width / 2;
750 p_pic->p[U_PLANE].i_pixel_pitch = 1;
751 p_pic->p[U_PLANE].i_visible_pitch = p_vout->output.i_width / 2;
754 p_pic->V_PIXELS = p_pic->U_PIXELS + p_vout->output.i_height * p_vout->output.i_width / 4;
755 p_pic->p[V_PLANE].i_lines = p_vout->output.i_height / 2;
756 p_pic->p[V_PLANE].i_visible_lines = p_vout->output.i_height / 2;
757 p_pic->p[V_PLANE].i_pitch = p_vout->output.i_width / 2;
758 p_pic->p[V_PLANE].i_pixel_pitch = 1;
759 p_pic->p[V_PLANE].i_visible_pitch = p_vout->output.i_width / 2;
761 /* We allocated 3 planes */
764 #define P p_pic->p_sys->pixmap_i420
765 P.componentInfoY.offset = (void *)p_pic->Y_PIXELS
766 - p_pic->p_sys->p_data;
767 P.componentInfoCb.offset = (void *)p_pic->U_PIXELS
768 - p_pic->p_sys->p_data;
769 P.componentInfoCr.offset = (void *)p_pic->V_PIXELS
770 - p_pic->p_sys->p_data;
772 P.componentInfoY.rowBytes = p_vout->output.i_width;
773 P.componentInfoCb.rowBytes = p_vout->output.i_width / 2;
774 P.componentInfoCr.rowBytes = p_vout->output.i_width / 2;
779 /* Unknown chroma, tell the guy to get lost */
780 free( p_pic->p_sys );
781 msg_Err( p_vout, "never heard of chroma 0x%.8x (%4.4s)",
782 p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma );
790 /*****************************************************************************
791 * QTFreePicture: destroy a picture allocated with QTNewPicture
792 *****************************************************************************/
793 static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
795 switch( p_vout->output.i_chroma )
797 case VLC_FOURCC('I','4','2','0'):
798 free( p_pic->p_data_orig );
802 free( p_pic->p_sys );
805 /*****************************************************************************
806 * VLCQTView implementation
807 *****************************************************************************/
808 @implementation VLCQTView
810 - (id) initWithVout:(vout_thread_t *)_p_vout
816 - (void)drawRect:(NSRect)rect
818 [[NSColor blackColor] set];
820 [super drawRect: rect];
822 p_vout->i_changes |= VOUT_SIZE_CHANGE;