]> git.sesse.net Git - vlc/blob - plugins/mga/mga.c
96747ef51427ab90c02821871dd0f944035f73fa
[vlc] / plugins / mga / mga.c
1 /*****************************************************************************
2  * mga.c : Matrox Graphic Array plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 VideoLAN
5  * $Id: mga.c,v 1.10 2002/01/05 03:49:18 sam Exp $
6  *
7  * Authors: Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
8  *          Samuel Hocevar <sam@zoy.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <unistd.h>                                               /* close() */
30 #include <stdlib.h>                                                /* free() */
31 #include <string.h>                                            /* strerror() */
32 #include <fcntl.h>                                                 /* open() */
33 #include <sys/ioctl.h>                                            /* ioctl() */
34 #include <sys/mman.h>                                          /* PROT_WRITE */
35
36 #include <videolan/vlc.h>
37
38 #ifdef SYS_BSD
39 #include <sys/types.h>                                     /* typedef ushort */
40 #endif
41
42 #include "video.h"
43 #include "video_output.h"
44
45 /*****************************************************************************
46  * Capabilities defined in the other files.
47  *****************************************************************************/
48 static void vout_getfunctions( function_list_t * p_function_list );
49
50 static int  vout_Probe     ( probedata_t *p_data );
51 static int  vout_Create    ( vout_thread_t * );
52 static int  vout_Init      ( vout_thread_t * );
53 static void vout_End       ( vout_thread_t * );
54 static void vout_Destroy   ( vout_thread_t * );
55 static int  vout_Manage    ( vout_thread_t * );
56 static void vout_Render    ( vout_thread_t *, picture_t * );
57 static void vout_Display   ( vout_thread_t *, picture_t * );
58
59 /*****************************************************************************
60  * Building configuration tree
61  *****************************************************************************/
62 MODULE_CONFIG_START
63 MODULE_CONFIG_STOP
64
65 MODULE_INIT_START
66     SET_DESCRIPTION( "Matrox Graphic Array video module" )
67     ADD_CAPABILITY( VOUT, 10 )
68     ADD_SHORTCUT( "mga" )
69 MODULE_INIT_STOP
70
71 MODULE_ACTIVATE_START
72     vout_getfunctions( &p_module->p_functions->vout );
73 MODULE_ACTIVATE_STOP
74
75 MODULE_DEACTIVATE_START
76 MODULE_DEACTIVATE_STOP
77
78 /*****************************************************************************
79  * vout_sys_t: video output MGA method descriptor
80  *****************************************************************************
81  * This structure is part of the video output thread descriptor.
82  * It describes the MGA specific properties of an output thread.
83  *****************************************************************************/
84 #ifndef __LINUX_MGAVID_H
85 #   define __LINUX_MGAVID_H
86 #   define MGA_VID_CONFIG _IOR('J', 1, mga_vid_config_t)
87 #   define MGA_VID_ON     _IO ('J', 2)
88 #   define MGA_VID_OFF    _IO ('J', 3)
89 #   define MGA_G200 0x1234
90 #   define MGA_G400 0x5678
91 typedef struct mga_vid_config_s
92 {
93     u32     card_type;
94     u32     ram_size;
95     u32     src_width;
96     u32     src_height;
97     u32     dest_width;
98     u32     dest_height;
99     u32     x_org;
100     u32     y_org;
101     u8      colkey_on;
102     u8      colkey_red;
103     u8      colkey_green;
104     u8      colkey_blue;
105 } mga_vid_config_t;
106 #endif
107
108 typedef struct vout_sys_s
109 {
110     /* MGA specific variables */
111     int                 i_fd;
112     int                 i_size;
113     mga_vid_config_t    mga;
114     byte_t *            p_mga_vid_base;
115     boolean_t           b_g400;
116
117 } vout_sys_t;
118
119 #define DUMMY_WIDTH 16
120 #define DUMMY_HEIGHT 16
121 #define DUMMY_BITS_PER_PLANE 16
122 #define DUMMY_BYTES_PER_PIXEL 2
123
124 /*****************************************************************************
125  * Local prototypes
126  *****************************************************************************/
127 /*****************************************************************************
128  * Functions exported as capabilities. They are declared as static so that
129  * we don't pollute the namespace too much.
130  *****************************************************************************/
131 static void vout_getfunctions( function_list_t * p_function_list )
132 {
133     p_function_list->pf_probe = vout_Probe;
134     p_function_list->functions.vout.pf_create     = vout_Create;
135     p_function_list->functions.vout.pf_init       = vout_Init;
136     p_function_list->functions.vout.pf_end        = vout_End;
137     p_function_list->functions.vout.pf_destroy    = vout_Destroy;
138     p_function_list->functions.vout.pf_manage     = vout_Manage;
139     p_function_list->functions.vout.pf_render     = vout_Render;
140     p_function_list->functions.vout.pf_display    = vout_Display;
141 }
142
143 /*****************************************************************************
144  * intf_Probe: return a score
145  *****************************************************************************/
146 static int vout_Probe( probedata_t *p_data )
147 {
148     int i_fd;
149
150     i_fd = open( "/dev/mga_vid", O_RDWR );
151
152     if( i_fd == -1 )
153     {
154         return 0;
155     }
156
157     close( i_fd );
158
159     return 10;
160 }
161
162 /*****************************************************************************
163  * vout_Create: allocates dummy video thread output method
164  *****************************************************************************
165  * This function allocates and initializes a dummy vout method.
166  *****************************************************************************/
167 static int vout_Create( vout_thread_t *p_vout )
168 {
169     /* Allocate structure */
170     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
171     if( p_vout->p_sys == NULL )
172     {
173         intf_ErrMsg("vout error: %s", strerror(ENOMEM) );
174         return( 1 );
175     }
176
177     if( (p_vout->p_sys->i_fd = open( "/dev/mga_vid", O_RDWR )) == -1 )
178     {
179         intf_ErrMsg( "vout error: can't open MGA driver /dev/mga_vid" );
180         free( p_vout->p_sys );
181         return( 1 );
182     }
183
184     return( 0 );
185 }
186
187 /*****************************************************************************
188  * vout_Init: initialize dummy video thread output method
189  *****************************************************************************/
190 static int vout_Init( vout_thread_t *p_vout )
191 {
192     /* create the MGA output */
193     p_vout->output.i_width = p_vout->render.i_width;
194     p_vout->output.i_height = p_vout->render.i_height;
195     p_vout->output.i_aspect = p_vout->render.i_aspect;
196
197     /* FIXME: we should initialize these ones according to the streams */
198     p_vout->p_sys->mga.src_width = p_vout->output.i_width;
199     p_vout->p_sys->mga.src_height = p_vout->output.i_height;
200     p_vout->p_sys->mga.dest_width = 900;
201     p_vout->p_sys->mga.dest_height = 700;
202     p_vout->p_sys->mga.x_org = 50;
203     p_vout->p_sys->mga.y_org = 50;
204     p_vout->p_sys->mga.colkey_on = 0;
205
206     if( ioctl(p_vout->p_sys->i_fd, MGA_VID_CONFIG, &p_vout->p_sys->mga) )
207     {
208         intf_ErrMsg( "vout error: MGA config ioctl failed" );
209     }
210
211     if( p_vout->p_sys->mga.card_type == MGA_G200 )
212     {
213         intf_Msg( "vout: detected MGA G200 (%d MB Ram)",
214                   p_vout->p_sys->mga.ram_size );
215         p_vout->p_sys->b_g400 = 0;
216     }
217     else
218     {
219         intf_Msg( "vout: detected MGA G400 (%d MB Ram)",
220                   p_vout->p_sys->mga.ram_size );
221         p_vout->p_sys->b_g400 = 1;
222     }
223
224     ioctl( p_vout->p_sys->i_fd, MGA_VID_ON, 0 );
225
226     p_vout->p_sys->i_size = ( (p_vout->p_sys->mga.src_width + 31) & ~31 )
227                              * p_vout->p_sys->mga.src_height;
228
229     p_vout->p_sys->p_mga_vid_base = mmap( 0, p_vout->p_sys->i_size
230                                              + p_vout->p_sys->i_size / 2,
231                                           PROT_WRITE, MAP_SHARED,
232                                           p_vout->p_sys->i_fd, 0 );
233
234     memset( p_vout->p_sys->p_mga_vid_base,
235             0x00, p_vout->p_sys->i_size );
236
237     memset( p_vout->p_sys->p_mga_vid_base + p_vout->p_sys->i_size,
238             0x80, p_vout->p_sys->i_size / 2 );
239
240     return( 0 );
241 }
242
243 /*****************************************************************************
244  * vout_End: terminate dummy video thread output method
245  *****************************************************************************/
246 static void vout_End( vout_thread_t *p_vout )
247 {
248     ioctl( p_vout->p_sys->i_fd, MGA_VID_OFF, 0 );
249 }
250
251 /*****************************************************************************
252  * vout_Destroy: destroy dummy video thread output method
253  *****************************************************************************
254  * Terminate an output method created by DummyCreateOutputMethod
255  *****************************************************************************/
256 static void vout_Destroy( vout_thread_t *p_vout )
257 {
258     close( p_vout->p_sys->i_fd );
259
260     free( p_vout->p_sys );
261 }
262
263 /*****************************************************************************
264  * vout_Manage: handle dummy events
265  *****************************************************************************
266  * This function should be called regularly by video output thread. It manages
267  * console events. It returns a non null value on error.
268  *****************************************************************************/
269 static int vout_Manage( vout_thread_t *p_vout )
270 {
271     return( 0 );
272 }
273
274 /*****************************************************************************
275  * vout_Render: displays previously calculated output
276  *****************************************************************************/
277 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
278 {
279     ;
280 }
281
282 /*****************************************************************************
283  * vout_Display: displays previously rendered output
284  *****************************************************************************/
285 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
286 {
287     ;
288 }
289