]> git.sesse.net Git - vlc/blob - plugins/macosx/vout_macosx_qt.c
c61e60699fcbfd223a2de7172290271192d83a1f
[vlc] / plugins / macosx / vout_macosx_qt.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  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 #include "modules_inner.h"
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include "defs.h"
29
30 #include <errno.h>                                                 /* ENOMEM */
31 #include <stdlib.h>                                                /* free() */
32 #include <string.h>                                            /* strerror() */
33
34 #include "config.h"
35 #include "common.h"
36 #include "threads.h"
37 #include "mtime.h"
38 #include "tests.h"
39
40 #include "interface.h"
41 #include "intf_msg.h"
42
43 #include "video.h"
44 #include "video_output.h"
45
46 #include "modules.h"
47 #include "main.h"
48
49 #include "macosx_qt_common.h"
50
51 /*****************************************************************************
52  * Local prototypes
53  *****************************************************************************/
54 static int  vout_Probe     ( probedata_t *p_data );
55 static int  vout_Create    ( struct vout_thread_s * );
56 static int  vout_Init      ( struct vout_thread_s * );
57 static void vout_End       ( struct vout_thread_s * );
58 static void vout_Destroy   ( struct vout_thread_s * );
59 static int  vout_Manage    ( struct vout_thread_s * );
60 void vout_OSX_Display   ( struct vout_thread_s * );
61
62 /* OS specific */
63 static int vout_OSX_create_sequence( vout_thread_t *p_vout ) ;
64
65 /*****************************************************************************
66  * Functions exported as capabilities. They are declared as static so that
67  * we don't pollute the namespace too much.
68  *****************************************************************************/
69 void _M( vout_getfunctions )( function_list_t * p_function_list )
70 {
71     p_function_list->pf_probe = vout_Probe;
72     p_function_list->functions.vout.pf_create     = vout_Create;
73     p_function_list->functions.vout.pf_init       = vout_Init;
74     p_function_list->functions.vout.pf_end        = vout_End;
75     p_function_list->functions.vout.pf_destroy    = vout_Destroy;
76     p_function_list->functions.vout.pf_manage     = vout_Manage;
77     p_function_list->functions.vout.pf_display    = vout_OSX_Display;
78     p_function_list->functions.vout.pf_setpalette = NULL;
79 }
80
81 /*****************************************************************************
82  * intf_Probe: return a score
83  *****************************************************************************/
84 static int vout_Probe( probedata_t *p_data )
85 {
86     if( TestMethod( VOUT_METHOD_VAR, "macosx_qt" ) )
87     {
88         return( 999 );
89     }
90
91     return( 90 );
92 }
93
94 /*****************************************************************************
95  * vout_Create: allocates MacOS X video thread output method
96  *****************************************************************************
97  * This function allocates and initializes a MacOS X vout method.
98  *****************************************************************************/
99 static int vout_Create( vout_thread_t *p_vout )
100 {
101     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
102     if( p_vout->p_sys == NULL )
103     {
104         intf_ErrMsg( "error: %s", strerror( ENOMEM ) );
105         return( 1 );
106     }
107
108     EnterMovies() ;
109
110     return( 0 );
111 }
112
113 /*****************************************************************************
114  * MakeWindow: open and set-up a Mac OS main window
115  *****************************************************************************/
116 static int vout_OSX_create_sequence( vout_thread_t *p_vout )
117 {
118     ImageDescriptionPtr descr_ptr ;
119     OSErr qterror ;
120
121     p_vout->p_sys->h_img_descr = (ImageDescriptionHandle)NewHandleClear(sizeof(ImageDescription)) ;
122     p_vout->p_sys->i_img_size = p_vout->i_width * p_vout->i_height * 1.5 ; //before: 2
123     if (! (p_vout->p_sys->p_img  = malloc(p_vout->p_sys->i_img_size))) {
124         intf_ErrMsg("couldn't allocate image:") ;
125         return 1 ;
126     }
127
128     HLock((Handle)p_vout->p_sys->h_img_descr) ; 
129     descr_ptr = *p_vout->p_sys->h_img_descr ;
130     descr_ptr->idSize = sizeof(ImageDescription) ;
131     descr_ptr->cType = 'y420' ; //before: yuv2
132     descr_ptr->resvd1 = 0 ; //Reserved
133     descr_ptr->resvd2 = 0 ; //Reserved
134     descr_ptr->dataRefIndex = 0 ; //Reserved
135     descr_ptr->version = 1 ; //
136     descr_ptr->revisionLevel = 0 ;
137     descr_ptr->vendor = 'appl' ; //How do we get a vendor id??
138     descr_ptr->width = p_vout->i_width  ;
139     descr_ptr->height = p_vout->i_height ;
140     descr_ptr->hRes = Long2Fix(72) ;
141     descr_ptr->vRes = Long2Fix(72) ;
142     descr_ptr->spatialQuality = codecLosslessQuality ;
143     descr_ptr->dataSize = p_vout->p_sys->i_img_size ;
144     descr_ptr->frameCount = 1 ;
145     //memcpy(descr_ptr->name, "\pComponent Video\0") ;
146     descr_ptr->depth = 12 ; //before: 24
147     descr_ptr->clutID = -1 ; //We don't need a color table
148     HUnlock((Handle)p_vout->p_sys->h_img_descr) ;
149
150     SetPortWindowPort(p_main->p_intf->p_sys->p_window) ;
151     qterror = DecompressSequenceBeginS(&p_vout->p_sys->i_seq, 
152                                 p_vout->p_sys->h_img_descr,
153                                 (void *)p_vout->p_sys->p_img,
154                                 p_vout->p_sys->i_img_size,
155                                 GetWindowPort(p_main->p_intf->p_sys->p_window),
156                                 NULL, //device to display (is set implicit via the qdPort)
157                                 NULL, //src-rect
158                                 NULL, //matrix
159                                 0, //just do plain copying
160                                 NULL, //no mask region
161                                 codecFlagUseScreenBuffer,
162                                 codecLosslessQuality,
163                                 (DecompressorComponent) bestSpeedCodec) ;
164    intf_WarnMsg(1, "DecompressSequenceBeginS: %d\n", qterror) ;
165    
166    if (qterror)
167    {
168         return(1) ; 
169    }
170
171    p_vout->b_need_render = 0 ;
172    p_vout->i_bytes_per_line = p_vout->i_width ;
173
174     return( 0 );
175 }
176
177 /*****************************************************************************
178  * vout_Init: initialize video thread output method
179  *****************************************************************************/
180 static int vout_Init( vout_thread_t *p_vout )
181 {
182     if ( vout_OSX_create_sequence( p_vout ) )
183     {
184         intf_ErrMsg( "vout error: can't create quicktime view" );
185         free( p_vout->p_sys );
186         return( 1 );
187     }
188
189     return( 0 );
190 }
191
192 /*****************************************************************************
193  * vout_End: terminate video thread output method
194  *****************************************************************************/
195 static void vout_End( vout_thread_t *p_vout )
196 {
197         CDSequenceEnd(p_vout->p_sys->i_seq) ;
198 }
199
200 /*****************************************************************************
201  * vout_Destroy: destroy video thread output method
202  *****************************************************************************/
203 static void vout_Destroy( vout_thread_t *p_vout )
204 {
205     free( p_vout->p_sys );
206 }
207
208 /*****************************************************************************
209  * vout_Manage: handle events
210  *****************************************************************************
211  * This function should be called regularly by video output thread. It manages
212  * console events. It returns a non null value on error.
213  *****************************************************************************/
214 static int vout_Manage( vout_thread_t *p_vout )
215 {
216     return( 0 );
217 }
218
219
220 /*****************************************************************************
221  * vout_OSX_Display: displays previously rendered output
222  *****************************************************************************
223  * This function send the currently rendered image to image, waits until
224  * it is displayed and switch the two rendering buffers, preparing next frame.
225  *****************************************************************************/
226 void vout_OSX_Display( vout_thread_t *p_vout )
227 {
228         OSErr qterror ;
229 //      unsigned int x,y, height=p_vout->i_height, width=p_vout->i_width ;
230         CodecFlags out_flags ;
231         PlanarPixmapInfoYUV420 y420_info ;
232
233         if (!p_main->p_intf->p_sys->b_active)
234                 return ;
235
236 /*      for(x=0; x < height; x++)
237         {
238                 for(y=0; y < (width/2); y++)
239                 {
240                         p_vout->p_sys->p_img[(width/2)*x + y] =
241                                 (p_vout->p_rendered_pic->p_y[width*x + 2*y]) << 24 |
242                                 ((p_vout->p_rendered_pic->p_u[(width/2)*(x/2) + y] ^ 0x80) << 16) |
243                                 (p_vout->p_rendered_pic->p_y[width*x + 2*y + 1] << 8) |
244                                 (p_vout->p_rendered_pic->p_v[(width/2)*(x/2) + y] ^ 0x80) ;   
245                 }
246         }
247 */
248
249         y420_info.componentInfoY.offset = p_vout->p_rendered_pic->p_y - p_vout->p_sys->p_img ;
250         y420_info.componentInfoY.rowBytes = p_vout->i_width ;
251         y420_info.componentInfoCb.offset = p_vout->p_rendered_pic->p_u - p_vout->p_sys->p_img ;
252         y420_info.componentInfoCb.rowBytes = p_vout->i_width / 2;
253         y420_info.componentInfoCr.offset = p_vout->p_rendered_pic->p_v - p_vout->p_sys->p_img ;
254         y420_info.componentInfoCr.rowBytes = p_vout->i_width / 2;
255
256         memcpy(p_vout->p_sys->p_img, &y420_info, sizeof(PlanarPixmapInfoYUV420)) ;
257
258         qterror = DecompressSequenceFrameWhen(
259                 p_vout->p_sys->i_seq,
260                 (void *)p_vout->p_sys->p_img,
261                 p_vout->p_sys->i_img_size,
262                 codecFlagUseScreenBuffer,
263                 &out_flags,
264                 nil,
265                 nil) ;
266
267 //      intf_WarnMsg(1, "DecompressSequenceFrameWhen: %d", qterror) ;
268  }