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

📄 xcommon.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 5 页
字号:
/***************************************************************************** * xcommon.c: Functions common to the X11 and XVideo plugins ***************************************************************************** * Copyright (C) 1998-2006 the VideoLAN team * $Id$ * * Authors: Vincent Seguin <seguin@via.ecp.fr> *          Sam Hocevar <sam@zoy.org> *          David Kennedy <dkennedy@tinytoad.com> *          Gildas Bazin <gbazin@videolan.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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <vlc_interface.h>#include <vlc_playlist.h>#include <vlc_vout.h>#include <vlc_keys.h>#include <errno.h>                                                 /* ENOMEM */#ifdef HAVE_MACHINE_PARAM_H    /* BSD */#   include <machine/param.h>#   include <sys/types.h>                                  /* typedef ushort */#   include <sys/ipc.h>#endif#ifndef WIN32#   include <netinet/in.h>                            /* BSD: struct in_addr */#endif#ifdef HAVE_XSP#include <X11/extensions/Xsp.h>#endif#ifdef HAVE_SYS_SHM_H#   include <sys/shm.h>                                /* shmget(), shmctl() */#endif#include <X11/Xlib.h>#include <X11/Xproto.h>#include <X11/Xmd.h>#include <X11/Xutil.h>#include <X11/keysym.h>#include <X11/XF86keysym.h>#ifdef HAVE_SYS_SHM_H#   include <X11/extensions/XShm.h>#endif#ifdef DPMSINFO_IN_DPMS_H#   include <X11/extensions/dpms.h>#endif#if defined(MODULE_NAME_IS_xvideo) || defined(MODULE_NAME_IS_xvmc)#   include <X11/extensions/Xv.h>#   include <X11/extensions/Xvlib.h>#endif#ifdef MODULE_NAME_IS_glx#   include <GL/glx.h>#endif#ifdef HAVE_XINERAMA#   include <X11/extensions/Xinerama.h>#endif#ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H#   include <X11/extensions/xf86vmode.h>#endif#ifdef MODULE_NAME_IS_xvmc#   include <X11/extensions/vldXvMC.h>#   include "../../codec/xvmc/accel_xvmc.h"#endif#include "xcommon.h"/***************************************************************************** * Local prototypes *****************************************************************************/int  Activate   ( vlc_object_t * );void Deactivate ( vlc_object_t * );static int  InitVideo      ( vout_thread_t * );static void EndVideo       ( vout_thread_t * );static void DisplayVideo   ( vout_thread_t *, picture_t * );static int  ManageVideo    ( vout_thread_t * );static int  Control        ( vout_thread_t *, int, va_list );static int  InitDisplay    ( vout_thread_t * );static int  CreateWindow   ( vout_thread_t *, x11_window_t * );static void DestroyWindow  ( vout_thread_t *, x11_window_t * );static int  NewPicture     ( vout_thread_t *, picture_t * );static void FreePicture    ( vout_thread_t *, picture_t * );#ifndef MODULE_NAME_IS_glxstatic IMAGE_TYPE *CreateImage    ( vout_thread_t *,                                    Display *, EXTRA_ARGS, int, int );#endif#ifdef HAVE_SYS_SHM_H#ifndef MODULE_NAME_IS_glxIMAGE_TYPE *CreateShmImage ( vout_thread_t *,                                    Display *, EXTRA_ARGS_SHM, int, int );#endifstatic int i_shm_major = 0;#endifstatic void ToggleFullScreen      ( vout_thread_t * );static void EnableXScreenSaver    ( vout_thread_t * );static void DisableXScreenSaver   ( vout_thread_t * );static void CreateCursor   ( vout_thread_t * );static void DestroyCursor  ( vout_thread_t * );static void ToggleCursor   ( vout_thread_t * );#if defined(MODULE_NAME_IS_xvideo) || defined(MODULE_NAME_IS_xvmc)static int  XVideoGetPort    ( vout_thread_t *, vlc_fourcc_t, picture_heap_t * );static void XVideoReleasePort( vout_thread_t *, int );#endif#ifdef MODULE_NAME_IS_x11static void SetPalette     ( vout_thread_t *,                             uint16_t *, uint16_t *, uint16_t * );#endif#ifdef MODULE_NAME_IS_xvmcstatic void RenderVideo    ( vout_thread_t *, picture_t * );static int  xvmc_check_yv12( Display *display, XvPortID port );static void xvmc_update_XV_DOUBLE_BUFFER( vout_thread_t *p_vout );#endifstatic void TestNetWMSupport( vout_thread_t * );static int ConvertKey( int );static int WindowOnTop( vout_thread_t *, bool );static int X11ErrorHandler( Display *, XErrorEvent * );#ifdef HAVE_XSPstatic void EnablePixelDoubling( vout_thread_t *p_vout );static void DisablePixelDoubling( vout_thread_t *p_vout );#endif#ifdef HAVE_OSSOstatic const int i_backlight_on_interval = 300;#endif/***************************************************************************** * Activate: 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 Activate ( vlc_object_t *p_this ){    vout_thread_t *p_vout = (vout_thread_t *)p_this;    char *        psz_display;    vlc_value_t   val;#if defined(MODULE_NAME_IS_xvmc)    char *psz_value;#endif#if defined(MODULE_NAME_IS_xvideo) || defined(MODULE_NAME_IS_xvmc)    char *       psz_chroma;    vlc_fourcc_t i_chroma = 0;    bool   b_chroma = 0;#endif    p_vout->pf_init = InitVideo;    p_vout->pf_end = EndVideo;    p_vout->pf_manage = ManageVideo;#ifdef MODULE_NAME_IS_xvmc    p_vout->pf_render = RenderVideo;#else    p_vout->pf_render = NULL;#endif    p_vout->pf_display = DisplayVideo;    p_vout->pf_control = Control;    /* Allocate structure */    p_vout->p_sys = malloc( sizeof( vout_sys_t ) );    if( p_vout->p_sys == NULL )        return VLC_ENOMEM;    vlc_mutex_init( &p_vout->p_sys->lock );    /* Open display, using the "display" config variable or the DISPLAY     * environment variable */    psz_display = config_GetPsz( p_vout, MODULE_STRING "-display" );    p_vout->p_sys->p_display = XOpenDisplay( psz_display );    if( p_vout->p_sys->p_display == NULL )                         /* error */    {        msg_Err( p_vout, "cannot open display %s",                         XDisplayName( psz_display ) );        free( p_vout->p_sys );        free( psz_display );        return VLC_EGENERIC;    }    free( psz_display );    /* Replace error handler so we can intercept some non-fatal errors */    XSetErrorHandler( X11ErrorHandler );    /* Get a screen ID matching the XOpenDisplay return value */    p_vout->p_sys->i_screen = DefaultScreen( p_vout->p_sys->p_display );#if defined(MODULE_NAME_IS_xvideo) || defined(MODULE_NAME_IS_xvmc)    psz_chroma = config_GetPsz( p_vout, "xvideo-chroma" );    if( psz_chroma )    {        if( strlen( psz_chroma ) >= 4 )        {            /* Do not use direct assignment because we are not sure of the             * alignment. */            memcpy(&i_chroma, psz_chroma, 4);            b_chroma = 1;        }        free( psz_chroma );    }    if( b_chroma )    {        msg_Dbg( p_vout, "forcing chroma 0x%.8x (%4.4s)",                 i_chroma, (char*)&i_chroma );    }    else    {        i_chroma = p_vout->render.i_chroma;    }    /* Check that we have access to an XVideo port providing this chroma */    p_vout->p_sys->i_xvport = XVideoGetPort( p_vout, VLC2X11_FOURCC(i_chroma),                                             &p_vout->output );    if( p_vout->p_sys->i_xvport < 0 )    {        /* If a specific chroma format was requested, then we don't try to         * be cleverer than the user. He knew pretty well what he wanted. */        if( b_chroma )        {            XCloseDisplay( p_vout->p_sys->p_display );            free( p_vout->p_sys );            return VLC_EGENERIC;        }        /* It failed, but it's not completely lost ! We try to open an         * XVideo port for an YUY2 picture. We'll need to do an YUV         * conversion, but at least it has got scaling. */        p_vout->p_sys->i_xvport =                        XVideoGetPort( p_vout, X11_FOURCC('Y','U','Y','2'),                                               &p_vout->output );        if( p_vout->p_sys->i_xvport < 0 )        {            /* It failed, but it's not completely lost ! We try to open an             * XVideo port for a simple 16bpp RGB picture. We'll need to do             * an YUV conversion, but at least it has got scaling. */            p_vout->p_sys->i_xvport =                            XVideoGetPort( p_vout, X11_FOURCC('R','V','1','6'),                                                   &p_vout->output );            if( p_vout->p_sys->i_xvport < 0 )            {                XCloseDisplay( p_vout->p_sys->p_display );                free( p_vout->p_sys );                return VLC_EGENERIC;            }        }    }    p_vout->output.i_chroma = X112VLC_FOURCC(p_vout->output.i_chroma);#elif defined(MODULE_NAME_IS_glx)    {        int i_opcode, i_evt, i_err = 0;        int i_maj, i_min = 0;        /* Check for GLX extension */        if( !XQueryExtension( p_vout->p_sys->p_display, "GLX",                              &i_opcode, &i_evt, &i_err ) )        {            msg_Err( p_this, "GLX extension not supported" );            XCloseDisplay( p_vout->p_sys->p_display );            free( p_vout->p_sys );            return VLC_EGENERIC;        }        if( !glXQueryExtension( p_vout->p_sys->p_display, &i_err, &i_evt ) )        {            msg_Err( p_this, "glXQueryExtension failed" );            XCloseDisplay( p_vout->p_sys->p_display );            free( p_vout->p_sys );            return VLC_EGENERIC;        }        /* Check GLX version */        if (!glXQueryVersion( p_vout->p_sys->p_display, &i_maj, &i_min ) )        {            msg_Err( p_this, "glXQueryVersion failed" );            XCloseDisplay( p_vout->p_sys->p_display );            free( p_vout->p_sys );            return VLC_EGENERIC;        }        if( i_maj <= 0 || ((i_maj == 1) && (i_min < 3)) )        {            p_vout->p_sys->b_glx13 = false;            msg_Dbg( p_this, "using GLX 1.2 API" );        }        else        {            p_vout->p_sys->b_glx13 = true;            msg_Dbg( p_this, "using GLX 1.3 API" );        }    }#endif    /* Create blank cursor (for mouse cursor autohiding) */    p_vout->p_sys->i_time_mouse_last_moved = mdate();    p_vout->p_sys->i_mouse_hide_timeout =        var_GetInteger(p_vout, "mouse-hide-timeout") * 1000;    p_vout->p_sys->b_mouse_pointer_visible = 1;    CreateCursor( p_vout );    /* Set main window's size */    p_vout->p_sys->original_window.i_width = p_vout->i_window_width;    p_vout->p_sys->original_window.i_height = p_vout->i_window_height;    var_Create( p_vout, "video-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT );    /* Spawn base window - this window will include the video output window,     * but also command buttons, subtitles and other indicators */    if( CreateWindow( p_vout, &p_vout->p_sys->original_window ) )    {        msg_Err( p_vout, "cannot create X11 window" );

⌨️ 快捷键说明

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