1
/*****************************************************************************
2
* svgalib.c : SVGAlib plugin for vlc
3
*****************************************************************************
4
* Copyright (C) 2002 VideoLAN
5
* $Id: svgalib.c 6961 2004-03-05 17:34:23Z sam $
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22
*****************************************************************************/
24
/*****************************************************************************
26
*****************************************************************************/
34
#include <vgakeyboard.h>
36
/*****************************************************************************
38
*****************************************************************************/
39
static int Create ( vlc_object_t * );
40
static void Destroy ( vlc_object_t * );
42
static int Init ( vout_thread_t * );
43
static void End ( vout_thread_t * );
44
static int Manage ( vout_thread_t * );
45
static void Display ( vout_thread_t *, picture_t * );
47
static void SetPalette( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
49
/*****************************************************************************
51
*****************************************************************************/
53
set_description( _("SVGAlib video output") );
54
set_capability( "video output", 0 );
55
set_callbacks( Create, Destroy );
56
linked_with_a_crap_library_which_uses_atexit();
59
/*****************************************************************************
60
* vout_sys_t: video output descriptor
61
*****************************************************************************
62
* This structure is part of the video output thread descriptor.
63
* It describes the SVGAlib specific properties of an output thread.
64
*****************************************************************************/
70
/*****************************************************************************
71
* Create: allocates video thread
72
*****************************************************************************
73
* This function allocates and initializes a vout method.
74
*****************************************************************************/
75
static int Create( vlc_object_t *p_this )
77
vout_thread_t *p_vout = (vout_thread_t *)p_this;
79
/* Allocate instance and initialize some members */
80
p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
81
if( p_vout->p_sys == NULL )
86
/* FIXME: find a way to test for SVGAlib availability. We cannot call
87
* vga_init from here because it needs to be closed from the same thread
88
* and we might give away the video output to another thread. Bah, it
89
* doesn't matter anyway ... SVGAlib is being an UGLY DIRTY PIG and calls
90
* atexit() and exit() so what can we do? */
92
p_vout->pf_init = Init;
94
p_vout->pf_manage = Manage;
95
p_vout->pf_render = NULL;
96
p_vout->pf_display = Display;
101
/*****************************************************************************
102
* Init: initialize video thread
103
*****************************************************************************/
104
static int Init( vout_thread_t *p_vout )
109
I_OUTPUTPICTURES = 0;
111
/* SVGAlib shut up! */
112
vga_disabledriverreport();
114
/* We cannot call vga_init() in Create() because it has to be run
115
* from the same thread as the other vga calls. */
118
/* Check that we have a 8bpp mode available */
119
p_vout->p_sys->i_vgamode = vga_getdefaultmode();
120
if( p_vout->p_sys->i_vgamode == -1
121
|| vga_getmodeinfo(p_vout->p_sys->i_vgamode)->bytesperpixel != 1 )
123
p_vout->p_sys->i_vgamode = G320x200x256;
126
if( !vga_hasmode( p_vout->p_sys->i_vgamode ) )
128
msg_Err( p_vout, "mode %i not available", p_vout->p_sys->i_vgamode );
132
vga_setmode( p_vout->p_sys->i_vgamode );
133
gl_setcontextvga( p_vout->p_sys->i_vgamode );
136
if( keyboard_init() )
138
msg_Err( p_vout, "could not initialize keyboard" );
144
keyboard_translatekeys( TRANSLATE_CURSORKEYS |
145
TRANSLATE_KEYPADENTER |
146
TRANSLATE_DIAGONAL );
148
/* Initialize the output structure: RGB with square pixels, whatever
149
* the input format is, since it's the only format we know */
150
p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
151
p_vout->output.pf_setpalette = SetPalette;
152
p_vout->output.i_width = vga_getxdim();
153
p_vout->output.i_height = vga_getydim();
154
p_vout->output.i_aspect = p_vout->output.i_width
155
* VOUT_ASPECT_FACTOR / p_vout->output.i_height;
157
/* Try to initialize 1 direct buffer */
160
/* Find an empty picture slot */
161
for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
163
if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
165
p_pic = p_vout->p_picture + i_index;
170
/* Allocate the picture */
176
vout_AllocatePicture( p_vout, p_pic, p_vout->output.i_chroma,
177
p_vout->output.i_width, p_vout->output.i_height,
178
p_vout->output.i_aspect );
180
if( p_pic->i_planes == 0 )
185
p_pic->i_status = DESTROYED_PICTURE;
186
p_pic->i_type = DIRECT_PICTURE;
188
PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
195
/*****************************************************************************
196
* End: terminate video thread
197
*****************************************************************************/
198
static void End( vout_thread_t *p_vout )
205
/*****************************************************************************
206
* Destroy: destroy video thread
207
*****************************************************************************
208
* Terminate an output method created by Create
209
*****************************************************************************/
210
static void Destroy( vlc_object_t *p_this )
212
vout_thread_t *p_vout = (vout_thread_t *)p_this;
214
/* Destroy structure */
215
free( p_vout->p_sys );
218
/*****************************************************************************
219
* Manage: handle SVGAlib events
220
*****************************************************************************
221
* This function should be called regularly by video output thread. It manages
222
* console events. It returns a non null value on error.
223
*****************************************************************************/
224
static int Manage( vout_thread_t *p_vout )
228
if( keyboard_keypressed(SCANCODE_ESCAPE)
229
|| keyboard_keypressed(SCANCODE_Q ) )
231
p_vout->p_vlc->b_die = VLC_TRUE;
237
/*****************************************************************************
238
* Display: displays previously rendered output
239
*****************************************************************************
240
* This function sends the currently rendered image to the VGA card.
241
*****************************************************************************/
242
static void Display( vout_thread_t *p_vout, picture_t *p_pic )
244
gl_putbox( 0, 0, p_vout->output.i_width,
245
p_vout->output.i_height, p_pic->p->p_pixels );
248
/*****************************************************************************
249
* SetPalette: set a 8bpp palette
250
*****************************************************************************
251
* TODO: support 8 bits clut (for Mach32 cards and others).
252
*****************************************************************************/
253
static void SetPalette( vout_thread_t *p_vout,
254
uint16_t *red, uint16_t *green, uint16_t *blue )
260
vga_setpalette( i, red[i]>>10, green[i]>>10, blue[i]>>10 );