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 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
38 #include <vgakeyboard.h>
40 /*****************************************************************************
42 *****************************************************************************/
43 static int Create ( vlc_object_t * );
44 static void Destroy ( vlc_object_t * );
46 static int Init ( vout_thread_t * );
47 static void End ( vout_thread_t * );
48 static int Manage ( vout_thread_t * );
49 static void Display ( vout_thread_t *, picture_t * );
51 static void SetPalette( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
53 /*****************************************************************************
55 *****************************************************************************/
57 set_shortname( "SVGAlib" );
58 set_category( CAT_VIDEO );
59 set_subcategory( SUBCAT_VIDEO_VOUT );
60 set_description( N_("SVGAlib video output") );
61 set_capability( "video output", 0 );
62 set_callbacks( Create, Destroy );
63 linked_with_a_crap_library_which_uses_atexit();
66 /*****************************************************************************
67 * vout_sys_t: video output descriptor
68 *****************************************************************************
69 * This structure is part of the video output thread descriptor.
70 * It describes the SVGAlib specific properties of an output thread.
71 *****************************************************************************/
77 /*****************************************************************************
78 * Create: allocates video thread
79 *****************************************************************************
80 * This function allocates and initializes a vout method.
81 *****************************************************************************/
82 static int Create( vlc_object_t *p_this )
84 vout_thread_t *p_vout = (vout_thread_t *)p_this;
86 /* Allocate instance and initialize some members */
87 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
88 if( p_vout->p_sys == NULL )
93 /* FIXME: find a way to test for SVGAlib availability. We cannot call
94 * vga_init from here because it needs to be closed from the same thread
95 * and we might give away the video output to another thread. Bah, it
96 * doesn't matter anyway ... SVGAlib is being an UGLY DIRTY PIG and calls
97 * atexit() and exit() so what can we do? */
99 p_vout->pf_init = Init;
100 p_vout->pf_end = End;
101 p_vout->pf_manage = Manage;
102 p_vout->pf_render = NULL;
103 p_vout->pf_display = Display;
108 /*****************************************************************************
109 * Init: initialize video thread
110 *****************************************************************************/
111 static int Init( vout_thread_t *p_vout )
116 I_OUTPUTPICTURES = 0;
118 /* SVGAlib shut up! */
119 vga_disabledriverreport();
121 /* We cannot call vga_init() in Create() because it has to be run
122 * from the same thread as the other vga calls. */
125 /* Check that we have a 8bpp mode available */
126 p_vout->p_sys->i_vgamode = vga_getdefaultmode();
127 if( p_vout->p_sys->i_vgamode == -1
128 || vga_getmodeinfo(p_vout->p_sys->i_vgamode)->bytesperpixel != 1 )
130 p_vout->p_sys->i_vgamode = G320x200x256;
133 if( !vga_hasmode( p_vout->p_sys->i_vgamode ) )
135 msg_Err( p_vout, "mode %i not available", p_vout->p_sys->i_vgamode );
139 vga_setmode( p_vout->p_sys->i_vgamode );
140 gl_setcontextvga( p_vout->p_sys->i_vgamode );
143 if( keyboard_init() )
145 msg_Err( p_vout, "could not initialize keyboard" );
151 keyboard_translatekeys( TRANSLATE_CURSORKEYS |
152 TRANSLATE_KEYPADENTER |
153 TRANSLATE_DIAGONAL );
155 /* Initialize the output structure: RGB with square pixels, whatever
156 * the input format is, since it's the only format we know */
157 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
158 p_vout->output.pf_setpalette = SetPalette;
159 p_vout->output.i_width = vga_getxdim();
160 p_vout->output.i_height = vga_getydim();
161 p_vout->output.i_aspect = p_vout->output.i_width
162 * VOUT_ASPECT_FACTOR / p_vout->output.i_height;
164 /* Try to initialize 1 direct buffer */
167 /* Find an empty picture slot */
168 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
170 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
172 p_pic = p_vout->p_picture + i_index;
177 /* Allocate the picture */
183 vout_AllocatePicture( p_vout, p_pic, p_vout->output.i_chroma,
184 p_vout->output.i_width, p_vout->output.i_height,
185 p_vout->output.i_aspect );
187 if( p_pic->i_planes == 0 )
192 p_pic->i_status = DESTROYED_PICTURE;
193 p_pic->i_type = DIRECT_PICTURE;
195 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
202 /*****************************************************************************
203 * End: terminate video thread
204 *****************************************************************************/
205 static void End( vout_thread_t *p_vout )
212 /*****************************************************************************
213 * Destroy: destroy video thread
214 *****************************************************************************
215 * Terminate an output method created by Create
216 *****************************************************************************/
217 static void Destroy( vlc_object_t *p_this )
219 vout_thread_t *p_vout = (vout_thread_t *)p_this;
221 /* Destroy structure */
222 free( p_vout->p_sys );
225 /*****************************************************************************
226 * Manage: handle SVGAlib events
227 *****************************************************************************
228 * This function should be called regularly by video output thread. It manages
229 * console events. It returns a non null value on error.
230 *****************************************************************************/
231 static int Manage( vout_thread_t *p_vout )
235 if( keyboard_keypressed(SCANCODE_ESCAPE)
236 || keyboard_keypressed(SCANCODE_Q ) )
238 vlc_object_kill( p_vout->p_libvlc );
244 /*****************************************************************************
245 * Display: displays previously rendered output
246 *****************************************************************************
247 * This function sends the currently rendered image to the VGA card.
248 *****************************************************************************/
249 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
251 gl_putbox( 0, 0, p_vout->output.i_width,
252 p_vout->output.i_height, p_pic->p->p_pixels );
255 /*****************************************************************************
256 * SetPalette: set a 8bpp palette
257 *****************************************************************************
258 * TODO: support 8 bits clut (for Mach32 cards and others).
259 *****************************************************************************/
260 static void SetPalette( vout_thread_t *p_vout,
261 uint16_t *red, uint16_t *green, uint16_t *blue )
267 vga_setpalette( i, red[i]>>10, green[i]>>10, blue[i]>>10 );