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