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 change_safe(); /* ioctl() prevents doing bad things */
96 add_bool( "fb-tty", 1, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
98 add_string( "fb-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
101 add_string( "fb-aspect-ratio", NULL, NULL, ASPECT_RATIO_TEXT,
102 ASPECT_RATIO_LONGTEXT, VLC_TRUE );
104 add_integer( "fb-mode", 4, NULL, FB_MODE_TEXT, FB_MODE_LONGTEXT,
107 set_description( _("GNU/Linux console framebuffer video output") );
108 set_capability( "video output", 30 );
109 set_callbacks( Create, Destroy );
112 /*****************************************************************************
113 * vout_sys_t: video output framebuffer method descriptor
114 *****************************************************************************
115 * This structure is part of the video output thread descriptor.
116 * It describes the FB specific properties of an output thread.
117 *****************************************************************************/
120 /* System information */
121 int i_tty; /* tty device handle */
123 struct termios old_termios;
125 /* Original configuration information */
126 struct sigaction sig_usr1; /* USR1 previous handler */
127 struct sigaction sig_usr2; /* USR2 previous handler */
128 struct vt_mode vt_mode; /* previous VT mode */
130 /* Framebuffer information */
131 int i_fd; /* device handle */
132 struct fb_var_screeninfo old_info; /* original mode information */
133 struct fb_var_screeninfo var_info; /* current mode information */
134 vlc_bool_t b_pan; /* does device supports panning ? */
135 struct fb_cmap fb_cmap; /* original colormap */
136 uint16_t *p_palette; /* original palette */
138 /* Video information */
142 int i_bytes_per_pixel;
143 vlc_bool_t b_auto; /* Automatically adjust video size to fb size */
144 vlc_fourcc_t i_chroma;
147 byte_t * p_video; /* base adress */
148 size_t i_page_size; /* page size */
151 /*****************************************************************************
152 * Create: allocates FB video thread output method
153 *****************************************************************************
154 * This function allocates and initializes a FB vout method.
155 *****************************************************************************/
156 static int Create( vlc_object_t *p_this )
158 vout_thread_t *p_vout = (vout_thread_t *)p_this;
163 struct sigaction sig_tty; /* sigaction for tty change */
164 struct vt_mode vt_mode; /* vt current mode */
165 struct termios new_termios;
167 /* Allocate instance and initialize some members */
168 p_vout->p_sys = p_sys = malloc( sizeof( vout_sys_t ) );
169 if( p_vout->p_sys == NULL )
171 msg_Err( p_vout, "out of memory" );
174 memset( p_sys, 0, sizeof(vout_sys_t) );
176 p_vout->pf_init = Init;
177 p_vout->pf_end = End;
178 p_vout->pf_manage = Manage;
179 p_vout->pf_render = NULL;
180 p_vout->pf_display = Display;
181 p_vout->pf_control = Control;
183 /* Set tty and fb devices */
184 p_sys->i_tty = 0; /* 0 == /dev/tty0 == current console */
185 p_sys->b_tty = var_CreateGetBool( p_vout, "fb-tty" );
187 #if defined(HAVE_ISATTY)
188 /* Check that stdin is a TTY */
189 if( p_sys->b_tty && !isatty( 0 ) )
191 msg_Warn( p_vout, "fd 0 is not a TTY" );
196 msg_Warn( p_vout, "disabling tty handling, use with caution because "
197 "there is no way to return to the tty." );
202 psz_chroma = var_CreateGetNonEmptyString( p_vout, "fb-chroma" );
205 if( strlen( psz_chroma ) == 4 )
207 p_sys->i_chroma = VLC_FOURCC( psz_chroma[0],
211 msg_Dbg( p_vout, "forcing chroma '%s'", psz_chroma );
215 msg_Warn( p_vout, "invalid chroma (%s), using defaults.",
222 p_sys->i_aspect = -1;
223 psz_aspect = var_CreateGetNonEmptyString( p_vout, "fb-aspect-ratio" );
226 char *psz_parser = strchr( psz_aspect, ':' );
230 *psz_parser++ = '\0';
231 p_sys->i_aspect = ( atoi( psz_aspect )
232 * VOUT_ASPECT_FACTOR ) / atoi( psz_parser );
234 msg_Dbg( p_vout, "using aspect ratio %d:%d",
235 atoi( psz_aspect ), atoi( psz_parser ) );
241 p_sys->b_auto = VLC_FALSE;
242 i_mode = var_CreateGetInteger( p_vout, "fb-mode" );
246 p_sys->i_width = 176;
247 p_sys->i_height = 144;
250 p_sys->i_width = 352;
251 p_sys->i_height = 288;
254 p_sys->i_width = 640;
255 p_sys->i_height = 480;
258 p_sys->i_width = 704;
259 p_sys->i_height = 576;
263 p_sys->b_auto = VLC_TRUE;
270 GfxMode( p_sys->i_tty );
272 /* Set keyboard settings */
273 if( tcgetattr(0, &p_vout->p_sys->old_termios) == -1 )
275 msg_Err( p_vout, "tcgetattr failed" );
278 if( tcgetattr(0, &new_termios) == -1 )
280 msg_Err( p_vout, "tcgetattr failed" );
283 /* new_termios.c_lflag &= ~ (ICANON | ISIG);
284 new_termios.c_lflag |= (ECHO | ECHOCTL); */
285 new_termios.c_lflag &= ~ (ICANON);
286 new_termios.c_lflag &= ~(ECHO | ECHOCTL);
287 new_termios.c_iflag = 0;
288 new_termios.c_cc[VMIN] = 1;
289 new_termios.c_cc[VTIME] = 0;
291 if( tcsetattr(0, TCSAFLUSH, &new_termios) == -1 )
293 msg_Err( p_vout, "tcsetattr failed" );
296 ioctl( p_sys->i_tty, VT_RELDISP, VT_ACKACQ );
298 /* Set-up tty signal handler to be aware of tty changes */
299 memset( &sig_tty, 0, sizeof( sig_tty ) );
300 sig_tty.sa_handler = SwitchDisplay;
301 sigemptyset( &sig_tty.sa_mask );
302 if( sigaction( SIGUSR1, &sig_tty, &p_vout->p_sys->sig_usr1 ) ||
303 sigaction( SIGUSR2, &sig_tty, &p_vout->p_sys->sig_usr2 ) )
305 msg_Err( p_vout, "cannot set signal handler (%m)" );
306 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
307 TextMode( p_sys->i_tty );
308 free( p_vout->p_sys );
312 /* Set-up tty according to new signal handler */
313 if( -1 == ioctl( p_sys->i_tty, VT_GETMODE, &p_vout->p_sys->vt_mode ) )
315 msg_Err( p_vout, "cannot get terminal mode (%m)" );
316 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
317 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
318 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
319 TextMode( p_sys->i_tty );
320 free( p_vout->p_sys );
323 memcpy( &vt_mode, &p_vout->p_sys->vt_mode, sizeof( vt_mode ) );
324 vt_mode.mode = VT_PROCESS;
326 vt_mode.relsig = SIGUSR1;
327 vt_mode.acqsig = SIGUSR2;
329 if( -1 == ioctl( p_sys->i_tty, VT_SETMODE, &vt_mode ) )
331 msg_Err( p_vout, "cannot set terminal mode (%m)" );
332 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
333 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
334 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
335 TextMode( p_sys->i_tty );
336 free( p_vout->p_sys );
341 if( OpenDisplay( p_vout ) )
345 ioctl( p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode );
346 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
347 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
348 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
349 TextMode( p_sys->i_tty );
351 free( p_vout->p_sys );
358 /*****************************************************************************
359 * Init: initialize framebuffer video thread output method
360 *****************************************************************************/
361 static int Init( vout_thread_t *p_vout )
363 vout_sys_t *p_sys = p_vout->p_sys;
367 I_OUTPUTPICTURES = 0;
369 if( p_sys->i_chroma == 0 )
371 /* Initialize the output structure: RGB with square pixels, whatever
372 * the input format is, since it's the only format we know */
373 switch( p_sys->var_info.bits_per_pixel )
375 case 8: /* FIXME: set the palette */
376 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2'); break;
378 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5'); break;
380 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6'); break;
382 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4'); break;
384 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2'); break;
386 msg_Err( p_vout, "unknown screen depth %i",
387 p_vout->p_sys->var_info.bits_per_pixel );
391 if( p_sys->var_info.bits_per_pixel != 8 )
393 p_vout->output.i_rmask = ( (1 << p_sys->var_info.red.length) - 1 )
394 << p_sys->var_info.red.offset;
395 p_vout->output.i_gmask = ( (1 << p_sys->var_info.green.length) - 1 )
396 << p_sys->var_info.green.offset;
397 p_vout->output.i_bmask = ( (1 << p_sys->var_info.blue.length) - 1 )
398 << p_sys->var_info.blue.offset;
403 p_vout->output.i_chroma = p_sys->i_chroma;
405 p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
409 p_vout->render.i_width = p_sys->i_width;
410 p_vout->render.i_height = p_sys->i_height;
412 p_vout->output.i_width = p_sys->i_width;
413 p_vout->output.i_height = p_sys->i_height;
415 /* Assume we have square pixels */
416 if( p_sys->i_aspect < 0 )
418 p_vout->output.i_aspect = ( p_sys->i_width
419 * VOUT_ASPECT_FACTOR ) / p_sys->i_height;
421 else p_vout->output.i_aspect = p_sys->i_aspect;
423 p_vout->fmt_out.i_sar_num = p_vout->fmt_out.i_sar_den = 1;
424 p_vout->fmt_out.i_aspect = p_vout->render.i_aspect = p_vout->output.i_aspect;
426 /* Clear the screen */
427 memset( p_sys->p_video, 0, p_sys->i_page_size );
429 /* Try to initialize 1 direct buffer */
432 /* Find an empty picture slot */
433 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
435 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
437 p_pic = p_vout->p_picture + i_index;
442 /* Allocate the picture */
448 /* We know the chroma, allocate a buffer which will be used
449 * directly by the decoder */
450 p_pic->p->p_pixels = p_vout->p_sys->p_video;
451 p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel;
452 p_pic->p->i_lines = p_vout->p_sys->var_info.yres;
453 p_pic->p->i_visible_lines = p_vout->p_sys->var_info.yres;
455 if( p_vout->p_sys->var_info.xres_virtual )
457 p_pic->p->i_pitch = p_vout->p_sys->var_info.xres_virtual
458 * p_vout->p_sys->i_bytes_per_pixel;
462 p_pic->p->i_pitch = p_vout->p_sys->var_info.xres
463 * p_vout->p_sys->i_bytes_per_pixel;
466 p_pic->p->i_visible_pitch = p_vout->p_sys->var_info.xres
467 * p_vout->p_sys->i_bytes_per_pixel;
469 p_pic->i_status = DESTROYED_PICTURE;
470 p_pic->i_type = DIRECT_PICTURE;
472 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
479 /*****************************************************************************
480 * End: terminate framebuffer video thread output method
481 *****************************************************************************/
482 static void End( vout_thread_t *p_vout )
484 /* Clear the screen */
485 memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
488 /*****************************************************************************
489 * Destroy: destroy FB video thread output method
490 *****************************************************************************
491 * Terminate an output method created by Create
492 *****************************************************************************/
493 static void Destroy( vlc_object_t *p_this )
495 vout_thread_t *p_vout = (vout_thread_t *)p_this;
497 CloseDisplay( p_vout );
499 if( p_vout->p_sys->b_tty )
501 /* Reset the terminal */
502 ioctl( p_vout->p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode );
504 /* Remove signal handlers */
505 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
506 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
508 /* Reset the keyboard state */
509 tcsetattr( 0, 0, &p_vout->p_sys->old_termios );
511 /* Return to text mode */
512 TextMode( p_vout->p_sys->i_tty );
515 /* Destroy structure */
516 free( p_vout->p_sys );
519 /*****************************************************************************
520 * Control: control facility for the vout
521 *****************************************************************************/
522 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
527 return vout_vaControlDefault( p_vout, i_query, args );
531 /*****************************************************************************
532 * Manage: handle FB events
533 *****************************************************************************
534 * This function should be called regularly by video output thread. It manages
535 * console events. It returns a non null value on error.
536 *****************************************************************************/
537 static int Manage( vout_thread_t *p_vout )
542 if ( read(0, &buf, 1) == 1)
547 vlc_object_kill( p_vout->p_libvlc );
559 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
561 msg_Dbg( p_vout, "reinitializing framebuffer screen" );
562 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
564 /* Destroy XImages to change their size */
567 /* Recreate XImages. If SysInit failed, the thread can't go on. */
570 msg_Err( p_vout, "cannot reinit framebuffer screen" );
575 memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
578 /* Tell the video output thread that it will need to rebuild YUV
579 * tables. This is needed since conversion buffer size may have changed */
580 p_vout->i_changes |= VOUT_YUV_CHANGE;
587 /*****************************************************************************
588 * Display: displays previously rendered output
589 *****************************************************************************
590 * This function send the currently rendered image to FB image, waits until
591 * it is displayed and switch the two rendering buffers, preparing next frame.
592 *****************************************************************************/
593 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
596 /* swap the two Y offsets if the drivers supports panning */
597 if( p_vout->p_sys->b_pan )
599 p_vout->p_sys->var_info.yoffset = 0;
600 /*p_vout->p_sys->var_info.yoffset = p_vout->p_sys->var_info.yres; */
602 /* the X offset should be 0, but who knows ...
603 * some other app might have played with the framebuffer */
604 p_vout->p_sys->var_info.xoffset = 0;
608 ioctl( p_vout->p_sys->i_fd,
609 FBIOPAN_DISPLAY, &p_vout->p_sys->var_info );
616 static void SetPalette( vout_thread_t *p_vout, uint16_t *red, uint16_t *green,
617 uint16_t *blue, uint16_t *transp )
619 struct fb_cmap cmap = { 0, 256, red, green, blue, transp };
621 ioctl( p_vout->p_sys->i_fd, FBIOPUTCMAP, &cmap );
625 /* following functions are local */
627 /*****************************************************************************
628 * OpenDisplay: initialize framebuffer
629 *****************************************************************************/
630 static int OpenDisplay( vout_thread_t *p_vout )
632 vout_sys_t *p_sys = (vout_sys_t *) p_vout->p_sys;
633 char *psz_device; /* framebuffer device path */
634 struct fb_fix_screeninfo fix_info; /* framebuffer fix information */
636 /* Open framebuffer device */
637 if( !(psz_device = config_GetPsz( p_vout, FB_DEV_VAR )) )
639 msg_Err( p_vout, "don't know which fb device to open" );
643 p_sys->i_fd = open( psz_device, O_RDWR);
644 if( p_sys->i_fd == -1 )
646 msg_Err( p_vout, "cannot open %s (%m)", psz_device );
653 /* Get framebuffer device information */
654 if( ioctl( p_sys->i_fd, FBIOGET_VSCREENINFO, &p_sys->var_info ) )
656 msg_Err( p_vout, "cannot get fb info (%m)" );
657 close( p_sys->i_fd );
661 memcpy( &p_sys->old_info, &p_sys->var_info,
662 sizeof( struct fb_var_screeninfo ) );
664 /* Get some info on the framebuffer itself */
667 p_sys->var_info.xres = p_sys->var_info.xres_virtual = p_sys->i_width;
668 p_sys->var_info.yres = p_sys->var_info.yres_virtual = p_sys->i_height;
669 p_vout->fmt_out.i_width = p_sys->i_width;
670 p_vout->fmt_out.i_height = p_sys->i_height;
673 /* Set some attributes */
674 p_sys->var_info.activate = p_sys->b_tty
675 ? FB_ACTIVATE_NXTOPEN
677 p_sys->var_info.xoffset = 0;
678 p_sys->var_info.yoffset = 0;
680 if( ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->var_info ) )
682 msg_Err( p_vout, "cannot set fb info (%m)" );
683 close( p_sys->i_fd );
687 /* Get some information again, in the definitive configuration */
688 if( ioctl( p_sys->i_fd, FBIOGET_FSCREENINFO, &fix_info )
689 || ioctl( p_sys->i_fd, FBIOGET_VSCREENINFO, &p_sys->var_info ) )
691 msg_Err( p_vout, "cannot get additional fb info (%m)" );
693 /* Restore fb config */
694 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->old_info );
696 close( p_sys->i_fd );
700 /* If the fb has limitations on mode change,
701 * then keep the resolution of the fb */
702 if( (p_sys->i_height != p_sys->var_info.yres) ||
703 (p_sys->i_width != p_sys->var_info.xres) )
705 p_sys->b_auto = VLC_TRUE;
707 "using framebuffer native resolution instead of requested (%ix%i)",
708 p_sys->i_width, p_sys->i_height );
710 p_sys->i_height = p_sys->var_info.yres;
711 p_sys->i_width = p_sys->var_info.xres_virtual
712 ? p_sys->var_info.xres_virtual
713 : p_sys->var_info.xres;
715 /* FIXME: if the image is full-size, it gets cropped on the left
716 * because of the xres / xres_virtual slight difference */
717 msg_Dbg( p_vout, "%ix%i (virtual %ix%i) (request %ix%i)",
718 p_sys->var_info.xres, p_sys->var_info.yres,
719 p_sys->var_info.xres_virtual,
720 p_sys->var_info.yres_virtual,
721 p_sys->i_width, p_sys->i_height );
723 p_sys->p_palette = NULL;
724 p_sys->b_pan = ( fix_info.ypanstep || fix_info.ywrapstep );
726 switch( p_sys->var_info.bits_per_pixel )
729 p_sys->p_palette = malloc( 8 * 256 * sizeof( uint16_t ) );
730 if( !p_sys->p_palette )
732 msg_Err( p_vout, "out of memory" );
734 /* Restore fb config */
735 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->old_info );
737 close( p_sys->i_fd );
740 p_sys->fb_cmap.start = 0;
741 p_sys->fb_cmap.len = 256;
742 p_sys->fb_cmap.red = p_sys->p_palette;
743 p_sys->fb_cmap.green = p_sys->p_palette + 256 * sizeof( uint16_t );
744 p_sys->fb_cmap.blue = p_sys->p_palette + 2 * 256 * sizeof( uint16_t );
745 p_sys->fb_cmap.transp = p_sys->p_palette + 3 * 256 * sizeof( uint16_t );
747 /* Save the colormap */
748 ioctl( p_sys->i_fd, FBIOGETCMAP, &p_sys->fb_cmap );
750 p_sys->i_bytes_per_pixel = 1;
755 p_sys->i_bytes_per_pixel = 2;
759 p_sys->i_bytes_per_pixel = 3;
763 p_sys->i_bytes_per_pixel = 4;
767 msg_Err( p_vout, "screen depth %d is not supported",
768 p_sys->var_info.bits_per_pixel );
770 /* Restore fb config */
771 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->old_info );
773 close( p_sys->i_fd );
777 p_sys->i_page_size = p_sys->i_width * p_sys->i_height *
778 p_sys->i_bytes_per_pixel;
780 /* Map a framebuffer at the beginning */
781 p_sys->p_video = mmap( 0, p_sys->i_page_size,
782 PROT_READ | PROT_WRITE, MAP_SHARED,
785 if( p_sys->p_video == ((void*)-1) )
787 msg_Err( p_vout, "cannot map video memory (%m)" );
789 if( p_sys->var_info.bits_per_pixel == 8 )
791 free( p_sys->p_palette );
792 p_sys->p_palette = NULL;
795 /* Restore fb config */
796 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_vout->p_sys->old_info );
798 close( p_sys->i_fd );
802 msg_Dbg( p_vout, "framebuffer type=%d, visual=%d, ypanstep=%d, "
803 "ywrap=%d, accel=%d", fix_info.type, fix_info.visual,
804 fix_info.ypanstep, fix_info.ywrapstep, fix_info.accel );
808 /*****************************************************************************
809 * CloseDisplay: terminate FB video thread output method
810 *****************************************************************************/
811 static void CloseDisplay( vout_thread_t *p_vout )
814 memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
816 /* Restore palette */
817 if( p_vout->p_sys->var_info.bits_per_pixel == 8 )
819 ioctl( p_vout->p_sys->i_fd,
820 FBIOPUTCMAP, &p_vout->p_sys->fb_cmap );
821 free( p_vout->p_sys->p_palette );
822 p_vout->p_sys->p_palette = NULL;
825 /* Restore fb config */
826 ioctl( p_vout->p_sys->i_fd,
827 FBIOPUT_VSCREENINFO, &p_vout->p_sys->old_info );
830 close( p_vout->p_sys->i_fd );
833 /*****************************************************************************
834 * SwitchDisplay: VT change signal handler
835 *****************************************************************************
836 * This function activates or deactivates the output of the thread. It is
837 * called by the VT driver, on terminal change.
838 *****************************************************************************/
839 static void SwitchDisplay(int i_signal)
842 vout_thread_t *p_vout;
844 vlc_mutex_lock( &p_vout_bank->lock );
846 /* XXX: only test the first video output */
847 if( p_vout_bank->i_count )
849 p_vout = p_vout_bank->pp_vout[0];
853 case SIGUSR1: /* vt has been released */
854 p_vout->b_active = 0;
855 ioctl( p_sys->i_tty, VT_RELDISP, 1 );
857 case SIGUSR2: /* vt has been acquired */
858 p_vout->b_active = 1;
859 ioctl( p_sys->i_tty, VT_RELDISP, VT_ACTIVATE );
860 /* handle blanking */
861 vlc_mutex_lock( &p_vout->change_lock );
862 p_vout->i_changes |= VOUT_SIZE_CHANGE;
863 vlc_mutex_unlock( &p_vout->change_lock );
868 vlc_mutex_unlock( &p_vout_bank->lock );
872 /*****************************************************************************
873 * TextMode and GfxMode : switch tty to text/graphic mode
874 *****************************************************************************
875 * These functions toggle the tty mode.
876 *****************************************************************************/
877 static void TextMode( int i_tty )
879 /* return to text mode */
880 if( -1 == ioctl(i_tty, KDSETMODE, KD_TEXT) )
882 /*msg_Err( p_vout, "failed ioctl KDSETMODE KD_TEXT" );*/
886 static void GfxMode( int i_tty )
888 /* switch to graphic mode */
889 if( -1 == ioctl(i_tty, KDSETMODE, KD_GRAPHICS) )
891 /*msg_Err( p_vout, "failed ioctl KDSETMODE KD_GRAPHICS" );*/