1 /*****************************************************************************
2 * fb.c : framebuffer plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2009 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 *****************************************************************************/
33 #include <errno.h> /* ENOMEM */
34 #include <signal.h> /* SIGUSR1, SIGUSR2 */
35 #include <fcntl.h> /* open() */
36 #include <unistd.h> /* close() */
38 #include <termios.h> /* struct termios */
39 #include <sys/ioctl.h>
40 #include <sys/mman.h> /* mmap() */
43 #include <linux/vt.h> /* VT_* */
44 #include <linux/kd.h> /* KD* */
46 #include <vlc_common.h>
47 #include <vlc_plugin.h>
49 #include <vlc_interface.h>
51 /*****************************************************************************
53 *****************************************************************************/
54 #define FB_DEV_VAR "fbdev"
56 #define DEVICE_TEXT N_("Framebuffer device")
57 #define DEVICE_LONGTEXT N_( \
58 "Framebuffer device to use for rendering (usually /dev/fb0).")
60 #define TTY_TEXT N_("Run fb on current tty.")
61 #define TTY_LONGTEXT N_( \
62 "Run framebuffer on current TTY device (default enabled). " \
63 "(disable tty handling with caution)" )
65 #define FB_MODE_TEXT N_("Framebuffer resolution to use.")
66 #define FB_MODE_LONGTEXT N_( \
67 "Select the resolution for the framebuffer. Currently it supports " \
68 "the values 0=QCIF 1=CIF 2=NTSC 3=PAL, 4=auto (default 4=auto)" )
70 #define HW_ACCEL_TEXT N_("Framebuffer uses hw acceleration.")
71 #define HW_ACCEL_LONGTEXT N_( \
72 "If your framebuffer supports hardware acceleration or does double buffering " \
73 "in hardware then you must disable this option. It then does double buffering " \
76 static int Open ( vlc_object_t * );
77 static void Close( vlc_object_t * );
80 set_shortname( "Framebuffer" )
81 set_category( CAT_VIDEO )
82 set_subcategory( SUBCAT_VIDEO_VOUT )
83 add_file( FB_DEV_VAR, "/dev/fb0", NULL, DEVICE_TEXT, DEVICE_LONGTEXT,
85 add_bool( "fb-tty", 1, NULL, TTY_TEXT, TTY_LONGTEXT, true )
86 add_obsolete_string( "fb-chroma" );
87 add_obsolete_string( "fb-aspect-ratio" );
88 add_integer( "fb-mode", 4, NULL, FB_MODE_TEXT, FB_MODE_LONGTEXT,
90 add_bool( "fb-hw-accel", true, NULL, HW_ACCEL_TEXT, HW_ACCEL_LONGTEXT,
92 set_description( N_("GNU/Linux framebuffer video output") )
93 set_capability( "video output", 30 )
94 set_callbacks( Open, Close )
98 /*****************************************************************************
100 *****************************************************************************/
101 static int Init ( vout_thread_t * );
102 static void End ( vout_thread_t * );
103 static int Manage ( vout_thread_t * );
104 static void Display ( vout_thread_t *, picture_t * );
105 static int Control ( vout_thread_t *, int, va_list );
107 static int NewPicture ( vout_thread_t *, picture_t * );
108 static void FreePicture ( vout_thread_t *, picture_t * );
110 static int OpenDisplay ( vout_thread_t * );
111 static void CloseDisplay ( vout_thread_t * );
112 static void SwitchDisplay ( int i_signal );
113 static void TextMode ( int i_tty );
114 static void GfxMode ( int i_tty );
116 static int TtyInit( vout_thread_t * );
117 static void TtyExit( vout_thread_t * );
119 #define MAX_DIRECTBUFFERS 1
121 /*****************************************************************************
122 * vout_sys_t: video output framebuffer method descriptor
123 *****************************************************************************
124 * This structure is part of the video output thread descriptor.
125 * It describes the FB specific properties of an output thread.
126 *****************************************************************************/
129 /* System information */
130 int i_tty; /* tty device handle */
132 struct termios old_termios;
134 /* Original configuration information */
135 struct sigaction sig_usr1; /* USR1 previous handler */
136 struct sigaction sig_usr2; /* USR2 previous handler */
137 struct vt_mode vt_mode; /* previous VT mode */
139 /* Framebuffer information */
140 int i_fd; /* device handle */
141 struct fb_var_screeninfo old_info; /* original mode information */
142 struct fb_var_screeninfo var_info; /* current mode information */
143 bool b_pan; /* does device supports panning ? */
144 struct fb_cmap fb_cmap; /* original colormap */
145 uint16_t *p_palette; /* original palette */
146 bool b_hw_accel; /* has hardware support */
148 /* Video information */
151 int i_bytes_per_pixel;
152 bool b_auto; /* Automatically adjust video size to fb size */
155 uint8_t *p_video; /* base adress */
156 size_t i_page_size; /* page size */
161 uint8_t * p_data; /* base adress */
165 * This function allocates and initializes a FB vout method.
167 static int Open( vlc_object_t *p_this )
169 vout_thread_t *p_vout = (vout_thread_t *)p_this;
172 /* Allocate instance and initialize some members */
173 p_vout->p_sys = p_sys = calloc( 1, sizeof( *p_sys ) );
177 p_sys->p_video = MAP_FAILED;
179 /* Does the framebuffer uses hw acceleration? */
180 p_sys->b_hw_accel = var_CreateGetBool( p_vout, "fb-hw-accel" );
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" );
196 msg_Warn( p_vout, "disabling tty handling, use with caution because "
197 "there is no way to return to the tty." );
202 p_sys->b_auto = false;
203 const int i_mode = var_CreateGetInteger( p_vout, "fb-mode" );
207 p_sys->i_width = 176;
208 p_sys->i_height = 144;
211 p_sys->i_width = 352;
212 p_sys->i_height = 288;
215 p_sys->i_width = 640;
216 p_sys->i_height = 480;
219 p_sys->i_width = 704;
220 p_sys->i_height = 576;
224 p_sys->b_auto = true;
229 if( p_sys->b_tty && TtyInit( p_vout ) )
235 if( OpenDisplay( p_vout ) )
237 Close( VLC_OBJECT(p_vout) );
242 p_vout->pf_init = Init;
243 p_vout->pf_end = End;
244 p_vout->pf_manage = Manage;
245 p_vout->pf_render = NULL;
246 p_vout->pf_display = Display;
247 p_vout->pf_control = Control;
253 * Terminate an output method created by Open
255 static void Close( vlc_object_t *p_this )
257 vout_thread_t *p_vout = (vout_thread_t *)p_this;
259 CloseDisplay( p_vout );
261 if( p_vout->p_sys->b_tty )
264 /* Destroy structure */
265 free( p_vout->p_sys );
268 static int TtyInit( vout_thread_t *p_vout )
270 vout_sys_t *p_sys = p_vout->p_sys;
272 struct termios new_termios;
274 GfxMode( p_sys->i_tty );
276 /* Set keyboard settings */
277 if( tcgetattr(0, &p_sys->old_termios) == -1 )
279 msg_Err( p_vout, "tcgetattr failed" );
282 if( tcgetattr(0, &new_termios) == -1 )
284 msg_Err( p_vout, "tcgetattr failed" );
287 /* new_termios.c_lflag &= ~ (ICANON | ISIG);
288 new_termios.c_lflag |= (ECHO | ECHOCTL); */
289 new_termios.c_lflag &= ~ (ICANON);
290 new_termios.c_lflag &= ~(ECHO | ECHOCTL);
291 new_termios.c_iflag = 0;
292 new_termios.c_cc[VMIN] = 1;
293 new_termios.c_cc[VTIME] = 0;
295 if( tcsetattr(0, TCSAFLUSH, &new_termios) == -1 )
297 msg_Err( p_vout, "tcsetattr failed" );
300 ioctl( p_sys->i_tty, VT_RELDISP, VT_ACKACQ );
302 /* Set-up tty signal handler to be aware of tty changes */
303 struct sigaction sig_tty;
304 memset( &sig_tty, 0, sizeof( sig_tty ) );
305 sig_tty.sa_handler = SwitchDisplay;
306 sigemptyset( &sig_tty.sa_mask );
307 if( sigaction( SIGUSR1, &sig_tty, &p_sys->sig_usr1 ) ||
308 sigaction( SIGUSR2, &sig_tty, &p_sys->sig_usr2 ) )
310 msg_Err( p_vout, "cannot set signal handler (%m)" );
311 tcsetattr(0, 0, &p_sys->old_termios);
312 TextMode( p_sys->i_tty );
316 /* Set-up tty according to new signal handler */
317 if( -1 == ioctl( p_sys->i_tty, VT_GETMODE, &p_sys->vt_mode ) )
319 msg_Err( p_vout, "cannot get terminal mode (%m)" );
320 sigaction( SIGUSR1, &p_sys->sig_usr1, NULL );
321 sigaction( SIGUSR2, &p_sys->sig_usr2, NULL );
322 tcsetattr(0, 0, &p_sys->old_termios);
323 TextMode( p_sys->i_tty );
326 struct vt_mode vt_mode = p_sys->vt_mode;
327 vt_mode.mode = VT_PROCESS;
329 vt_mode.relsig = SIGUSR1;
330 vt_mode.acqsig = SIGUSR2;
332 if( -1 == ioctl( p_sys->i_tty, VT_SETMODE, &vt_mode ) )
334 msg_Err( p_vout, "cannot set terminal mode (%m)" );
335 sigaction( SIGUSR1, &p_sys->sig_usr1, NULL );
336 sigaction( SIGUSR2, &p_sys->sig_usr2, NULL );
337 tcsetattr(0, 0, &p_sys->old_termios);
338 TextMode( p_sys->i_tty );
343 static void TtyExit( vout_thread_t *p_vout )
345 vout_sys_t *p_sys = p_vout->p_sys;
347 /* Reset the terminal */
348 ioctl( p_sys->i_tty, VT_SETMODE, &p_sys->vt_mode );
350 /* Remove signal handlers */
351 sigaction( SIGUSR1, &p_sys->sig_usr1, NULL );
352 sigaction( SIGUSR2, &p_sys->sig_usr2, NULL );
354 /* Reset the keyboard state */
355 tcsetattr( 0, 0, &p_sys->old_termios );
357 /* Return to text mode */
358 TextMode( p_sys->i_tty );
361 /*****************************************************************************
362 * NewPicture: allocate a picture
363 *****************************************************************************
364 * Returns 0 on success, -1 otherwise
365 *****************************************************************************/
366 static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
368 /* We know the chroma, allocate a buffer which will be used
369 * directly by the decoder */
370 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
371 if( p_pic->p_sys == NULL )
376 /* Fill in picture_t fields */
377 if( picture_Setup( p_pic, p_vout->output.i_chroma,
378 p_vout->output.i_width, p_vout->output.i_height,
379 p_vout->output.i_aspect ) )
385 p_pic->p_sys->p_data = malloc( p_vout->p_sys->i_page_size );
386 if( !p_pic->p_sys->p_data )
388 free( p_pic->p_sys );
393 p_pic->p->p_pixels = (uint8_t*) p_pic->p_sys->p_data;
395 p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel;
396 p_pic->p->i_lines = p_vout->p_sys->var_info.yres;
397 p_pic->p->i_visible_lines = p_vout->p_sys->var_info.yres;
399 if( p_vout->p_sys->var_info.xres_virtual )
401 p_pic->p->i_pitch = p_vout->p_sys->var_info.xres_virtual
402 * p_vout->p_sys->i_bytes_per_pixel;
406 p_pic->p->i_pitch = p_vout->p_sys->var_info.xres
407 * p_vout->p_sys->i_bytes_per_pixel;
410 p_pic->p->i_visible_pitch = p_vout->p_sys->var_info.xres
411 * p_vout->p_sys->i_bytes_per_pixel;
417 /*****************************************************************************
418 * FreePicture: destroy a picture allocated with NewPicture
419 *****************************************************************************
420 * Destroy Image AND associated data.
421 *****************************************************************************/
422 static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
425 free( p_pic->p_sys->p_data );
426 free( p_pic->p_sys );
430 /*****************************************************************************
431 * Init: initialize framebuffer video thread output method
432 *****************************************************************************/
433 static int Init( vout_thread_t *p_vout )
435 vout_sys_t *p_sys = p_vout->p_sys;
437 picture_t *p_pic = NULL;
439 I_OUTPUTPICTURES = 0;
441 p_vout->output.i_width = p_vout->render.i_width;
442 p_vout->output.i_height = p_vout->render.i_height;
443 p_vout->output.i_aspect = p_vout->render.i_aspect;
445 p_vout->fmt_out = p_vout->fmt_in;
447 /* Initialize the output structure: RGB with square pixels, whatever
448 * the input format is, since it's the only format we know */
449 switch( p_sys->var_info.bits_per_pixel )
451 case 8: /* FIXME: set the palette */
452 p_vout->output.i_chroma = VLC_CODEC_RGB8; break;
454 p_vout->output.i_chroma = VLC_CODEC_RGB15; break;
456 p_vout->output.i_chroma = VLC_CODEC_RGB16; break;
458 p_vout->output.i_chroma = VLC_CODEC_RGB24; break;
460 p_vout->output.i_chroma = VLC_CODEC_RGB32; break;
462 msg_Err( p_vout, "unknown screen depth %i",
463 p_vout->p_sys->var_info.bits_per_pixel );
467 if( p_sys->var_info.bits_per_pixel != 8 )
469 p_vout->output.i_rmask = ( (1 << p_sys->var_info.red.length) - 1 )
470 << p_sys->var_info.red.offset;
471 p_vout->output.i_gmask = ( (1 << p_sys->var_info.green.length) - 1 )
472 << p_sys->var_info.green.offset;
473 p_vout->output.i_bmask = ( (1 << p_sys->var_info.blue.length) - 1 )
474 << p_sys->var_info.blue.offset;
476 p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
478 p_vout->output.i_width =
479 p_vout->fmt_out.i_width =
480 p_vout->fmt_out.i_visible_width = p_sys->i_width;
481 p_vout->output.i_height =
482 p_vout->fmt_out.i_height =
483 p_vout->fmt_out.i_visible_height = p_sys->i_height;
485 /* Assume we have square pixels */
486 p_vout->output.i_aspect = ( p_sys->i_width
487 * VOUT_ASPECT_FACTOR ) / p_sys->i_height;
489 p_vout->fmt_out.i_sar_num = p_vout->fmt_out.i_sar_den = 1;
490 p_vout->fmt_out.i_aspect = p_vout->render.i_aspect = p_vout->output.i_aspect;
491 p_vout->fmt_out.i_x_offset= p_vout->fmt_out.i_y_offset = 0;
493 /* Clear the screen */
494 memset( p_sys->p_video, 0, p_sys->i_page_size );
496 if( !p_sys->b_hw_accel )
498 /* Try to initialize up to MAX_DIRECTBUFFERS direct buffers */
499 while( I_OUTPUTPICTURES < MAX_DIRECTBUFFERS )
503 /* Find an empty picture slot */
504 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
506 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
508 p_pic = p_vout->p_picture + i_index;
513 /* Allocate the picture */
514 if( p_pic == NULL || NewPicture( p_vout, p_pic ) )
519 p_pic->i_status = DESTROYED_PICTURE;
520 p_pic->i_type = DIRECT_PICTURE;
522 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
529 /* Try to initialize 1 direct buffer */
532 /* Find an empty picture slot */
533 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
535 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
537 p_pic = p_vout->p_picture + i_index;
542 /* Allocate the picture */
548 /* We know the chroma, allocate a buffer which will be used
549 * directly by the decoder */
550 p_pic->p->p_pixels = p_vout->p_sys->p_video;
551 p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel;
552 p_pic->p->i_lines = p_vout->p_sys->var_info.yres;
553 p_pic->p->i_visible_lines = p_vout->p_sys->var_info.yres;
555 if( p_vout->p_sys->var_info.xres_virtual )
557 p_pic->p->i_pitch = p_vout->p_sys->var_info.xres_virtual
558 * p_vout->p_sys->i_bytes_per_pixel;
562 p_pic->p->i_pitch = p_vout->p_sys->var_info.xres
563 * p_vout->p_sys->i_bytes_per_pixel;
566 p_pic->p->i_visible_pitch = p_vout->p_sys->var_info.xres
567 * p_vout->p_sys->i_bytes_per_pixel;
569 p_pic->i_status = DESTROYED_PICTURE;
570 p_pic->i_type = DIRECT_PICTURE;
572 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
580 /*****************************************************************************
581 * End: terminate framebuffer video thread output method
582 *****************************************************************************/
583 static void End( vout_thread_t *p_vout )
585 if( !p_vout->p_sys->b_hw_accel )
589 /* Free the direct buffers we allocated */
590 for( i_index = I_OUTPUTPICTURES ; i_index ; )
593 FreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );
597 /* Clear the screen */
598 memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
601 /*****************************************************************************
602 * Control: control facility for the vout
603 *****************************************************************************/
604 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
606 (void) p_vout; (void) i_query; (void) args;
610 /*****************************************************************************
611 * Manage: handle FB events
612 *****************************************************************************
613 * This function should be called regularly by video output thread. It manages
614 * console events. It returns a non null value on error.
615 *****************************************************************************/
616 static int Manage( vout_thread_t *p_vout )
621 if ( read(0, &buf, 1) == 1)
626 libvlc_Quit( p_vout->p_libvlc );
638 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
640 msg_Dbg( p_vout, "reinitializing framebuffer screen" );
641 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
643 /* Destroy XImages to change their size */
646 /* Recreate XImages. If SysInit failed, the thread can't go on. */
649 msg_Err( p_vout, "cannot reinit framebuffer screen" );
654 memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
657 /* Tell the video output thread that it will need to rebuild YUV
658 * tables. This is needed since conversion buffer size may have changed */
659 p_vout->i_changes |= VOUT_YUV_CHANGE;
666 /*****************************************************************************
667 * Display: displays previously rendered output
668 *****************************************************************************
669 * This function send the currently rendered image to FB image, waits until
670 * it is displayed and switch the two rendering buffers, preparing next frame.
671 *****************************************************************************/
672 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
675 /* swap the two Y offsets if the drivers supports panning */
676 if( p_vout->p_sys->b_pan )
678 p_vout->p_sys->var_info.yoffset = 0;
679 /*p_vout->p_sys->var_info.yoffset = p_vout->p_sys->var_info.yres; */
681 /* the X offset should be 0, but who knows ...
682 * some other app might have played with the framebuffer */
683 p_vout->p_sys->var_info.xoffset = 0;
687 ioctl( p_vout->p_sys->i_fd,
688 FBIOPAN_DISPLAY, &p_vout->p_sys->var_info );
693 if( !p_vout->p_sys->b_hw_accel )
695 vlc_memcpy( p_vout->p_sys->p_video, p_pic->p->p_pixels,
696 p_vout->p_sys->i_page_size );
701 static void SetPalette( vout_thread_t *p_vout, uint16_t *red, uint16_t *green,
702 uint16_t *blue, uint16_t *transp )
704 struct fb_cmap cmap = { 0, 256, red, green, blue, transp };
706 ioctl( p_vout->p_sys->i_fd, FBIOPUTCMAP, &cmap );
710 /* following functions are local */
712 /*****************************************************************************
713 * OpenDisplay: initialize framebuffer
714 *****************************************************************************/
715 static int OpenDisplay( vout_thread_t *p_vout )
717 vout_sys_t *p_sys = (vout_sys_t *) p_vout->p_sys;
718 char *psz_device; /* framebuffer device path */
719 struct fb_fix_screeninfo fix_info; /* framebuffer fix information */
721 /* Open framebuffer device */
722 if( !(psz_device = config_GetPsz( p_vout, FB_DEV_VAR )) )
724 msg_Err( p_vout, "don't know which fb device to open" );
728 p_sys->i_fd = open( psz_device, O_RDWR);
729 if( p_sys->i_fd == -1 )
731 msg_Err( p_vout, "cannot open %s (%m)", psz_device );
737 /* Get framebuffer device information */
738 if( ioctl( p_sys->i_fd, FBIOGET_VSCREENINFO, &p_sys->var_info ) )
740 msg_Err( p_vout, "cannot get fb info (%m)" );
741 close( p_sys->i_fd );
745 memcpy( &p_sys->old_info, &p_sys->var_info,
746 sizeof( struct fb_var_screeninfo ) );
748 /* Get some info on the framebuffer itself */
751 p_sys->var_info.xres = p_sys->var_info.xres_virtual = p_sys->i_width;
752 p_sys->var_info.yres = p_sys->var_info.yres_virtual = p_sys->i_height;
753 p_vout->fmt_out.i_width = p_sys->i_width;
754 p_vout->fmt_out.i_height = p_sys->i_height;
757 /* Set some attributes */
758 p_sys->var_info.activate = p_sys->b_tty
759 ? FB_ACTIVATE_NXTOPEN
761 p_sys->var_info.xoffset = 0;
762 p_sys->var_info.yoffset = 0;
764 if( ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->var_info ) )
766 msg_Err( p_vout, "cannot set fb info (%m)" );
767 close( p_sys->i_fd );
771 /* Get some information again, in the definitive configuration */
772 if( ioctl( p_sys->i_fd, FBIOGET_FSCREENINFO, &fix_info )
773 || ioctl( p_sys->i_fd, FBIOGET_VSCREENINFO, &p_sys->var_info ) )
775 msg_Err( p_vout, "cannot get additional fb info (%m)" );
777 /* Restore fb config */
778 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->old_info );
780 close( p_sys->i_fd );
784 /* If the fb has limitations on mode change,
785 * then keep the resolution of the fb */
786 if( (p_sys->i_height != p_sys->var_info.yres) ||
787 (p_sys->i_width != p_sys->var_info.xres) )
789 p_sys->b_auto = true;
791 "using framebuffer native resolution instead of requested (%ix%i)",
792 p_sys->i_width, p_sys->i_height );
794 p_sys->i_height = p_sys->var_info.yres;
795 p_sys->i_width = p_sys->var_info.xres_virtual
796 ? p_sys->var_info.xres_virtual
797 : p_sys->var_info.xres;
799 /* FIXME: if the image is full-size, it gets cropped on the left
800 * because of the xres / xres_virtual slight difference */
801 msg_Dbg( p_vout, "%ix%i (virtual %ix%i) (request %ix%i)",
802 p_sys->var_info.xres, p_sys->var_info.yres,
803 p_sys->var_info.xres_virtual,
804 p_sys->var_info.yres_virtual,
805 p_sys->i_width, p_sys->i_height );
807 p_sys->p_palette = NULL;
808 p_sys->b_pan = ( fix_info.ypanstep || fix_info.ywrapstep );
810 switch( p_sys->var_info.bits_per_pixel )
813 p_sys->p_palette = malloc( 8 * 256 * sizeof( uint16_t ) );
814 if( !p_sys->p_palette )
816 /* Restore fb config */
817 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->old_info );
819 close( p_sys->i_fd );
822 p_sys->fb_cmap.start = 0;
823 p_sys->fb_cmap.len = 256;
824 p_sys->fb_cmap.red = p_sys->p_palette;
825 p_sys->fb_cmap.green = p_sys->p_palette + 256 * sizeof( uint16_t );
826 p_sys->fb_cmap.blue = p_sys->p_palette + 2 * 256 * sizeof( uint16_t );
827 p_sys->fb_cmap.transp = p_sys->p_palette + 3 * 256 * sizeof( uint16_t );
829 /* Save the colormap */
830 ioctl( p_sys->i_fd, FBIOGETCMAP, &p_sys->fb_cmap );
832 p_sys->i_bytes_per_pixel = 1;
837 p_sys->i_bytes_per_pixel = 2;
841 p_sys->i_bytes_per_pixel = 3;
845 p_sys->i_bytes_per_pixel = 4;
849 msg_Err( p_vout, "screen depth %d is not supported",
850 p_sys->var_info.bits_per_pixel );
852 /* Restore fb config */
853 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->old_info );
855 close( p_sys->i_fd );
859 p_sys->i_page_size = p_sys->i_width * p_sys->i_height *
860 p_sys->i_bytes_per_pixel;
862 /* Map a framebuffer at the beginning */
863 p_sys->p_video = mmap( NULL, p_sys->i_page_size,
864 PROT_READ | PROT_WRITE, MAP_SHARED,
867 if( p_sys->p_video == MAP_FAILED )
869 msg_Err( p_vout, "cannot map video memory (%m)" );
871 if( p_sys->var_info.bits_per_pixel == 8 )
873 free( p_sys->p_palette );
874 p_sys->p_palette = NULL;
877 /* Restore fb config */
878 ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_vout->p_sys->old_info );
880 close( p_sys->i_fd );
884 msg_Dbg( p_vout, "framebuffer type=%d, visual=%d, ypanstep=%d, "
885 "ywrap=%d, accel=%d", fix_info.type, fix_info.visual,
886 fix_info.ypanstep, fix_info.ywrapstep, fix_info.accel );
890 /*****************************************************************************
891 * CloseDisplay: terminate FB video thread output method
892 *****************************************************************************/
893 static void CloseDisplay( vout_thread_t *p_vout )
895 if( p_vout->p_sys->p_video != MAP_FAILED )
898 memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
899 munmap( p_vout->p_sys->p_video, p_vout->p_sys->i_page_size );
902 if( p_vout->p_sys->i_fd >= 0 )
904 /* Restore palette */
905 if( p_vout->p_sys->var_info.bits_per_pixel == 8 )
907 ioctl( p_vout->p_sys->i_fd,
908 FBIOPUTCMAP, &p_vout->p_sys->fb_cmap );
909 free( p_vout->p_sys->p_palette );
910 p_vout->p_sys->p_palette = NULL;
913 /* Restore fb config */
914 ioctl( p_vout->p_sys->i_fd,
915 FBIOPUT_VSCREENINFO, &p_vout->p_sys->old_info );
918 close( p_vout->p_sys->i_fd );
922 /*****************************************************************************
923 * SwitchDisplay: VT change signal handler
924 *****************************************************************************
925 * This function activates or deactivates the output of the thread. It is
926 * called by the VT driver, on terminal change.
927 *****************************************************************************/
928 static void SwitchDisplay( int i_signal )
930 VLC_UNUSED( i_signal );
932 vout_thread_t *p_vout;
934 vlc_mutex_lock( &p_vout_bank->lock );
936 /* XXX: only test the first video output */
937 if( p_vout_bank->i_count )
939 p_vout = p_vout_bank->pp_vout[0];
943 case SIGUSR1: /* vt has been released */
944 p_vout->b_active = 0;
945 ioctl( p_sys->i_tty, VT_RELDISP, 1 );
947 case SIGUSR2: /* vt has been acquired */
948 p_vout->b_active = 1;
949 ioctl( p_sys->i_tty, VT_RELDISP, VT_ACTIVATE );
950 /* handle blanking */
951 vlc_mutex_lock( &p_vout->change_lock );
952 p_vout->i_changes |= VOUT_SIZE_CHANGE;
953 vlc_mutex_unlock( &p_vout->change_lock );
958 vlc_mutex_unlock( &p_vout_bank->lock );
962 /*****************************************************************************
963 * TextMode and GfxMode : switch tty to text/graphic mode
964 *****************************************************************************
965 * These functions toggle the tty mode.
966 *****************************************************************************/
967 static void TextMode( int i_tty )
969 /* return to text mode */
970 if( -1 == ioctl(i_tty, KDSETMODE, KD_TEXT) )
972 /*msg_Err( p_vout, "failed ioctl KDSETMODE KD_TEXT" );*/
976 static void GfxMode( int i_tty )
978 /* switch to graphic mode */
979 if( -1 == ioctl(i_tty, KDSETMODE, KD_GRAPHICS) )
981 /*msg_Err( p_vout, "failed ioctl KDSETMODE KD_GRAPHICS" );*/