]> git.sesse.net Git - vlc/blob - modules/video_output/fb.c
utf8_* -> vlc_* (sed roxxors)
[vlc] / modules / video_output / fb.c
1 /*****************************************************************************
2  * fb.c : framebuffer plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *          Jean-Paul Saman
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <signal.h>                                      /* SIGUSR1, SIGUSR2 */
34 #include <fcntl.h>                                                 /* open() */
35 #include <unistd.h>                                               /* close() */
36
37 #include <termios.h>                                       /* struct termios */
38 #include <sys/ioctl.h>
39 #include <sys/mman.h>                                              /* mmap() */
40
41 #include <linux/fb.h>
42 #include <linux/vt.h>                                                /* VT_* */
43 #include <linux/kd.h>                                                 /* KD* */
44
45 #include <vlc_common.h>
46 #include <vlc_plugin.h>
47 #include <vlc_vout_display.h>
48 #include <vlc_picture_pool.h>
49 #include <vlc_fs.h>
50
51 /*****************************************************************************
52  * Module descriptor
53  *****************************************************************************/
54 #define FB_DEV_VAR "fbdev"
55
56 #define DEVICE_TEXT N_("Framebuffer device")
57 #define DEVICE_LONGTEXT N_(\
58     "Framebuffer device to use for rendering (usually /dev/fb0).")
59
60 #define TTY_TEXT N_("Run fb on current tty.")
61 #define TTY_LONGTEXT N_(\
62     "Run framebuffer on current TTY device (default enabled). " \
63     "(disable tty handling with caution)")
64
65 #define FB_MODE_TEXT N_("Framebuffer resolution to use.")
66 #define FB_MODE_LONGTEXT N_(\
67     "Select the resolution for the framebuffer. Currently it supports " \
68     "the values 0=QCIF 1=CIF 2=NTSC 3=PAL, 4=auto (default 4=auto)")
69
70 #define HW_ACCEL_TEXT N_("Framebuffer uses hw acceleration.")
71 #define HW_ACCEL_LONGTEXT N_(\
72     "If your framebuffer supports hardware acceleration or does double buffering " \
73     "in hardware then you must disable this option. It then does double buffering " \
74     "in software.")
75
76 #define CHROMA_TEXT N_("Image format (default RGB).")
77 #define CHROMA_LONGTEXT N_("Chroma fourcc used by the framebuffer. Default is RGB since the fb device has no way to report its chroma.")
78
79 static int  Open (vlc_object_t *);
80 static void Close(vlc_object_t *);
81
82 vlc_module_begin ()
83     set_shortname("Framebuffer")
84     set_category(CAT_VIDEO)
85     set_subcategory(SUBCAT_VIDEO_VOUT)
86     add_file(FB_DEV_VAR, "/dev/fb0", NULL, DEVICE_TEXT, DEVICE_LONGTEXT,
87               false)
88     add_bool("fb-tty", true, NULL, TTY_TEXT, TTY_LONGTEXT, true)
89     add_string( "fb-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT, true )
90     add_obsolete_string("fb-aspect-ratio")
91     add_integer("fb-mode", 4, NULL, FB_MODE_TEXT, FB_MODE_LONGTEXT,
92                  true)
93     add_bool("fb-hw-accel", true, NULL, HW_ACCEL_TEXT, HW_ACCEL_LONGTEXT,
94               true)
95     set_description(N_("GNU/Linux framebuffer video output"))
96     set_capability("vout display", 30)
97     set_callbacks(Open, Close)
98 vlc_module_end ()
99
100 /*****************************************************************************
101  * Local prototypes
102  *****************************************************************************/
103 static picture_pool_t *Pool  (vout_display_t *, unsigned);
104 static void           Display(vout_display_t *, picture_t *);
105 static int            Control(vout_display_t *, int, va_list);
106 static void           Manage (vout_display_t *);
107
108 /* */
109 static int  OpenDisplay  (vout_display_t *, bool force_resolution);
110 static void CloseDisplay (vout_display_t *);
111 static void SwitchDisplay(int i_signal);
112 static void TextMode     (int tty);
113 static void GfxMode      (int tty);
114
115 static int  TtyInit(vout_display_t *);
116 static void TtyExit(vout_display_t *);
117
118 /* */
119 struct vout_display_sys_t {
120     /* System information */
121     int                 tty;                          /* tty device handle */
122     bool                is_tty;
123     struct termios      old_termios;
124
125     /* Original configuration information */
126     struct sigaction            sig_usr1;           /* USR1 previous handler */
127     struct sigaction            sig_usr2;           /* USR2 previous handler */
128     struct vt_mode              vt_mode;                 /* previous VT mode */
129
130     /* Framebuffer information */
131     int                         fd;                       /* device handle */
132     struct fb_var_screeninfo    old_info;       /* original mode information */
133     struct fb_var_screeninfo    var_info;        /* current mode information */
134     bool                        has_pan;   /* does device supports panning ? */
135     struct fb_cmap              fb_cmap;                /* original colormap */
136     uint16_t                    *palette;                /* original palette */
137     bool                        is_hw_accel;         /* has hardware support */
138
139     /* Video information */
140     uint32_t width;
141     uint32_t height;
142     uint32_t line_length;
143     vlc_fourcc_t chroma;
144     int      bytes_per_pixel;
145
146     /* Video memory */
147     uint8_t     *video_ptr;                                  /* base adress */
148     size_t      video_size;                                    /* page size */
149
150     picture_t       *picture;
151     picture_pool_t  *pool;
152 };
153
154
155 static void ClearScreen(vout_display_sys_t *sys)
156 {
157     switch (sys->chroma) {
158     /* XXX: add other chromas */
159     case VLC_CODEC_UYVY: {
160         unsigned int j, size = sys->video_size / 4;
161         uint32_t *ptr = (uint32_t*)((uintptr_t)(sys->video_ptr + 3) & ~3);
162         for(j=0; j < size; j++)
163             ptr[j] = 0x10801080;    /* U = V = 16, Y = 128 */
164         break;
165     }
166     default:    /* RGB */
167         memset(sys->video_ptr, 0, sys->video_size);
168     }
169 }
170
171 /**
172  * This function allocates and initializes a FB vout method.
173  */
174 static int Open(vlc_object_t *object)
175 {
176     vout_display_t     *vd = (vout_display_t *)object;
177     vout_display_sys_t *sys;
178
179     /* Allocate instance and initialize some members */
180     vd->sys = sys = calloc(1, sizeof(*sys));
181     if (!sys)
182         return VLC_ENOMEM;
183
184     /* Does the framebuffer uses hw acceleration? */
185     sys->is_hw_accel = var_CreateGetBool(vd, "fb-hw-accel");
186
187     /* Set tty and fb devices */
188     sys->tty = 0; /* 0 == /dev/tty0 == current console */
189     sys->is_tty = var_CreateGetBool(vd, "fb-tty");
190 #if !defined(WIN32) &&  defined(HAVE_ISATTY)
191     /* Check that stdin is a TTY */
192     if (sys->is_tty && !isatty(0)) {
193         msg_Warn(vd, "fd 0 is not a TTY");
194         free(sys);
195         return VLC_EGENERIC;
196     }
197     msg_Warn(vd, "disabling tty handling, use with caution because "
198                  "there is no way to return to the tty.");
199 #endif
200
201     const int mode = var_CreateGetInteger(vd, "fb-mode");
202     bool force_resolution = true;
203     switch (mode) {
204     case 0: /* QCIF */
205         sys->width  = 176;
206         sys->height = 144;
207         break;
208     case 1: /* CIF */
209         sys->width  = 352;
210         sys->height = 288;
211         break;
212     case 2: /* NTSC */
213         sys->width  = 640;
214         sys->height = 480;
215         break;
216     case 3: /* PAL */
217         sys->width  = 704;
218         sys->height = 576;
219         break;
220     case 4:
221     default:
222         force_resolution = false;
223         break;
224     }
225
226     char *chroma = var_CreateGetNonEmptyString(vd, "fb-chroma");
227     if (chroma) {
228         sys->chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, chroma);
229
230         if (sys->chroma)
231             msg_Dbg(vd, "forcing chroma '%s'", chroma);
232         else
233             msg_Warn(vd, "chroma %s invalid, using default", chroma);
234
235         free(chroma);
236     } else
237         sys->chroma = 0;
238
239     /* tty handling */
240     if (sys->is_tty && TtyInit(vd)) {
241         free(sys);
242         return VLC_EGENERIC;
243     }
244
245     /* */
246     sys->video_ptr = MAP_FAILED;
247     sys->picture = NULL;
248     sys->pool = NULL;
249
250     if (OpenDisplay(vd, force_resolution)) {
251         Close(VLC_OBJECT(vd));
252         return VLC_EGENERIC;
253     }
254
255     /* */
256     video_format_t fmt = vd->fmt;
257
258     if (sys->chroma) {
259         fmt.i_chroma = sys->chroma;
260     } else {
261         /* Assume RGB */
262
263         msg_Dbg(vd, "%d bppd", sys->var_info.bits_per_pixel);
264         switch (sys->var_info.bits_per_pixel) {
265         case 8: /* FIXME: set the palette */
266             fmt.i_chroma = VLC_CODEC_RGB8;
267             break;
268         case 15:
269             fmt.i_chroma = VLC_CODEC_RGB15;
270             break;
271         case 16:
272             fmt.i_chroma = VLC_CODEC_RGB16;
273             break;
274         case 24:
275             fmt.i_chroma = VLC_CODEC_RGB24;
276             break;
277         case 32:
278             fmt.i_chroma = VLC_CODEC_RGB32;
279             break;
280         default:
281             msg_Err(vd, "unknown screendepth %i", sys->var_info.bits_per_pixel);
282             Close(VLC_OBJECT(vd));
283             return VLC_EGENERIC;
284         }
285         if (sys->var_info.bits_per_pixel != 8) {
286             fmt.i_rmask = ((1 << sys->var_info.red.length) - 1)
287                                  << sys->var_info.red.offset;
288             fmt.i_gmask = ((1 << sys->var_info.green.length) - 1)
289                                  << sys->var_info.green.offset;
290             fmt.i_bmask = ((1 << sys->var_info.blue.length) - 1)
291                                  << sys->var_info.blue.offset;
292         }
293     }
294
295     fmt.i_width  = sys->width;
296     fmt.i_height = sys->height;
297
298     /* */
299     vout_display_info_t info = vd->info;
300     info.has_hide_mouse = true;
301
302     /* */
303     vd->fmt     = fmt;
304     vd->info    = info;
305     vd->pool    = Pool;
306     vd->prepare = NULL;
307     vd->display = Display;
308     vd->control = Control;
309     vd->manage  = Manage;
310
311     /* */
312     vout_display_SendEventFullscreen(vd, true);
313     vout_display_SendEventDisplaySize(vd, fmt.i_width, fmt.i_height, true);
314     return VLC_SUCCESS;
315 }
316
317 /**
318  * Terminate an output method created by Open
319  */
320 static void Close(vlc_object_t *object)
321 {
322     vout_display_t *vd = (vout_display_t *)object;
323     vout_display_sys_t *sys = vd->sys;
324
325     if (sys->pool)
326         picture_pool_Delete(sys->pool);
327     if (!sys->is_hw_accel && sys->picture)
328         picture_Release(sys->picture);
329
330     CloseDisplay(vd);
331
332     if (sys->is_tty)
333         TtyExit(vd);
334
335     free(sys);
336 }
337
338 /* */
339 static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
340 {
341     vout_display_sys_t *sys = vd->sys;
342
343     if (!sys->pool) {
344         if (!sys->picture) {
345             picture_resource_t rsc;
346
347             memset(&rsc, 0, sizeof(rsc));
348             rsc.p[0].p_pixels = sys->video_ptr;
349             rsc.p[0].i_lines  = sys->var_info.yres;
350             rsc.p[0].i_pitch = sys->line_length;
351
352             sys->picture = picture_NewFromResource(&vd->fmt, &rsc);
353             if (!sys->picture)
354                 return NULL;
355         }
356
357         if (sys->is_hw_accel)
358             sys->pool = picture_pool_New(1, &sys->picture);
359         else
360             sys->pool = picture_pool_NewFromFormat(&vd->fmt, count);
361     }
362     return sys->pool;
363 }
364 static void Display(vout_display_t *vd, picture_t *picture)
365 {
366     vout_display_sys_t *sys = vd->sys;
367
368     /* swap the two Y offsets if the drivers supports panning */
369     if (sys->has_pan) {
370         sys->var_info.yoffset = 0;
371         /*vd->sys->var_info.yoffset = vd->sys->var_info.yres; */
372
373         /* the X offset should be 0, but who knows ...
374          * some other app might have played with the framebuffer */
375         sys->var_info.xoffset = 0;
376
377         /* FIXME 'static' is damn wrong and it's dead code ... */
378         static int panned = 0;
379         if (panned < 0) {
380             ioctl(sys->fd, FBIOPAN_DISPLAY, &sys->var_info);
381             panned++;
382         }
383     }
384
385     if (!sys->is_hw_accel)
386         picture_Copy(sys->picture, picture);
387
388     picture_Release(picture);
389 }
390 static int Control(vout_display_t *vd, int query, va_list args)
391 {
392     vout_display_sys_t *sys = vd->sys;
393
394     switch (query) {
395     case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE: {
396         const vout_display_cfg_t *cfg = va_arg(args, const vout_display_cfg_t *);
397         if (cfg->display.width  != sys->width ||
398             cfg->display.height != sys->height)
399             return VLC_EGENERIC;
400         return VLC_SUCCESS;
401     }
402     default:
403         msg_Err(vd, "Unsupported query in vout display fb");
404         return VLC_EGENERIC;
405     }
406 }
407 static void Manage (vout_display_t *vd)
408 {
409     VLC_UNUSED(vd);
410 #if 0
411     /*
412      * Size change
413      */
414     if (vd->i_changes & VOUT_SIZE_CHANGE)
415     {
416         msg_Dbg(vd, "reinitializing framebuffer screen");
417         vd->i_changes &= ~VOUT_SIZE_CHANGE;
418
419         vout_display_SendEventDisplaySize();
420
421         ClearScreen(vd->sys);
422     }
423 #endif
424 }
425
426 /* following functions are local */
427 static int TtyInit(vout_display_t *vd)
428 {
429     vout_display_sys_t *sys = vd->sys;
430
431     struct termios new_termios;
432
433     GfxMode(sys->tty);
434
435     /* Set keyboard settings */
436     if (tcgetattr(0, &sys->old_termios) == -1) {
437         msg_Err(vd, "tcgetattr failed");
438     }
439
440     if (tcgetattr(0, &new_termios) == -1) {
441         msg_Err(vd, "tcgetattr failed");
442     }
443
444     /* new_termios.c_lflag &= ~ (ICANON | ISIG);
445     new_termios.c_lflag |= (ECHO | ECHOCTL); */
446     new_termios.c_lflag &= ~ (ICANON);
447     new_termios.c_lflag &= ~(ECHO | ECHOCTL);
448     new_termios.c_iflag = 0;
449     new_termios.c_cc[VMIN] = 1;
450     new_termios.c_cc[VTIME] = 0;
451
452     if (tcsetattr(0, TCSAFLUSH, &new_termios) == -1) {
453         msg_Err(vd, "tcsetattr failed");
454     }
455
456     ioctl(sys->tty, VT_RELDISP, VT_ACKACQ);
457
458     /* Set-up tty signal handler to be aware of tty changes */
459     struct sigaction sig_tty;
460     memset(&sig_tty, 0, sizeof(sig_tty));
461     sig_tty.sa_handler = SwitchDisplay;
462     sigemptyset(&sig_tty.sa_mask);
463     if (sigaction(SIGUSR1, &sig_tty, &sys->sig_usr1) ||
464         sigaction(SIGUSR2, &sig_tty, &sys->sig_usr2)) {
465         msg_Err(vd, "cannot set signal handler (%m)");
466         /* FIXME SIGUSR1 could have succeed */
467         goto error_signal;
468     }
469
470     /* Set-up tty according to new signal handler */
471     if (-1 == ioctl(sys->tty, VT_GETMODE, &sys->vt_mode)) {
472         msg_Err(vd, "cannot get terminal mode (%m)");
473         goto error;
474     }
475     struct vt_mode vt_mode = sys->vt_mode;
476     vt_mode.mode   = VT_PROCESS;
477     vt_mode.waitv  = 0;
478     vt_mode.relsig = SIGUSR1;
479     vt_mode.acqsig = SIGUSR2;
480
481     if (-1 == ioctl(sys->tty, VT_SETMODE, &vt_mode)) {
482         msg_Err(vd, "cannot set terminal mode (%m)");
483         goto error;
484     }
485     return VLC_SUCCESS;
486
487 error:
488     sigaction(SIGUSR1, &sys->sig_usr1, NULL);
489     sigaction(SIGUSR2, &sys->sig_usr2, NULL);
490 error_signal:
491     tcsetattr(0, 0, &sys->old_termios);
492     TextMode(sys->tty);
493     return VLC_EGENERIC;
494 }
495 static void TtyExit(vout_display_t *vd)
496 {
497     vout_display_sys_t *sys = vd->sys;
498
499     /* Reset the terminal */
500     ioctl(sys->tty, VT_SETMODE, &sys->vt_mode);
501
502     /* Remove signal handlers */
503     sigaction(SIGUSR1, &sys->sig_usr1, NULL);
504     sigaction(SIGUSR2, &sys->sig_usr2, NULL);
505
506     /* Reset the keyboard state */
507     tcsetattr(0, 0, &sys->old_termios);
508
509     /* Return to text mode */
510     TextMode(sys->tty);
511 }
512
513 /*****************************************************************************
514  * OpenDisplay: initialize framebuffer
515  *****************************************************************************/
516 static int OpenDisplay(vout_display_t *vd, bool force_resolution)
517 {
518     vout_display_sys_t *sys = vd->sys;
519     char *psz_device;                             /* framebuffer device path */
520
521     /* Open framebuffer device */
522     if (!(psz_device = var_InheritString(vd, FB_DEV_VAR))) {
523         msg_Err(vd, "don't know which fb device to open");
524         return VLC_EGENERIC;
525     }
526
527     sys->fd = vlc_open(psz_device, O_RDWR);
528     if (sys->fd == -1) {
529         msg_Err(vd, "cannot open %s (%m)", psz_device);
530         free(psz_device);
531         return VLC_EGENERIC;
532     }
533     free(psz_device);
534
535     /* Get framebuffer device information */
536     if (ioctl(sys->fd, FBIOGET_VSCREENINFO, &sys->var_info)) {
537         msg_Err(vd, "cannot get fb info (%m)");
538         close(sys->fd);
539         return VLC_EGENERIC;
540     }
541     sys->old_info = sys->var_info;
542
543     /* Get some info on the framebuffer itself */
544     if (force_resolution) {
545         sys->var_info.xres = sys->var_info.xres_virtual = sys->width;
546         sys->var_info.yres = sys->var_info.yres_virtual = sys->height;
547     }
548
549     /* Set some attributes */
550     sys->var_info.activate = sys->is_tty ? FB_ACTIVATE_NXTOPEN :
551                                            FB_ACTIVATE_NOW;
552     sys->var_info.xoffset  =  0;
553     sys->var_info.yoffset  =  0;
554
555     if (ioctl(sys->fd, FBIOPUT_VSCREENINFO, &sys->var_info)) {
556         msg_Err(vd, "cannot set fb info (%m)");
557         close(sys->fd);
558         return VLC_EGENERIC;
559     }
560
561     struct fb_fix_screeninfo fix_info;
562     /* Get some information again, in the definitive configuration */
563     if (ioctl(sys->fd, FBIOGET_FSCREENINFO, &fix_info) ||
564         ioctl(sys->fd, FBIOGET_VSCREENINFO, &sys->var_info)) {
565         msg_Err(vd, "cannot get additional fb info (%m)");
566
567         /* Restore fb config */
568         ioctl(sys->fd, FBIOPUT_VSCREENINFO, &sys->old_info);
569
570         close(sys->fd);
571         return VLC_EGENERIC;
572     }
573
574     /* If the fb has limitations on mode change,
575      * then keep the resolution of the fb */
576     if ((sys->height != sys->var_info.yres) ||
577         (sys->width != sys->var_info.xres)) {
578         msg_Warn(vd,
579                  "using framebuffer native resolution instead of requested (%ix%i)",
580                  sys->width, sys->height);
581     }
582     sys->height = sys->var_info.yres;
583     sys->width  = sys->var_info.xres_virtual ? sys->var_info.xres_virtual :
584                                                sys->var_info.xres;
585     sys->line_length = fix_info.line_length;
586
587     /* FIXME: if the image is full-size, it gets cropped on the left
588      * because of the xres / xres_virtual slight difference */
589     msg_Dbg(vd, "%ix%i (virtual %ix%i) (request %ix%i)",
590             sys->var_info.xres, sys->var_info.yres,
591             sys->var_info.xres_virtual,
592             sys->var_info.yres_virtual,
593             sys->width, sys->height);
594
595     sys->palette = NULL;
596     sys->has_pan = (fix_info.ypanstep || fix_info.ywrapstep);
597
598     switch (sys->var_info.bits_per_pixel) {
599     case 8:
600         sys->palette = malloc(8 * 256 * sizeof(uint16_t));
601         if (!sys->palette) {
602             /* Restore fb config */
603             ioctl(sys->fd, FBIOPUT_VSCREENINFO, &sys->old_info);
604
605             close(sys->fd);
606             return VLC_ENOMEM;
607         }
608         sys->fb_cmap.start = 0;
609         sys->fb_cmap.len = 256;
610         sys->fb_cmap.red = sys->palette;
611         sys->fb_cmap.green = sys->palette + 256 * sizeof(uint16_t);
612         sys->fb_cmap.blue = sys->palette + 2 * 256 * sizeof(uint16_t);
613         sys->fb_cmap.transp = sys->palette + 3 * 256 * sizeof(uint16_t);
614
615         /* Save the colormap */
616         ioctl(sys->fd, FBIOGETCMAP, &sys->fb_cmap);
617
618         sys->bytes_per_pixel = 1;
619         break;
620
621     case 15:
622     case 16:
623         sys->bytes_per_pixel = 2;
624         break;
625
626     case 24:
627         sys->bytes_per_pixel = 3;
628         break;
629
630     case 32:
631         sys->bytes_per_pixel = 4;
632         break;
633
634     default:
635         msg_Err(vd, "screen depth %d is not supported",
636                 sys->var_info.bits_per_pixel);
637
638         /* Restore fb config */
639         ioctl(sys->fd, FBIOPUT_VSCREENINFO, &sys->old_info);
640
641         close(sys->fd);
642         return VLC_EGENERIC;
643     }
644
645     sys->video_size = sys->line_length * sys->var_info.yres_virtual;
646
647     /* Map a framebuffer at the beginning */
648     sys->video_ptr = mmap(NULL, sys->video_size,
649                           PROT_READ | PROT_WRITE, MAP_SHARED, sys->fd, 0);
650
651     if (sys->video_ptr == MAP_FAILED) {
652         msg_Err(vd, "cannot map video memory (%m)");
653
654         if (sys->var_info.bits_per_pixel == 8) {
655             free(sys->palette);
656             sys->palette = NULL;
657         }
658
659         /* Restore fb config */
660         ioctl(sys->fd, FBIOPUT_VSCREENINFO, &sys->old_info);
661
662         close(sys->fd);
663         return VLC_EGENERIC;
664     }
665
666     ClearScreen(sys);
667
668     msg_Dbg(vd,
669             "framebuffer type=%d, visual=%d, ypanstep=%d, ywrap=%d, accel=%d",
670             fix_info.type, fix_info.visual,
671             fix_info.ypanstep, fix_info.ywrapstep, fix_info.accel);
672     return VLC_SUCCESS;
673 }
674
675 /*****************************************************************************
676  * CloseDisplay: terminate FB video thread output method
677  *****************************************************************************/
678 static void CloseDisplay(vout_display_t *vd)
679 {
680     vout_display_sys_t *sys = vd->sys;
681
682     if (sys->video_ptr != MAP_FAILED) {
683         ClearScreen(sys);
684         munmap(sys->video_ptr, sys->video_size);
685     }
686
687     if (sys->fd >= 0) {
688         /* Restore palette */
689         if (sys->var_info.bits_per_pixel == 8) {
690             ioctl(sys->fd, FBIOPUTCMAP, &sys->fb_cmap);
691             free(sys->palette);
692             sys->palette = NULL;
693         }
694
695         /* Restore fb config */
696         ioctl(sys->fd, FBIOPUT_VSCREENINFO, &sys->old_info);
697
698         /* Close fb */
699         close(sys->fd);
700     }
701 }
702
703 /*****************************************************************************
704  * SwitchDisplay: VT change signal handler
705  *****************************************************************************
706  * This function activates or deactivates the output of the thread. It is
707  * called by the VT driver, on terminal change.
708  *****************************************************************************/
709 static void SwitchDisplay(int i_signal)
710 {
711     VLC_UNUSED(i_signal);
712 #if 0
713     vout_display_t *vd;
714
715     vlc_mutex_lock(&p_vout_bank->lock);
716
717     /* XXX: only test the first video output */
718     if (p_vout_bank->i_count)
719     {
720         vd = p_vout_bank->pp_vout[0];
721
722         switch (i_signal)
723         {
724         case SIGUSR1:                                /* vt has been released */
725             vd->b_active = 0;
726             ioctl(sys->tty, VT_RELDISP, 1);
727             break;
728         case SIGUSR2:                                /* vt has been acquired */
729             vd->b_active = 1;
730             ioctl(sys->tty, VT_RELDISP, VT_ACTIVATE);
731             /* handle blanking */
732             vlc_mutex_lock(&vd->change_lock);
733             vd->i_changes |= VOUT_SIZE_CHANGE;
734             vlc_mutex_unlock(&vd->change_lock);
735             break;
736         }
737     }
738
739     vlc_mutex_unlock(&p_vout_bank->lock);
740 #endif
741 }
742
743 /*****************************************************************************
744  * TextMode and GfxMode : switch tty to text/graphic mode
745  *****************************************************************************
746  * These functions toggle the tty mode.
747  *****************************************************************************/
748 static void TextMode(int tty)
749 {
750     /* return to text mode */
751     if (-1 == ioctl(tty, KDSETMODE, KD_TEXT)) {
752         /*msg_Err(vd, "failed ioctl KDSETMODE KD_TEXT");*/
753     }
754 }
755
756 static void GfxMode(int tty)
757 {
758     /* switch to graphic mode */
759     if (-1 == ioctl(tty, KDSETMODE, KD_GRAPHICS)) {
760         /*msg_Err(vd, "failed ioctl KDSETMODE KD_GRAPHICS");*/
761     }
762 }