1 /*****************************************************************************
2 * fb.c : framebuffer plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
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.
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.
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 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <errno.h> /* ENOMEM */
29 #include <signal.h> /* SIGUSR1, SIGUSR2 */
30 #include <fcntl.h> /* open() */
31 #include <unistd.h> /* close() */
33 #include <termios.h> /* struct termios */
34 #include <sys/ioctl.h>
35 #include <sys/mman.h> /* mmap() */
38 #include <linux/vt.h> /* VT_* */
39 #include <linux/kd.h> /* KD* */
44 /*****************************************************************************
46 *****************************************************************************/
47 static int Create ( vlc_object_t * );
48 static void Destroy ( vlc_object_t * );
50 static int Init ( vout_thread_t * );
51 static void End ( vout_thread_t * );
52 static int Manage ( vout_thread_t * );
53 static void Display ( vout_thread_t *, picture_t * );
55 static int OpenDisplay ( vout_thread_t * );
56 static void CloseDisplay ( vout_thread_t * );
57 static void SwitchDisplay ( int i_signal );
58 static void TextMode ( int i_tty );
59 static void GfxMode ( int i_tty );
61 /*****************************************************************************
63 *****************************************************************************/
64 #define FB_DEV_VAR "fbdev"
66 #define DEVICE_TEXT N_("Framebuffer device")
67 #define DEVICE_LONGTEXT N_( \
68 "Framebuffer device to use for rendering (usually /dev/fb0).")
70 #define TTY_TEXT N_("Run fb on current tty.")
71 #define TTY_LONGTEXT N_( \
72 "Run framebuffer on current TTY device (default enabled). " \
73 "(disable tty handling with caution)" );
75 #define CHROMA_TEXT N_("Chroma used.")
76 #define CHROMA_LONGTEXT N_( \
77 "Force use of a specific chroma for output. Default is I420." )
79 #define ASPECT_RATIO_TEXT N_("Video aspect ratio")
80 #define ASPECT_RATIO_LONGTEXT N_( \
81 "Aspect ratio of the video image (4:3, 16:9). Default is square pixels." )
84 set_shortname( "Framebuffer" );
85 set_category( CAT_VIDEO );
86 set_subcategory( SUBCAT_VIDEO_VOUT );
87 add_file( FB_DEV_VAR, "/dev/fb0", NULL, DEVICE_TEXT, DEVICE_LONGTEXT,
89 add_bool( "fb-tty", 1, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
90 add_string( "fb-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
92 add_string( "fb-aspect-ratio", NULL, NULL, ASPECT_RATIO_TEXT,
93 ASPECT_RATIO_LONGTEXT, VLC_TRUE );
94 set_description( _("GNU/Linux console framebuffer video output") );
95 set_capability( "video output", 30 );
96 set_callbacks( Create, Destroy );
99 /*****************************************************************************
100 * vout_sys_t: video output framebuffer method descriptor
101 *****************************************************************************
102 * This structure is part of the video output thread descriptor.
103 * It describes the FB specific properties of an output thread.
104 *****************************************************************************/
107 /* System information */
108 int i_tty; /* tty device handle */
110 struct termios old_termios;
112 /* Original configuration information */
113 struct sigaction sig_usr1; /* USR1 previous handler */
114 struct sigaction sig_usr2; /* USR2 previous handler */
115 struct vt_mode vt_mode; /* previous VT mode */
117 /* Framebuffer information */
118 int i_fd; /* device handle */
119 struct fb_var_screeninfo old_info; /* original mode information */
120 struct fb_var_screeninfo var_info; /* current mode information */
121 vlc_bool_t b_pan; /* does device supports panning ? */
122 struct fb_cmap fb_cmap; /* original colormap */
123 uint16_t *p_palette; /* original palette */
125 /* Video information */
129 int i_bytes_per_pixel;
130 vlc_fourcc_t i_chroma;
133 byte_t * p_video; /* base adress */
134 size_t i_page_size; /* page size */
137 /*****************************************************************************
138 * Create: allocates FB video thread output method
139 *****************************************************************************
140 * This function allocates and initializes a FB vout method.
141 *****************************************************************************/
142 static int Create( vlc_object_t *p_this )
144 vout_thread_t *p_vout = (vout_thread_t *)p_this;
148 struct sigaction sig_tty; /* sigaction for tty change */
149 struct vt_mode vt_mode; /* vt current mode */
150 struct termios new_termios;
152 /* Allocate instance and initialize some members */
153 p_vout->p_sys = p_sys = malloc( sizeof( vout_sys_t ) );
154 if( p_vout->p_sys == NULL )
156 msg_Err( p_vout, "out of memory" );
159 memset( p_sys, 0, sizeof(vout_sys_t) );
161 p_vout->pf_init = Init;
162 p_vout->pf_end = End;
163 p_vout->pf_manage = Manage;
164 p_vout->pf_render = NULL;
165 p_vout->pf_display = Display;
167 /* Set tty and fb devices */
168 p_sys->i_tty = 0; /* 0 == /dev/tty0 == current console */
169 p_sys->b_tty = var_CreateGetBool( p_vout, "fb-tty" );
171 #if defined(HAVE_ISATTY)
172 /* Check that stdin is a TTY */
173 if( !p_sys->b_tty && !isatty( 0 ) )
175 msg_Warn( p_vout, "fd 0 is not a TTY" );
180 msg_Warn( p_vout, "disabling tty handling, use with caution because "
181 "there is no way to return to the tty." );
186 psz_chroma = var_CreateGetNonEmptyString( p_vout, "fb-chroma" );
189 if( strlen( psz_chroma ) == 4 )
191 p_sys->i_chroma = VLC_FOURCC( psz_chroma[0],
195 msg_Dbg( p_vout, "forcing chroma '%s'", psz_chroma );
199 msg_Warn( p_vout, "invalid chroma (%s), using defaults.",
206 p_sys->i_aspect = -1;
207 psz_aspect = var_CreateGetNonEmptyString( p_vout, "fb-aspect-ratio" );
210 char *psz_parser = strchr( psz_aspect, ':' );
214 *psz_parser++ = '\0';
215 p_sys->i_aspect = ( atoi( psz_aspect )
216 * VOUT_ASPECT_FACTOR ) / atoi( psz_parser );
218 msg_Dbg( p_vout, "using aspect ratio %d:%d",
219 atoi( psz_aspect ), atoi( psz_parser ) );
228 GfxMode( p_sys->i_tty );
230 /* Set keyboard settings */
231 if( tcgetattr(0, &p_vout->p_sys->old_termios) == -1 )
233 msg_Err( p_vout, "tcgetattr failed" );
236 if( tcgetattr(0, &new_termios) == -1 )
238 msg_Err( p_vout, "tcgetattr failed" );
241 /* new_termios.c_lflag &= ~ (ICANON | ISIG);
242 new_termios.c_lflag |= (ECHO | ECHOCTL); */
243 new_termios.c_lflag &= ~ (ICANON);
244 new_termios.c_lflag &= ~(ECHO | ECHOCTL);
245 new_termios.c_iflag = 0;
246 new_termios.c_cc[VMIN] = 1;
247 new_termios.c_cc[VTIME] = 0;
249 if( tcsetattr(0, TCSAFLUSH, &new_termios) == -1 )
251 msg_Err( p_vout, "tcsetattr failed" );
254 ioctl( p_sys->i_tty, VT_RELDISP, VT_ACKACQ );
256 /* Set-up tty signal handler to be aware of tty changes */
257 memset( &sig_tty, 0, sizeof( sig_tty ) );
258 sig_tty.sa_handler = SwitchDisplay;
259 sigemptyset( &sig_tty.sa_mask );
260 if( sigaction( SIGUSR1, &sig_tty, &p_vout->p_sys->sig_usr1 ) ||
261 sigaction( SIGUSR2, &sig_tty, &p_vout->p_sys->sig_usr2 ) )
263 msg_Err( p_vout, "cannot set signal handler (%s)", strerror(errno) );
264 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
265 TextMode( p_sys->i_tty );
266 free( p_vout->p_sys );
270 /* Set-up tty according to new signal handler */
271 if( -1 == ioctl( p_sys->i_tty, VT_GETMODE, &p_vout->p_sys->vt_mode ) )
273 msg_Err( p_vout, "cannot get terminal mode (%s)", strerror(errno) );
274 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
275 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
276 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
277 TextMode( p_sys->i_tty );
278 free( p_vout->p_sys );
281 memcpy( &vt_mode, &p_vout->p_sys->vt_mode, sizeof( vt_mode ) );
282 vt_mode.mode = VT_PROCESS;
284 vt_mode.relsig = SIGUSR1;
285 vt_mode.acqsig = SIGUSR2;
287 if( -1 == ioctl( p_sys->i_tty, VT_SETMODE, &vt_mode ) )
289 msg_Err( p_vout, "cannot set terminal mode (%s)", strerror(errno) );
290 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
291 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
292 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
293 TextMode( p_sys->i_tty );
294 free( p_vout->p_sys );
299 if( OpenDisplay( p_vout ) )
303 ioctl( p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode );
304 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
305 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
306 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
307 TextMode( p_sys->i_tty );
309 free( p_vout->p_sys );
316 /*****************************************************************************
317 * Init: initialize framebuffer video thread output method
318 *****************************************************************************/
319 static int Init( vout_thread_t *p_vout )
321 vout_sys_t *p_sys = p_vout->p_sys;
325 I_OUTPUTPICTURES = 0;
327 if( p_sys->i_chroma == 0 )
329 /* Initialize the output structure: RGB with square pixels, whatever
330 * the input format is, since it's the only format we know */
331 switch( p_sys->var_info.bits_per_pixel )
333 case 8: /* FIXME: set the palette */
334 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2'); break;
336 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5'); break;
338 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6'); break;
340 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4'); break;
342 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2'); break;
344 msg_Err( p_vout, "unknown screen depth %i",
345 p_vout->p_sys->var_info.bits_per_pixel );
349 if( p_sys->var_info.bits_per_pixel != 8 )
351 p_vout->output.i_rmask = ( (1 << p_sys->var_info.red.length) - 1 )
352 << p_sys->var_info.red.offset;
353 p_vout->output.i_gmask = ( (1 << p_sys->var_info.green.length) - 1 )
354 << p_sys->var_info.green.offset;
355 p_vout->output.i_bmask = ( (1 << p_sys->var_info.blue.length) - 1 )
356 << p_sys->var_info.blue.offset;
361 p_vout->output.i_chroma = p_sys->i_chroma;
363 p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
365 p_vout->output.i_width = p_sys->i_width;
366 p_vout->output.i_height = p_sys->i_height;
368 /* Assume we have square pixels */
369 if( p_sys->i_aspect < 0 )
371 p_vout->output.i_aspect = ( p_sys->i_width
372 * VOUT_ASPECT_FACTOR ) / p_sys->i_height;
374 else p_vout->output.i_aspect = p_sys->i_aspect;
376 p_vout->fmt_out.i_sar_num = p_vout->fmt_out.i_sar_den = 1;
377 p_vout->fmt_out.i_aspect = p_vout->output.i_aspect;
379 /* Clear the screen */
380 memset( p_sys->p_video, 0, p_sys->i_page_size );
382 /* Try to initialize 1 direct buffer */
385 /* Find an empty picture slot */
386 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
388 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
390 p_pic = p_vout->p_picture + i_index;
395 /* Allocate the picture */
401 /* We know the chroma, allocate a buffer which will be used
402 * directly by the decoder */
403 p_pic->p->p_pixels = p_vout->p_sys->p_video;
404 p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel;
405 p_pic->p->i_lines = p_vout->p_sys->var_info.yres;
406 p_pic->p->i_visible_lines = p_vout->p_sys->var_info.yres;
408 if( p_vout->p_sys->var_info.xres_virtual )
410 p_pic->p->i_pitch = p_vout->p_sys->var_info.xres_virtual
411 * p_vout->p_sys->i_bytes_per_pixel;
415 p_pic->p->i_pitch = p_vout->p_sys->var_info.xres
416 * p_vout->p_sys->i_bytes_per_pixel;
419 p_pic->p->i_visible_pitch = p_vout->p_sys->var_info.xres
420 * p_vout->p_sys->i_bytes_per_pixel;
424 p_pic->i_status = DESTROYED_PICTURE;
425 p_pic->i_type = DIRECT_PICTURE;
427 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
434 /*****************************************************************************
435 * End: terminate framebuffer video thread output method
436 *****************************************************************************/
437 static void End( vout_thread_t *p_vout )
439 /* Clear the screen */
440 memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
443 /*****************************************************************************
444 * Destroy: destroy FB video thread output method
445 *****************************************************************************
446 * Terminate an output method created by Create
447 *****************************************************************************/
448 static void Destroy( vlc_object_t *p_this )
450 vout_thread_t *p_vout = (vout_thread_t *)p_this;
452 CloseDisplay( p_vout );
454 if( p_vout->p_sys->b_tty )
456 /* Reset the terminal */
457 ioctl( p_vout->p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode );
459 /* Remove signal handlers */
460 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
461 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
463 /* Reset the keyboard state */
464 tcsetattr( 0, 0, &p_vout->p_sys->old_termios );
466 /* Return to text mode */
467 TextMode( p_vout->p_sys->i_tty );
470 /* Destroy structure */
471 free( p_vout->p_sys );
474 /*****************************************************************************
475 * Manage: handle FB events
476 *****************************************************************************
477 * This function should be called regularly by video output thread. It manages
478 * console events. It returns a non null value on error.
479 *****************************************************************************/
480 static int Manage( vout_thread_t *p_vout )
485 if ( read(0, &buf, 1) == 1)
490 vlc_object_kill( p_vout->p_libvlc );
502 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
504 msg_Dbg( p_vout, "reinitializing framebuffer screen" );
505 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
507 /* Destroy XImages to change their size */
510 /* Recreate XImages. If SysInit failed, the thread can't go on. */
513 msg_Err( p_vout, "cannot reinit framebuffer screen" );
518 memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
521 /* Tell the video output thread that it will need to rebuild YUV
522 * tables. This is needed since conversion buffer size may have changed */
523 p_vout->i_changes |= VOUT_YUV_CHANGE;
530 /*****************************************************************************
531 * Display: displays previously rendered output
532 *****************************************************************************
533 * This function send the currently rendered image to FB image, waits until
534 * it is displayed and switch the two rendering buffers, preparing next frame.
535 *****************************************************************************/
536 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
539 /* swap the two Y offsets if the drivers supports panning */
540 if( p_vout->p_sys->b_pan )
542 p_vout->p_sys->var_info.yoffset = 0;
543 /*p_vout->p_sys->var_info.yoffset = p_vout->p_sys->var_info.yres; */
545 /* the X offset should be 0, but who knows ...
546 * some other app might have played with the framebuffer */
547 p_vout->p_sys->var_info.xoffset = 0;
551 ioctl( p_vout->p_sys->i_fd,
552 FBIOPAN_DISPLAY, &p_vout->p_sys->var_info );
559 static void SetPalette( vout_thread_t *p_vout, uint16_t *red, uint16_t *green,
560 uint16_t *blue, uint16_t *transp )
562 struct fb_cmap cmap = { 0, 256, red, green, blue, transp };
564 ioctl( p_vout->p_sys->i_fd, FBIOPUTCMAP, &cmap );
568 /* following functions are local */
570 /*****************************************************************************
571 * OpenDisplay: initialize framebuffer
572 *****************************************************************************/
573 static int OpenDisplay( vout_thread_t *p_vout )
575 char *psz_device; /* framebuffer device path */
576 struct fb_fix_screeninfo fix_info; /* framebuffer fix information */
578 /* Open framebuffer device */
579 if( !(psz_device = config_GetPsz( p_vout, FB_DEV_VAR )) )
581 msg_Err( p_vout, "don't know which fb device to open" );
585 p_vout->p_sys->i_fd = open( psz_device, O_RDWR);
586 if( p_vout->p_sys->i_fd == -1 )
588 msg_Err( p_vout, "cannot open %s (%s)", psz_device, strerror(errno) );
595 /* Get framebuffer device information */
596 if( ioctl( p_vout->p_sys->i_fd,
597 FBIOGET_VSCREENINFO, &p_vout->p_sys->var_info ) )
599 msg_Err( p_vout, "cannot get fb info (%s)", strerror(errno) );
600 close( p_vout->p_sys->i_fd );
604 memcpy( &p_vout->p_sys->old_info, &p_vout->p_sys->var_info,
605 sizeof( struct fb_var_screeninfo ) );
607 /* Set some attributes */
608 p_vout->p_sys->var_info.activate = FB_ACTIVATE_NXTOPEN;
609 p_vout->p_sys->var_info.xoffset = 0;
610 p_vout->p_sys->var_info.yoffset = 0;
612 if( ioctl( p_vout->p_sys->i_fd,
613 FBIOPUT_VSCREENINFO, &p_vout->p_sys->var_info ) )
615 msg_Err( p_vout, "cannot set fb info (%s)", strerror(errno) );
616 close( p_vout->p_sys->i_fd );
620 /* Get some information again, in the definitive configuration */
621 if( ioctl( p_vout->p_sys->i_fd, FBIOGET_FSCREENINFO, &fix_info )
622 || ioctl( p_vout->p_sys->i_fd,
623 FBIOGET_VSCREENINFO, &p_vout->p_sys->var_info ) )
625 msg_Err( p_vout, "cannot get additional fb info (%s)",
628 /* Restore fb config */
629 ioctl( p_vout->p_sys->i_fd,
630 FBIOPUT_VSCREENINFO, &p_vout->p_sys->old_info );
632 close( p_vout->p_sys->i_fd );
636 /* FIXME: if the image is full-size, it gets cropped on the left
637 * because of the xres / xres_virtual slight difference */
638 msg_Dbg( p_vout, "%ix%i (virtual %ix%i)",
639 p_vout->p_sys->var_info.xres, p_vout->p_sys->var_info.yres,
640 p_vout->p_sys->var_info.xres_virtual,
641 p_vout->p_sys->var_info.yres_virtual );
643 p_vout->p_sys->i_height = p_vout->p_sys->var_info.yres;
644 p_vout->p_sys->i_width = p_vout->p_sys->var_info.xres_virtual
645 ? p_vout->p_sys->var_info.xres_virtual
646 : p_vout->p_sys->var_info.xres;
648 p_vout->p_sys->p_palette = NULL;
649 p_vout->p_sys->b_pan = ( fix_info.ypanstep || fix_info.ywrapstep );
651 switch( p_vout->p_sys->var_info.bits_per_pixel )
654 p_vout->p_sys->p_palette = malloc( 8 * 256 * sizeof( uint16_t ) );
655 if( !p_vout->p_sys->p_palette )
657 msg_Err( p_vout, "out of memory" );
659 /* Restore fb config */
660 ioctl( p_vout->p_sys->i_fd,
661 FBIOPUT_VSCREENINFO, &p_vout->p_sys->old_info );
663 close( p_vout->p_sys->i_fd );
666 p_vout->p_sys->fb_cmap.start = 0;
667 p_vout->p_sys->fb_cmap.len = 256;
668 p_vout->p_sys->fb_cmap.red = p_vout->p_sys->p_palette;
669 p_vout->p_sys->fb_cmap.green = p_vout->p_sys->p_palette + 256 * sizeof( uint16_t );
670 p_vout->p_sys->fb_cmap.blue = p_vout->p_sys->p_palette + 2 * 256 * sizeof( uint16_t );
671 p_vout->p_sys->fb_cmap.transp = p_vout->p_sys->p_palette + 3 * 256 * sizeof( uint16_t );
673 /* Save the colormap */
674 ioctl( p_vout->p_sys->i_fd, FBIOGETCMAP, &p_vout->p_sys->fb_cmap );
676 p_vout->p_sys->i_bytes_per_pixel = 1;
681 p_vout->p_sys->i_bytes_per_pixel = 2;
685 p_vout->p_sys->i_bytes_per_pixel = 3;
689 p_vout->p_sys->i_bytes_per_pixel = 4;
693 msg_Err( p_vout, "screen depth %d is not supported",
694 p_vout->p_sys->var_info.bits_per_pixel );
696 /* Restore fb config */
697 ioctl( p_vout->p_sys->i_fd,
698 FBIOPUT_VSCREENINFO, &p_vout->p_sys->old_info );
700 close( p_vout->p_sys->i_fd );
704 p_vout->p_sys->i_page_size = p_vout->p_sys->i_width *
705 p_vout->p_sys->i_height * p_vout->p_sys->i_bytes_per_pixel;
707 /* Map a framebuffer at the beginning */
708 p_vout->p_sys->p_video = mmap( 0, p_vout->p_sys->i_page_size,
709 PROT_READ | PROT_WRITE, MAP_SHARED,
710 p_vout->p_sys->i_fd, 0 );
712 if( p_vout->p_sys->p_video == ((void*)-1) )
714 msg_Err( p_vout, "cannot map video memory (%s)", strerror(errno) );
716 if( p_vout->p_sys->var_info.bits_per_pixel == 8 )
718 free( p_vout->p_sys->p_palette );
719 p_vout->p_sys->p_palette = NULL;
722 /* Restore fb config */
723 ioctl( p_vout->p_sys->i_fd,
724 FBIOPUT_VSCREENINFO, &p_vout->p_sys->old_info );
726 close( p_vout->p_sys->i_fd );
730 msg_Dbg( p_vout, "framebuffer type=%d, visual=%d, ypanstep=%d, "
731 "ywrap=%d, accel=%d", fix_info.type, fix_info.visual,
732 fix_info.ypanstep, fix_info.ywrapstep, fix_info.accel );
736 /*****************************************************************************
737 * CloseDisplay: terminate FB video thread output method
738 *****************************************************************************/
739 static void CloseDisplay( vout_thread_t *p_vout )
742 memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
744 /* Restore palette */
745 if( p_vout->p_sys->var_info.bits_per_pixel == 8 )
747 ioctl( p_vout->p_sys->i_fd,
748 FBIOPUTCMAP, &p_vout->p_sys->fb_cmap );
749 free( p_vout->p_sys->p_palette );
750 p_vout->p_sys->p_palette = NULL;
753 /* Restore fb config */
754 ioctl( p_vout->p_sys->i_fd,
755 FBIOPUT_VSCREENINFO, &p_vout->p_sys->old_info );
758 close( p_vout->p_sys->i_fd );
761 /*****************************************************************************
762 * SwitchDisplay: VT change signal handler
763 *****************************************************************************
764 * This function activates or deactivates the output of the thread. It is
765 * called by the VT driver, on terminal change.
766 *****************************************************************************/
767 static void SwitchDisplay(int i_signal)
770 vout_thread_t *p_vout;
772 vlc_mutex_lock( &p_vout_bank->lock );
774 /* XXX: only test the first video output */
775 if( p_vout_bank->i_count )
777 p_vout = p_vout_bank->pp_vout[0];
781 case SIGUSR1: /* vt has been released */
782 p_vout->b_active = 0;
783 ioctl( p_sys->i_tty, VT_RELDISP, 1 );
785 case SIGUSR2: /* vt has been acquired */
786 p_vout->b_active = 1;
787 ioctl( p_sys->i_tty, VT_RELDISP, VT_ACTIVATE );
788 /* handle blanking */
789 vlc_mutex_lock( &p_vout->change_lock );
790 p_vout->i_changes |= VOUT_SIZE_CHANGE;
791 vlc_mutex_unlock( &p_vout->change_lock );
796 vlc_mutex_unlock( &p_vout_bank->lock );
800 /*****************************************************************************
801 * TextMode and GfxMode : switch tty to text/graphic mode
802 *****************************************************************************
803 * These functions toggle the tty mode.
804 *****************************************************************************/
805 static void TextMode( int i_tty )
807 /* return to text mode */
808 if( -1 == ioctl(i_tty, KDSETMODE, KD_TEXT) )
810 /*msg_Err( p_vout, "failed ioctl KDSETMODE KD_TEXT" );*/
814 static void GfxMode( int i_tty )
816 /* switch to graphic mode */
817 if( -1 == ioctl(i_tty, KDSETMODE, KD_GRAPHICS) )
819 /*msg_Err( p_vout, "failed ioctl KDSETMODE KD_GRAPHICS" );*/