Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

svgalib.c

00001 /*****************************************************************************
00002  * svgalib.c : SVGAlib plugin for vlc
00003  *****************************************************************************
00004  * Copyright (C) 2002 the VideoLAN team
00005  * $Id: svgalib.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Samuel Hocevar <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>
00028 
00029 #include <vlc/vlc.h>
00030 #include <vlc/vout.h>
00031 
00032 #include <vga.h>
00033 #include <vgagl.h>
00034 #include <vgakeyboard.h>
00035 
00036 /*****************************************************************************
00037  * Local prototypes
00038  *****************************************************************************/
00039 static int  Create    ( vlc_object_t * );
00040 static void Destroy   ( vlc_object_t * );
00041 
00042 static int  Init      ( vout_thread_t * );
00043 static void End       ( vout_thread_t * );
00044 static int  Manage    ( vout_thread_t * );
00045 static void Display   ( vout_thread_t *, picture_t * );
00046 
00047 static void SetPalette( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
00048 
00049 /*****************************************************************************
00050  * Module descriptor
00051  *****************************************************************************/
00052 vlc_module_begin();
00053     set_shortname( "SVGAlib" );
00054     set_category( CAT_VIDEO );
00055     set_subcategory( SUBCAT_VIDEO_VOUT );
00056     set_description( _("SVGAlib video output") );
00057     set_capability( "video output", 0 );
00058     set_callbacks( Create, Destroy );
00059     linked_with_a_crap_library_which_uses_atexit();
00060 vlc_module_end();
00061 
00062 /*****************************************************************************
00063  * vout_sys_t: video output descriptor
00064  *****************************************************************************
00065  * This structure is part of the video output thread descriptor.
00066  * It describes the SVGAlib specific properties of an output thread.
00067  *****************************************************************************/
00068 struct vout_sys_t
00069 {
00070     int i_vgamode;
00071 };
00072 
00073 /*****************************************************************************
00074  * Create: allocates video thread
00075  *****************************************************************************
00076  * This function allocates and initializes a vout method.
00077  *****************************************************************************/
00078 static int Create( vlc_object_t *p_this )
00079 {
00080     vout_thread_t *p_vout = (vout_thread_t *)p_this;
00081 
00082     /* Allocate instance and initialize some members */
00083     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
00084     if( p_vout->p_sys == NULL )
00085     {
00086         return VLC_ENOMEM;
00087     }
00088 
00089     /* FIXME: find a way to test for SVGAlib availability. We cannot call
00090      * vga_init from here because it needs to be closed from the same thread
00091      * and we might give away the video output to another thread. Bah, it
00092      * doesn't matter anyway ... SVGAlib is being an UGLY DIRTY PIG and calls
00093      * atexit() and exit() so what can we do? */
00094 
00095     p_vout->pf_init = Init;
00096     p_vout->pf_end = End;
00097     p_vout->pf_manage = Manage;
00098     p_vout->pf_render = NULL;
00099     p_vout->pf_display = Display;
00100 
00101     return VLC_SUCCESS;
00102 }
00103 
00104 /*****************************************************************************
00105  * Init: initialize video thread
00106  *****************************************************************************/
00107 static int Init( vout_thread_t *p_vout )
00108 {
00109     int i_index;
00110     picture_t *p_pic;
00111 
00112     I_OUTPUTPICTURES = 0;
00113 
00114     /* SVGAlib shut up! */
00115     vga_disabledriverreport();
00116 
00117     /* We cannot call vga_init() in Create() because it has to be run
00118      * from the same thread as the other vga calls. */
00119     vga_init();
00120 
00121     /* Check that we have a 8bpp mode available */
00122     p_vout->p_sys->i_vgamode = vga_getdefaultmode();
00123     if( p_vout->p_sys->i_vgamode == -1
00124          || vga_getmodeinfo(p_vout->p_sys->i_vgamode)->bytesperpixel != 1 )
00125     {
00126         p_vout->p_sys->i_vgamode = G320x200x256;
00127     }
00128 
00129     if( !vga_hasmode( p_vout->p_sys->i_vgamode ) )
00130     {
00131         msg_Err( p_vout, "mode %i not available", p_vout->p_sys->i_vgamode );
00132         return VLC_EGENERIC;
00133     }
00134 
00135     vga_setmode( p_vout->p_sys->i_vgamode );
00136     gl_setcontextvga( p_vout->p_sys->i_vgamode );
00137     gl_enableclipping();
00138 
00139     if( keyboard_init() )
00140     {
00141         msg_Err( p_vout, "could not initialize keyboard" );
00142         vga_setmode( TEXT );
00143         return VLC_EGENERIC;
00144     }
00145 
00146     /* Just in case */
00147     keyboard_translatekeys( TRANSLATE_CURSORKEYS |
00148                             TRANSLATE_KEYPADENTER |
00149                             TRANSLATE_DIAGONAL );
00150 
00151     /* Initialize the output structure: RGB with square pixels, whatever
00152      * the input format is, since it's the only format we know */
00153     p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
00154     p_vout->output.pf_setpalette = SetPalette;
00155     p_vout->output.i_width = vga_getxdim();
00156     p_vout->output.i_height = vga_getydim();
00157     p_vout->output.i_aspect = p_vout->output.i_width
00158                                * VOUT_ASPECT_FACTOR / p_vout->output.i_height;
00159 
00160     /* Try to initialize 1 direct buffer */
00161     p_pic = NULL;
00162 
00163     /* Find an empty picture slot */
00164     for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
00165     {
00166         if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
00167         {
00168             p_pic = p_vout->p_picture + i_index;
00169             break;
00170         }
00171     }
00172 
00173     /* Allocate the picture */
00174     if( p_pic == NULL )
00175     {
00176         return VLC_SUCCESS;
00177     }
00178 
00179     vout_AllocatePicture( p_vout, p_pic, p_vout->output.i_chroma,
00180                           p_vout->output.i_width, p_vout->output.i_height,
00181                           p_vout->output.i_aspect );
00182 
00183     if( p_pic->i_planes == 0 )
00184     {
00185         return VLC_SUCCESS;
00186     }
00187 
00188     p_pic->i_status = DESTROYED_PICTURE;
00189     p_pic->i_type   = DIRECT_PICTURE;
00190 
00191     PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
00192 
00193     I_OUTPUTPICTURES++;
00194 
00195     return VLC_SUCCESS;
00196 }
00197 
00198 /*****************************************************************************
00199  * End: terminate video thread
00200  *****************************************************************************/
00201 static void End( vout_thread_t *p_vout )
00202 {
00203     keyboard_close();
00204     vga_clear();
00205     vga_setmode( TEXT );
00206 }
00207 
00208 /*****************************************************************************
00209  * Destroy: destroy video thread
00210  *****************************************************************************
00211  * Terminate an output method created by Create
00212  *****************************************************************************/
00213 static void Destroy( vlc_object_t *p_this )
00214 {
00215     vout_thread_t *p_vout = (vout_thread_t *)p_this;
00216 
00217     /* Destroy structure */
00218     free( p_vout->p_sys );
00219 }
00220 
00221 /*****************************************************************************
00222  * Manage: handle SVGAlib events
00223  *****************************************************************************
00224  * This function should be called regularly by video output thread. It manages
00225  * console events. It returns a non null value on error.
00226  *****************************************************************************/
00227 static int Manage( vout_thread_t *p_vout )
00228 {
00229     keyboard_update();
00230 
00231     if( keyboard_keypressed(SCANCODE_ESCAPE)
00232          || keyboard_keypressed(SCANCODE_Q ) )
00233     {
00234         p_vout->p_vlc->b_die = VLC_TRUE;
00235     }
00236 
00237     return VLC_SUCCESS;
00238 }
00239 
00240 /*****************************************************************************
00241  * Display: displays previously rendered output
00242  *****************************************************************************
00243  * This function sends the currently rendered image to the VGA card.
00244  *****************************************************************************/
00245 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
00246 {
00247     gl_putbox( 0, 0, p_vout->output.i_width,
00248                p_vout->output.i_height, p_pic->p->p_pixels );
00249 }
00250 
00251 /*****************************************************************************
00252  * SetPalette: set a 8bpp palette
00253  *****************************************************************************
00254  * TODO: support 8 bits clut (for Mach32 cards and others).
00255  *****************************************************************************/
00256 static void SetPalette( vout_thread_t *p_vout,
00257                         uint16_t *red, uint16_t *green, uint16_t *blue )
00258 {
00259     int i = 256;
00260 
00261     while( i-- )
00262     {
00263         vga_setpalette( i, red[i]>>10, green[i]>>10, blue[i]>>10 );
00264     }
00265 }
00266 

Generated on Tue Dec 20 10:14:55 2005 for vlc-0.8.4a by  doxygen 1.4.2