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