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 * );
54 static int Control ( vout_thread_t *, int, va_list );
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 );
62 /*****************************************************************************
64 *****************************************************************************/
65 #define FB_DEV_VAR "fbdev"
67 #define DEVICE_TEXT N_("Framebuffer device")
68 #define DEVICE_LONGTEXT N_( \
69 "Framebuffer device to use for rendering (usually /dev/fb0).")
71 #define TTY_TEXT N_("Run fb on current tty.")
72 #define TTY_LONGTEXT N_( \
73 "Run framebuffer on current TTY device (default enabled). " \
74 "(disable tty handling with caution)" );
76 #define CHROMA_TEXT N_("Chroma used.")
77 #define CHROMA_LONGTEXT N_( \
78 "Force use of a specific chroma for output. Default is I420." )
80 #define ASPECT_RATIO_TEXT N_("Video aspect ratio")
81 #define ASPECT_RATIO_LONGTEXT N_( \
82 "Aspect ratio of the video image (4:3, 16:9). Default is square pixels." )
84 #define FB_MODE_TEXT N_("Framebuffer resolution to use.")
85 #define FB_MODE_LONGTEXT N_( \
86 "Select the resolution for the framebuffer. Currently it supports " \
87 "the values 0=QCIF 1=CIF 2=NTSC 3=PAL (default 3=PAL)" )
90 set_shortname( "Framebuffer" );
91 set_category( CAT_VIDEO );
92 set_subcategory( SUBCAT_VIDEO_VOUT );
93 add_file( FB_DEV_VAR, "/dev/fb0", NULL, DEVICE_TEXT, DEVICE_LONGTEXT,
95 add_bool( "fb-tty", 1, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
96 add_string( "fb-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
98 add_string( "fb-aspect-ratio", NULL, NULL, ASPECT_RATIO_TEXT,
99 ASPECT_RATIO_LONGTEXT, VLC_TRUE );
100 add_integer( "fb-mode", 3, NULL, FB_MODE_TEXT, FB_MODE_LONGTEXT,
102 set_description( _("GNU/Linux console framebuffer video output") );
103 set_capability( "video output", 30 );
104 set_callbacks( Create, Destroy );
107 /*****************************************************************************
108 * vout_sys_t: video output framebuffer method descriptor
109 *****************************************************************************
110 * This structure is part of the video output thread descriptor.
111 * It describes the FB specific properties of an output thread.
112 *****************************************************************************/
115 /* System information */
116 int i_tty; /* tty device handle */
118 struct termios old_termios;
120 /* Original configuration information */
121 struct sigaction sig_usr1; /* USR1 previous handler */
122 struct sigaction sig_usr2; /* USR2 previous handler */
123 struct vt_mode vt_mode; /* previous VT mode */
125 /* Framebuffer information */
126 int i_fd; /* device handle */
127 struct fb_var_screeninfo old_info; /* original mode information */
128 struct fb_var_screeninfo var_info; /* current mode information */
129 vlc_bool_t b_pan; /* does device supports panning ? */
130 struct fb_cmap fb_cmap; /* original colormap */
131 uint16_t *p_palette; /* original palette */
133 /* Video information */
137 int i_bytes_per_pixel;
138 vlc_fourcc_t i_chroma;
141 byte_t * p_video; /* base adress */
142 size_t i_page_size; /* page size */
145 /*****************************************************************************
146 * Create: allocates FB video thread output method
147 *****************************************************************************
148 * This function allocates and initializes a FB vout method.
149 *****************************************************************************/
150 static int Create( vlc_object_t *p_this )
152 vout_thread_t *p_vout = (vout_thread_t *)p_this;
157 struct sigaction sig_tty; /* sigaction for tty change */
158 struct vt_mode vt_mode; /* vt current mode */
159 struct termios new_termios;
161 /* Allocate instance and initialize some members */
162 p_vout->p_sys = p_sys = malloc( sizeof( vout_sys_t ) );
163 if( p_vout->p_sys == NULL )
165 msg_Err( p_vout, "out of memory" );
168 memset( p_sys, 0, sizeof(vout_sys_t) );
170 p_vout->pf_init = Init;
171 p_vout->pf_end = End;
172 p_vout->pf_manage = Manage;
173 p_vout->pf_render = NULL;
174 p_vout->pf_display = Display;
175 p_vout->pf_control = Control;
177 /* Set tty and fb devices */
178 p_sys->i_tty = 0; /* 0 == /dev/tty0 == current console */
179 p_sys->b_tty = var_CreateGetBool( p_vout, "fb-tty" );
181 #if defined(HAVE_ISATTY)
182 /* Check that stdin is a TTY */
183 if( !p_sys->b_tty && !isatty( 0 ) )
185 msg_Warn( p_vout, "fd 0 is not a TTY" );
190 msg_Warn( p_vout, "disabling tty handling, use with caution because "
191 "there is no way to return to the tty." );
196 psz_chroma = var_CreateGetNonEmptyString( p_vout, "fb-chroma" );
199 if( strlen( psz_chroma ) == 4 )
201 p_sys->i_chroma = VLC_FOURCC( psz_chroma[0],
205 msg_Dbg( p_vout, "forcing chroma '%s'", psz_chroma );
209 msg_Warn( p_vout, "invalid chroma (%s), using defaults.",
216 p_sys->i_aspect = -1;
217 psz_aspect = var_CreateGetNonEmptyString( p_vout, "fb-aspect-ratio" );
220 char *psz_parser = strchr( psz_aspect, ':' );
224 *psz_parser++ = '\0';
225 p_sys->i_aspect = ( atoi( psz_aspect )
226 * VOUT_ASPECT_FACTOR ) / atoi( psz_parser );
228 msg_Dbg( p_vout, "using aspect ratio %d:%d",
229 atoi( psz_aspect ), atoi( psz_parser ) );
235 i_mode = var_CreateGetInteger( p_vout, "fb-mode" );
239 p_sys->i_width = 176;
240 p_sys->i_height = 144;
243 p_sys->i_width = 352;
244 p_sys->i_height = 288;
247 p_sys->i_width = 640;
248 p_sys->i_height = 480;
252 p_sys->i_width = 704;
253 p_sys->i_height = 576;
260 GfxMode( p_sys->i_tty );
262 /* Set keyboard settings */
263 if( tcgetattr(0, &p_vout->p_sys->old_termios) == -1 )
265 msg_Err( p_vout, "tcgetattr failed" );
268 if( tcgetattr(0, &new_termios) == -1 )
270 msg_Err( p_vout, "tcgetattr failed" );
273 /* new_termios.c_lflag &= ~ (ICANON | ISIG);
274 new_termios.c_lflag |= (ECHO | ECHOCTL); */
275 new_termios.c_lflag &= ~ (ICANON);
276 new_termios.c_lflag &= ~(ECHO | ECHOCTL);
277 new_termios.c_iflag = 0;
278 new_termios.c_cc[VMIN] = 1;
279 new_termios.c_cc[VTIME] = 0;
281 if( tcsetattr(0, TCSAFLUSH, &new_termios) == -1 )
283 msg_Err( p_vout, "tcsetattr failed" );
286 ioctl( p_sys->i_tty, VT_RELDISP, VT_ACKACQ );
288 /* Set-up tty signal handler to be aware of tty changes */
289 memset( &sig_tty, 0, sizeof( sig_tty ) );
290 sig_tty.sa_handler = SwitchDisplay;
291 sigemptyset( &sig_tty.sa_mask );
292 if( sigaction( SIGUSR1, &sig_tty, &p_vout->p_sys->sig_usr1 ) ||
293 sigaction( SIGUSR2, &sig_tty, &p_vout->p_sys->sig_usr2 ) )
295 msg_Err( p_vout, "cannot set signal handler (%m)" );
296 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
297 TextMode( p_sys->i_tty );
298 free( p_vout->p_sys );
302 /* Set-up tty according to new signal handler */
303 if( -1 == ioctl( p_sys->i_tty, VT_GETMODE, &p_vout->p_sys->vt_mode ) )
305 msg_Err( p_vout, "cannot get terminal mode (%m)" );
306 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
307 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
308 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
309 TextMode( p_sys->i_tty );
310 free( p_vout->p_sys );
313 memcpy( &vt_mode, &p_vout->p_sys->vt_mode, sizeof( vt_mode ) );
314 vt_mode.mode = VT_PROCESS;
316 vt_mode.relsig = SIGUSR1;
317 vt_mode.acqsig = SIGUSR2;
319 if( -1 == ioctl( p_sys->i_tty, VT_SETMODE, &vt_mode ) )
321 msg_Err( p_vout, "cannot set terminal mode (%m)" );
322 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
323 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
324 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
325 TextMode( p_sys->i_tty );
326 free( p_vout->p_sys );
331 if( OpenDisplay( p_vout ) )
335 ioctl( p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode );
336 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
337 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
338 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
339 TextMode( p_sys->i_tty );
341 free( p_vout->p_sys );
348 /*****************************************************************************
349 * Init: initialize framebuffer video thread output method
350 *****************************************************************************/
351 static int Init( vout_thread_t *p_vout )
353 vout_sys_t *p_sys = p_vout->p_sys;
357 I_OUTPUTPICTURES = 0;
359 if( p_sys->i_chroma == 0 )
361 /* Initialize the output structure: RGB with square pixels, whatever
362 * the input format is, since it's the only format we know */
363 switch( p_sys->var_info.bits_per_pixel )
365 case 8: /* FIXME: set the palette */
366 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2'); break;
368 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5'); break;
370 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6'); break;
372 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4'); break;
374 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2'); break;
376 msg_Err( p_vout, "unknown screen depth %i",
377 p_vout->p_sys->var_info.bits_per_pixel );
381 if( p_sys->var_info.bits_per_pixel != 8 )
383 p_vout->output.i_rmask = ( (1 << p_sys->var_info.red.length) - 1 )
384 << p_sys->var_info.red.offset;
385 p_vout->output.i_gmask = ( (1 << p_sys->var_info.green.length) - 1 )
386 << p_sys->var_info.green.offset;
387 p_vout->output.i_bmask = ( (1 << p_sys->var_info.blue.length) - 1 )
388 << p_sys->var_info.blue.offset;
393 p_vout->output.i_chroma = p_sys->i_chroma;
395 p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
397 p_vout->output.i_width = p_vout->render.i_width = p_sys->i_width;
398 p_vout->output.i_height = p_vout->render.i_height = p_sys->i_height;
400 /* Assume we have square pixels */
401 if( p_sys->i_aspect < 0 )
403 p_vout->output.i_aspect = ( p_sys->i_width
404 * VOUT_ASPECT_FACTOR ) / p_sys->i_height;
406 else p_vout->output.i_aspect = p_sys->i_aspect;
408 p_vout->fmt_out.i_sar_num = p_vout->fmt_out.i_sar_den = 1;
409 p_vout->fmt_out.i_aspect = p_vout->render.i_aspect = p_vout->output.i_aspect;
411 /* Clear the screen */
412 memset( p_sys->p_video, 0, p_sys->i_page_size );
414 /* Try to initialize 1 direct buffer */
417 /* Find an empty picture slot */
418 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
420 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
422 p_pic = p_vout->p_picture + i_index;
427 /* Allocate the picture */
433 /* We know the chroma, allocate a buffer which will be used
434 * directly by the decoder */
435 p_pic->p->p_pixels = p_vout->p_sys->p_video;
436 p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel;
437 p_pic->p->i_lines = p_vout->p_sys->var_info.yres;
438 p_pic->p->i_visible_lines = p_vout->p_sys->var_info.yres;
440 if( p_vout->p_sys->var_info.xres_virtual )
442 p_pic->p->i_pitch = p_vout->p_sys->var_info.xres_virtual
443 * p_vout->p_sys->i_bytes_per_pixel;
447 p_pic->p->i_pitch = p_vout->p_sys->var_info.xres
448 * p_vout->p_sys->i_bytes_per_pixel;
451 p_pic->p->i_visible_pitch = p_vout->p_sys->var_info.xres
452 * p_vout->p_sys->i_bytes_per_pixel;
456 p_pic->i_status = DESTROYED_PICTURE;
457 p_pic->i_type = DIRECT_PICTURE;
459 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
466 /*****************************************************************************
467 * End: terminate framebuffer video thread output method
468 *****************************************************************************/
469 static void End( vout_thread_t *p_vout )
471 /* Clear the screen */
472 memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
475 /*****************************************************************************
476 * Destroy: destroy FB video thread output method
477 *****************************************************************************
478 * Terminate an output method created by Create
479 *****************************************************************************/
480 static void Destroy( vlc_object_t *p_this )
482 vout_thread_t *p_vout = (vout_thread_t *)p_this;
484 CloseDisplay( p_vout );
486 if( p_vout->p_sys->b_tty )
488 /* Reset the terminal */
489 ioctl( p_vout->p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode );
491 /* Remove signal handlers */
492 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
493 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
495 /* Reset the keyboard state */
496 tcsetattr( 0, 0, &p_vout->p_sys->old_termios );
498 /* Return to text mode */
499 TextMode( p_vout->p_sys->i_tty );
502 /* Destroy structure */
503 free( p_vout->p_sys );
506 /*****************************************************************************
507 * Control: control facility for the vout
508 *****************************************************************************/
509 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
514 return vout_vaControlDefault( p_vout, i_query, args );
518 /*****************************************************************************
519 * Manage: handle FB events
520 *****************************************************************************
521 * This function should be called regularly by video output thread. It manages
522 * console events. It returns a non null value on error.
523 *****************************************************************************/
524 static int Manage( vout_thread_t *p_vout )
529 if ( read(0, &buf, 1) == 1)
534 vlc_object_kill( p_vout->p_libvlc );
546 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
548 msg_Dbg( p_vout, "reinitializing framebuffer screen" );
549 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
551 /* Destroy XImages to change their size */
554 /* Recreate XImages. If SysInit failed, the thread can't go on. */
557 msg_Err( p_vout, "cannot reinit framebuffer screen" );
562 memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
565 /* Tell the video output thread that it will need to rebuild YUV
566 * tables. This is needed since conversion buffer size may have changed */
567 p_vout->i_changes |= VOUT_YUV_CHANGE;
574 /*****************************************************************************
575 * Display: displays previously rendered output
576 *****************************************************************************
577 * This function send the currently rendered image to FB image, waits until
578 * it is displayed and switch the two rendering buffers, preparing next frame.
579 *****************************************************************************/
580 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
583 /* swap the two Y offsets if the drivers supports panning */
584 if( p_vout->p_sys->b_pan )
586 p_vout->p_sys->var_info.yoffset = 0;
587 /*p_vout->p_sys->var_info.yoffset = p_vout->p_sys->var_info.yres; */
589 /* the X offset should be 0, but who knows ...
590 * some other app might have played with the framebuffer */
591 p_vout->p_sys->var_info.xoffset = 0;
595 ioctl( p_vout->p_sys->i_fd,
596 FBIOPAN_DISPLAY, &p_vout->p_sys->var_info );
603 static void SetPalette( vout_thread_t *p_vout, uint16_t *red, uint16_t *green,
604 uint16_t *blue, uint16_t *transp )
606 struct fb_cmap cmap = { 0, 256, red, green, blue, transp };
608 ioctl( p_vout->p_sys->i_fd, FBIOPUTCMAP, &cmap );
612 /* following functions are local */
614 /*****************************************************************************
615 * OpenDisplay: initialize framebuffer
616 *****************************************************************************/
617 static int OpenDisplay( vout_thread_t *p_vout )
619 vout_sys_t *p_sys = (vout_sys_t *) p_vout->p_sys;
620 char *psz_device; /* framebuffer device path */
621 struct fb_fix_screeninfo fix_info; /* framebuffer fix information */
623 /* Open framebuffer device */
624 if( !(psz_device = config_GetPsz( p_vout, FB_DEV_VAR )) )
626 msg_Err( p_vout, "don't know which fb device to open" );
630 p_sys->i_fd = open( psz_device, O_RDWR);
631 if( p_sys->i_fd == -1 )
633 msg_Err( p_vout, "cannot open %s (%m)", psz_device );
640 /* Get framebuffer device information */
641 if( ioctl( p_sys->i_fd, FBIOGET_VSCREENINFO, &p_sys->var_info ) )
643 msg_Err( p_vout, "cannot get fb info (%m)" );
644 close( p_sys->i_fd );
648 memcpy( &p_sys->old_info, &p_sys->var_info,
649 sizeof( struct fb_var_screeninfo ) );
651 /* Get some info on the framebuffer itself */
652 if( ioctl( p_sys->i_fd, FBIOGET_FSCREENINFO, &fix_info ) == 0 )
654 p_sys->var_info.xres = p_sys->var_info.xres_virtual = p_sys->i_width;
655 p_sys->var_info.yres = p_sys->var_info.yres_virtual = p_sys->i_height;
656 p_vout->fmt_out.i_width = p_sys->i_width;
657 p_vout->fmt_out.i_height = p_sys->i_height;
660 /* Set some attributes */
661 p_sys->var_info.activate = p_sys->b_tty
662 ? FB_ACTIVATE_NXTOPEN
664 p_sys->var_info.xoffset = 0;
665 p_sys->var_info.yoffset = 0;
667 if( ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->var_info ) )
669 msg_Err( p_vout, "cannot set fb info (%m)" );
670 close( p_sys->i_fd );
674 /* Get some information again, in the definitive configuration */
675 if( ioctl( p_sys->i_fd, FBIOGET_FSCREENINFO, &fix_info )
676 || ioctl( p_sys->i_fd, FBIOGET_VSCREENINFO, &p_sys->var_info ) )
678 msg_Err( p_vout, "cannot get additional fb info (%m)" );
680 /* Restore fb config */
681 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->old_info );
683 close( p_sys->i_fd );
687 /* FIXME: if the image is full-size, it gets cropped on the left
688 * because of the xres / xres_virtual slight difference */
689 msg_Dbg( p_vout, "%ix%i (virtual %ix%i)",
690 p_sys->var_info.xres, p_sys->var_info.yres,
691 p_sys->var_info.xres_virtual,
692 p_sys->var_info.yres_virtual );
694 /* If the fb has limitations on mode change,
695 * then keep the resolution of the fb */
696 p_sys->i_height = p_sys->var_info.yres;
697 p_sys->i_width = p_sys->var_info.xres_virtual
698 ? p_sys->var_info.xres_virtual
699 : p_sys->var_info.xres;
701 p_sys->p_palette = NULL;
702 p_sys->b_pan = ( fix_info.ypanstep || fix_info.ywrapstep );
704 switch( p_sys->var_info.bits_per_pixel )
707 p_sys->p_palette = malloc( 8 * 256 * sizeof( uint16_t ) );
708 if( !p_sys->p_palette )
710 msg_Err( p_vout, "out of memory" );
712 /* Restore fb config */
713 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->old_info );
715 close( p_sys->i_fd );
718 p_sys->fb_cmap.start = 0;
719 p_sys->fb_cmap.len = 256;
720 p_sys->fb_cmap.red = p_sys->p_palette;
721 p_sys->fb_cmap.green = p_sys->p_palette + 256 * sizeof( uint16_t );
722 p_sys->fb_cmap.blue = p_sys->p_palette + 2 * 256 * sizeof( uint16_t );
723 p_sys->fb_cmap.transp = p_sys->p_palette + 3 * 256 * sizeof( uint16_t );
725 /* Save the colormap */
726 ioctl( p_sys->i_fd, FBIOGETCMAP, &p_sys->fb_cmap );
728 p_sys->i_bytes_per_pixel = 1;
733 p_sys->i_bytes_per_pixel = 2;
737 p_sys->i_bytes_per_pixel = 3;
741 p_sys->i_bytes_per_pixel = 4;
745 msg_Err( p_vout, "screen depth %d is not supported",
746 p_sys->var_info.bits_per_pixel );
748 /* Restore fb config */
749 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->old_info );
751 close( p_sys->i_fd );
755 p_sys->i_page_size = p_sys->i_width * p_sys->i_height *
756 p_sys->i_bytes_per_pixel;
758 /* Map a framebuffer at the beginning */
759 p_sys->p_video = mmap( 0, p_sys->i_page_size,
760 PROT_READ | PROT_WRITE, MAP_SHARED,
763 if( p_sys->p_video == ((void*)-1) )
765 msg_Err( p_vout, "cannot map video memory (%m)" );
767 if( p_sys->var_info.bits_per_pixel == 8 )
769 free( p_sys->p_palette );
770 p_sys->p_palette = NULL;
773 /* Restore fb config */
774 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_vout->p_sys->old_info );
776 close( p_sys->i_fd );
780 msg_Dbg( p_vout, "framebuffer type=%d, visual=%d, ypanstep=%d, "
781 "ywrap=%d, accel=%d", fix_info.type, fix_info.visual,
782 fix_info.ypanstep, fix_info.ywrapstep, fix_info.accel );
786 /*****************************************************************************
787 * CloseDisplay: terminate FB video thread output method
788 *****************************************************************************/
789 static void CloseDisplay( vout_thread_t *p_vout )
792 memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
794 /* Restore palette */
795 if( p_vout->p_sys->var_info.bits_per_pixel == 8 )
797 ioctl( p_vout->p_sys->i_fd,
798 FBIOPUTCMAP, &p_vout->p_sys->fb_cmap );
799 free( p_vout->p_sys->p_palette );
800 p_vout->p_sys->p_palette = NULL;
803 /* Restore fb config */
804 ioctl( p_vout->p_sys->i_fd,
805 FBIOPUT_VSCREENINFO, &p_vout->p_sys->old_info );
808 close( p_vout->p_sys->i_fd );
811 /*****************************************************************************
812 * SwitchDisplay: VT change signal handler
813 *****************************************************************************
814 * This function activates or deactivates the output of the thread. It is
815 * called by the VT driver, on terminal change.
816 *****************************************************************************/
817 static void SwitchDisplay(int i_signal)
820 vout_thread_t *p_vout;
822 vlc_mutex_lock( &p_vout_bank->lock );
824 /* XXX: only test the first video output */
825 if( p_vout_bank->i_count )
827 p_vout = p_vout_bank->pp_vout[0];
831 case SIGUSR1: /* vt has been released */
832 p_vout->b_active = 0;
833 ioctl( p_sys->i_tty, VT_RELDISP, 1 );
835 case SIGUSR2: /* vt has been acquired */
836 p_vout->b_active = 1;
837 ioctl( p_sys->i_tty, VT_RELDISP, VT_ACTIVATE );
838 /* handle blanking */
839 vlc_mutex_lock( &p_vout->change_lock );
840 p_vout->i_changes |= VOUT_SIZE_CHANGE;
841 vlc_mutex_unlock( &p_vout->change_lock );
846 vlc_mutex_unlock( &p_vout_bank->lock );
850 /*****************************************************************************
851 * TextMode and GfxMode : switch tty to text/graphic mode
852 *****************************************************************************
853 * These functions toggle the tty mode.
854 *****************************************************************************/
855 static void TextMode( int i_tty )
857 /* return to text mode */
858 if( -1 == ioctl(i_tty, KDSETMODE, KD_TEXT) )
860 /*msg_Err( p_vout, "failed ioctl KDSETMODE KD_TEXT" );*/
864 static void GfxMode( int i_tty )
866 /* switch to graphic mode */
867 if( -1 == ioctl(i_tty, KDSETMODE, KD_GRAPHICS) )
869 /*msg_Err( p_vout, "failed ioctl KDSETMODE KD_GRAPHICS" );*/