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

📄 vout.c

📁 VLC媒体播放程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** * vout.c: QNX RTOS video output display method ***************************************************************************** * Copyright (C) 2001, 2002 VideoLAN * * Authors: Jon Lech Johansen <jon-vl@nanocrew.net> *          Pascal Levesque <Pascal.Levesque@mindready.com> * * 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 <stdlib.h>                                                /* free() */#include <string.h>                                            /* strerror() */#include <photon/PtWidget.h>#include <photon/PtWindow.h>#include <photon/PtLabel.h>#include <photon/PdDirect.h>#include <vlc/vlc.h>#include <vlc/intf.h>#include <vlc/vout.h>/***************************************************************************** * vout_sys_t: video output QNX method descriptor ***************************************************************************** * This structure is part of the video output thread descriptor. * It describes the QNX specific properties of an output thread. QNX video * output is performed through regular resizable windows. Windows can be * dynamically resized to adapt to the size of the streams. *****************************************************************************/#define MAX_DIRECTBUFFERS 2#define MODE_NORMAL_MEM     0#define MODE_SHARED_MEM     1#define MODE_VIDEO_MEM      2#define MODE_VIDEO_OVERLAY  3struct vout_sys_t{    /* video mode */    int                     i_mode;    /* internal stuff */    PtWidget_t *            p_window;    /* Color palette for 8bpp */    PgColor_t p_colors[255];    /* [shared] memory blit */    int                     i_img_type;    /* video memory blit */    /* video overlay */    PgVideoChannel_t *      p_channel;    int                     i_vc_flags;    int                     i_vc_format;    int                 i_screen_depth;    int                 i_bytes_per_pixel;    int                 i_bytes_per_line;    /* position & dimensions */    PhPoint_t               pos;    PhDim_t                 dim;    PhPoint_t               old_pos;    PhDim_t                 old_dim;    PhDim_t                 screen_dim;    PhRect_t                frame;};/***************************************************************************** * picture_sys_t: direct buffer method descriptor ***************************************************************************** * This structure is part of the picture descriptor, it describes the * XVideo specific properties of a direct buffer. *****************************************************************************/struct picture_sys_t{    /* [shared] memory blit */    PhImage_t *             p_image;    /* video memory blit and video overlay */    PdOffscreenContext_t *  p_ctx[3];   /* 0: y, 1: u, 2: v */    char *                  p_buf[3];};/***************************************************************************** * Local prototypes *****************************************************************************/static int  QNXInit      ( vout_thread_t * );static void QNXEnd       ( vout_thread_t * );static int  QNXManage    ( vout_thread_t * );static void QNXDisplay   ( vout_thread_t *, picture_t * );static int  QNXInitDisplay ( vout_thread_t * );static int  QNXCreateWnd   ( vout_thread_t * );static int  QNXDestroyWnd  ( vout_thread_t * );static int  NewPicture     ( vout_thread_t *, picture_t *, int );static void FreePicture    ( vout_thread_t *, picture_t * );static int  ResizeOverlayOutput ( vout_thread_t * );static void SetPalette     ( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );/***************************************************************************** * OpenVideo: allocate QNX video thread output method ***************************************************************************** * This function allocate and initialize a QNX 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 E_(OpenVideo) ( vlc_object_t *p_this ){    vout_thread_t * p_vout = (vout_thread_t *)p_this;    /* init connection to photon */    if( PtInit( "/dev/photon" ) != 0 )    {        msg_Err( p_vout, "unable to connect to photon" );        return( 1 );    }    /* allocate structure */    p_vout->p_sys = malloc( sizeof( vout_sys_t ) );    if( p_vout->p_sys == NULL )    {        msg_Err( p_vout, "out of memory" );        return( 1 );    }    memset( p_vout->p_sys, 0, sizeof( vout_sys_t ) );    p_vout->b_fullscreen = config_GetInt( p_vout, "fullscreen" );    p_vout->p_sys->i_mode = config_GetInt( p_vout, "overlay" ) ?                                MODE_VIDEO_OVERLAY : MODE_VIDEO_MEM;    p_vout->p_sys->dim.w = p_vout->i_window_width;    p_vout->p_sys->dim.h = p_vout->i_window_height;    /* init display and create window */    if( QNXInitDisplay( p_vout ) || QNXCreateWnd( p_vout ) )    {        free( p_vout->p_sys );        return( 1 );    }    p_vout->pf_init = QNXInit;    p_vout->pf_end = QNXEnd;    p_vout->pf_manage = QNXManage;    p_vout->pf_render = NULL;    p_vout->pf_display = QNXDisplay;    return( 0 );}/***************************************************************************** * QNXInit: initialize QNX video thread output method ***************************************************************************** * This function create the buffers needed by the output thread. It is called * at the beginning of the thread, but also each time the window is resized. *****************************************************************************/static int QNXInit( vout_thread_t *p_vout ){    int i_index;    picture_t *p_pic;    I_OUTPUTPICTURES = 0;    switch( p_vout->p_sys->i_mode )    {    case MODE_NORMAL_MEM:    case MODE_SHARED_MEM:        p_vout->output.i_width = p_vout->p_sys->dim.w;        p_vout->output.i_height = p_vout->p_sys->dim.h;        /* Assume we have square pixels */        p_vout->output.i_aspect = p_vout->p_sys->dim.w                               * VOUT_ASPECT_FACTOR / p_vout->p_sys->dim.h;        break;    case MODE_VIDEO_MEM:        p_vout->output.i_width = p_vout->p_sys->dim.w;        p_vout->output.i_height = p_vout->p_sys->dim.h;        /* Assume we have square pixels */        p_vout->output.i_aspect = p_vout->p_sys->dim.w                               * VOUT_ASPECT_FACTOR / p_vout->p_sys->dim.h;        break;    case MODE_VIDEO_OVERLAY:        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;        if (ResizeOverlayOutput(p_vout))        {            return (1);        }        break;    default:        /* This shouldn't happen ! */        break;    }    /* Try to initialize up to MAX_DIRECTBUFFERS direct buffers */    while( I_OUTPUTPICTURES < 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( p_pic == NULL || NewPicture( p_vout, p_pic, I_OUTPUTPICTURES ) )        {            break;        }        p_pic->i_status = DESTROYED_PICTURE;        p_pic->i_type   = DIRECT_PICTURE;        PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;        I_OUTPUTPICTURES++;    }    return( 0 );}/***************************************************************************** * QNXEnd: terminate QNX video thread output method ***************************************************************************** * Destroy the buffers created by QNXInit. It is called at the end of * the thread, but also each time the window is resized. *****************************************************************************/static void QNXEnd( vout_thread_t *p_vout ){    int i_index;    /* Free the direct buffers we allocated */    for( i_index = I_OUTPUTPICTURES ; i_index ; )    {        i_index--;        FreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );    }}/***************************************************************************** * CloseVideo: destroy QNX video thread output method ***************************************************************************** * Terminate an output method created by QNXCreate *****************************************************************************/void E_(CloseVideo) ( vlc_object_t *p_this ){    vout_thread_t * p_vout = (vout_thread_t *)p_this;    /* destroy the window */    QNXDestroyWnd( p_vout );    /* destroy structure */    free( p_vout->p_sys );}/***************************************************************************** * QNXManage: handle QNX events ***************************************************************************** * This function should be called regularly by video output thread. It allows * window resizing. It returns a non null value on error. *****************************************************************************/static int QNXManage( vout_thread_t *p_vout ){    int i_ev,  i_buflen;    PhEvent_t *p_event;    vlc_bool_t b_repos = 0;    if (p_vout->b_die == 1)    {        return ( 0 );    }    /* allocate buffer for event */    i_buflen = sizeof( PhEvent_t ) * 4;    if( ( p_event = malloc( i_buflen ) ) == NULL )    {        msg_Err( p_vout, "out of memory" );        return( 1 );    }    /* event loop */    do    {        memset( p_event, 0, i_buflen );        i_ev = PhEventPeek( p_event, i_buflen );        if( i_ev == Ph_RESIZE_MSG )        {            i_buflen = PhGetMsgSize( p_event );            if( ( p_event = realloc( p_event, i_buflen ) ) == NULL )            {                msg_Err( p_vout, "out of memory" );                return( 1 );            }        }        else if( i_ev == Ph_EVENT_MSG )        {            PtEventHandler( p_event );            if( p_event->type == Ph_EV_WM )            {                PhWindowEvent_t *p_ev = PhGetData( p_event );                switch( p_ev->event_f )                {                case Ph_WM_CLOSE:                    p_vout->p_vlc->b_die = 1;                    break;                case Ph_WM_MOVE:                    p_vout->p_sys->pos.x = p_ev->pos.x;                    p_vout->p_sys->pos.y = p_ev->pos.y;                    b_repos = 1;                    break;                case Ph_WM_RESIZE:                    p_vout->p_sys->old_dim.w = p_vout->p_sys->dim.w;                    p_vout->p_sys->old_dim.h = p_vout->p_sys->dim.h;                    p_vout->p_sys->dim.w = p_ev->size.w;                    p_vout->p_sys->dim.h = p_ev->size.h;                    p_vout->i_changes |= VOUT_SIZE_CHANGE;                    break;                }            }            else if( p_event->type == Ph_EV_KEY )            {                PhKeyEvent_t *p_ev = PhGetData( p_event );                long i_key = p_ev->key_sym;

⌨️ 快捷键说明

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