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