1 /*****************************************************************************
2 * hd1000v.cpp: HD1000 video output display method
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
7 * Authors: Jean-Paul Saman <jpsaman _at_ videolan _dot_ org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
33 #include <vlc_playlist.h>
36 #include <cascade/graphics/CascadeBitmap.h>
37 #include <cascade/graphics/CascadeScreen.h>
39 /*****************************************************************************
41 *****************************************************************************/
42 static int Create ( vlc_object_t * );
43 static void Destroy ( vlc_object_t * );
45 static int Init ( vout_thread_t * );
46 static void End ( vout_thread_t * );
47 static void Display ( vout_thread_t *, picture_t * );
49 static int NewPicture ( vout_thread_t *, picture_t * );
50 static void FreePicture( vout_thread_t *, picture_t * );
52 /*****************************************************************************
54 *****************************************************************************/
56 set_description( _("HD1000 video output") );
57 set_capability( "video output", 100 );
58 add_shortcut( "hd1000v" );
59 set_callbacks( Create, Destroy );
62 /*****************************************************************************
63 * vout_sys_t: video output method descriptor
64 *****************************************************************************
65 * This structure is part of the video output thread descriptor.
66 * It describes the aa specific properties of an output thread.
67 *****************************************************************************/
70 uint32_t i_width; /* width of main window */
71 uint32_t i_height; /* height of main window */
72 uint32_t i_screen_depth;
73 vlc_bool_t b_double_buffered;
75 uint32_t u_current; /* Current output resolution. */
76 CascadeScreen *p_screen;
81 CascadeSharedMemZone *p_image;
84 /*****************************************************************************
85 * Create: allocates video thread output method
86 *****************************************************************************
87 * This function allocates and initializes a aa vout method.
88 *****************************************************************************/
89 static int Create( vlc_object_t *p_this )
91 vout_thread_t *p_vout = (vout_thread_t *)p_this;
92 bool b_double_buffered = false;
94 p_vout->p_sys = (struct vout_sys_t*) malloc( sizeof(struct vout_sys_t) );
95 if( p_vout->p_sys == NULL )
97 msg_Err( p_vout, "out of memory" );
101 /* Allocate a screen for VLC vout. */
102 p_vout->p_sys->p_screen = new CascadeScreen();
103 if( p_vout->p_sys->p_screen == NULL )
105 msg_Err( p_vout, "unable to allocate screen" );
106 free( p_vout->p_sys );
110 p_vout->pf_init = Init;
111 p_vout->pf_end = End;
112 p_vout->pf_manage = NULL;
113 p_vout->pf_render = NULL;
114 p_vout->pf_display = Display;
116 /* Get current screen resolution */
117 msg_Dbg( p_vout, "number of screen resolutions supported %u",
118 p_vout->p_sys->p_screen->GetNumScreenResolutionsSupported() );
120 p_vout->p_sys->p_screen->GetCurrentScreenResolution( (u32) p_vout->p_sys->u_current );
121 p_vout->p_sys->p_screen->SetScreenResolution( (u32) p_vout->p_sys->u_current );
124 msg_Dbg( p_vout, "available screen resolutions:" );
125 for (u32 i=0; i<p_vout->p_sys->p_screen->GetNumScreenResolutionsSupported(); i++)
132 p_vout->p_sys->p_screen->GetSupportedScreenResolutionAt( i,
133 i_width, i_height, i_screen_depth, b_buffered);
134 msg_Dbg( p_vout, " screen index = %u, width = %u, height = %u, depth = %u, double buffered = %s",
135 i, i_width, i_height, i_screen_depth, (b_buffered ? "yes" : "no") );
139 p_vout->p_sys->p_screen->GetSupportedScreenResolutionAt( (u32) p_vout->p_sys->u_current,
140 (u32) p_vout->p_sys->i_width,
141 (u32) p_vout->p_sys->i_height,
142 (u8) p_vout->p_sys->i_screen_depth,
144 p_vout->p_sys->b_double_buffered = (vlc_bool_t) b_double_buffered;
145 msg_Dbg( p_vout, "using screen index = %u, width = %u, height = %u, depth = %u, double buffered = %d",
146 p_vout->p_sys->u_current, /* Current screen. */
147 p_vout->p_sys->i_width,
148 p_vout->p_sys->i_height,
149 p_vout->p_sys->i_screen_depth,
150 p_vout->p_sys->b_double_buffered );
155 static void Destroy( vlc_object_t *p_this )
157 vout_thread_t *p_vout = (vout_thread_t *)p_this;
159 delete p_vout->p_sys->p_screen;
160 free( p_vout->p_sys );
163 /*****************************************************************************
164 * Init: initialize video thread output method
165 *****************************************************************************/
166 static int Init( vout_thread_t *p_vout )
169 picture_t *p_pic = NULL;
171 I_OUTPUTPICTURES = 0;
173 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
174 p_vout->output.i_width = p_vout->p_sys->i_width;
175 p_vout->output.i_height = p_vout->p_sys->i_height;
176 p_vout->output.i_aspect = p_vout->p_sys->i_width
177 * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
179 /* Only RGBA 32bpp is supported by output device. */
180 switch( p_vout->p_sys->i_screen_depth )
182 case 8: /* FIXME: set the palette */
183 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2'); break;
185 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5'); break;
187 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6'); break;
189 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4'); break;
191 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2'); break;
193 msg_Err( p_vout, "unknown screen depth %i",
194 p_vout->p_sys->i_screen_depth );
198 /* Find an empty picture slot */
199 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
201 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
203 p_pic = p_vout->p_picture + i_index;
208 if( p_pic == NULL || NewPicture( p_vout, p_pic ) )
213 /* Allocate the picture */
214 p_pic->p->i_lines = p_vout->p_sys->i_height;
215 p_pic->p->i_visible_lines = p_vout->p_sys->i_height;
216 p_pic->p->i_pitch = p_vout->p_sys->i_width;
217 p_pic->p->i_pixel_pitch = 1;
218 p_pic->p->i_visible_pitch = p_vout->p_sys->i_width;
221 p_pic->i_status = DESTROYED_PICTURE;
222 p_pic->i_type = DIRECT_PICTURE;
224 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
230 /*****************************************************************************
231 * End: terminate video thread output method
232 *****************************************************************************/
233 static void End( vout_thread_t *p_vout )
237 /* Free the direct buffers we allocated */
238 for( i_index = I_OUTPUTPICTURES ; i_index ; )
241 FreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );
245 /*****************************************************************************
246 * NewPicture: Allocate shared memory zone for video output
247 *****************************************************************************/
248 static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
250 CascadeDims p_dims = p_vout->p_sys->p_screen->GetDims();
252 p_pic->p_sys = (picture_sys_t *) malloc( sizeof( picture_sys_t ) );
253 if( p_pic->p_sys == NULL )
258 /* Fill in picture_t fields */
259 vout_InitPicture( VLC_OBJECT(p_vout), p_pic, p_vout->output.i_chroma,
260 p_vout->output.i_width, p_vout->output.i_height,
261 p_vout->output.i_aspect );
263 p_pic->p_sys->p_image = new CascadeSharedMemZone();
264 if( p_pic->p_sys->p_image == NULL )
266 free( p_pic->p_sys );
270 if( p_pic->p_sys->p_image->Open( "vlc_hd1000v", p_vout->output.i_width *
271 p_vout->output.i_height * p_vout->p_sys->i_screen_depth,
274 msg_Err( p_vout, "failed to allocate shared memory" );
275 free( p_pic->p_sys );
279 p_pic->p->i_lines = p_vout->output.i_height;
280 p_pic->p->i_visible_lines = p_vout->output.i_height;
281 p_pic->p->p_pixels = (uint8_t*) p_pic->p_sys->p_image->MapLock();
282 p_pic->p->i_pitch = p_vout->p_sys->i_screen_depth;
283 p_pic->p->i_visible_pitch = p_pic->p->i_pixel_pitch
284 * p_vout->output.i_width;
289 /*****************************************************************************
290 * FreePicture: destroy a picture allocated with NewPicture
291 *****************************************************************************
292 * Destroy SharedMemZoned AND associated data. The picture normally will be
293 * unlocked in the Display() function except when the video output is closed
294 * before the picture is displayed.
295 *****************************************************************************/
296 static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
298 if( p_pic->p_sys->p_image->Unlock() )
299 { /* Just a test to see the effect described above. REMOVE THIS */
300 msg_Err( p_vout, "unlocking shared memory failed, already unlocked" );
303 if( p_pic->p_sys->p_image->Close() )
305 msg_Err( p_vout, "closing shared memory failed. Leaking memory of %ul",
306 p_pic->p_sys->p_image->GetSize() );
309 delete p_pic->p_sys->p_image;
310 free( p_pic->p_sys );
313 /*****************************************************************************
314 * Display: Map p_image onto the screen
315 *****************************************************************************/
316 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
318 uint32_t i_width, i_height, i_x, i_y;
319 uint32_t i_offset = 0;
321 vout_PlacePicture( p_vout, p_vout->p_sys->i_width,
322 p_vout->p_sys->i_height,
323 &i_x, &i_y, &i_width, &i_height );
324 msg_Dbg( p_vout, "PlacePicture at x_left = %d, y_left = %d, x_bottom = %d, y_bottom = %d",
325 i_x, i_y, i_width, i_height );
327 /* Currently the only pixel format supported is 32bpp RGBA.*/
328 p_vout->p_sys->p_screen->LockScreen();
330 /* Unlock the shared memory region first. */
331 if( p_pic->p_sys->p_image->Unlock() )
333 msg_Err( p_vout, "unlocking shared memory failed. Expect threading problems." );
336 p_vout->p_sys->p_screen->Blit( CascadePoint( (u32) i_x, (u32) i_y ), /* Place bitmap at */
337 (*p_pic->p_sys->p_image) , /* Image data */
338 (u32) i_offset, /* Offset in SharedMemoryZone */
339 (u32) i_width, /* Source bitmap width */
340 (u32) i_height, /* Source bitmap height */
341 (u32) p_vout->p_sys->i_screen_depth, /* Source pixel depth */
342 CascadeRect( (u32) i_x, (u32) i_y, (u32) i_width, (u32) i_height ) );
344 p_vout->p_sys->p_screen->UnlockScreen();