]> git.sesse.net Git - vlc/blob - plugins/macosx/vout_macosx.c
* ./plugins/macosx/vout_macosx.c: memalign -> vlc_memalign
[vlc] / plugins / macosx / vout_macosx.c
1 /*****************************************************************************
2  * vout_macosx.c: MacOS X video output plugin
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  *
6  * Authors: Colin Delacroix <colin@zoy.org>
7  *          Florian G. Pflug <fgp@phlo.org>
8  *          Jon Lech Johansen <jon-vl@nanocrew.net>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <stdlib.h>                                                /* free() */
30 #include <string.h>                                            /* strerror() */
31 #include <mach/mach_init.h>
32 #include <mach/task_policy.h>
33 #include <mach/thread_act.h>
34 #include <mach/thread_policy.h>
35 #include <sys/sysctl.h>
36
37 #include <videolan/vlc.h>
38
39 #include "video.h"
40 #include "video_output.h"
41
42 #include "interface.h"
43
44 #include "macosx.h"
45
46 #define QT_MAX_DIRECTBUFFERS 10
47
48 typedef struct picture_sys_s
49 {
50     void *p_info;
51     unsigned int i_size;
52
53     /* When using I420 output */
54     PlanarPixmapInfoYUV420 pixmap_i420;
55
56 } picture_sys_t;
57
58 /*****************************************************************************
59  * Local prototypes
60  *****************************************************************************/
61 static int  vout_Create    ( struct vout_thread_s * );
62 static int  vout_Init      ( struct vout_thread_s * );
63 static void vout_End       ( struct vout_thread_s * );
64 static void vout_Destroy   ( struct vout_thread_s * );
65 static int  vout_Manage    ( struct vout_thread_s * );
66 static void vout_Render    ( struct vout_thread_s *, struct picture_s * );
67 static void vout_Display   ( struct vout_thread_s *, struct picture_s * );
68
69 static int  CoSendRequest      ( struct vout_thread_s *, long i_request );
70 static int  CoCreateWindow     ( struct vout_thread_s * );
71 static int  CoDestroyWindow    ( struct vout_thread_s * );
72 static int  CoToggleFullscreen ( struct vout_thread_s * );
73
74 static void QTScaleMatrix      ( struct vout_thread_s * );
75 static int  QTCreateSequence   ( struct vout_thread_s * );
76 static void QTDestroySequence  ( struct vout_thread_s * );
77 static int  QTNewPicture       ( struct vout_thread_s *, struct picture_s * );
78 static void QTFreePicture      ( struct vout_thread_s *, struct picture_s * );
79
80 /*****************************************************************************
81  * Functions exported as capabilities. They are declared as static so that
82  * we don't pollute the namespace too much.
83  *****************************************************************************/
84 void _M( vout_getfunctions )( function_list_t * p_function_list )
85 {
86     p_function_list->functions.vout.pf_create     = vout_Create;
87     p_function_list->functions.vout.pf_init       = vout_Init;
88     p_function_list->functions.vout.pf_end        = vout_End;
89     p_function_list->functions.vout.pf_destroy    = vout_Destroy;
90     p_function_list->functions.vout.pf_manage     = vout_Manage;
91     p_function_list->functions.vout.pf_render     = vout_Render;
92     p_function_list->functions.vout.pf_display    = vout_Display;
93 }
94
95 /*****************************************************************************
96  * vout_Create: allocates MacOS X video thread output method
97  *****************************************************************************
98  * This function allocates and initializes a MacOS X vout method.
99  *****************************************************************************/
100 static int vout_Create( vout_thread_t *p_vout )
101 {
102     OSErr err;
103
104     if( !p_main->p_intf || !p_main->p_intf->p_module ||
105         strcmp( p_main->p_intf->p_module->psz_name, MODULE_STRING ) != 0 )
106     {
107         intf_ErrMsg( "vout error: MacOS X interface module required" );
108         return( 1 );
109     }
110
111     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
112     if( p_vout->p_sys == NULL )
113     {
114         intf_ErrMsg( "vout error: %s", strerror( ENOMEM ) );
115         return( 1 );
116     }
117
118     memset( p_vout->p_sys, 0, sizeof( vout_sys_t ) );
119
120     p_vout->p_sys->h_img_descr = 
121         (ImageDescriptionHandle)NewHandleClear( sizeof(ImageDescription) );
122     p_vout->p_sys->p_matrix = (MatrixRecordPtr)malloc( sizeof(MatrixRecord) );
123
124     p_vout->p_sys->b_mouse_pointer_visible = 1;
125
126     /* set window size */
127     p_vout->p_sys->s_rect.size.width = p_vout->i_window_width;
128     p_vout->p_sys->s_rect.size.height = p_vout->i_window_height;
129
130     if( ( err = EnterMovies() ) != noErr )
131     {
132         intf_ErrMsg( "vout error: EnterMovies failed: %d", err );
133         free( p_vout->p_sys->p_matrix );
134         DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
135         free( p_vout->p_sys );
136         return( 1 );
137     } 
138
139     if( vout_ChromaCmp( p_vout->render.i_chroma, FOURCC_I420 ) )
140     {
141         err = FindCodec( kYUV420CodecType, bestSpeedCodec,
142                          nil, &p_vout->p_sys->img_dc );
143         if( err == noErr && p_vout->p_sys->img_dc != 0 )
144         {
145             p_vout->output.i_chroma = FOURCC_I420;
146             p_vout->p_sys->i_codec = kYUV420CodecType;
147         }
148         else
149         {
150             intf_ErrMsg( "vout error: failed to find an appropriate codec" );
151         }
152     }
153     else
154     {
155         intf_ErrMsg( "vout error: chroma 0x%08x not supported",
156                      p_vout->render.i_chroma );
157     }
158
159     if( p_vout->p_sys->img_dc == 0 )
160     {
161         free( p_vout->p_sys->p_matrix );
162         DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
163         free( p_vout->p_sys );
164         return( 1 );        
165     }
166
167     if( CoCreateWindow( p_vout ) )
168     {
169         intf_ErrMsg( "vout error: unable to create window" );
170         free( p_vout->p_sys->p_matrix );
171         DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
172         free( p_vout->p_sys ); 
173         return( 1 );
174     }
175
176     return( 0 );
177 }
178
179 /*****************************************************************************
180  * vout_Init: initialize video thread output method
181  *****************************************************************************/
182 static int vout_Init( vout_thread_t *p_vout )
183 {
184     int i_index;
185     picture_t *p_pic;
186
187     struct thread_time_constraint_policy ttcpolicy;
188     int mib[2];
189     unsigned int miblen;
190     int i_busspeed;
191     size_t len;
192
193     I_OUTPUTPICTURES = 0;
194
195     /* Initialize the output structure; we already found a codec,
196      * and the corresponding chroma we will be using. Since we can
197      * arbitrary scale, stick to the coordinates and aspect. */
198     p_vout->output.i_width  = p_vout->render.i_width;
199     p_vout->output.i_height = p_vout->render.i_height;
200     p_vout->output.i_aspect = p_vout->render.i_aspect;
201
202     SetPort( p_vout->p_sys->p_qdport );
203     QTScaleMatrix( p_vout );
204
205     if( QTCreateSequence( p_vout ) )
206     {
207         intf_ErrMsg( "vout error: unable to create sequence" );
208         return( 1 );
209     }
210
211     /* Try to initialize up to QT_MAX_DIRECTBUFFERS direct buffers */
212     while( I_OUTPUTPICTURES < QT_MAX_DIRECTBUFFERS )
213     {
214         p_pic = NULL;
215
216         /* Find an empty picture slot */
217         for( i_index = 0; i_index < VOUT_MAX_PICTURES; i_index++ )
218         {
219             if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
220             {
221                 p_pic = p_vout->p_picture + i_index;
222                 break;
223             }
224         }
225
226         /* Allocate the picture */
227         if( p_pic == NULL || QTNewPicture( p_vout, p_pic ) )
228         {
229             break;
230         }
231
232         p_pic->i_status = DESTROYED_PICTURE;
233         p_pic->i_type   = DIRECT_PICTURE;
234
235         PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
236
237         I_OUTPUTPICTURES++;
238     }
239
240     /* Go to time-constrained thread policy */
241
242     /* Get bus speed */
243     mib[0] = CTL_HW;
244     mib[1] = HW_BUS_FREQ;
245     miblen = 2;
246     len = 4;
247     if( sysctl(mib, miblen, &i_busspeed, &len, NULL, 0) == -1 )
248     {
249         intf_ErrMsg("vout error: couldn't go to time-constrained policy (bus speed)");
250     }
251     else
252     {
253         /* This is in AbsoluteTime units, which are equal to
254          * 1/4 the bus speed on most machines. */
255
256         /* hard-coded numbers are approximations for 100 MHz bus speed.
257          * assume that app deals in frame-sized chunks, e.g. 30 per second.
258          * ttcpolicy.period = 833333; */
259         ttcpolicy.period = i_busspeed / 120;
260         /* ttcpolicy.computation = 60000; */
261         ttcpolicy.computation = i_busspeed / 1440;
262         /* ttcpolicy.constraint = 120000; */
263         ttcpolicy.constraint = i_busspeed / 720;
264         ttcpolicy.preemptible = 1;
265
266         if (thread_policy_set(mach_thread_self(),
267                   THREAD_TIME_CONSTRAINT_POLICY, (int *)&ttcpolicy,
268                   THREAD_TIME_CONSTRAINT_POLICY_COUNT) != KERN_SUCCESS)
269         {
270             intf_ErrMsg("vout error: couldn't go to time-constrained policy (thread_policy_set)");
271         }
272     }
273
274     return( 0 );
275 }
276
277 /*****************************************************************************
278  * vout_End: terminate video thread output method
279  *****************************************************************************/
280 static void vout_End( vout_thread_t *p_vout )
281 {
282     int i_index;
283
284     QTDestroySequence( p_vout );
285
286     /* Free the direct buffers we allocated */
287     for( i_index = I_OUTPUTPICTURES; i_index; )
288     {
289         i_index--;
290         QTFreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );
291     }
292 }
293
294 /*****************************************************************************
295  * vout_Destroy: destroy video thread output method
296  *****************************************************************************/
297 static void vout_Destroy( vout_thread_t *p_vout )
298 {
299     if( CoDestroyWindow( p_vout ) )
300     {
301         intf_ErrMsg( "vout error: unable to destroy window" );
302     }
303
304     ExitMovies();
305
306     free( p_vout->p_sys->p_matrix );
307     DisposeHandle( (Handle)p_vout->p_sys->h_img_descr );
308     free( p_vout->p_sys );
309 }
310
311 /*****************************************************************************
312  * vout_Manage: handle events
313  *****************************************************************************
314  * This function should be called regularly by video output thread. It manages
315  * console events. It returns a non null value on error.
316  *****************************************************************************/
317 static int vout_Manage( vout_thread_t *p_vout )
318 {    
319     if( p_vout->i_changes & VOUT_SIZE_CHANGE ) 
320     {
321         QTScaleMatrix( p_vout );
322         SetDSequenceMatrix( p_vout->p_sys->i_seq, 
323                             p_vout->p_sys->p_matrix );
324  
325         p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
326     }
327
328     if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
329     {
330         if( CoToggleFullscreen( p_vout ) )  
331         {
332             return( 1 );
333         }
334
335         p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
336     }
337
338     /* hide/show mouse cursor */
339     if( p_vout->p_sys->b_mouse_moved ||
340         p_vout->p_sys->i_time_mouse_last_moved )
341     {
342         boolean_t b_change = 0;
343
344         if( !p_vout->p_sys->b_mouse_pointer_visible )
345         {
346             CGDisplayShowCursor( kCGDirectMainDisplay );
347             b_change = 1;
348         }
349         else if( !p_vout->p_sys->b_mouse_moved && 
350             mdate() - p_vout->p_sys->i_time_mouse_last_moved > 2000000 &&
351             p_vout->p_sys->b_mouse_pointer_visible )
352         {
353             CGDisplayHideCursor( kCGDirectMainDisplay );
354             b_change = 1;
355         }
356
357         if( b_change )
358         {
359             p_vout->p_sys->i_time_mouse_last_moved = 0;
360             p_vout->p_sys->b_mouse_moved = 0;
361             p_vout->p_sys->b_mouse_pointer_visible =
362                 !p_vout->p_sys->b_mouse_pointer_visible;
363         }
364     }
365
366     return( 0 );
367 }
368
369 /*****************************************************************************
370  * vout_Render: render previously calculated output
371  *****************************************************************************/
372 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
373 {
374     ;
375 }
376
377 /*****************************************************************************
378  * vout_Display: displays previously rendered output
379  *****************************************************************************
380  * This function sends the currently rendered image to the display.
381  *****************************************************************************/
382 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
383 {
384     OSErr err;
385     CodecFlags flags;
386
387     if( ( err = DecompressSequenceFrameS( 
388                     p_vout->p_sys->i_seq,
389                     p_pic->p_sys->p_info,
390                     p_pic->p_sys->i_size,                    
391                     codecFlagUseImageBuffer, &flags, nil ) != noErr ) )
392     {
393         intf_ErrMsg( "DecompressSequenceFrameS failed: %d", err );
394     }
395 }
396
397 /*****************************************************************************
398  * CoSendRequest: send request to interface thread
399  *****************************************************************************
400  * Returns 0 on success, 1 otherwise
401  *****************************************************************************/
402 static int CoSendRequest( vout_thread_t *p_vout, long i_request )
403 {
404     NSArray *o_array;
405     NSPortMessage *o_msg;
406     struct vout_req_s req;
407     struct vout_req_s *p_req = &req;
408     NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
409     NSPort *recvPort = [[NSPort port] retain];
410
411     memset( &req, 0, sizeof(req) );
412     req.i_type = i_request;
413     req.p_vout = p_vout;
414
415     req.o_lock = [[NSConditionLock alloc] initWithCondition: 0];
416
417     o_array = [NSArray arrayWithObject:
418         [NSData dataWithBytes: &p_req length: sizeof(void *)]];
419     o_msg = [[NSPortMessage alloc]
420         initWithSendPort: p_main->p_intf->p_sys->o_port
421         receivePort: recvPort
422         components: o_array];
423
424     [o_msg sendBeforeDate: [NSDate distantPast]];
425     [req.o_lock lockWhenCondition: 1];
426     [req.o_lock unlock];
427
428     [o_msg release];
429     [req.o_lock release];
430
431     [recvPort release];
432     [o_pool release];
433
434     return( !req.i_result );
435 }
436
437 /*****************************************************************************
438  * CoCreateWindow: create new window 
439  *****************************************************************************
440  * Returns 0 on success, 1 otherwise
441  *****************************************************************************/
442 static int CoCreateWindow( vout_thread_t *p_vout )
443 {
444     if( CoSendRequest( p_vout, VOUT_REQ_CREATE_WINDOW ) )
445     {
446         intf_ErrMsg( "CoSendRequest (CREATE_WINDOW) failed" );
447         return( 1 );
448     }
449
450     return( 0 );
451 }
452
453 /*****************************************************************************
454  * CoDestroyWindow: destroy window 
455  *****************************************************************************
456  * Returns 0 on success, 1 otherwise
457  *****************************************************************************/
458 static int CoDestroyWindow( vout_thread_t *p_vout )
459 {
460     if( !p_vout->p_sys->b_mouse_pointer_visible )
461     {
462         CGDisplayShowCursor( kCGDirectMainDisplay );
463         p_vout->p_sys->b_mouse_pointer_visible = 1;
464     }
465
466     if( CoSendRequest( p_vout, VOUT_REQ_DESTROY_WINDOW ) )
467     {
468         intf_ErrMsg( "CoSendRequest (DESTROY_WINDOW) failed" );
469         return( 1 );
470     }
471
472     return( 0 );
473 }
474
475 /*****************************************************************************
476  * CoToggleFullscreen: toggle fullscreen 
477  *****************************************************************************
478  * Returns 0 on success, 1 otherwise
479  *****************************************************************************/
480 static int CoToggleFullscreen( vout_thread_t *p_vout )
481 {
482     QTDestroySequence( p_vout );
483
484     if( CoDestroyWindow( p_vout ) )
485     {
486         intf_ErrMsg( "vout error: unable to destroy window" );
487         return( 1 );
488     }
489     
490     p_vout->b_fullscreen = !p_vout->b_fullscreen;
491
492     if( CoCreateWindow( p_vout ) )
493     {
494         intf_ErrMsg( "vout error: unable to create window" );
495         return( 1 );
496     }
497
498     SetPort( p_vout->p_sys->p_qdport );
499     QTScaleMatrix( p_vout );
500
501     if( QTCreateSequence( p_vout ) )
502     {
503         intf_ErrMsg( "vout error: unable to create sequence" );
504         return( 1 ); 
505     } 
506
507     return( 0 );
508 }
509
510 /*****************************************************************************
511  * QTScaleMatrix: scale matrix 
512  *****************************************************************************/
513 static void QTScaleMatrix( vout_thread_t *p_vout )
514 {
515     Rect s_rect;
516     Fixed factor_x;
517     Fixed factor_y;
518
519     GetPortBounds( p_vout->p_sys->p_qdport, &s_rect );
520
521     factor_x = FixDiv( Long2Fix( s_rect.right - s_rect.left ),
522                        Long2Fix( p_vout->output.i_width ) );
523     factor_y = FixDiv( Long2Fix( s_rect.bottom - s_rect.top ),
524                        Long2Fix( p_vout->output.i_height ) );
525
526     SetIdentityMatrix( p_vout->p_sys->p_matrix );
527     ScaleMatrix( p_vout->p_sys->p_matrix,
528                  factor_x, factor_y,
529                  Long2Fix(0), Long2Fix(0) );            
530 }
531
532 /*****************************************************************************
533  * QTCreateSequence: create a new sequence 
534  *****************************************************************************
535  * Returns 0 on success, 1 otherwise
536  *****************************************************************************/
537 static int QTCreateSequence( vout_thread_t *p_vout )
538 {
539     OSErr err;
540     ImageDescriptionPtr p_descr;
541
542     HLock( (Handle)p_vout->p_sys->h_img_descr );
543     p_descr = *p_vout->p_sys->h_img_descr;
544
545     p_descr->idSize = sizeof(ImageDescription);
546     p_descr->cType = p_vout->p_sys->i_codec;
547     p_descr->version = 1;
548     p_descr->revisionLevel = 0;
549     p_descr->vendor = 'appl';
550     p_descr->width = p_vout->output.i_width;
551     p_descr->height = p_vout->output.i_height;
552     p_descr->hRes = Long2Fix(72);
553     p_descr->vRes = Long2Fix(72);
554     p_descr->spatialQuality = codecLosslessQuality;
555     p_descr->frameCount = 1;
556     p_descr->clutID = -1;
557
558     p_descr->dataSize = p_vout->output.i_width *
559                         p_vout->output.i_height * 3 / 2;
560     p_descr->depth = 12;
561
562     HUnlock( (Handle)p_vout->p_sys->h_img_descr );
563
564     if( ( err = DecompressSequenceBeginS( 
565                               &p_vout->p_sys->i_seq,
566                               p_vout->p_sys->h_img_descr,
567                               NULL, 0,
568                               p_vout->p_sys->p_qdport,
569                               NULL, NULL,
570                               p_vout->p_sys->p_matrix,
571                               0, NULL,
572                               codecFlagUseImageBuffer,
573                               codecLosslessQuality,
574                               p_vout->p_sys->img_dc ) ) )
575     {
576         intf_ErrMsg( "DecompressSequenceBeginS failed: %d", err );
577         return( 1 );
578     }
579
580     return( 0 );
581 }
582
583 /*****************************************************************************
584  * QTDestroySequence: destroy sequence 
585  *****************************************************************************/
586 static void QTDestroySequence( vout_thread_t *p_vout )
587 {
588     CDSequenceEnd( p_vout->p_sys->i_seq );
589 }
590
591 /*****************************************************************************
592  * QTNewPicture: allocate a picture
593  *****************************************************************************
594  * Returns 0 on success, 1 otherwise
595  *****************************************************************************/
596 static int QTNewPicture( vout_thread_t *p_vout, picture_t *p_pic )
597 {
598     int i_width  = p_vout->output.i_width;
599     int i_height = p_vout->output.i_height;
600
601     /* We know the chroma, allocate a buffer which will be used
602      * directly by the decoder */
603     p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
604
605     if( p_pic->p_sys == NULL )
606     {
607         return( -1 );
608     }
609
610     switch( p_vout->output.i_chroma )
611     {
612         case FOURCC_I420:
613
614             p_pic->p_sys->p_info = (void *)&p_pic->p_sys->pixmap_i420;
615             p_pic->p_sys->i_size = sizeof(PlanarPixmapInfoYUV420);
616
617             /* Allocate the memory buffer */
618             p_pic->p_data = vlc_memalign( 16, i_width * i_height * 3 / 2,
619                                           &p_pic->p_data_orig );
620
621             /* Y buffer */
622             p_pic->Y_PIXELS = p_pic->p_data; 
623             p_pic->p[Y_PLANE].i_lines = i_height;
624             p_pic->p[Y_PLANE].i_pitch = i_width;
625             p_pic->p[Y_PLANE].i_pixel_bytes = 1;
626             p_pic->p[Y_PLANE].b_margin = 0;
627
628             /* U buffer */
629             p_pic->U_PIXELS = p_pic->Y_PIXELS + i_height * i_width;
630             p_pic->p[U_PLANE].i_lines = i_height / 2;
631             p_pic->p[U_PLANE].i_pitch = i_width / 2;
632             p_pic->p[U_PLANE].i_pixel_bytes = 1;
633             p_pic->p[U_PLANE].b_margin = 0;
634
635             /* V buffer */
636             p_pic->V_PIXELS = p_pic->U_PIXELS + i_height * i_width / 4;
637             p_pic->p[V_PLANE].i_lines = i_height / 2;
638             p_pic->p[V_PLANE].i_pitch = i_width / 2;
639             p_pic->p[V_PLANE].i_pixel_bytes = 1;
640             p_pic->p[V_PLANE].b_margin = 0;
641
642             /* We allocated 3 planes */
643             p_pic->i_planes = 3;
644
645 #define P p_pic->p_sys->pixmap_i420
646             P.componentInfoY.offset = (void *)p_pic->Y_PIXELS
647                                        - p_pic->p_sys->p_info;
648             P.componentInfoCb.offset = (void *)p_pic->U_PIXELS
649                                         - p_pic->p_sys->p_info;
650             P.componentInfoCr.offset = (void *)p_pic->V_PIXELS
651                                         - p_pic->p_sys->p_info;
652
653             P.componentInfoY.rowBytes = i_width;
654             P.componentInfoCb.rowBytes = i_width / 2;
655             P.componentInfoCr.rowBytes = i_width / 2;
656 #undef P
657
658             break;
659
660     default:
661         /* Unknown chroma, tell the guy to get lost */
662         free( p_pic->p_sys );
663         intf_ErrMsg( "vout error: never heard of chroma 0x%.8x (%4.4s)",
664                      p_vout->output.i_chroma, 
665                      (char*)&p_vout->output.i_chroma );
666         p_pic->i_planes = 0;
667         return( -1 );
668     }
669
670     return( 0 );
671 }
672
673 /*****************************************************************************
674  * QTFreePicture: destroy a picture allocated with QTNewPicture
675  *****************************************************************************/
676 static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
677 {
678     switch( p_vout->output.i_chroma )
679     {
680         case FOURCC_I420:
681             free( p_pic->p_data_orig );
682             break;
683     }
684
685     free( p_pic->p_sys );
686 }
687