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

📄 vout_mga.c

📁 vlc stand 0.1.99 ist sehr einfach
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * vout_mga.c: MGA video output display method ***************************************************************************** * Copyright (C) 1998, 1999, 2000 VideoLAN * * Authors: * * 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 "defs.h"#include <errno.h>                                                 /* ENOMEM */#include <stdlib.h>                                                /* free() */#include <string.h>                                            /* strerror() */#include <fcntl.h>                                                 /* open() */#include <sys/ioctl.h>                                            /* ioctl() */#include <sys/mman.h>                                          /* PROT_WRITE */#ifdef SYS_BSD#include <sys/types.h>                                     /* typedef ushort */#endif#include <sys/shm.h>                                   /* shmget(), shmctl() */#include <X11/Xlib.h>#include <X11/Xutil.h>#include <X11/extensions/XShm.h>#include "config.h"#include "common.h"#include "threads.h"#include "mtime.h"#include "plugins.h"#include "video.h"#include "video_output.h"#include "intf_msg.h"#include "vout_mga.h"/***************************************************************************** * vout_SysCreate: allocate X11 video thread output method ***************************************************************************** * This function allocate and initialize a X11 vout method. It uses some of the * vout properties to choose the window size, and change them according to the * actual properties of the display. *****************************************************************************/int vout_SysCreate( vout_thread_t *p_vout, char *psz_display,                    int i_root_window, void *p_data ){    /* Allocate structure */    p_vout->p_sys = malloc( sizeof( vout_sys_t ) );    if( p_vout->p_sys == NULL )    {        intf_ErrMsg("error: %s\n", strerror(ENOMEM) );        return( 1 );    }    /* Allocate MGA configuration structure */    p_vout->p_sys->p_mga = malloc( sizeof( mga_vid_config_t ) );    if( p_vout->p_sys->p_mga == NULL )    {        intf_ErrMsg("error: %s\n", strerror(ENOMEM) );        free( p_vout->p_sys );        return( 1 );    }    if( (p_vout->p_sys->i_fd = open("/dev/mga_vid",O_RDWR)) == -1 )    {        intf_ErrMsg("error: can't open MGA driver /dev/mga_vid\n" );        free( p_vout->p_sys->p_mga );        free( p_vout->p_sys );        return( 1 );    }    /* Open and initialize device. This function issues its own error messages.     * Since XLib is usually not thread-safe, we can't use the same display     * pointer than the interface or another thread. However, the root window     * id is still valid. */    if( X11OpenDisplay( p_vout, psz_display, i_root_window ) )    {        intf_ErrMsg("error: can't initialize X11 display\n" );        free( p_vout->p_sys->p_mga );        free( p_vout->p_sys );        return( 1 );    }    return( 0 );}/***************************************************************************** * vout_SysInit: initialize X11 video thread output method ***************************************************************************** * This function create the XImages needed by the output thread. It is called * at the beginning of the thread, but also each time the window is resized. *****************************************************************************/int vout_SysInit( vout_thread_t *p_vout ){    int i_err, i_dummy;    /* create the MGA output */    p_vout->p_sys->p_mga->src_width = p_vout->i_width;    p_vout->p_sys->p_mga->src_height = p_vout->i_height;    /* FIXME: we should initialize these ones according to the streams */    p_vout->p_sys->p_mga->dest_width = p_vout->i_width;    p_vout->p_sys->p_mga->dest_height = p_vout->i_height;    //p_vout->p_sys->p_mga->dest_width = 400;    //p_vout->p_sys->p_mga->dest_height = 300;    p_vout->p_sys->p_mga->x_org = 100;    p_vout->p_sys->p_mga->y_org = 100;    p_vout->p_sys->p_mga->colkey_on = 0;    if( ioctl(p_vout->p_sys->i_fd, MGA_VID_CONFIG, p_vout->p_sys->p_mga) )    {        intf_ErrMsg("error in config ioctl\n");    }    if (p_vout->p_sys->p_mga->card_type == MGA_G200)    {        intf_Msg( "detected MGA G200 (%d MB Ram)\n",                  p_vout->p_sys->p_mga->ram_size );        p_vout->p_sys->b_g400 = 0;    }    else    {        intf_Msg( "detected MGA G400 (%d MB Ram)\n",                  p_vout->p_sys->p_mga->ram_size );        p_vout->p_sys->b_g400 = 1;    }    ioctl( p_vout->p_sys->i_fd, MGA_VID_ON, 0 );    p_vout->p_sys->i_size = ( (p_vout->p_sys->p_mga->src_width + 31) & ~31 )                             * p_vout->p_sys->p_mga->src_height;    p_vout->p_sys->p_mga_vid_base = mmap( 0, p_vout->p_sys->i_size                                             + p_vout->p_sys->i_size / 2,                                          PROT_WRITE, MAP_SHARED,                                          p_vout->p_sys->i_fd, 0 );    memset( p_vout->p_sys->p_mga_vid_base,            0x00, p_vout->p_sys->i_size );    memset( p_vout->p_sys->p_mga_vid_base + p_vout->p_sys->i_size,            0x80, p_vout->p_sys->i_size / 2 );    /* Create XImages using XShm extension - on failure, fall back to regular     * way (and destroy the first image if it was created successfully) */    if( p_vout->p_sys->b_shm )    {        /* Create first image */        i_err = X11CreateShmImage( p_vout, &p_vout->p_sys->p_ximage[0],                                   &p_vout->p_sys->shm_info[0] );        if( !i_err )                         /* first image has been created */        {            /* Create second image */            if( X11CreateShmImage( p_vout, &p_vout->p_sys->p_ximage[1],                                   &p_vout->p_sys->shm_info[1] ) )            {                             /* error creating the second image */                X11DestroyShmImage( p_vout, p_vout->p_sys->p_ximage[0],                                    &p_vout->p_sys->shm_info[0] );                i_err = 1;            }        }        if( i_err )                                      /* an error occured */        {            intf_Msg("XShm video sextension desactivated\n" );            p_vout->p_sys->b_shm = 0;        }    }    /* Create XImages without XShm extension */    if( !p_vout->p_sys->b_shm )    {        if( X11CreateImage( p_vout, &p_vout->p_sys->p_ximage[0] ) )        {            intf_ErrMsg("error: can't create images\n");            p_vout->p_sys->p_ximage[0] = NULL;            p_vout->p_sys->p_ximage[1] = NULL;            return( 1 );        }        if( X11CreateImage( p_vout, &p_vout->p_sys->p_ximage[1] ) )        {            intf_ErrMsg("error: can't create images\n");            X11DestroyImage( p_vout->p_sys->p_ximage[0] );            p_vout->p_sys->p_ximage[0] = NULL;            p_vout->p_sys->p_ximage[1] = NULL;            return( 1 );        }    }    /* Set bytes per line and initialize buffers */    p_vout->i_bytes_per_line = p_vout->p_sys->p_ximage[0]->bytes_per_line;    vout_SetBuffers( p_vout, p_vout->p_sys->p_ximage[ 0 ]->data,                     p_vout->p_sys->p_ximage[ 1 ]->data );    return( 0 );}/***************************************************************************** * vout_SysEnd: terminate X11 video thread output method ***************************************************************************** * Destroy the X11 XImages created by vout_SysInit. It is called at the end of * the thread, but also each time the window is resized. *****************************************************************************/void vout_SysEnd( vout_thread_t *p_vout ){    if( p_vout->p_sys->b_shm )                             /* Shm XImages... */    {        X11DestroyShmImage( p_vout, p_vout->p_sys->p_ximage[0],                            &p_vout->p_sys->shm_info[0] );        X11DestroyShmImage( p_vout, p_vout->p_sys->p_ximage[1],                            &p_vout->p_sys->shm_info[1] );    }    else                                          /* ...or regular XImages */    {        X11DestroyImage( p_vout->p_sys->p_ximage[0] );        X11DestroyImage( p_vout->p_sys->p_ximage[1] );    }}/***************************************************************************** * vout_SysDestroy: destroy X11 video thread output method ***************************************************************************** * Terminate an output method created by vout_CreateOutputMethod *****************************************************************************/void vout_SysDestroy( vout_thread_t *p_vout ){    X11CloseDisplay( p_vout );    ioctl( p_vout->p_sys->i_fd, MGA_VID_OFF, 0 );    close( p_vout->p_sys->i_fd );    free( p_vout->p_sys->p_mga );    free( p_vout->p_sys );}/***************************************************************************** * vout_SysManage: handle X11 events ***************************************************************************** * This function should be called regularly by video output thread. It manages * X11 events and allows window resizing. It returns a non null value on * error. *****************************************************************************/int vout_SysManage( vout_thread_t *p_vout ){    /*     * Color/Grayscale or gamma change: in 8bpp, just change the colormap     */    if( (p_vout->i_changes & VOUT_GRAYSCALE_CHANGE) && (p_vout->i_screen_depth == 8) )    {        /* FIXME: clear flags ?? */    }    /*     * Size change     */    if( p_vout->i_changes & VOUT_SIZE_CHANGE )    {        intf_DbgMsg("resizing window\n");        p_vout->i_changes &= ~VOUT_SIZE_CHANGE;        /* Resize window */        XResizeWindow( p_vout->p_sys->p_display, p_vout->p_sys->window,                       p_vout->i_width, p_vout->i_height );        /* Destroy XImages to change their size */        vout_SysEnd( p_vout );        /* Recreate XImages. If SysInit failed, the thread can't go on. */        if( vout_SysInit( p_vout ) )        {            intf_ErrMsg("error: can't resize display\n");            return( 1 );        }        /* Tell the video output thread that it will need to rebuild YUV         * tables. This is needed since convertion buffer size may have changed */        p_vout->i_changes |= VOUT_YUV_CHANGE;        intf_Msg("Video display resized (%dx%d)\n", p_vout->i_width, p_vout->i_height);    }    return 0;}/***************************************************************************** * vout_SysDisplay: displays previously rendered output ***************************************************************************** * This function send the currently rendered image to X11 server, wait until * it is displayed and switch the two rendering buffer, preparing next frame. *****************************************************************************/void vout_SysDisplay( vout_thread_t *p_vout ){    if( p_vout->p_sys->b_shm)                                /* XShm is used */    {        /* Display rendered image using shared memory extension */        XShmPutImage(p_vout->p_sys->p_display, p_vout->p_sys->window, p_vout->p_sys->gc,                     p_vout->p_sys->p_ximage[ p_vout->i_buffer_index ],                     0, 0, 0, 0,                     p_vout->p_sys->p_ximage[ p_vout->i_buffer_index ]->width,                     p_vout->p_sys->p_ximage[ p_vout->i_buffer_index ]->height, True);        /* Send the order to the X server */        XFlush(p_vout->p_sys->p_display);    }    else                                /* regular X11 capabilities are used */    {        XPutImage(p_vout->p_sys->p_display, p_vout->p_sys->window, p_vout->p_sys->gc,                  p_vout->p_sys->p_ximage[ p_vout->i_buffer_index ],                  0, 0, 0, 0,                  p_vout->p_sys->p_ximage[ p_vout->i_buffer_index ]->width,                  p_vout->p_sys->p_ximage[ p_vout->i_buffer_index ]->height);        /* Send the order to the X server */        XFlush(p_vout->p_sys->p_display);    }}/* following functions are local *//***************************************************************************** * X11OpenDisplay: open and initialize X11 device ***************************************************************************** * Create a window according to video output given size, and set other * properties according to the display properties. *****************************************************************************/static int X11OpenDisplay( vout_thread_t *p_vout, char *psz_display, Window root_window ){

⌨️ 快捷键说明

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