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

📄 osd_parser.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * osd_parser.c - The OSD Menu  parser core code. ***************************************************************************** * Copyright (C) 2005 M2X * $Id: osd_parser.c 16773 2006-09-21 18:46:25Z hartman $ * * Authors: Jean-Paul Saman <jpsaman #_at_# m2x dot nl> * * 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 <stdlib.h>#include <string.h>#include <vlc/vlc.h>#include <vlc_config.h>#include <vlc_video.h>#include <vlc_keys.h>#include <vlc_image.h>#include <vlc_osd.h>#include <charset.h>#undef OSD_MENU_DEBUG/***************************************************************************** * Local prototypes *****************************************************************************/static const char *ppsz_button_states[] = { "unselect", "select", "pressed" };/* OSD Menu structure support routines */static osd_menu_t   *osd_MenuNew( osd_menu_t *, const char *, int, int );static osd_button_t *osd_ButtonNew( const char *, int, int );static osd_state_t  *osd_StateNew( vlc_object_t *, const char *, const char * );static void osd_MenuFree  ( vlc_object_t *, osd_menu_t * );static void osd_ButtonFree( vlc_object_t *, osd_button_t * );static void osd_StatesFree( vlc_object_t *, osd_state_t * );static picture_t *osd_LoadImage( vlc_object_t *, const char *);/***************************************************************************** * osd_LoadImage: loads the logo image into memory *****************************************************************************/static picture_t *osd_LoadImage( vlc_object_t *p_this, const char *psz_filename ){    picture_t *p_pic = NULL;    image_handler_t *p_image;    video_format_t fmt_in, fmt_out;    memset( &fmt_in, 0, sizeof(video_format_t) );    memset( &fmt_out, 0, sizeof(video_format_t) );    fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');    p_image = image_HandlerCreate( p_this );    if( p_image )    {        p_pic = image_ReadUrl( p_image, psz_filename, &fmt_in, &fmt_out );        image_HandlerDelete( p_image );#if 0        p_pic = osd_YuvaYuvp( p_this, p_pic );#endif    }    else msg_Err( p_this, "unable to handle this chroma" );    return p_pic;}/***************************************************************************** * Create a new Menu structure *****************************************************************************/static osd_menu_t *osd_MenuNew( osd_menu_t *p_menu, const char *psz_path, int i_x, int i_y ){    if( !p_menu ) return NULL;    p_menu->p_state = (osd_menu_state_t *) malloc( sizeof( osd_menu_state_t ) );    if( !p_menu->p_state )        msg_Err( p_menu, "Memory allocation for OSD Menu state failed" );    if( psz_path != NULL )        p_menu->psz_path = strdup( psz_path );    else        p_menu->psz_path = NULL;    p_menu->i_x = i_x;    p_menu->i_y = i_y;    return p_menu;}/***************************************************************************** * Free the menu *****************************************************************************/static void osd_MenuFree( vlc_object_t *p_this, osd_menu_t *p_menu ){    msg_Dbg( p_this, "freeing menu" );    osd_ButtonFree( p_this, p_menu->p_button );    p_menu->p_button = NULL;    p_menu->p_last_button = NULL;    if( p_menu->psz_path ) free( p_menu->psz_path );    p_menu->psz_path = NULL;    if( p_menu->p_state ) free( p_menu->p_state );    p_menu->p_state = NULL;}/***************************************************************************** * Create a new button *****************************************************************************/static osd_button_t *osd_ButtonNew( const char *psz_action, int i_x, int i_y ){    osd_button_t *p_button = NULL;    p_button = (osd_button_t*) malloc( sizeof(osd_button_t) );    if( !p_button )        return NULL;    memset( p_button, 0, sizeof(osd_button_t) );    p_button->psz_action = strdup(psz_action);    p_button->psz_action_down = NULL;    p_button->p_feedback = NULL;    p_button->i_x = i_x;    p_button->i_y = i_y;    return p_button;}/***************************************************************************** * Free a button *****************************************************************************/static void osd_ButtonFree( vlc_object_t *p_this, osd_button_t *p_button ){    osd_button_t *p_current = p_button;    osd_button_t *p_next = NULL;    osd_button_t *p_prev = NULL;    /* First walk to the end. */    while( p_current->p_next )    {        p_next = p_current->p_next;        p_current = p_next;    }    /* Then free end first and walk to the start. */    while( p_current->p_prev )    {        msg_Dbg( p_this, "+ freeing button %s [%p]", p_current->psz_action, p_current );        p_prev = p_current->p_prev;        p_current = p_prev;        if( p_current->p_next )        {            if( p_current->p_next->psz_name )                free( p_current->p_next->psz_name );            if( p_current->p_next->psz_action )                free( p_current->p_next->psz_action );            if( p_current->p_next->psz_action_down )                free( p_current->p_next->psz_action_down );            if( p_current->p_feedback && p_current->p_feedback->p_data_orig )                free( p_current->p_feedback->p_data_orig );            if( p_current->p_feedback )                free( p_current->p_feedback );            p_current->p_next->psz_action_down = NULL;            p_current->p_next->psz_action = NULL;            p_current->p_next->psz_name = NULL;            p_current->p_feedback = NULL;            /* Free all states first */            if( p_current->p_next->p_states )                osd_StatesFree( p_this, p_current->p_next->p_states );            p_current->p_next->p_states = NULL;            if( p_current->p_next) free( p_current->p_next );            p_current->p_next = NULL;        }        if( p_current->p_up )        {            if( p_current->p_up->psz_name )                free( p_current->p_up->psz_name );            if( p_current->p_up->psz_action )                free( p_current->p_up->psz_action );            if( p_current->p_up->psz_action_down )                free( p_current->p_up->psz_action_down );            if( p_current->p_feedback && p_current->p_feedback->p_data_orig )                free( p_current->p_feedback->p_data_orig );            if( p_current->p_feedback )                free( p_current->p_feedback );            p_current->p_up->psz_action_down = NULL;            p_current->p_up->psz_action = NULL;            p_current->p_up->psz_name = NULL;            p_current->p_feedback = NULL;            /* Free all states first */            if( p_current->p_up->p_states )                osd_StatesFree( p_this, p_current->p_up->p_states );            p_current->p_up->p_states = NULL;            if( p_current->p_up ) free( p_current->p_up );            p_current->p_up = NULL;        }    }    /* Free the last one. */    if( p_button )    {        msg_Dbg( p_this, "+ freeing button %s [%p]", p_button->psz_action, p_button );        if( p_button->psz_name ) free( p_button->psz_name );        if( p_button->psz_action ) free( p_button->psz_action );        if( p_button->psz_action_down ) free( p_button->psz_action_down );        if( p_current->p_feedback && p_current->p_feedback->p_data_orig )            free( p_current->p_feedback->p_data_orig );        if( p_current->p_feedback )            free( p_current->p_feedback );        p_button->psz_name = NULL;        p_button->psz_action = NULL;        p_button->psz_action_down = NULL;        p_current->p_feedback = NULL;        if( p_button->p_states )            osd_StatesFree( p_this, p_button->p_states );        p_button->p_states = NULL;        free( p_button );        p_button = NULL;    }}/***************************************************************************** * Create a new state image *****************************************************************************/static osd_state_t *osd_StateNew( vlc_object_t *p_this, const char *psz_file, const char *psz_state ){    osd_state_t *p_state = NULL;    p_state = (osd_state_t*) malloc( sizeof(osd_state_t) );    if( !p_state )        return NULL;    memset( p_state, 0, sizeof(osd_state_t) );    p_state->p_pic = osd_LoadImage( p_this, psz_file );    if( psz_state )    {        p_state->psz_state = strdup( psz_state );        if( strncmp( ppsz_button_states[0], psz_state, strlen(ppsz_button_states[0]) ) == 0 )            p_state->i_state = OSD_BUTTON_UNSELECT;        else if( strncmp( ppsz_button_states[1], psz_state, strlen(ppsz_button_states[1]) ) == 0 )            p_state->i_state = OSD_BUTTON_SELECT;        else if( strncmp( ppsz_button_states[2], psz_state, strlen(ppsz_button_states[2]) ) == 0 )            p_state->i_state = OSD_BUTTON_PRESSED;    }    return p_state;}/***************************************************************************** * Free state images *****************************************************************************/static void osd_StatesFree( vlc_object_t *p_this, osd_state_t *p_states ){    osd_state_t *p_state = p_states;    osd_state_t *p_next = NULL;    osd_state_t *p_prev = NULL;    while( p_state->p_next )    {        p_next = p_state->p_next;        p_state = p_next;    }    /* Then free end first and walk to the start. */    while( p_state->p_prev )    {        msg_Dbg( p_this, " |- freeing state %s [%p]", p_state->psz_state, p_state );        p_prev = p_state->p_prev;        p_state = p_prev;        if( p_state->p_next )        {            if( p_state->p_next->p_pic && p_state->p_next->p_pic->p_data_orig )                free( p_state->p_next->p_pic->p_data_orig );            if( p_state->p_next->p_pic ) free( p_state->p_next->p_pic );            p_state->p_next->p_pic = NULL;            if( p_state->p_next->psz_state ) free( p_state->p_next->psz_state );            p_state->p_next->psz_state = NULL;            free( p_state->p_next );            p_state->p_next = NULL;        }    }    /* Free the last one. */    if( p_states )    {        msg_Dbg( p_this, " |- freeing state %s [%p]", p_state->psz_state, p_states );        if( p_states->p_pic && p_states->p_pic->p_data_orig )            free( p_states->p_pic->p_data_orig );        if( p_states->p_pic ) free( p_states->p_pic );        p_states->p_pic = NULL;        if( p_state->psz_state ) free( p_state->psz_state );        p_state->psz_state = NULL;        free( p_states );        p_states = NULL;    }}/***************************************************************************** * osd_ConfigLoader: Load and parse osd text configurationfile *****************************************************************************/int osd_ConfigLoader( vlc_object_t *p_this, const char *psz_file,    osd_menu_t **p_menu ){    osd_button_t   *p_current = NULL; /* button currently processed */    osd_button_t   *p_prev = NULL;    /* previous processed button */#define MAX_FILE_PATH 256    FILE       *fd = NULL;    int        result = 0;    msg_Dbg( p_this, "opening osd definition file %s", psz_file );    fd = utf8_fopen( psz_file, "r" );    if( !fd )    {        msg_Err( p_this, "failed to open OSD definition file %s", psz_file );        return VLC_EGENERIC;    }    /* Read first line */    if( !feof( fd ) )    {        char action[25] = "";        char path[MAX_FILE_PATH] = "";        char *psz_path = NULL;        size_t i_len = 0;        /* override images path ? */        psz_path = config_GetPsz( p_this, "osdmenu-file-path" );        if( psz_path == NULL )        {            result = fscanf(fd, "%24s %255s", &action[0], &path[0] );        }        else        {            /* psz_path is not null and therefor &path[0] cannot be NULL             * it might be null terminated.             */            strncpy( &path[0], psz_path, MAX_FILE_PATH );            free( psz_path );            psz_path = NULL;        }        /* NULL terminate before asking the length of path[] */

⌨️ 快捷键说明

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