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

📄 dynamicoverlay_commands.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * dynamicoverlay_commands.c : dynamic overlay plugin commands ***************************************************************************** * Copyright (C) 2008 the VideoLAN team * $Id$ * * Author: Soren Bog <avacore@videolan.org> *         Jean-Paul Saman <jpsaman@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. *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <vlc_arrays.h>#include <vlc_vout.h>#include <vlc_filter.h>#include <vlc_osd.h>#include <string.h>#include <ctype.h>#if defined(HAVE_SYS_SHM_H)#include <sys/shm.h>#endif#include "dynamicoverlay.h"/***************************************************************************** * overlay_t: Overlay descriptor *****************************************************************************/overlay_t *OverlayCreate( void ){    overlay_t *p_ovl = malloc( sizeof( overlay_t ) );    if( p_ovl == NULL )       return NULL;    memset( p_ovl, 0, sizeof( overlay_t ) );    p_ovl->i_x = p_ovl->i_y = 0;    p_ovl->i_alpha = 0xFF;    p_ovl->b_active = false;    vout_InitFormat( &p_ovl->format, VLC_FOURCC( '\0','\0','\0','\0') , 0, 0,                     VOUT_ASPECT_FACTOR );    memcpy( &p_ovl->fontstyle, &default_text_style, sizeof(struct text_style_t) );    p_ovl->data.p_text = NULL;    return p_ovl;}int OverlayDestroy( overlay_t *p_ovl ){    if( p_ovl->data.p_text != NULL )        free( p_ovl->data.p_text );    return VLC_SUCCESS;}/***************************************************************************** * Command parsers *****************************************************************************/static int skip_space( char **psz_command ){    char *psz_temp = *psz_command;    while( isspace( *psz_temp ) )    {        ++psz_temp;    }    if( psz_temp == *psz_command )    {        return VLC_EGENERIC;    }    *psz_command = psz_temp;    return VLC_SUCCESS;}static int parse_digit( char **psz_command, int32_t *value ){    char *psz_temp;    *value = strtol( *psz_command, &psz_temp, 10 );    if( psz_temp == *psz_command )    {        return VLC_EGENERIC;    }    *psz_command = psz_temp;    return VLC_SUCCESS;}static int parse_char( char **psz_command, char **psz_end,                       int count, char *psz_value ){    if( *psz_end - *psz_command < count )    {        return VLC_EGENERIC;    }    memcpy( psz_value, *psz_command, count );    *psz_command += count;    return VLC_SUCCESS;}static int parser_DataSharedMem( char *psz_command,                                 char *psz_end,                                 commandparams_t *p_params ){    /* Parse: 0 128 128 RGBA 9404459 */    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )            return VLC_EGENERIC;    }    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &p_params->i_width ) == VLC_EGENERIC )            return VLC_EGENERIC;    }    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &p_params->i_height ) == VLC_EGENERIC )            return VLC_EGENERIC;    }    skip_space( &psz_command );    if( isascii( *psz_command ) )    {        if( parse_char( &psz_command, &psz_end, 4, (char*)&p_params->fourcc )            == VLC_EGENERIC )            return VLC_EGENERIC;    }    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &p_params->i_shmid ) == VLC_EGENERIC )            return VLC_EGENERIC;    }    return VLC_SUCCESS;}static int parser_Id( char *psz_command, char *psz_end,                      commandparams_t *p_params ){    VLC_UNUSED(psz_end);    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )            return VLC_EGENERIC;    }    return VLC_SUCCESS;}static int parser_None( char *psz_command, char *psz_end,                        commandparams_t *p_params ){    VLC_UNUSED(psz_command);    VLC_UNUSED(psz_end);    VLC_UNUSED(p_params);    return VLC_SUCCESS;}static int parser_SetAlpha( char *psz_command, char *psz_end,                            commandparams_t *p_params ){    VLC_UNUSED(psz_end);    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC  )            return VLC_EGENERIC;    }    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &p_params->i_alpha ) == VLC_EGENERIC )            return VLC_EGENERIC;    }    return VLC_SUCCESS;}static int parser_SetPosition( char *psz_command, char *psz_end,                               commandparams_t *p_params ){    VLC_UNUSED(psz_end);    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )            return VLC_EGENERIC;    }    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &p_params->i_x ) == VLC_EGENERIC )            return VLC_EGENERIC;    }    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &p_params->i_y ) == VLC_EGENERIC )            return VLC_EGENERIC;    }    return VLC_SUCCESS;}static int parser_SetTextAlpha( char *psz_command, char *psz_end,                                commandparams_t *p_params ){    VLC_UNUSED(psz_end);    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )            return VLC_EGENERIC;    }    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &p_params->fontstyle.i_font_alpha ) == VLC_EGENERIC )            return VLC_EGENERIC;    }    return VLC_SUCCESS;}static int parser_SetTextColor( char *psz_command, char *psz_end,                                commandparams_t *p_params ){    int r, g, b;    VLC_UNUSED(psz_end);    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )            return VLC_EGENERIC;    }    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &r ) == VLC_EGENERIC )            return VLC_EGENERIC;    }    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &g ) == VLC_EGENERIC )            return VLC_EGENERIC;    }    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &b ) == VLC_EGENERIC )            return VLC_EGENERIC;    }    p_params->fontstyle.i_font_color = (r<<24) | (g<<16) | (b<<8);    return VLC_SUCCESS;}static int parser_SetTextSize( char *psz_command, char *psz_end,                               commandparams_t *p_params ){    VLC_UNUSED(psz_end);    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )            return VLC_EGENERIC;    }    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &p_params->fontstyle.i_font_size ) == VLC_EGENERIC )            return VLC_EGENERIC;    }    return VLC_SUCCESS;}static int parser_SetVisibility( char *psz_command, char *psz_end,                                 commandparams_t *p_params ){    VLC_UNUSED(psz_end);    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        if( parse_digit( &psz_command, &p_params->i_id ) == VLC_EGENERIC )            return VLC_EGENERIC;    }    skip_space( &psz_command );    if( isdigit( *psz_command ) )    {        int32_t i_vis = 0;        if( parse_digit( &psz_command, &i_vis ) == VLC_EGENERIC )            return VLC_EGENERIC;        p_params->b_visible = (i_vis == 1) ? true : false;    }    return VLC_SUCCESS;}/***************************************************************************** * Command unparser functions *****************************************************************************/static int unparse_default( const commandparams_t *p_results,                            buffer_t *p_output ){    VLC_UNUSED(p_results);    VLC_UNUSED(p_output);    return VLC_SUCCESS;}static int unparse_GenImage( const commandparams_t *p_results,                             buffer_t *p_output ){    int ret = BufferPrintf( p_output, " %d", p_results->i_id );    if( ret != VLC_SUCCESS )        return ret;    return VLC_SUCCESS;}static int unparse_GetAlpha( const commandparams_t *p_results,                             buffer_t *p_output ){    int ret = BufferPrintf( p_output, " %d", p_results->i_alpha );    if( ret != VLC_SUCCESS )        return ret;    return VLC_SUCCESS;}static int unparse_GetPosition( const commandparams_t *p_results,                                buffer_t *p_output ){    int ret = BufferPrintf( p_output, " %d", p_results->i_x );    if( ret != VLC_SUCCESS )        return ret;    ret = BufferPrintf( p_output, " %d", p_results->i_y );    if( ret != VLC_SUCCESS )        return ret;    return VLC_SUCCESS;}static int unparse_GetTextAlpha( const commandparams_t *p_results,                                 buffer_t *p_output ){    int ret = BufferPrintf( p_output, " %d", p_results->fontstyle.i_font_alpha );    if( ret != VLC_SUCCESS )        return ret;    return VLC_SUCCESS;}static int unparse_GetTextColor( const commandparams_t *p_results,                                 buffer_t *p_output ){    int ret = BufferPrintf( p_output, " %d", (p_results->fontstyle.i_font_color & 0xff0000)>>24 );    if( ret != VLC_SUCCESS )        return ret;    ret = BufferPrintf( p_output, " %d", (p_results->fontstyle.i_font_color & 0x00ff00)>>16 );    if( ret != VLC_SUCCESS )        return ret;    ret = BufferPrintf( p_output, " %d", (p_results->fontstyle.i_font_color & 0x0000ff)>>8 );    if( ret != VLC_SUCCESS )        return ret;    return VLC_SUCCESS;}static int unparse_GetTextSize( const commandparams_t *p_results,                                buffer_t *p_output ){    int ret = BufferPrintf( p_output, " %d", p_results->fontstyle.i_font_size );    if( ret != VLC_SUCCESS )        return ret;    return VLC_SUCCESS;}static int unparse_GetVisibility( const commandparams_t *p_results,                             buffer_t *p_output ){    int ret = BufferPrintf( p_output, " %d", (p_results->b_visible ? 1 : 0) );    if( ret != VLC_SUCCESS ) {        return ret;    }    return VLC_SUCCESS;}/***************************************************************************** * Command functions *****************************************************************************/static int exec_DataSharedMem( filter_t *p_filter,                               const commandparams_t *p_params,                               commandparams_t *p_results ){#if defined(HAVE_SYS_SHM_H)    filter_sys_t *p_sys = (filter_sys_t*) p_filter->p_sys;    struct shmid_ds shminfo;    overlay_t *p_ovl;    size_t i_size;    VLC_UNUSED(p_results);    p_ovl = ListGet( &p_sys->overlays, p_params->i_id );    if( p_ovl == NULL )    {        msg_Err( p_filter, "Invalid overlay: %d", p_params->i_id );        return VLC_EGENERIC;    }    if( shmctl( p_params->i_shmid, IPC_STAT, &shminfo ) == -1 )    {        msg_Err( p_filter, "Unable to access shared memory" );        return VLC_EGENERIC;    }    i_size = shminfo.shm_segsz;    if( p_params->fourcc == VLC_FOURCC('T','E','X','T') )    {        char *p_data;        if( (p_params->i_height != 1) || (p_params->i_width < 1) )        {            msg_Err( p_filter,                     "Invalid width and/or height. when specifing text height "                     "must be 1 and width the number of bytes in the string, "                     "including the null terminator" );            return VLC_EGENERIC;        }        if( (size_t)p_params->i_width > i_size )        {            msg_Err( p_filter,                     "Insufficient data in shared memory. need %d, got %zu",                     p_params->i_width, i_size );            return VLC_EGENERIC;        }        p_ovl->data.p_text = malloc( p_params->i_width );        if( p_ovl->data.p_text == NULL )        {            msg_Err( p_filter, "Unable to allocate string storage" );            return VLC_ENOMEM;        }        vout_InitFormat( &p_ovl->format, VLC_FOURCC('T','E','X','T'),                         0, 0, 0 );        p_data = shmat( p_params->i_shmid, NULL, SHM_RDONLY );        if( p_data == NULL )

⌨️ 快捷键说明

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