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, 4=auto (default 4=auto)" )
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", 4, 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_bool_t b_auto; /* Automatically adjust video size to fb size */
139 vlc_fourcc_t i_chroma;
142 byte_t * p_video; /* base adress */
143 size_t i_page_size; /* page size */
146 /*****************************************************************************
147 * Create: allocates FB video thread output method
148 *****************************************************************************
149 * This function allocates and initializes a FB vout method.
150 *****************************************************************************/
151 static int Create( vlc_object_t *p_this )
153 vout_thread_t *p_vout = (vout_thread_t *)p_this;
158 struct sigaction sig_tty; /* sigaction for tty change */
159 struct vt_mode vt_mode; /* vt current mode */
160 struct termios new_termios;
162 /* Allocate instance and initialize some members */
163 p_vout->p_sys = p_sys = malloc( sizeof( vout_sys_t ) );
164 if( p_vout->p_sys == NULL )
166 msg_Err( p_vout, "out of memory" );
169 memset( p_sys, 0, sizeof(vout_sys_t) );
171 p_vout->pf_init = Init;
172 p_vout->pf_end = End;
173 p_vout->pf_manage = Manage;
174 p_vout->pf_render = NULL;
175 p_vout->pf_display = Display;
176 p_vout->pf_control = Control;
178 /* Set tty and fb devices */
179 p_sys->i_tty = 0; /* 0 == /dev/tty0 == current console */
180 p_sys->b_tty = var_CreateGetBool( p_vout, "fb-tty" );
182 #if defined(HAVE_ISATTY)
183 /* Check that stdin is a TTY */
184 if( p_sys->b_tty && !isatty( 0 ) )
186 msg_Warn( p_vout, "fd 0 is not a TTY" );
191 msg_Warn( p_vout, "disabling tty handling, use with caution because "
192 "there is no way to return to the tty." );
197 psz_chroma = var_CreateGetNonEmptyString( p_vout, "fb-chroma" );
200 if( strlen( psz_chroma ) == 4 )
202 p_sys->i_chroma = VLC_FOURCC( psz_chroma[0],
206 msg_Dbg( p_vout, "forcing chroma '%s'", psz_chroma );
210 msg_Warn( p_vout, "invalid chroma (%s), using defaults.",
217 p_sys->i_aspect = -1;
218 psz_aspect = var_CreateGetNonEmptyString( p_vout, "fb-aspect-ratio" );
221 char *psz_parser = strchr( psz_aspect, ':' );
225 *psz_parser++ = '\0';
226 p_sys->i_aspect = ( atoi( psz_aspect )
227 * VOUT_ASPECT_FACTOR ) / atoi( psz_parser );
229 msg_Dbg( p_vout, "using aspect ratio %d:%d",
230 atoi( psz_aspect ), atoi( psz_parser ) );
236 p_sys->b_auto = VLC_FALSE;
237 i_mode = var_CreateGetInteger( p_vout, "fb-mode" );
241 p_sys->i_width = 176;
242 p_sys->i_height = 144;
245 p_sys->i_width = 352;
246 p_sys->i_height = 288;
249 p_sys->i_width = 640;
250 p_sys->i_height = 480;
253 p_sys->i_width = 704;
254 p_sys->i_height = 576;
258 p_sys->b_auto = VLC_TRUE;
265 GfxMode( p_sys->i_tty );
267 /* Set keyboard settings */
268 if( tcgetattr(0, &p_vout->p_sys->old_termios) == -1 )
270 msg_Err( p_vout, "tcgetattr failed" );
273 if( tcgetattr(0, &new_termios) == -1 )
275 msg_Err( p_vout, "tcgetattr failed" );
278 /* new_termios.c_lflag &= ~ (ICANON | ISIG);
279 new_termios.c_lflag |= (ECHO | ECHOCTL); */
280 new_termios.c_lflag &= ~ (ICANON);
281 new_termios.c_lflag &= ~(ECHO | ECHOCTL);
282 new_termios.c_iflag = 0;
283 new_termios.c_cc[VMIN] = 1;
284 new_termios.c_cc[VTIME] = 0;
286 if( tcsetattr(0, TCSAFLUSH, &new_termios) == -1 )
288 msg_Err( p_vout, "tcsetattr failed" );
291 ioctl( p_sys->i_tty, VT_RELDISP, VT_ACKACQ );
293 /* Set-up tty signal handler to be aware of tty changes */
294 memset( &sig_tty, 0, sizeof( sig_tty ) );
295 sig_tty.sa_handler = SwitchDisplay;
296 sigemptyset( &sig_tty.sa_mask );
297 if( sigaction( SIGUSR1, &sig_tty, &p_vout->p_sys->sig_usr1 ) ||
298 sigaction( SIGUSR2, &sig_tty, &p_vout->p_sys->sig_usr2 ) )
300 msg_Err( p_vout, "cannot set signal handler (%m)" );
301 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
302 TextMode( p_sys->i_tty );
303 free( p_vout->p_sys );
307 /* Set-up tty according to new signal handler */
308 if( -1 == ioctl( p_sys->i_tty, VT_GETMODE, &p_vout->p_sys->vt_mode ) )
310 msg_Err( p_vout, "cannot get terminal mode (%m)" );
311 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
312 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
313 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
314 TextMode( p_sys->i_tty );
315 free( p_vout->p_sys );
318 memcpy( &vt_mode, &p_vout->p_sys->vt_mode, sizeof( vt_mode ) );
319 vt_mode.mode = VT_PROCESS;
321 vt_mode.relsig = SIGUSR1;
322 vt_mode.acqsig = SIGUSR2;
324 if( -1 == ioctl( p_sys->i_tty, VT_SETMODE, &vt_mode ) )
326 msg_Err( p_vout, "cannot set terminal mode (%m)" );
327 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
328 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
329 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
330 TextMode( p_sys->i_tty );
331 free( p_vout->p_sys );
336 if( OpenDisplay( p_vout ) )
340 ioctl( p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode );
341 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
342 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
343 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
344 TextMode( p_sys->i_tty );
346 free( p_vout->p_sys );
353 /*****************************************************************************
354 * Init: initialize framebuffer video thread output method
355 *****************************************************************************/
356 static int Init( vout_thread_t *p_vout )
358 vout_sys_t *p_sys = p_vout->p_sys;
362 I_OUTPUTPICTURES = 0;
364 if( p_sys->i_chroma == 0 )
366 /* Initialize the output structure: RGB with square pixels, whatever
367 * the input format is, since it's the only format we know */
368 switch( p_sys->var_info.bits_per_pixel )
370 case 8: /* FIXME: set the palette */
371 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2'); break;
373 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5'); break;
375 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6'); break;
377 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4'); break;
379 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2'); break;
381 msg_Err( p_vout, "unknown screen depth %i",
382 p_vout->p_sys->var_info.bits_per_pixel );
386 if( p_sys->var_info.bits_per_pixel != 8 )
388 p_vout->output.i_rmask = ( (1 << p_sys->var_info.red.length) - 1 )
389 << p_sys->var_info.red.offset;
390 p_vout->output.i_gmask = ( (1 << p_sys->var_info.green.length) - 1 )
391 << p_sys->var_info.green.offset;
392 p_vout->output.i_bmask = ( (1 << p_sys->var_info.blue.length) - 1 )
393 << p_sys->var_info.blue.offset;
398 p_vout->output.i_chroma = p_sys->i_chroma;
400 p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
404 p_vout->render.i_width = p_sys->i_width;
405 p_vout->render.i_height = p_sys->i_height;
407 p_vout->output.i_width = p_sys->i_width;
408 p_vout->output.i_height = p_sys->i_height;
410 /* Assume we have square pixels */
411 if( p_sys->i_aspect < 0 )
413 p_vout->output.i_aspect = ( p_sys->i_width
414 * VOUT_ASPECT_FACTOR ) / p_sys->i_height;
416 else p_vout->output.i_aspect = p_sys->i_aspect;
418 p_vout->fmt_out.i_sar_num = p_vout->fmt_out.i_sar_den = 1;
419 p_vout->fmt_out.i_aspect = p_vout->render.i_aspect = p_vout->output.i_aspect;
421 /* Clear the screen */
422 memset( p_sys->p_video, 0, p_sys->i_page_size );
424 /* Try to initialize 1 direct buffer */
427 /* Find an empty picture slot */
428 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
430 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
432 p_pic = p_vout->p_picture + i_index;
437 /* Allocate the picture */
443 /* We know the chroma, allocate a buffer which will be used
444 * directly by the decoder */
445 p_pic->p->p_pixels = p_vout->p_sys->p_video;
446 p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel;
447 p_pic->p->i_lines = p_vout->p_sys->var_info.yres;
448 p_pic->p->i_visible_lines = p_vout->p_sys->var_info.yres;
450 if( p_vout->p_sys->var_info.xres_virtual )
452 p_pic->p->i_pitch = p_vout->p_sys->var_info.xres_virtual
453 * p_vout->p_sys->i_bytes_per_pixel;
457 p_pic->p->i_pitch = p_vout->p_sys->var_info.xres
458 * p_vout->p_sys->i_bytes_per_pixel;
461 p_pic->p->i_visible_pitch = p_vout->p_sys->var_info.xres
462 * p_vout->p_sys->i_bytes_per_pixel;
464 p_pic->i_status = DESTROYED_PICTURE;
465 p_pic->i_type = DIRECT_PICTURE;
467 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
474 /*****************************************************************************
475 * End: terminate framebuffer video thread output method
476 *****************************************************************************/
477 static void End( vout_thread_t *p_vout )
479 /* Clear the screen */
480 memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
483 /*****************************************************************************
484 * Destroy: destroy FB video thread output method
485 *****************************************************************************
486 * Terminate an output method created by Create
487 *****************************************************************************/
488 static void Destroy( vlc_object_t *p_this )
490 vout_thread_t *p_vout = (vout_thread_t *)p_this;
492 CloseDisplay( p_vout );
494 if( p_vout->p_sys->b_tty )
496 /* Reset the terminal */
497 ioctl( p_vout->p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode );
499 /* Remove signal handlers */
500 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
501 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
503 /* Reset the keyboard state */
504 tcsetattr( 0, 0, &p_vout->p_sys->old_termios );
506 /* Return to text mode */
507 TextMode( p_vout->p_sys->i_tty );
510 /* Destroy structure */
511 free( p_vout->p_sys );
514 /*****************************************************************************
515 * Control: control facility for the vout
516 *****************************************************************************/
517 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
522 return vout_vaControlDefault( p_vout, i_query, args );
526 /*****************************************************************************
527 * Manage: handle FB events
528 *****************************************************************************
529 * This function should be called regularly by video output thread. It manages
530 * console events. It returns a non null value on error.
531 *****************************************************************************/
532 static int Manage( vout_thread_t *p_vout )
537 if ( read(0, &buf, 1) == 1)
542 vlc_object_kill( p_vout->p_libvlc );
554 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
556 msg_Dbg( p_vout, "reinitializing framebuffer screen" );
557 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
559 /* Destroy XImages to change their size */
562 /* Recreate XImages. If SysInit failed, the thread can't go on. */
565 msg_Err( p_vout, "cannot reinit framebuffer screen" );
570 memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
573 /* Tell the video output thread that it will need to rebuild YUV
574 * tables. This is needed since conversion buffer size may have changed */
575 p_vout->i_changes |= VOUT_YUV_CHANGE;
582 /*****************************************************************************
583 * Display: displays previously rendered output
584 *****************************************************************************
585 * This function send the currently rendered image to FB image, waits until
586 * it is displayed and switch the two rendering buffers, preparing next frame.
587 *****************************************************************************/
588 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
591 /* swap the two Y offsets if the drivers supports panning */
592 if( p_vout->p_sys->b_pan )
594 p_vout->p_sys->var_info.yoffset = 0;
595 /*p_vout->p_sys->var_info.yoffset = p_vout->p_sys->var_info.yres; */
597 /* the X offset should be 0, but who knows ...
598 * some other app might have played with the framebuffer */
599 p_vout->p_sys->var_info.xoffset = 0;
603 ioctl( p_vout->p_sys->i_fd,
604 FBIOPAN_DISPLAY, &p_vout->p_sys->var_info );
611 static void SetPalette( vout_thread_t *p_vout, uint16_t *red, uint16_t *green,
612 uint16_t *blue, uint16_t *transp )
614 struct fb_cmap cmap = { 0, 256, red, green, blue, transp };
616 ioctl( p_vout->p_sys->i_fd, FBIOPUTCMAP, &cmap );
620 /* following functions are local */
622 /*****************************************************************************
623 * OpenDisplay: initialize framebuffer
624 *****************************************************************************/
625 static int OpenDisplay( vout_thread_t *p_vout )
627 vout_sys_t *p_sys = (vout_sys_t *) p_vout->p_sys;
628 char *psz_device; /* framebuffer device path */
629 struct fb_fix_screeninfo fix_info; /* framebuffer fix information */
631 /* Open framebuffer device */
632 if( !(psz_device = config_GetPsz( p_vout, FB_DEV_VAR )) )
634 msg_Err( p_vout, "don't know which fb device to open" );
638 p_sys->i_fd = open( psz_device, O_RDWR);
639 if( p_sys->i_fd == -1 )
641 msg_Err( p_vout, "cannot open %s (%m)", psz_device );
648 /* Get framebuffer device information */
649 if( ioctl( p_sys->i_fd, FBIOGET_VSCREENINFO, &p_sys->var_info ) )
651 msg_Err( p_vout, "cannot get fb info (%m)" );
652 close( p_sys->i_fd );
656 memcpy( &p_sys->old_info, &p_sys->var_info,
657 sizeof( struct fb_var_screeninfo ) );
659 /* Get some info on the framebuffer itself */
662 p_sys->var_info.xres = p_sys->var_info.xres_virtual = p_sys->i_width;
663 p_sys->var_info.yres = p_sys->var_info.yres_virtual = p_sys->i_height;
664 p_vout->fmt_out.i_width = p_sys->i_width;
665 p_vout->fmt_out.i_height = p_sys->i_height;
668 /* Set some attributes */
669 p_sys->var_info.activate = p_sys->b_tty
670 ? FB_ACTIVATE_NXTOPEN
672 p_sys->var_info.xoffset = 0;
673 p_sys->var_info.yoffset = 0;
675 if( ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->var_info ) )
677 msg_Err( p_vout, "cannot set fb info (%m)" );
678 close( p_sys->i_fd );
682 /* Get some information again, in the definitive configuration */
683 if( ioctl( p_sys->i_fd, FBIOGET_FSCREENINFO, &fix_info )
684 || ioctl( p_sys->i_fd, FBIOGET_VSCREENINFO, &p_sys->var_info ) )
686 msg_Err( p_vout, "cannot get additional fb info (%m)" );
688 /* Restore fb config */
689 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->old_info );
691 close( p_sys->i_fd );
695 /* If the fb has limitations on mode change,
696 * then keep the resolution of the fb */
697 if( (p_sys->i_height != p_sys->var_info.yres) ||
698 (p_sys->i_width != p_sys->var_info.xres) )
700 p_sys->b_auto = VLC_TRUE;
702 "using framebuffer native resolution instead of requested (%ix%i)",
703 p_sys->i_width, p_sys->i_height );
705 p_sys->i_height = p_sys->var_info.yres;
706 p_sys->i_width = p_sys->var_info.xres_virtual
707 ? p_sys->var_info.xres_virtual
708 : p_sys->var_info.xres;
710 /* FIXME: if the image is full-size, it gets cropped on the left
711 * because of the xres / xres_virtual slight difference */
712 msg_Dbg( p_vout, "%ix%i (virtual %ix%i) (request %ix%i)",
713 p_sys->var_info.xres, p_sys->var_info.yres,
714 p_sys->var_info.xres_virtual,
715 p_sys->var_info.yres_virtual,
716 p_sys->i_width, p_sys->i_height );
718 p_sys->p_palette = NULL;
719 p_sys->b_pan = ( fix_info.ypanstep || fix_info.ywrapstep );
721 switch( p_sys->var_info.bits_per_pixel )
724 p_sys->p_palette = malloc( 8 * 256 * sizeof( uint16_t ) );
725 if( !p_sys->p_palette )
727 msg_Err( p_vout, "out of memory" );
729 /* Restore fb config */
730 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->old_info );
732 close( p_sys->i_fd );
735 p_sys->fb_cmap.start = 0;
736 p_sys->fb_cmap.len = 256;
737 p_sys->fb_cmap.red = p_sys->p_palette;
738 p_sys->fb_cmap.green = p_sys->p_palette + 256 * sizeof( uint16_t );
739 p_sys->fb_cmap.blue = p_sys->p_palette + 2 * 256 * sizeof( uint16_t );
740 p_sys->fb_cmap.transp = p_sys->p_palette + 3 * 256 * sizeof( uint16_t );
742 /* Save the colormap */
743 ioctl( p_sys->i_fd, FBIOGETCMAP, &p_sys->fb_cmap );
745 p_sys->i_bytes_per_pixel = 1;
750 p_sys->i_bytes_per_pixel = 2;
754 p_sys->i_bytes_per_pixel = 3;
758 p_sys->i_bytes_per_pixel = 4;
762 msg_Err( p_vout, "screen depth %d is not supported",
763 p_sys->var_info.bits_per_pixel );
765 /* Restore fb config */
766 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->old_info );
768 close( p_sys->i_fd );
772 p_sys->i_page_size = p_sys->i_width * p_sys->i_height *
773 p_sys->i_bytes_per_pixel;
775 /* Map a framebuffer at the beginning */
776 p_sys->p_video = mmap( 0, p_sys->i_page_size,
777 PROT_READ | PROT_WRITE, MAP_SHARED,
780 if( p_sys->p_video == ((void*)-1) )
782 msg_Err( p_vout, "cannot map video memory (%m)" );
784 if( p_sys->var_info.bits_per_pixel == 8 )
786 free( p_sys->p_palette );
787 p_sys->p_palette = NULL;
790 /* Restore fb config */
791 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_vout->p_sys->old_info );
793 close( p_sys->i_fd );
797 msg_Dbg( p_vout, "framebuffer type=%d, visual=%d, ypanstep=%d, "
798 "ywrap=%d, accel=%d", fix_info.type, fix_info.visual,
799 fix_info.ypanstep, fix_info.ywrapstep, fix_info.accel );
803 /*****************************************************************************
804 * CloseDisplay: terminate FB video thread output method
805 *****************************************************************************/
806 static void CloseDisplay( vout_thread_t *p_vout )
809 memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
811 /* Restore palette */
812 if( p_vout->p_sys->var_info.bits_per_pixel == 8 )
814 ioctl( p_vout->p_sys->i_fd,
815 FBIOPUTCMAP, &p_vout->p_sys->fb_cmap );
816 free( p_vout->p_sys->p_palette );
817 p_vout->p_sys->p_palette = NULL;
820 /* Restore fb config */
821 ioctl( p_vout->p_sys->i_fd,
822 FBIOPUT_VSCREENINFO, &p_vout->p_sys->old_info );
825 close( p_vout->p_sys->i_fd );
828 /*****************************************************************************
829 * SwitchDisplay: VT change signal handler
830 *****************************************************************************
831 * This function activates or deactivates the output of the thread. It is
832 * called by the VT driver, on terminal change.
833 *****************************************************************************/
834 static void SwitchDisplay(int i_signal)
837 vout_thread_t *p_vout;
839 vlc_mutex_lock( &p_vout_bank->lock );
841 /* XXX: only test the first video output */
842 if( p_vout_bank->i_count )
844 p_vout = p_vout_bank->pp_vout[0];
848 case SIGUSR1: /* vt has been released */
849 p_vout->b_active = 0;
850 ioctl( p_sys->i_tty, VT_RELDISP, 1 );
852 case SIGUSR2: /* vt has been acquired */
853 p_vout->b_active = 1;
854 ioctl( p_sys->i_tty, VT_RELDISP, VT_ACTIVATE );
855 /* handle blanking */
856 vlc_mutex_lock( &p_vout->change_lock );
857 p_vout->i_changes |= VOUT_SIZE_CHANGE;
858 vlc_mutex_unlock( &p_vout->change_lock );
863 vlc_mutex_unlock( &p_vout_bank->lock );
867 /*****************************************************************************
868 * TextMode and GfxMode : switch tty to text/graphic mode
869 *****************************************************************************
870 * These functions toggle the tty mode.
871 *****************************************************************************/
872 static void TextMode( int i_tty )
874 /* return to text mode */
875 if( -1 == ioctl(i_tty, KDSETMODE, KD_TEXT) )
877 /*msg_Err( p_vout, "failed ioctl KDSETMODE KD_TEXT" );*/
881 static void GfxMode( int i_tty )
883 /* switch to graphic mode */
884 if( -1 == ioctl(i_tty, KDSETMODE, KD_GRAPHICS) )
886 /*msg_Err( p_vout, "failed ioctl KDSETMODE KD_GRAPHICS" );*/