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* */
48 /*****************************************************************************
50 *****************************************************************************/
51 static int Create ( vlc_object_t * );
52 static void Destroy ( vlc_object_t * );
54 static int Init ( vout_thread_t * );
55 static void End ( vout_thread_t * );
56 static int Manage ( vout_thread_t * );
57 static void Display ( vout_thread_t *, picture_t * );
58 static int Control ( vout_thread_t *, int, va_list );
60 static int OpenDisplay ( vout_thread_t * );
61 static void CloseDisplay ( vout_thread_t * );
62 static void SwitchDisplay ( int i_signal );
63 static void TextMode ( int i_tty );
64 static void GfxMode ( int i_tty );
66 /*****************************************************************************
68 *****************************************************************************/
69 #define FB_DEV_VAR "fbdev"
71 #define DEVICE_TEXT N_("Framebuffer device")
72 #define DEVICE_LONGTEXT N_( \
73 "Framebuffer device to use for rendering (usually /dev/fb0).")
75 #define TTY_TEXT N_("Run fb on current tty.")
76 #define TTY_LONGTEXT N_( \
77 "Run framebuffer on current TTY device (default enabled). " \
78 "(disable tty handling with caution)" )
80 #define CHROMA_TEXT N_("Chroma used.")
81 #define CHROMA_LONGTEXT N_( \
82 "Force use of a specific chroma for output. Default is I420." )
84 #define ASPECT_RATIO_TEXT N_("Video aspect ratio")
85 #define ASPECT_RATIO_LONGTEXT N_( \
86 "Aspect ratio of the video image (4:3, 16:9). Default is square pixels." )
88 #define FB_MODE_TEXT N_("Framebuffer resolution to use.")
89 #define FB_MODE_LONGTEXT N_( \
90 "Select the resolution for the framebuffer. Currently it supports " \
91 "the values 0=QCIF 1=CIF 2=NTSC 3=PAL, 4=auto (default 4=auto)" )
94 set_shortname( "Framebuffer" );
95 set_category( CAT_VIDEO );
96 set_subcategory( SUBCAT_VIDEO_VOUT );
97 add_file( FB_DEV_VAR, "/dev/fb0", NULL, DEVICE_TEXT, DEVICE_LONGTEXT,
99 add_bool( "fb-tty", 1, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
100 add_string( "fb-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
102 add_string( "fb-aspect-ratio", NULL, NULL, ASPECT_RATIO_TEXT,
103 ASPECT_RATIO_LONGTEXT, VLC_TRUE );
104 add_integer( "fb-mode", 4, NULL, FB_MODE_TEXT, FB_MODE_LONGTEXT,
106 set_description( _("GNU/Linux console framebuffer video output") );
107 set_capability( "video output", 30 );
108 set_callbacks( Create, Destroy );
111 /*****************************************************************************
112 * vout_sys_t: video output framebuffer method descriptor
113 *****************************************************************************
114 * This structure is part of the video output thread descriptor.
115 * It describes the FB specific properties of an output thread.
116 *****************************************************************************/
119 /* System information */
120 int i_tty; /* tty device handle */
122 struct termios old_termios;
124 /* Original configuration information */
125 struct sigaction sig_usr1; /* USR1 previous handler */
126 struct sigaction sig_usr2; /* USR2 previous handler */
127 struct vt_mode vt_mode; /* previous VT mode */
129 /* Framebuffer information */
130 int i_fd; /* device handle */
131 struct fb_var_screeninfo old_info; /* original mode information */
132 struct fb_var_screeninfo var_info; /* current mode information */
133 vlc_bool_t b_pan; /* does device supports panning ? */
134 struct fb_cmap fb_cmap; /* original colormap */
135 uint16_t *p_palette; /* original palette */
137 /* Video information */
141 int i_bytes_per_pixel;
142 vlc_bool_t b_auto; /* Automatically adjust video size to fb size */
143 vlc_fourcc_t i_chroma;
146 byte_t * p_video; /* base adress */
147 size_t i_page_size; /* page size */
150 /*****************************************************************************
151 * Create: allocates FB video thread output method
152 *****************************************************************************
153 * This function allocates and initializes a FB vout method.
154 *****************************************************************************/
155 static int Create( vlc_object_t *p_this )
157 vout_thread_t *p_vout = (vout_thread_t *)p_this;
162 struct sigaction sig_tty; /* sigaction for tty change */
163 struct vt_mode vt_mode; /* vt current mode */
164 struct termios new_termios;
166 /* Allocate instance and initialize some members */
167 p_vout->p_sys = p_sys = malloc( sizeof( vout_sys_t ) );
168 if( p_vout->p_sys == NULL )
170 msg_Err( p_vout, "out of memory" );
173 memset( p_sys, 0, sizeof(vout_sys_t) );
175 p_vout->pf_init = Init;
176 p_vout->pf_end = End;
177 p_vout->pf_manage = Manage;
178 p_vout->pf_render = NULL;
179 p_vout->pf_display = Display;
180 p_vout->pf_control = Control;
182 /* Set tty and fb devices */
183 p_sys->i_tty = 0; /* 0 == /dev/tty0 == current console */
184 p_sys->b_tty = var_CreateGetBool( p_vout, "fb-tty" );
186 #if defined(HAVE_ISATTY)
187 /* Check that stdin is a TTY */
188 if( p_sys->b_tty && !isatty( 0 ) )
190 msg_Warn( p_vout, "fd 0 is not a TTY" );
195 msg_Warn( p_vout, "disabling tty handling, use with caution because "
196 "there is no way to return to the tty." );
201 psz_chroma = var_CreateGetNonEmptyString( p_vout, "fb-chroma" );
204 if( strlen( psz_chroma ) == 4 )
206 p_sys->i_chroma = VLC_FOURCC( psz_chroma[0],
210 msg_Dbg( p_vout, "forcing chroma '%s'", psz_chroma );
214 msg_Warn( p_vout, "invalid chroma (%s), using defaults.",
221 p_sys->i_aspect = -1;
222 psz_aspect = var_CreateGetNonEmptyString( p_vout, "fb-aspect-ratio" );
225 char *psz_parser = strchr( psz_aspect, ':' );
229 *psz_parser++ = '\0';
230 p_sys->i_aspect = ( atoi( psz_aspect )
231 * VOUT_ASPECT_FACTOR ) / atoi( psz_parser );
233 msg_Dbg( p_vout, "using aspect ratio %d:%d",
234 atoi( psz_aspect ), atoi( psz_parser ) );
240 p_sys->b_auto = VLC_FALSE;
241 i_mode = var_CreateGetInteger( p_vout, "fb-mode" );
245 p_sys->i_width = 176;
246 p_sys->i_height = 144;
249 p_sys->i_width = 352;
250 p_sys->i_height = 288;
253 p_sys->i_width = 640;
254 p_sys->i_height = 480;
257 p_sys->i_width = 704;
258 p_sys->i_height = 576;
262 p_sys->b_auto = VLC_TRUE;
269 GfxMode( p_sys->i_tty );
271 /* Set keyboard settings */
272 if( tcgetattr(0, &p_vout->p_sys->old_termios) == -1 )
274 msg_Err( p_vout, "tcgetattr failed" );
277 if( tcgetattr(0, &new_termios) == -1 )
279 msg_Err( p_vout, "tcgetattr failed" );
282 /* new_termios.c_lflag &= ~ (ICANON | ISIG);
283 new_termios.c_lflag |= (ECHO | ECHOCTL); */
284 new_termios.c_lflag &= ~ (ICANON);
285 new_termios.c_lflag &= ~(ECHO | ECHOCTL);
286 new_termios.c_iflag = 0;
287 new_termios.c_cc[VMIN] = 1;
288 new_termios.c_cc[VTIME] = 0;
290 if( tcsetattr(0, TCSAFLUSH, &new_termios) == -1 )
292 msg_Err( p_vout, "tcsetattr failed" );
295 ioctl( p_sys->i_tty, VT_RELDISP, VT_ACKACQ );
297 /* Set-up tty signal handler to be aware of tty changes */
298 memset( &sig_tty, 0, sizeof( sig_tty ) );
299 sig_tty.sa_handler = SwitchDisplay;
300 sigemptyset( &sig_tty.sa_mask );
301 if( sigaction( SIGUSR1, &sig_tty, &p_vout->p_sys->sig_usr1 ) ||
302 sigaction( SIGUSR2, &sig_tty, &p_vout->p_sys->sig_usr2 ) )
304 msg_Err( p_vout, "cannot set signal handler (%m)" );
305 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
306 TextMode( p_sys->i_tty );
307 free( p_vout->p_sys );
311 /* Set-up tty according to new signal handler */
312 if( -1 == ioctl( p_sys->i_tty, VT_GETMODE, &p_vout->p_sys->vt_mode ) )
314 msg_Err( p_vout, "cannot get terminal mode (%m)" );
315 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
316 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
317 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
318 TextMode( p_sys->i_tty );
319 free( p_vout->p_sys );
322 memcpy( &vt_mode, &p_vout->p_sys->vt_mode, sizeof( vt_mode ) );
323 vt_mode.mode = VT_PROCESS;
325 vt_mode.relsig = SIGUSR1;
326 vt_mode.acqsig = SIGUSR2;
328 if( -1 == ioctl( p_sys->i_tty, VT_SETMODE, &vt_mode ) )
330 msg_Err( p_vout, "cannot set terminal mode (%m)" );
331 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
332 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
333 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
334 TextMode( p_sys->i_tty );
335 free( p_vout->p_sys );
340 if( OpenDisplay( p_vout ) )
344 ioctl( p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode );
345 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
346 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
347 tcsetattr(0, 0, &p_vout->p_sys->old_termios);
348 TextMode( p_sys->i_tty );
350 free( p_vout->p_sys );
357 /*****************************************************************************
358 * Init: initialize framebuffer video thread output method
359 *****************************************************************************/
360 static int Init( vout_thread_t *p_vout )
362 vout_sys_t *p_sys = p_vout->p_sys;
366 I_OUTPUTPICTURES = 0;
368 if( p_sys->i_chroma == 0 )
370 /* Initialize the output structure: RGB with square pixels, whatever
371 * the input format is, since it's the only format we know */
372 switch( p_sys->var_info.bits_per_pixel )
374 case 8: /* FIXME: set the palette */
375 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2'); break;
377 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5'); break;
379 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6'); break;
381 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4'); break;
383 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2'); break;
385 msg_Err( p_vout, "unknown screen depth %i",
386 p_vout->p_sys->var_info.bits_per_pixel );
390 if( p_sys->var_info.bits_per_pixel != 8 )
392 p_vout->output.i_rmask = ( (1 << p_sys->var_info.red.length) - 1 )
393 << p_sys->var_info.red.offset;
394 p_vout->output.i_gmask = ( (1 << p_sys->var_info.green.length) - 1 )
395 << p_sys->var_info.green.offset;
396 p_vout->output.i_bmask = ( (1 << p_sys->var_info.blue.length) - 1 )
397 << p_sys->var_info.blue.offset;
402 p_vout->output.i_chroma = p_sys->i_chroma;
404 p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
408 p_vout->render.i_width = p_sys->i_width;
409 p_vout->render.i_height = p_sys->i_height;
411 p_vout->output.i_width = p_sys->i_width;
412 p_vout->output.i_height = p_sys->i_height;
414 /* Assume we have square pixels */
415 if( p_sys->i_aspect < 0 )
417 p_vout->output.i_aspect = ( p_sys->i_width
418 * VOUT_ASPECT_FACTOR ) / p_sys->i_height;
420 else p_vout->output.i_aspect = p_sys->i_aspect;
422 p_vout->fmt_out.i_sar_num = p_vout->fmt_out.i_sar_den = 1;
423 p_vout->fmt_out.i_aspect = p_vout->render.i_aspect = p_vout->output.i_aspect;
425 /* Clear the screen */
426 memset( p_sys->p_video, 0, p_sys->i_page_size );
428 /* Try to initialize 1 direct buffer */
431 /* Find an empty picture slot */
432 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
434 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
436 p_pic = p_vout->p_picture + i_index;
441 /* Allocate the picture */
447 /* We know the chroma, allocate a buffer which will be used
448 * directly by the decoder */
449 p_pic->p->p_pixels = p_vout->p_sys->p_video;
450 p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel;
451 p_pic->p->i_lines = p_vout->p_sys->var_info.yres;
452 p_pic->p->i_visible_lines = p_vout->p_sys->var_info.yres;
454 if( p_vout->p_sys->var_info.xres_virtual )
456 p_pic->p->i_pitch = p_vout->p_sys->var_info.xres_virtual
457 * p_vout->p_sys->i_bytes_per_pixel;
461 p_pic->p->i_pitch = p_vout->p_sys->var_info.xres
462 * p_vout->p_sys->i_bytes_per_pixel;
465 p_pic->p->i_visible_pitch = p_vout->p_sys->var_info.xres
466 * p_vout->p_sys->i_bytes_per_pixel;
468 p_pic->i_status = DESTROYED_PICTURE;
469 p_pic->i_type = DIRECT_PICTURE;
471 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
478 /*****************************************************************************
479 * End: terminate framebuffer video thread output method
480 *****************************************************************************/
481 static void End( vout_thread_t *p_vout )
483 /* Clear the screen */
484 memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
487 /*****************************************************************************
488 * Destroy: destroy FB video thread output method
489 *****************************************************************************
490 * Terminate an output method created by Create
491 *****************************************************************************/
492 static void Destroy( vlc_object_t *p_this )
494 vout_thread_t *p_vout = (vout_thread_t *)p_this;
496 CloseDisplay( p_vout );
498 if( p_vout->p_sys->b_tty )
500 /* Reset the terminal */
501 ioctl( p_vout->p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode );
503 /* Remove signal handlers */
504 sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
505 sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
507 /* Reset the keyboard state */
508 tcsetattr( 0, 0, &p_vout->p_sys->old_termios );
510 /* Return to text mode */
511 TextMode( p_vout->p_sys->i_tty );
514 /* Destroy structure */
515 free( p_vout->p_sys );
518 /*****************************************************************************
519 * Control: control facility for the vout
520 *****************************************************************************/
521 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
526 return vout_vaControlDefault( p_vout, i_query, args );
530 /*****************************************************************************
531 * Manage: handle FB events
532 *****************************************************************************
533 * This function should be called regularly by video output thread. It manages
534 * console events. It returns a non null value on error.
535 *****************************************************************************/
536 static int Manage( vout_thread_t *p_vout )
541 if ( read(0, &buf, 1) == 1)
546 vlc_object_kill( p_vout->p_libvlc );
558 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
560 msg_Dbg( p_vout, "reinitializing framebuffer screen" );
561 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
563 /* Destroy XImages to change their size */
566 /* Recreate XImages. If SysInit failed, the thread can't go on. */
569 msg_Err( p_vout, "cannot reinit framebuffer screen" );
574 memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
577 /* Tell the video output thread that it will need to rebuild YUV
578 * tables. This is needed since conversion buffer size may have changed */
579 p_vout->i_changes |= VOUT_YUV_CHANGE;
586 /*****************************************************************************
587 * Display: displays previously rendered output
588 *****************************************************************************
589 * This function send the currently rendered image to FB image, waits until
590 * it is displayed and switch the two rendering buffers, preparing next frame.
591 *****************************************************************************/
592 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
595 /* swap the two Y offsets if the drivers supports panning */
596 if( p_vout->p_sys->b_pan )
598 p_vout->p_sys->var_info.yoffset = 0;
599 /*p_vout->p_sys->var_info.yoffset = p_vout->p_sys->var_info.yres; */
601 /* the X offset should be 0, but who knows ...
602 * some other app might have played with the framebuffer */
603 p_vout->p_sys->var_info.xoffset = 0;
607 ioctl( p_vout->p_sys->i_fd,
608 FBIOPAN_DISPLAY, &p_vout->p_sys->var_info );
615 static void SetPalette( vout_thread_t *p_vout, uint16_t *red, uint16_t *green,
616 uint16_t *blue, uint16_t *transp )
618 struct fb_cmap cmap = { 0, 256, red, green, blue, transp };
620 ioctl( p_vout->p_sys->i_fd, FBIOPUTCMAP, &cmap );
624 /* following functions are local */
626 /*****************************************************************************
627 * OpenDisplay: initialize framebuffer
628 *****************************************************************************/
629 static int OpenDisplay( vout_thread_t *p_vout )
631 vout_sys_t *p_sys = (vout_sys_t *) p_vout->p_sys;
632 char *psz_device; /* framebuffer device path */
633 struct fb_fix_screeninfo fix_info; /* framebuffer fix information */
635 /* Open framebuffer device */
636 if( !(psz_device = config_GetPsz( p_vout, FB_DEV_VAR )) )
638 msg_Err( p_vout, "don't know which fb device to open" );
642 p_sys->i_fd = open( psz_device, O_RDWR);
643 if( p_sys->i_fd == -1 )
645 msg_Err( p_vout, "cannot open %s (%m)", psz_device );
652 /* Get framebuffer device information */
653 if( ioctl( p_sys->i_fd, FBIOGET_VSCREENINFO, &p_sys->var_info ) )
655 msg_Err( p_vout, "cannot get fb info (%m)" );
656 close( p_sys->i_fd );
660 memcpy( &p_sys->old_info, &p_sys->var_info,
661 sizeof( struct fb_var_screeninfo ) );
663 /* Get some info on the framebuffer itself */
666 p_sys->var_info.xres = p_sys->var_info.xres_virtual = p_sys->i_width;
667 p_sys->var_info.yres = p_sys->var_info.yres_virtual = p_sys->i_height;
668 p_vout->fmt_out.i_width = p_sys->i_width;
669 p_vout->fmt_out.i_height = p_sys->i_height;
672 /* Set some attributes */
673 p_sys->var_info.activate = p_sys->b_tty
674 ? FB_ACTIVATE_NXTOPEN
676 p_sys->var_info.xoffset = 0;
677 p_sys->var_info.yoffset = 0;
679 if( ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->var_info ) )
681 msg_Err( p_vout, "cannot set fb info (%m)" );
682 close( p_sys->i_fd );
686 /* Get some information again, in the definitive configuration */
687 if( ioctl( p_sys->i_fd, FBIOGET_FSCREENINFO, &fix_info )
688 || ioctl( p_sys->i_fd, FBIOGET_VSCREENINFO, &p_sys->var_info ) )
690 msg_Err( p_vout, "cannot get additional fb info (%m)" );
692 /* Restore fb config */
693 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->old_info );
695 close( p_sys->i_fd );
699 /* If the fb has limitations on mode change,
700 * then keep the resolution of the fb */
701 if( (p_sys->i_height != p_sys->var_info.yres) ||
702 (p_sys->i_width != p_sys->var_info.xres) )
704 p_sys->b_auto = VLC_TRUE;
706 "using framebuffer native resolution instead of requested (%ix%i)",
707 p_sys->i_width, p_sys->i_height );
709 p_sys->i_height = p_sys->var_info.yres;
710 p_sys->i_width = p_sys->var_info.xres_virtual
711 ? p_sys->var_info.xres_virtual
712 : p_sys->var_info.xres;
714 /* FIXME: if the image is full-size, it gets cropped on the left
715 * because of the xres / xres_virtual slight difference */
716 msg_Dbg( p_vout, "%ix%i (virtual %ix%i) (request %ix%i)",
717 p_sys->var_info.xres, p_sys->var_info.yres,
718 p_sys->var_info.xres_virtual,
719 p_sys->var_info.yres_virtual,
720 p_sys->i_width, p_sys->i_height );
722 p_sys->p_palette = NULL;
723 p_sys->b_pan = ( fix_info.ypanstep || fix_info.ywrapstep );
725 switch( p_sys->var_info.bits_per_pixel )
728 p_sys->p_palette = malloc( 8 * 256 * sizeof( uint16_t ) );
729 if( !p_sys->p_palette )
731 msg_Err( p_vout, "out of memory" );
733 /* Restore fb config */
734 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->old_info );
736 close( p_sys->i_fd );
739 p_sys->fb_cmap.start = 0;
740 p_sys->fb_cmap.len = 256;
741 p_sys->fb_cmap.red = p_sys->p_palette;
742 p_sys->fb_cmap.green = p_sys->p_palette + 256 * sizeof( uint16_t );
743 p_sys->fb_cmap.blue = p_sys->p_palette + 2 * 256 * sizeof( uint16_t );
744 p_sys->fb_cmap.transp = p_sys->p_palette + 3 * 256 * sizeof( uint16_t );
746 /* Save the colormap */
747 ioctl( p_sys->i_fd, FBIOGETCMAP, &p_sys->fb_cmap );
749 p_sys->i_bytes_per_pixel = 1;
754 p_sys->i_bytes_per_pixel = 2;
758 p_sys->i_bytes_per_pixel = 3;
762 p_sys->i_bytes_per_pixel = 4;
766 msg_Err( p_vout, "screen depth %d is not supported",
767 p_sys->var_info.bits_per_pixel );
769 /* Restore fb config */
770 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->old_info );
772 close( p_sys->i_fd );
776 p_sys->i_page_size = p_sys->i_width * p_sys->i_height *
777 p_sys->i_bytes_per_pixel;
779 /* Map a framebuffer at the beginning */
780 p_sys->p_video = mmap( 0, p_sys->i_page_size,
781 PROT_READ | PROT_WRITE, MAP_SHARED,
784 if( p_sys->p_video == ((void*)-1) )
786 msg_Err( p_vout, "cannot map video memory (%m)" );
788 if( p_sys->var_info.bits_per_pixel == 8 )
790 free( p_sys->p_palette );
791 p_sys->p_palette = NULL;
794 /* Restore fb config */
795 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_vout->p_sys->old_info );
797 close( p_sys->i_fd );
801 msg_Dbg( p_vout, "framebuffer type=%d, visual=%d, ypanstep=%d, "
802 "ywrap=%d, accel=%d", fix_info.type, fix_info.visual,
803 fix_info.ypanstep, fix_info.ywrapstep, fix_info.accel );
807 /*****************************************************************************
808 * CloseDisplay: terminate FB video thread output method
809 *****************************************************************************/
810 static void CloseDisplay( vout_thread_t *p_vout )
813 memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
815 /* Restore palette */
816 if( p_vout->p_sys->var_info.bits_per_pixel == 8 )
818 ioctl( p_vout->p_sys->i_fd,
819 FBIOPUTCMAP, &p_vout->p_sys->fb_cmap );
820 free( p_vout->p_sys->p_palette );
821 p_vout->p_sys->p_palette = NULL;
824 /* Restore fb config */
825 ioctl( p_vout->p_sys->i_fd,
826 FBIOPUT_VSCREENINFO, &p_vout->p_sys->old_info );
829 close( p_vout->p_sys->i_fd );
832 /*****************************************************************************
833 * SwitchDisplay: VT change signal handler
834 *****************************************************************************
835 * This function activates or deactivates the output of the thread. It is
836 * called by the VT driver, on terminal change.
837 *****************************************************************************/
838 static void SwitchDisplay(int i_signal)
841 vout_thread_t *p_vout;
843 vlc_mutex_lock( &p_vout_bank->lock );
845 /* XXX: only test the first video output */
846 if( p_vout_bank->i_count )
848 p_vout = p_vout_bank->pp_vout[0];
852 case SIGUSR1: /* vt has been released */
853 p_vout->b_active = 0;
854 ioctl( p_sys->i_tty, VT_RELDISP, 1 );
856 case SIGUSR2: /* vt has been acquired */
857 p_vout->b_active = 1;
858 ioctl( p_sys->i_tty, VT_RELDISP, VT_ACTIVATE );
859 /* handle blanking */
860 vlc_mutex_lock( &p_vout->change_lock );
861 p_vout->i_changes |= VOUT_SIZE_CHANGE;
862 vlc_mutex_unlock( &p_vout->change_lock );
867 vlc_mutex_unlock( &p_vout_bank->lock );
871 /*****************************************************************************
872 * TextMode and GfxMode : switch tty to text/graphic mode
873 *****************************************************************************
874 * These functions toggle the tty mode.
875 *****************************************************************************/
876 static void TextMode( int i_tty )
878 /* return to text mode */
879 if( -1 == ioctl(i_tty, KDSETMODE, KD_TEXT) )
881 /*msg_Err( p_vout, "failed ioctl KDSETMODE KD_TEXT" );*/
885 static void GfxMode( int i_tty )
887 /* switch to graphic mode */
888 if( -1 == ioctl(i_tty, KDSETMODE, KD_GRAPHICS) )
890 /*msg_Err( p_vout, "failed ioctl KDSETMODE KD_GRAPHICS" );*/