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