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

📄 sdl.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** * sdl.c: SDL video output display method ***************************************************************************** * Copyright (C) 1998-2001 the VideoLAN team * $Id$ * * Authors: Samuel Hocevar <sam@zoy.org> *          Pierre Baillet <oct@zoy.org> *          Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr> * * 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 *****************************************************************************/#include <errno.h>                                                 /* ENOMEM */#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <vlc_plugin.h>#include <vlc_interface.h>#include <vlc_playlist.h>#include <vlc_vout.h>#include <vlc_keys.h>//#include <vlc_aout.h>#include <sys/types.h>#ifndef WIN32#   include <netinet/in.h>                            /* BSD: struct in_addr */#endif#include SDL_INCLUDE_FILE/* SDL is not able to crop overlays - so use only 1 direct buffer */#define SDL_MAX_DIRECTBUFFERS 1#define SDL_DEFAULT_BPP 16/***************************************************************************** * vout_sys_t: video output SDL method descriptor ***************************************************************************** * This structure is part of the video output thread descriptor. * It describes the SDL specific properties of an output thread. *****************************************************************************/struct vout_sys_t{    SDL_Surface *   p_display;                             /* display device */    int i_width;    int i_height;#if SDL_VERSION_ATLEAST(1,2,10)    unsigned int i_desktop_width;    unsigned int i_desktop_height;#endif    /* For YUV output */    SDL_Overlay * p_overlay;   /* An overlay we keep to grab the XVideo port */    /* For RGB output */    int i_surfaces;    bool  b_cursor;    bool  b_cursor_autohidden;    mtime_t     i_lastmoved;    mtime_t     i_mouse_hide_timeout;    mtime_t     i_lastpressed;                        /* to track dbl-clicks */};/***************************************************************************** * picture_sys_t: direct buffer method descriptor ***************************************************************************** * This structure is part of the picture descriptor, it describes the * SDL specific properties of a direct buffer. *****************************************************************************/struct picture_sys_t{    SDL_Overlay *p_overlay;};/***************************************************************************** * Local prototypes *****************************************************************************/static int  Open      ( vlc_object_t * );static void Close     ( 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 int  NewPicture      ( vout_thread_t *, picture_t * );static void SetPalette      ( vout_thread_t *,                              uint16_t *, uint16_t *, uint16_t * );static int ConvertKey( SDLKey );#define CHROMA_TEXT N_("SDL chroma format")#define CHROMA_LONGTEXT N_( \    "Force the SDL renderer to use a specific chroma format instead of " \    "trying to improve performances by using the most efficient one.")/***************************************************************************** * Module descriptor *****************************************************************************/vlc_module_begin();    set_shortname( "SDL" );    set_category( CAT_VIDEO );    set_subcategory( SUBCAT_VIDEO_VOUT );    set_description( N_("Simple DirectMedia Layer video output") );    set_capability( "video output", 60 );    add_shortcut( "sdl" );    add_string( "sdl-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT, true );    set_callbacks( Open, Close );#if defined( __i386__ ) || defined( __x86_64__ )    /* On i386, SDL is linked against svgalib */    linked_with_a_crap_library_which_uses_atexit();#endifvlc_module_end();/***************************************************************************** * OpenVideo: allocate SDL video thread output method ***************************************************************************** * This function allocate and initialize a SDL vout method. It uses some of the * vout properties to choose the correct mode, and change them according to the * mode actually used. *****************************************************************************/static int Open ( vlc_object_t *p_this ){    vout_thread_t * p_vout = (vout_thread_t *)p_this;    /* XXX: check for conflicts with the SDL audio output */    vlc_mutex_t *lock = var_AcquireMutex( "sdl" );#ifdef HAVE_SETENV    char *psz_method;#endif    if( lock == NULL )        return VLC_ENOMEM;    p_vout->p_sys = malloc( sizeof( vout_sys_t ) );    if( p_vout->p_sys == NULL )    {        vlc_mutex_unlock( lock );        return VLC_ENOMEM;    }    memset( p_vout->p_sys, 0, sizeof( vout_sys_t ) );    /* Check if SDL video module has been initialized */    if( SDL_WasInit( SDL_INIT_VIDEO ) != 0 )    {        vlc_mutex_unlock( lock );        free( p_vout->p_sys );        return VLC_EGENERIC;    }    /* Allocate structure */    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;    p_vout->pf_control = NULL;#ifdef HAVE_SETENV    char* psz = psz_method = config_GetPsz( p_vout, "vout" );    if( psz_method )    {        while( *psz_method && *psz_method != ':' )        {            psz_method++;        }        if( *psz_method )        {            setenv( "SDL_VIDEODRIVER", psz_method + 1, 1 );        }    }    free( psz );#endif    /* Initialize library */    if( SDL_Init( SDL_INIT_VIDEO#ifndef WIN32    /* Win32 SDL implementation doesn't support SDL_INIT_EVENTTHREAD yet*/                | SDL_INIT_EVENTTHREAD#endif#ifndef NDEBUG    /* In debug mode you may want vlc to dump a core instead of staying     * stuck */                | SDL_INIT_NOPARACHUTE#endif                ) < 0 )    {        msg_Err( p_vout, "cannot initialize SDL (%s)", SDL_GetError() );        free( p_vout->p_sys );        vlc_mutex_unlock( lock );        return VLC_EGENERIC;    }    vlc_mutex_unlock( lock );    /* Translate keys into unicode */    SDL_EnableUNICODE(1);    /* Get the desktop resolution */#if SDL_VERSION_ATLEAST(1,2,10)    /* FIXME: SDL has a problem with virtual desktop */    p_vout->p_sys->i_desktop_width = SDL_GetVideoInfo()->current_w;    p_vout->p_sys->i_desktop_height = SDL_GetVideoInfo()->current_h;#endif    /* Create the cursor */    p_vout->p_sys->b_cursor = 1;    p_vout->p_sys->b_cursor_autohidden = 0;    p_vout->p_sys->i_lastmoved = p_vout->p_sys->i_lastpressed = mdate();    p_vout->p_sys->i_mouse_hide_timeout =        var_GetInteger(p_vout, "mouse-hide-timeout") * 1000;    if( OpenDisplay( p_vout ) )    {        msg_Err( p_vout, "cannot set up SDL (%s)", SDL_GetError() );        SDL_QuitSubSystem( SDL_INIT_VIDEO );        free( p_vout->p_sys );        return VLC_EGENERIC;    }    return VLC_SUCCESS;}/***************************************************************************** * Init: initialize SDL video thread output method ***************************************************************************** * This function initialize the SDL display device. *****************************************************************************/static int Init( vout_thread_t *p_vout ){    int i_index;    picture_t *p_pic;    p_vout->p_sys->i_surfaces = 0;    I_OUTPUTPICTURES = 0;    /* Initialize the output structure */    if( p_vout->p_sys->p_overlay == NULL )    {        /* All we have is an RGB image with square pixels */        p_vout->output.i_width  = p_vout->p_sys->i_width;        p_vout->output.i_height = p_vout->p_sys->i_height;        p_vout->output.i_aspect = p_vout->output.i_width                                   * VOUT_ASPECT_FACTOR                                   / p_vout->output.i_height;    }    else    {        /* We may need to convert the chroma, but at least we keep the         * aspect ratio */        p_vout->output.i_width  = p_vout->render.i_width;        p_vout->output.i_height = p_vout->render.i_height;        p_vout->output.i_aspect = p_vout->render.i_aspect;    }    /* Try to initialize SDL_MAX_DIRECTBUFFERS direct buffers */    while( I_OUTPUTPICTURES < SDL_MAX_DIRECTBUFFERS )    {        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 we found one */        if( p_pic == NULL || NewPicture( p_vout, p_pic ) )        {            break;        }        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 Sys video thread output method ***************************************************************************** * Terminate an output method created by OpenVideo *****************************************************************************/static void End( vout_thread_t *p_vout ){    int i_index;    /* Free the output buffers we allocated */    for( i_index = I_OUTPUTPICTURES ; i_index ; )    {        i_index--;        if( p_vout->p_sys->p_overlay == NULL )        {            /* RGB picture */        }        else        {            SDL_UnlockYUVOverlay(                    PP_OUTPUTPICTURE[ i_index ]->p_sys->p_overlay );            SDL_FreeYUVOverlay(                    PP_OUTPUTPICTURE[ i_index ]->p_sys->p_overlay );        }        free( PP_OUTPUTPICTURE[ i_index ]->p_sys );    }}/***************************************************************************** * CloseVideo: destroy Sys video thread output method ***************************************************************************** * Terminate an output method created by vout_SDLCreate *****************************************************************************/static void Close ( vlc_object_t *p_this ){    vout_thread_t * p_vout = (vout_thread_t *)p_this;    CloseDisplay( p_vout );    SDL_QuitSubSystem( SDL_INIT_VIDEO );    free( p_vout->p_sys );}/***************************************************************************** * Manage: handle Sys events ***************************************************************************** * This function should be called regularly by video output thread. It returns * a non null value if an error occurred. *****************************************************************************/static int Manage( vout_thread_t *p_vout ){    SDL_Event event;                                            /* SDL event */    vlc_value_t val;    unsigned int i_width, i_height, i_x, i_y;    /* Process events */    while( SDL_PollEvent( &event ) )

⌨️ 快捷键说明

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