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

📄 sdl.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** * sdl.c: SDL video output display method ***************************************************************************** * Copyright (C) 1998-2001 the VideoLAN team * $Id: sdl.c 16987 2006-10-08 12:54:12Z jpsaman $ * * 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 */#include <stdlib.h>                                                /* free() */#include <string.h>                                            /* strerror() */#include <vlc/vlc.h>#include <vlc/intf.h>#include <vlc/vout.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;    /* For YUV output */    SDL_Overlay * p_overlay;   /* An overlay we keep to grab the XVideo port */    /* For RGB output */    int i_surfaces;    vlc_bool_t  b_cursor;    vlc_bool_t  b_cursor_autohidden;    mtime_t     i_lastmoved;    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 * );/***************************************************************************** * Module descriptor *****************************************************************************/vlc_module_begin();    set_shortname( "SDL" );    set_category( CAT_VIDEO );    set_subcategory( SUBCAT_VIDEO_VOUT );    set_description( _("Simple DirectMedia Layer video output") );    set_capability( "video output", 60 );    add_shortcut( "sdl" );    set_callbacks( Open, Close );    /* XXX: check for conflicts with the SDL audio output */    var_Create( p_module->p_libvlc, "sdl", VLC_VAR_MUTEX );#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;    vlc_value_t lockval;#ifdef HAVE_SETENV    char *psz_method;#endif    var_Get( p_this->p_libvlc, "sdl", &lockval );    vlc_mutex_lock( lockval.p_address );    if( SDL_WasInit( SDL_INIT_VIDEO ) != 0 )    {        vlc_mutex_unlock( lockval.p_address );        return VLC_EGENERIC;    }    /* Allocate structure */    p_vout->p_sys = malloc( sizeof( vout_sys_t ) );    if( p_vout->p_sys == NULL )    {        msg_Err( p_vout, "out of memory" );        vlc_mutex_unlock( lockval.p_address );        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;#ifdef HAVE_SETENV    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 );        }    }#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#ifdef DEBUG    /* 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( lockval.p_address );        return VLC_EGENERIC;    }    vlc_mutex_unlock( lockval.p_address );    p_vout->p_sys->b_cursor = 1;    p_vout->p_sys->b_cursor_autohidden = 0;    p_vout->p_sys->i_lastmoved = mdate();    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;

⌨️ 快捷键说明

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