1 /*****************************************************************************
2 * svgalib.c : SVGAlib plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.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 *****************************************************************************/
37 #include <vgakeyboard.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 int Manage ( vout_thread_t * );
48 static void Display ( vout_thread_t *, picture_t * );
50 static void SetPalette( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
52 /*****************************************************************************
54 *****************************************************************************/
56 set_shortname( "SVGAlib" );
57 set_category( CAT_VIDEO );
58 set_subcategory( SUBCAT_VIDEO_VOUT );
59 set_description( _("SVGAlib video output") );
60 set_capability( "video output", 0 );
61 set_callbacks( Create, Destroy );
62 linked_with_a_crap_library_which_uses_atexit();
65 /*****************************************************************************
66 * vout_sys_t: video output descriptor
67 *****************************************************************************
68 * This structure is part of the video output thread descriptor.
69 * It describes the SVGAlib specific properties of an output thread.
70 *****************************************************************************/
76 /*****************************************************************************
77 * Create: allocates video thread
78 *****************************************************************************
79 * This function allocates and initializes a vout method.
80 *****************************************************************************/
81 static int Create( vlc_object_t *p_this )
83 vout_thread_t *p_vout = (vout_thread_t *)p_this;
85 /* Allocate instance and initialize some members */
86 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
87 if( p_vout->p_sys == NULL )
92 /* FIXME: find a way to test for SVGAlib availability. We cannot call
93 * vga_init from here because it needs to be closed from the same thread
94 * and we might give away the video output to another thread. Bah, it
95 * doesn't matter anyway ... SVGAlib is being an UGLY DIRTY PIG and calls
96 * atexit() and exit() so what can we do? */
98 p_vout->pf_init = Init;
100 p_vout->pf_manage = Manage;
101 p_vout->pf_render = NULL;
102 p_vout->pf_display = Display;
107 /*****************************************************************************
108 * Init: initialize video thread
109 *****************************************************************************/
110 static int Init( vout_thread_t *p_vout )
115 I_OUTPUTPICTURES = 0;
117 /* SVGAlib shut up! */
118 vga_disabledriverreport();
120 /* We cannot call vga_init() in Create() because it has to be run
121 * from the same thread as the other vga calls. */
124 /* Check that we have a 8bpp mode available */
125 p_vout->p_sys->i_vgamode = vga_getdefaultmode();
126 if( p_vout->p_sys->i_vgamode == -1
127 || vga_getmodeinfo(p_vout->p_sys->i_vgamode)->bytesperpixel != 1 )
129 p_vout->p_sys->i_vgamode = G320x200x256;
132 if( !vga_hasmode( p_vout->p_sys->i_vgamode ) )
134 msg_Err( p_vout, "mode %i not available", p_vout->p_sys->i_vgamode );
138 vga_setmode( p_vout->p_sys->i_vgamode );
139 gl_setcontextvga( p_vout->p_sys->i_vgamode );
142 if( keyboard_init() )
144 msg_Err( p_vout, "could not initialize keyboard" );
150 keyboard_translatekeys( TRANSLATE_CURSORKEYS |
151 TRANSLATE_KEYPADENTER |
152 TRANSLATE_DIAGONAL );
154 /* Initialize the output structure: RGB with square pixels, whatever
155 * the input format is, since it's the only format we know */
156 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
157 p_vout->output.pf_setpalette = SetPalette;
158 p_vout->output.i_width = vga_getxdim();
159 p_vout->output.i_height = vga_getydim();
160 p_vout->output.i_aspect = p_vout->output.i_width
161 * VOUT_ASPECT_FACTOR / p_vout->output.i_height;
163 /* Try to initialize 1 direct buffer */
166 /* Find an empty picture slot */
167 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
169 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
171 p_pic = p_vout->p_picture + i_index;
176 /* Allocate the picture */
182 vout_AllocatePicture( p_vout, p_pic, p_vout->output.i_chroma,
183 p_vout->output.i_width, p_vout->output.i_height,
184 p_vout->output.i_aspect );
186 if( p_pic->i_planes == 0 )
191 p_pic->i_status = DESTROYED_PICTURE;
192 p_pic->i_type = DIRECT_PICTURE;
194 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
201 /*****************************************************************************
202 * End: terminate video thread
203 *****************************************************************************/
204 static void End( vout_thread_t *p_vout )
211 /*****************************************************************************
212 * Destroy: destroy video thread
213 *****************************************************************************
214 * Terminate an output method created by Create
215 *****************************************************************************/
216 static void Destroy( vlc_object_t *p_this )
218 vout_thread_t *p_vout = (vout_thread_t *)p_this;
220 /* Destroy structure */
221 free( p_vout->p_sys );
224 /*****************************************************************************
225 * Manage: handle SVGAlib events
226 *****************************************************************************
227 * This function should be called regularly by video output thread. It manages
228 * console events. It returns a non null value on error.
229 *****************************************************************************/
230 static int Manage( vout_thread_t *p_vout )
234 if( keyboard_keypressed(SCANCODE_ESCAPE)
235 || keyboard_keypressed(SCANCODE_Q ) )
237 vlc_object_kill( p_vout->p_libvlc );
243 /*****************************************************************************
244 * Display: displays previously rendered output
245 *****************************************************************************
246 * This function sends the currently rendered image to the VGA card.
247 *****************************************************************************/
248 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
250 gl_putbox( 0, 0, p_vout->output.i_width,
251 p_vout->output.i_height, p_pic->p->p_pixels );
254 /*****************************************************************************
255 * SetPalette: set a 8bpp palette
256 *****************************************************************************
257 * TODO: support 8 bits clut (for Mach32 cards and others).
258 *****************************************************************************/
259 static void SetPalette( vout_thread_t *p_vout,
260 uint16_t *red, uint16_t *green, uint16_t *blue )
266 vga_setpalette( i, red[i]>>10, green[i]>>10, blue[i]>>10 );