⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fb.c

📁 video linux conference
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * fb.c : framebuffer plugin for vlc ***************************************************************************** * Copyright (C) 2000, 2001 VideoLAN * $Id: fb.c 11387 2005-06-10 15:32:08Z hartman $ * * Authors: Samuel Hocevar <sam@zoy.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <errno.h>                                                 /* ENOMEM */#include <signal.h>                                      /* SIGUSR1, SIGUSR2 */#include <stdlib.h>                                                /* free() */#include <string.h>                                            /* strerror() */#include <fcntl.h>                                                 /* open() */#include <unistd.h>                                               /* close() */#include <termios.h>                                       /* struct termios */#include <sys/ioctl.h>#include <sys/mman.h>                                              /* mmap() */#include <linux/fb.h>#include <linux/vt.h>                                                /* VT_* */#include <linux/kd.h>                                                 /* KD* */#include <vlc/vlc.h>#include <vlc/vout.h>/***************************************************************************** * Local prototypes *****************************************************************************/static int  Create    ( vlc_object_t * );static void Destroy   ( vlc_object_t * );static int  Init      ( vout_thread_t * );static void End       ( vout_thread_t * );static int  Manage    ( vout_thread_t * );static void Display   ( vout_thread_t *, picture_t * );static int  OpenDisplay    ( vout_thread_t * );static void CloseDisplay   ( vout_thread_t * );static void SwitchDisplay  ( int i_signal );static void TextMode       ( int i_tty );static void GfxMode        ( int i_tty );/***************************************************************************** * Module descriptor *****************************************************************************/#define FB_DEV_VAR "fbdev"#define DEVICE_TEXT N_("Framebuffer device")#define DEVICE_LONGTEXT N_( \    "You can select here the framebuffer device that will be used " \    "for rendering (usually /dev/fb0).")vlc_module_begin();    set_shortname( "Framebuffer" );    set_category( CAT_VIDEO );    set_subcategory( SUBCAT_VIDEO_VOUT );    add_file( FB_DEV_VAR, "/dev/fb0", NULL, DEVICE_TEXT, DEVICE_LONGTEXT,              VLC_FALSE );    set_description( _("GNU/Linux console framebuffer video output") );    set_capability( "video output", 30 );    set_callbacks( Create, Destroy );vlc_module_end();/***************************************************************************** * vout_sys_t: video output framebuffer method descriptor ***************************************************************************** * This structure is part of the video output thread descriptor. * It describes the FB specific properties of an output thread. *****************************************************************************/struct vout_sys_t{    /* System information */    int                 i_tty;                          /* tty device handle */    struct termios      old_termios;    /* Original configuration information */    struct sigaction            sig_usr1;           /* USR1 previous handler */    struct sigaction            sig_usr2;           /* USR2 previous handler */    struct vt_mode              vt_mode;                 /* previous VT mode */    /* Framebuffer information */    int                         i_fd;                       /* device handle */    struct fb_var_screeninfo    old_info;       /* original mode information */    struct fb_var_screeninfo    var_info;        /* current mode information */    vlc_bool_t                  b_pan;     /* does device supports panning ? */    struct fb_cmap              fb_cmap;                /* original colormap */    uint16_t                    *p_palette;              /* original palette */    /* Video information */    int i_width;    int i_height;    int i_bytes_per_pixel;    /* Video memory */    byte_t *    p_video;                                      /* base adress */    size_t      i_page_size;                                    /* page size */};/***************************************************************************** * Create: allocates FB video thread output method ***************************************************************************** * This function allocates and initializes a FB vout method. *****************************************************************************/static int Create( vlc_object_t *p_this ){    vout_thread_t *p_vout = (vout_thread_t *)p_this;    struct sigaction    sig_tty;                 /* sigaction for tty change */    struct vt_mode      vt_mode;                          /* vt current mode */    struct termios      new_termios;    /* Allocate instance and initialize some members */    p_vout->p_sys = malloc( sizeof( vout_sys_t ) );    if( p_vout->p_sys == NULL )    {        return VLC_ENOMEM;    };    p_vout->pf_init = Init;    p_vout->pf_end = End;    p_vout->pf_manage = Manage;    p_vout->pf_render = NULL;    p_vout->pf_display = Display;    /* Set tty and fb devices */    p_vout->p_sys->i_tty = 0;           /* 0 == /dev/tty0 == current console */    GfxMode( p_vout->p_sys->i_tty );    /* Set keyboard settings */    if (tcgetattr(0, &p_vout->p_sys->old_termios) == -1)    {        msg_Err( p_vout, "tcgetattr failed" );    }    if (tcgetattr(0, &new_termios) == -1)    {        msg_Err( p_vout, "tcgetattr failed" );    } /* new_termios.c_lflag &= ~ (ICANON | ISIG);    new_termios.c_lflag |= (ECHO | ECHOCTL); */    new_termios.c_lflag &= ~ (ICANON);    new_termios.c_lflag &= ~(ECHO | ECHOCTL);    new_termios.c_iflag = 0;    new_termios.c_cc[VMIN] = 1;    new_termios.c_cc[VTIME] = 0;    if (tcsetattr(0, TCSAFLUSH, &new_termios) == -1)    {        msg_Err( p_vout, "tcsetattr failed" );    }    ioctl( p_vout->p_sys->i_tty, VT_RELDISP, VT_ACKACQ );    /* Set-up tty signal handler to be aware of tty changes */    memset( &sig_tty, 0, sizeof( sig_tty ) );    sig_tty.sa_handler = SwitchDisplay;    sigemptyset( &sig_tty.sa_mask );    if( sigaction( SIGUSR1, &sig_tty, &p_vout->p_sys->sig_usr1 ) ||        sigaction( SIGUSR2, &sig_tty, &p_vout->p_sys->sig_usr2 ) )    {        msg_Err( p_vout, "cannot set signal handler (%s)", strerror(errno) );        tcsetattr(0, 0, &p_vout->p_sys->old_termios);        TextMode( p_vout->p_sys->i_tty );        free( p_vout->p_sys );        return VLC_EGENERIC;    }    /* Set-up tty according to new signal handler */    if( -1 == ioctl( p_vout->p_sys->i_tty,                     VT_GETMODE, &p_vout->p_sys->vt_mode ) )    {        msg_Err( p_vout, "cannot get terminal mode (%s)", strerror(errno) );        sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );        sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );        tcsetattr(0, 0, &p_vout->p_sys->old_termios);        TextMode( p_vout->p_sys->i_tty );        free( p_vout->p_sys );        return VLC_EGENERIC;    }    memcpy( &vt_mode, &p_vout->p_sys->vt_mode, sizeof( vt_mode ) );    vt_mode.mode   = VT_PROCESS;    vt_mode.waitv  = 0;    vt_mode.relsig = SIGUSR1;    vt_mode.acqsig = SIGUSR2;    if( -1 == ioctl( p_vout->p_sys->i_tty, VT_SETMODE, &vt_mode ) )    {        msg_Err( p_vout, "cannot set terminal mode (%s)", strerror(errno) );        sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );        sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );        tcsetattr(0, 0, &p_vout->p_sys->old_termios);        TextMode( p_vout->p_sys->i_tty );        free( p_vout->p_sys );        return VLC_EGENERIC;    }    if( OpenDisplay( p_vout ) )    {        ioctl( p_vout->p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode );        sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );        sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );        tcsetattr(0, 0, &p_vout->p_sys->old_termios);        TextMode( p_vout->p_sys->i_tty );        free( p_vout->p_sys );        return VLC_EGENERIC;    }    return VLC_SUCCESS;}/***************************************************************************** * Init: initialize framebuffer video thread output method *****************************************************************************/static int Init( vout_thread_t *p_vout ){    int i_index;    picture_t *p_pic;    I_OUTPUTPICTURES = 0;    /* Initialize the output structure: RGB with square pixels, whatever     * the input format is, since it's the only format we know */    switch( p_vout->p_sys->var_info.bits_per_pixel )    {        case 8: /* FIXME: set the palette */            p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2'); break;        case 15:            p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5'); break;        case 16:            p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6'); break;        case 24:            p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4'); break;        case 32:            p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2'); break;        default:            msg_Err( p_vout, "unknown screen depth %i",                     p_vout->p_sys->var_info.bits_per_pixel );            return VLC_EGENERIC;    }    /* Only useful for p_vout->p_sys->var_info.bits_per_pixel != 8 */    p_vout->output.i_rmask = ( (1 << p_vout->p_sys->var_info.red.length) - 1 )                     << p_vout->p_sys->var_info.red.offset;    p_vout->output.i_gmask = ( (1 << p_vout->p_sys->var_info.green.length) - 1 )                     << p_vout->p_sys->var_info.green.offset;    p_vout->output.i_bmask = ( (1 << p_vout->p_sys->var_info.blue.length) - 1 )                     << p_vout->p_sys->var_info.blue.offset;    p_vout->output.i_width = p_vout->p_sys->i_width;    p_vout->output.i_height = p_vout->p_sys->i_height;    /* Assume we have square pixels */    p_vout->output.i_aspect = p_vout->p_sys->i_width                               * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;    /* Clear the screen */    memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );    /* Try to initialize 1 direct buffer */    p_pic = NULL;    /* Find an empty picture slot */    for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )    {        if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )        {            p_pic = p_vout->p_picture + i_index;            break;        }    }    /* Allocate the picture */    if( p_pic == NULL )    {        return VLC_EGENERIC;    }    /* We know the chroma, allocate a buffer which will be used     * directly by the decoder */    p_pic->p->p_pixels = p_vout->p_sys->p_video;    p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel;    p_pic->p->i_lines = p_vout->p_sys->var_info.yres;    p_pic->p->i_visible_lines = p_vout->p_sys->var_info.yres;    if( p_vout->p_sys->var_info.xres_virtual )    {        p_pic->p->i_pitch = p_vout->p_sys->var_info.xres_virtual                             * p_vout->p_sys->i_bytes_per_pixel;    }    else    {        p_pic->p->i_pitch = p_vout->p_sys->var_info.xres                             * p_vout->p_sys->i_bytes_per_pixel;    }    p_pic->p->i_visible_pitch = p_vout->p_sys->var_info.xres                                 * p_vout->p_sys->i_bytes_per_pixel;    p_pic->i_planes = 1;    p_pic->i_status = DESTROYED_PICTURE;    p_pic->i_type   = DIRECT_PICTURE;    PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;    I_OUTPUTPICTURES++;    return VLC_SUCCESS;}/***************************************************************************** * End: terminate framebuffer video thread output method *****************************************************************************/static void End( vout_thread_t *p_vout ){    /* Clear the screen */    memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );}/***************************************************************************** * Destroy: destroy FB video thread output method ***************************************************************************** * Terminate an output method created by Create *****************************************************************************/static void Destroy( vlc_object_t *p_this ){    vout_thread_t *p_vout = (vout_thread_t *)p_this;    CloseDisplay( p_vout );    /* Reset the terminal */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -