]> git.sesse.net Git - vlc/blob - plugins/fb/fb.c
4c098e46756cb0640178c50ce65836d6421c0318
[vlc] / plugins / fb / fb.c
1 /*****************************************************************************
2  * fb.c : framebuffer plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 VideoLAN
5  * $Id: fb.c,v 1.18 2002/04/23 14:16:20 sam Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *      
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.
13  * 
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <errno.h>                                                 /* ENOMEM */
28 #include <signal.h>                                      /* SIGUSR1, SIGUSR2 */
29 #include <stdlib.h>                                                /* free() */
30 #include <string.h>                                            /* strerror() */
31 #include <fcntl.h>                                                 /* open() */
32 #include <unistd.h>                                               /* close() */
33
34 #include <termios.h>                                       /* struct termios */
35 #include <sys/ioctl.h>
36 #include <sys/mman.h>                                              /* mmap() */
37
38 #include <linux/fb.h>
39 #include <linux/vt.h>                                                /* VT_* */
40 #include <linux/kd.h>                                                 /* KD* */
41
42 #include <videolan/vlc.h>
43
44 #include "video.h"
45 #include "video_output.h"
46
47 /*****************************************************************************
48  * Capabilities defined in the other files.
49  *****************************************************************************/
50 static void vout_getfunctions( function_list_t * p_function_list );
51
52 static int  vout_Create    ( vout_thread_t * );
53 static void vout_Destroy   ( vout_thread_t * );
54 static void vout_Render    ( vout_thread_t *, picture_t * );
55 static void vout_Display   ( vout_thread_t *, picture_t * );
56 static int  vout_Manage    ( vout_thread_t * );
57 static int  vout_Init      ( vout_thread_t * );
58 static void vout_End       ( vout_thread_t * );
59
60 static int  OpenDisplay    ( vout_thread_t * );
61 static void CloseDisplay   ( vout_thread_t * );
62 static void SwitchDisplay  ( int i_signal );
63 static void TextMode       ( int i_tty );
64 static void GfxMode        ( int i_tty );
65
66 /*****************************************************************************
67  * Building configuration tree
68  *****************************************************************************/
69 #define FB_DEV_VAR "fbdev"
70
71 MODULE_CONFIG_START
72 ADD_CATEGORY_HINT( N_("Miscellaneous"), NULL )
73 ADD_STRING  ( FB_DEV_VAR, "/dev/fb0", NULL, N_("framebuffer device"), NULL )
74 MODULE_CONFIG_STOP
75
76 MODULE_INIT_START
77     SET_DESCRIPTION( _("Linux console framebuffer module") )
78     ADD_CAPABILITY( VOUT, 30 )
79     ADD_SHORTCUT( "fb" )
80 MODULE_INIT_STOP
81
82 MODULE_ACTIVATE_START
83     vout_getfunctions( &p_module->p_functions->vout );
84 MODULE_ACTIVATE_STOP
85
86 MODULE_DEACTIVATE_START
87 MODULE_DEACTIVATE_STOP
88
89 /*****************************************************************************
90  * vout_sys_t: video output framebuffer method descriptor
91  *****************************************************************************
92  * This structure is part of the video output thread descriptor.
93  * It describes the FB specific properties of an output thread.
94  *****************************************************************************/
95 typedef struct vout_sys_s
96 {
97     /* System informations */
98     int                 i_tty;                          /* tty device handle */
99     struct termios      old_termios;
100
101     /* Original configuration informations */
102     struct sigaction            sig_usr1;           /* USR1 previous handler */
103     struct sigaction            sig_usr2;           /* USR2 previous handler */
104     struct vt_mode              vt_mode;                 /* previous VT mode */
105
106     /* Framebuffer information */
107     int                         i_fd;                       /* device handle */
108     struct fb_var_screeninfo    old_info;      /* original mode informations */
109     struct fb_var_screeninfo    var_info;       /* current mode informations */
110     boolean_t                   b_pan;     /* does device supports panning ? */
111     struct fb_cmap              fb_cmap;                /* original colormap */
112     u16                         *p_palette;              /* original palette */
113
114     /* Video information */
115     int i_width;
116     int i_height;
117     int i_bytes_per_pixel;
118
119     /* Video memory */
120     byte_t *    p_video;                                      /* base adress */
121     size_t      i_page_size;                                    /* page size */
122
123 } vout_sys_t;
124
125 /*****************************************************************************
126  * Functions exported as capabilities. They are declared as static so that
127  * we don't pollute the namespace too much.
128  *****************************************************************************/
129 static void vout_getfunctions( function_list_t * p_function_list )
130 {
131     p_function_list->functions.vout.pf_create     = vout_Create;
132     p_function_list->functions.vout.pf_init       = vout_Init;
133     p_function_list->functions.vout.pf_end        = vout_End;
134     p_function_list->functions.vout.pf_destroy    = vout_Destroy;
135     p_function_list->functions.vout.pf_manage     = vout_Manage;
136     p_function_list->functions.vout.pf_render     = vout_Render;
137     p_function_list->functions.vout.pf_display    = vout_Display;
138 }
139
140 /*****************************************************************************
141  * vout_Create: allocates FB video thread output method
142  *****************************************************************************
143  * This function allocates and initializes a FB vout method.
144  *****************************************************************************/
145 static int vout_Create( vout_thread_t *p_vout )
146 {
147     struct sigaction    sig_tty;                 /* sigaction for tty change */
148     struct vt_mode      vt_mode;                          /* vt current mode */
149     struct termios      new_termios;
150
151     /* Allocate instance and initialize some members */
152     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
153     if( p_vout->p_sys == NULL )
154     {
155         return( 1 );
156     };
157
158     /* Set tty and fb devices */
159     p_vout->p_sys->i_tty = 0;           /* 0 == /dev/tty0 == current console */
160
161     GfxMode( p_vout->p_sys->i_tty );
162
163     /* Set keyboard settings */
164     if (tcgetattr(0, &p_vout->p_sys->old_termios) == -1)
165     {
166         intf_ErrMsg( "intf error: tcgetattr" );
167     }
168
169     if (tcgetattr(0, &new_termios) == -1)
170     {
171         intf_ErrMsg( "intf error: tcgetattr" );
172     }
173
174  /* new_termios.c_lflag &= ~ (ICANON | ISIG);
175     new_termios.c_lflag |= (ECHO | ECHOCTL); */
176     new_termios.c_lflag &= ~ (ICANON);
177     new_termios.c_lflag &= ~(ECHO | ECHOCTL);
178     new_termios.c_iflag = 0;
179     new_termios.c_cc[VMIN] = 1;
180     new_termios.c_cc[VTIME] = 0;
181
182     if (tcsetattr(0, TCSAFLUSH, &new_termios) == -1)
183     {
184         intf_ErrMsg( "intf error: tcsetattr" );
185     }
186
187     ioctl( p_vout->p_sys->i_tty, VT_RELDISP, VT_ACKACQ );
188
189     /* Set-up tty signal handler to be aware of tty changes */
190     memset( &sig_tty, 0, sizeof( sig_tty ) );
191     sig_tty.sa_handler = SwitchDisplay;
192     sigemptyset( &sig_tty.sa_mask );
193     if( sigaction( SIGUSR1, &sig_tty, &p_vout->p_sys->sig_usr1 ) ||
194         sigaction( SIGUSR2, &sig_tty, &p_vout->p_sys->sig_usr2 ) )
195     {
196         intf_ErrMsg( "intf error: can't set up signal handler (%s)",
197                      strerror(errno) );
198         tcsetattr(0, 0, &p_vout->p_sys->old_termios);
199         TextMode( p_vout->p_sys->i_tty );
200         free( p_vout->p_sys );
201         return( 1 );
202     }
203
204     /* Set-up tty according to new signal handler */
205     if( -1 == ioctl( p_vout->p_sys->i_tty,
206                      VT_GETMODE, &p_vout->p_sys->vt_mode ) )
207     {
208         intf_ErrMsg( "intf error: cant get terminal mode (%s)",
209                      strerror(errno) );
210         sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
211         sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
212         tcsetattr(0, 0, &p_vout->p_sys->old_termios);
213         TextMode( p_vout->p_sys->i_tty );
214         free( p_vout->p_sys );
215         return( 1 );
216     }
217     memcpy( &vt_mode, &p_vout->p_sys->vt_mode, sizeof( vt_mode ) );
218     vt_mode.mode   = VT_PROCESS;
219     vt_mode.waitv  = 0;
220     vt_mode.relsig = SIGUSR1;
221     vt_mode.acqsig = SIGUSR2;
222
223     if( -1 == ioctl( p_vout->p_sys->i_tty, VT_SETMODE, &vt_mode ) )
224     {
225         intf_ErrMsg( "intf error: can't set terminal mode (%s)",
226                      strerror(errno) );
227         sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
228         sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
229         tcsetattr(0, 0, &p_vout->p_sys->old_termios);
230         TextMode( p_vout->p_sys->i_tty );
231         free( p_vout->p_sys );
232         return( 1 );
233     }
234
235     if( OpenDisplay( p_vout ) )
236     {
237         ioctl( p_vout->p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode );
238         sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
239         sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
240         tcsetattr(0, 0, &p_vout->p_sys->old_termios);
241         TextMode( p_vout->p_sys->i_tty );
242         free( p_vout->p_sys );
243         return( 1 );
244     }
245
246     return( 0 );
247 }
248
249 /*****************************************************************************
250  * vout_Init: initialize framebuffer video thread output method
251  *****************************************************************************/
252 static int vout_Init( vout_thread_t *p_vout )
253 {
254     int i_index;
255     picture_t *p_pic;
256
257     I_OUTPUTPICTURES = 0;
258
259     /* Initialize the output structure: RGB with square pixels, whatever
260      * the input format is, since it's the only format we know */
261     switch( p_vout->p_sys->var_info.bits_per_pixel )
262     {
263         case 8: /* FIXME: set the palette */
264             p_vout->output.i_chroma = FOURCC_RGB2; break;
265         case 15:
266             p_vout->output.i_chroma = FOURCC_RV15; break;
267         case 16:
268             p_vout->output.i_chroma = FOURCC_RV16; break;
269         case 24:
270             p_vout->output.i_chroma = FOURCC_RV24; break;
271         case 32:
272             p_vout->output.i_chroma = FOURCC_RV32; break;
273         default:
274             intf_ErrMsg( "vout error: unknown screen depth" );
275             return 0;
276     }
277
278     /* Only useful for p_vout->p_sys->var_info.bits_per_pixel != 8 */
279     p_vout->output.i_rmask = ( (1 << p_vout->p_sys->var_info.red.length) - 1 )
280                      << p_vout->p_sys->var_info.red.offset;
281     p_vout->output.i_gmask = ( (1 << p_vout->p_sys->var_info.green.length) - 1 )
282                      << p_vout->p_sys->var_info.green.offset;
283     p_vout->output.i_bmask = ( (1 << p_vout->p_sys->var_info.blue.length) - 1 )
284                      << p_vout->p_sys->var_info.blue.offset;
285
286     p_vout->output.i_width = p_vout->p_sys->i_width;
287     p_vout->output.i_height = p_vout->p_sys->i_height;
288
289     /* Assume we have square pixels */
290     p_vout->output.i_aspect = p_vout->p_sys->i_width
291                                * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
292
293     /* Clear the screen */
294     memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
295
296     /* Try to initialize 1 direct buffer */
297     p_pic = NULL;
298
299     /* Find an empty picture slot */
300     for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
301     {
302         if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
303         {
304             p_pic = p_vout->p_picture + i_index;
305             break;
306         }
307     }
308
309     /* Allocate the picture */
310     if( p_pic == NULL )
311     {
312         return 0;
313     }
314
315     /* We know the chroma, allocate a buffer which will be used
316      * directly by the decoder */
317     p_pic->p->p_pixels = p_vout->p_sys->p_video;
318     p_pic->p->i_pixel_bytes = p_vout->p_sys->i_bytes_per_pixel;
319     p_pic->p->i_lines = p_vout->p_sys->var_info.yres;
320
321     if( p_vout->p_sys->var_info.xres_virtual )
322     {
323         p_pic->p->b_margin = 1;
324         p_pic->p->b_hidden = 1;
325         p_pic->p->i_pitch = p_vout->p_sys->var_info.xres_virtual
326                              * p_vout->p_sys->i_bytes_per_pixel;
327         p_pic->p->i_visible_bytes = p_vout->p_sys->var_info.xres
328                                      * p_vout->p_sys->i_bytes_per_pixel;
329     }
330     else
331     {
332         p_pic->p->b_margin = 0;
333         p_pic->p->i_pitch = p_vout->p_sys->var_info.xres
334                              * p_vout->p_sys->i_bytes_per_pixel;
335     }
336
337     p_pic->i_planes = 1;
338
339     p_pic->i_status = DESTROYED_PICTURE;
340     p_pic->i_type   = DIRECT_PICTURE;
341
342     PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
343
344     I_OUTPUTPICTURES++;
345
346     return( 0 );
347 }
348
349 /*****************************************************************************
350  * vout_End: terminate framebuffer video thread output method
351  *****************************************************************************/
352 static void vout_End( vout_thread_t *p_vout )
353 {
354     /* Clear the screen */
355     memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
356 }
357
358 /*****************************************************************************
359  * vout_Destroy: destroy FB video thread output method
360  *****************************************************************************
361  * Terminate an output method created by vout_CreateOutputMethod
362  *****************************************************************************/
363 static void vout_Destroy( vout_thread_t *p_vout )
364 {
365     CloseDisplay( p_vout );
366
367     /* Reset the terminal */
368     ioctl( p_vout->p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode );
369
370     /* Remove signal handlers */
371     sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
372     sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
373
374     /* Reset the keyboard state */
375     tcsetattr( 0, 0, &p_vout->p_sys->old_termios );
376
377     /* Return to text mode */
378     TextMode( p_vout->p_sys->i_tty );
379
380     /* Destroy structure */
381     free( p_vout->p_sys );
382 }
383
384 /*****************************************************************************
385  * vout_Manage: handle FB events
386  *****************************************************************************
387  * This function should be called regularly by video output thread. It manages
388  * console events. It returns a non null value on error.
389  *****************************************************************************/
390 static int vout_Manage( vout_thread_t *p_vout )
391 {
392 #if 0
393     u8 buf;
394
395     if ( read(0, &buf, 1) == 1)
396     {
397         switch( buf )
398         {
399         case 'q':
400             p_main->p_intf->b_die = 1;
401             break;
402
403         default:
404             break;
405         }
406     }
407 #endif
408
409     /*
410      * Size change
411      */
412     if( p_vout->i_changes & VOUT_SIZE_CHANGE )
413     {
414         intf_WarnMsg( 3, "vout: reinitializing framebuffer screen" );
415         p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
416
417         /* Destroy XImages to change their size */
418         vout_End( p_vout );
419
420         /* Recreate XImages. If SysInit failed, the thread can't go on. */
421         if( vout_Init( p_vout ) )
422         {
423             intf_ErrMsg("error: cannot reinit framebuffer screen" );
424             return( 1 );
425         }
426
427         /* Clear screen */
428         memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
429
430 #if 0
431         /* Tell the video output thread that it will need to rebuild YUV
432          * tables. This is needed since conversion buffer size may have changed */
433         p_vout->i_changes |= VOUT_YUV_CHANGE;
434 #endif
435     }
436
437     return 0;
438 }
439
440 /*****************************************************************************
441  * vout_Render: renders previously calculated output
442  *****************************************************************************/
443 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
444 {
445     ;
446 }
447
448 /*****************************************************************************
449  * vout_Display: displays previously rendered output
450  *****************************************************************************
451  * This function send the currently rendered image to FB image, waits until
452  * it is displayed and switch the two rendering buffers, preparing next frame.
453  *****************************************************************************/
454 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
455 {
456     /* swap the two Y offsets if the drivers supports panning */
457     if( p_vout->p_sys->b_pan )
458     {
459         p_vout->p_sys->var_info.yoffset = 0;
460         //p_vout->p_sys->var_info.yoffset = p_vout->p_sys->var_info.yres;
461    
462         /* the X offset should be 0, but who knows ...
463          * some other app might have played with the framebuffer */
464         p_vout->p_sys->var_info.xoffset = 0;
465
466         ioctl( p_vout->p_sys->i_fd,
467                FBIOPAN_DISPLAY, &p_vout->p_sys->var_info );
468     }
469 }
470
471 #if 0
472 static void vout_SetPalette( p_vout_thread_t p_vout,
473                              u16 *red, u16 *green, u16 *blue, u16 *transp )
474 {
475     struct fb_cmap cmap = { 0, 256, red, green, blue, transp };
476
477     ioctl( p_vout->p_sys->i_fd, FBIOPUTCMAP, &cmap );
478 }
479 #endif
480
481 /* following functions are local */
482
483 /*****************************************************************************
484  * OpenDisplay: initialize framebuffer
485  *****************************************************************************/
486 static int OpenDisplay( vout_thread_t *p_vout )
487 {
488     char *psz_device;                             /* framebuffer device path */
489     struct fb_fix_screeninfo    fix_info;     /* framebuffer fix information */
490
491     /* Open framebuffer device */
492     if( !(psz_device = config_GetPszVariable( FB_DEV_VAR )) )
493     {
494         intf_ErrMsg( "vout error: don't know which fb device to open" );
495         return( 1 );
496     }
497
498     p_vout->p_sys->i_fd = open( psz_device, O_RDWR);
499
500     if( p_vout->p_sys->i_fd == -1 )
501     {
502         intf_ErrMsg("vout error: can't open %s (%s)",
503                     psz_device, strerror(errno) );
504         free( psz_device );
505         return( 1 );
506     }
507     free( psz_device );
508
509     /* Get framebuffer device informations */
510     if( ioctl( p_vout->p_sys->i_fd,
511                FBIOGET_VSCREENINFO, &p_vout->p_sys->var_info ) )
512     {
513         intf_ErrMsg("vout error: can't get fb info (%s)", strerror(errno) );
514         close( p_vout->p_sys->i_fd );
515         return( 1 );
516     }
517
518     if( ioctl( p_vout->p_sys->i_fd,
519                FBIOGET_VSCREENINFO, &p_vout->p_sys->old_info ) )
520     {
521         intf_ErrMsg("vout error: can't get 2nd fb info (%s)", strerror(errno) );
522         close( p_vout->p_sys->i_fd );
523         return( 1 );
524     }
525
526     /* Set some attributes */
527     p_vout->p_sys->var_info.activate = FB_ACTIVATE_NXTOPEN;
528     p_vout->p_sys->var_info.xoffset =  0;
529     p_vout->p_sys->var_info.yoffset =  0;
530
531     if( ioctl( p_vout->p_sys->i_fd,
532                FBIOPUT_VSCREENINFO, &p_vout->p_sys->var_info ) )
533     {
534         intf_ErrMsg(" vout error: can't set fb info (%s)", strerror(errno) );
535         close( p_vout->p_sys->i_fd );
536         return( 1 );
537     }
538
539     /* Get some informations again, in the definitive configuration */
540     if( ioctl( p_vout->p_sys->i_fd, FBIOGET_FSCREENINFO, &fix_info )
541          || ioctl( p_vout->p_sys->i_fd,
542                    FBIOGET_VSCREENINFO, &p_vout->p_sys->var_info ) )
543     {
544         intf_ErrMsg( "vout error: can't get additional fb info (%s)",
545                      strerror(errno) );
546
547         /* Restore fb config */
548         ioctl( p_vout->p_sys->i_fd,
549                FBIOPUT_VSCREENINFO, &p_vout->p_sys->var_info );
550
551         close( p_vout->p_sys->i_fd );
552         return( 1 );
553     }
554
555     /* FIXME: if the image is full-size, it gets cropped on the left
556      * because of the xres / xres_virtual slight difference */
557     intf_WarnMsg( 3, "vout: %ix%i (virtual %ix%i)",
558                   p_vout->p_sys->var_info.xres, p_vout->p_sys->var_info.yres,
559                   p_vout->p_sys->var_info.xres_virtual,
560                   p_vout->p_sys->var_info.yres_virtual );
561
562     p_vout->p_sys->i_height = p_vout->p_sys->var_info.yres;
563     p_vout->p_sys->i_width  = p_vout->p_sys->var_info.xres_virtual
564                                ? p_vout->p_sys->var_info.xres_virtual
565                                : p_vout->p_sys->var_info.xres;
566
567     p_vout->p_sys->p_palette = NULL;
568     p_vout->p_sys->b_pan = ( fix_info.ypanstep || fix_info.ywrapstep );
569
570     switch( p_vout->p_sys->var_info.bits_per_pixel )
571     {
572     case 8:
573         p_vout->p_sys->p_palette = malloc( 8 * 256 * sizeof( u16 ) );
574         p_vout->p_sys->fb_cmap.start = 0;
575         p_vout->p_sys->fb_cmap.len = 256;
576         p_vout->p_sys->fb_cmap.red = p_vout->p_sys->p_palette;
577         p_vout->p_sys->fb_cmap.green = p_vout->p_sys->p_palette + 256 * sizeof( u16 );
578         p_vout->p_sys->fb_cmap.blue = p_vout->p_sys->p_palette + 2 * 256 * sizeof( u16 );
579         p_vout->p_sys->fb_cmap.transp = p_vout->p_sys->p_palette + 3 * 256 * sizeof( u16 );
580
581         /* Save the colormap */
582         ioctl( p_vout->p_sys->i_fd, FBIOGETCMAP, &p_vout->p_sys->fb_cmap );
583
584         p_vout->p_sys->i_bytes_per_pixel = 1;
585         break;
586
587     case 15:
588     case 16:
589         p_vout->p_sys->i_bytes_per_pixel = 2;
590         break;
591
592     case 24:
593         p_vout->p_sys->i_bytes_per_pixel = 3;
594         break;
595
596     case 32:
597         p_vout->p_sys->i_bytes_per_pixel = 4;
598         break;
599
600     default:
601         intf_ErrMsg( "vout error: screen depth %d is not supported",
602                      p_vout->p_sys->var_info.bits_per_pixel );
603
604         /* Restore fb config */
605         ioctl( p_vout->p_sys->i_fd,
606                FBIOPUT_VSCREENINFO, &p_vout->p_sys->var_info );
607
608         close( p_vout->p_sys->i_fd );
609         return 1;
610     }
611
612     p_vout->p_sys->i_page_size = p_vout->p_sys->i_width *
613                 p_vout->p_sys->i_height * p_vout->p_sys->i_bytes_per_pixel;
614
615     /* Map a framebuffer at the beginning */
616     p_vout->p_sys->p_video = mmap( 0, p_vout->p_sys->i_page_size,
617                                    PROT_READ | PROT_WRITE, MAP_SHARED,
618                                    p_vout->p_sys->i_fd, 0 );
619
620     if( p_vout->p_sys->p_video == ((void*)-1) )
621     {
622         intf_ErrMsg( "vout error: can't map video memory (%s)",
623                      strerror(errno) );
624
625         if( p_vout->p_sys->var_info.bits_per_pixel == 8 )
626         {
627             free( p_vout->p_sys->p_palette );
628         }
629
630         /* Restore fb config */
631         ioctl( p_vout->p_sys->i_fd,
632                FBIOPUT_VSCREENINFO, &p_vout->p_sys->var_info );
633
634         close( p_vout->p_sys->i_fd );
635         return( 1 );
636     }
637
638     intf_WarnMsg( 4, "vout: framebuffer type=%d, visual=%d, ypanstep=%d, "
639                      "ywrap=%d, accel=%d", fix_info.type, fix_info.visual,
640                      fix_info.ypanstep, fix_info.ywrapstep, fix_info.accel );
641     return( 0 );
642 }
643
644 /*****************************************************************************
645  * CloseDisplay: terminate FB video thread output method
646  *****************************************************************************/
647 static void CloseDisplay( vout_thread_t *p_vout )
648 {
649     /* Clear display */
650     memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
651
652     /* Restore palette */
653     if( p_vout->p_sys->var_info.bits_per_pixel == 8 );
654     {
655         ioctl( p_vout->p_sys->i_fd,
656                FBIOPUTCMAP, &p_vout->p_sys->fb_cmap );
657         free( p_vout->p_sys->p_palette );
658     }
659
660     /* Restore fb config */
661     ioctl( p_vout->p_sys->i_fd,
662            FBIOPUT_VSCREENINFO, &p_vout->p_sys->var_info );
663
664     /* Close fb */
665     close( p_vout->p_sys->i_fd );
666 }
667
668 /*****************************************************************************
669  * SwitchDisplay: VT change signal handler
670  *****************************************************************************
671  * This function activates or deactivates the output of the thread. It is
672  * called by the VT driver, on terminal change.
673  *****************************************************************************/
674 static void SwitchDisplay(int i_signal)
675 {
676 #if 0
677     vout_thread_t *p_vout;
678
679     vlc_mutex_lock( &p_vout_bank->lock );
680
681     /* XXX: only test the first video output */
682     if( p_vout_bank->i_count )
683     {
684         p_vout = p_vout_bank->pp_vout[0];
685
686         switch( i_signal )
687         {
688         case SIGUSR1:                                /* vt has been released */
689             p_vout->b_active = 0;
690             ioctl( p_vout->p_sys->i_tty, VT_RELDISP, 1 );
691             break;
692         case SIGUSR2:                                /* vt has been acquired */
693             p_vout->b_active = 1;
694             ioctl( p_vout->p_sys->i_tty, VT_RELDISP, VT_ACTIVATE );
695             /* handle blanking */
696             vlc_mutex_lock( &p_vout->change_lock );
697             p_vout->i_changes |= VOUT_SIZE_CHANGE;
698             vlc_mutex_unlock( &p_vout->change_lock );
699             break;
700         }
701     }
702
703     vlc_mutex_unlock( &p_vout_bank->lock );
704 #endif
705 }
706
707 /*****************************************************************************
708  * TextMode and GfxMode : switch tty to text/graphic mode
709  *****************************************************************************
710  * These functions toggle the tty mode.
711  *****************************************************************************/
712 static void TextMode( int i_tty )
713 {
714     /* return to text mode */
715     if( -1 == ioctl(i_tty, KDSETMODE, KD_TEXT) )
716     {
717         intf_ErrMsg( "intf error: failed ioctl KDSETMODE KD_TEXT" );
718     }
719 }
720
721 static void GfxMode( int i_tty )
722 {
723     /* switch to graphic mode */
724     if( -1 == ioctl(i_tty, KDSETMODE, KD_GRAPHICS) )
725     {
726         intf_ErrMsg( "intf error: failed ioctl KDSETMODE KD_GRAPHICS" );
727     }
728 }
729