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