1 /*****************************************************************************
2 * vout_macosx.c: MacOS X video output plugin
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
6 * Authors: Colin Delacroix <colin@zoy.org>
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.
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.
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 *****************************************************************************/
23 #include "modules_inner.h"
25 /*****************************************************************************
27 *****************************************************************************/
30 #include <errno.h> /* ENOMEM */
31 #include <stdlib.h> /* free() */
32 #include <string.h> /* strerror() */
40 #include "interface.h"
44 #include "video_output.h"
49 #include "macosx_qt_common.h"
51 /*****************************************************************************
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 * );
63 static int vout_OSX_create_sequence( vout_thread_t *p_vout ) ;
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 )
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;
81 /*****************************************************************************
82 * intf_Probe: return a score
83 *****************************************************************************/
84 static int vout_Probe( probedata_t *p_data )
86 if( TestMethod( VOUT_METHOD_VAR, "macosx_qt" ) )
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 )
101 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
102 if( p_vout->p_sys == NULL )
104 intf_ErrMsg( "error: %s", strerror( ENOMEM ) );
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 )
118 ImageDescriptionPtr descr_ptr ;
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:") ;
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) ;
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)
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) ;
171 p_vout->b_need_render = 0 ;
172 p_vout->i_bytes_per_line = p_vout->i_width ;
177 /*****************************************************************************
178 * vout_Init: initialize video thread output method
179 *****************************************************************************/
180 static int vout_Init( vout_thread_t *p_vout )
182 if ( vout_OSX_create_sequence( p_vout ) )
184 intf_ErrMsg( "vout error: can't create quicktime view" );
185 free( p_vout->p_sys );
192 /*****************************************************************************
193 * vout_End: terminate video thread output method
194 *****************************************************************************/
195 static void vout_End( vout_thread_t *p_vout )
197 CDSequenceEnd(p_vout->p_sys->i_seq) ;
200 /*****************************************************************************
201 * vout_Destroy: destroy video thread output method
202 *****************************************************************************/
203 static void vout_Destroy( vout_thread_t *p_vout )
205 free( p_vout->p_sys );
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 )
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 )
229 // unsigned int x,y, height=p_vout->i_height, width=p_vout->i_width ;
230 CodecFlags out_flags ;
231 PlanarPixmapInfoYUV420 y420_info ;
233 if (!p_main->p_intf->p_sys->b_active)
236 /* for(x=0; x < height; x++)
238 for(y=0; y < (width/2); y++)
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) ;
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;
256 memcpy(p_vout->p_sys->p_img, &y420_info, sizeof(PlanarPixmapInfoYUV420)) ;
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,
267 // intf_WarnMsg(1, "DecompressSequenceFrameWhen: %d", qterror) ;