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