📄 filter_chain.c
字号:
/***************************************************************************** * filter_chain.c : Handle chains of filter_t objects. ***************************************************************************** * Copyright (C) 2008 the VideoLAN team * $Id$ * * Author: Antoine Cellerier <dionoea at videolan dot 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_filter.h>#include <vlc_arrays.h>#include <libvlc.h>struct filter_chain_t{ vlc_object_t *p_this; /* Parent object */ vlc_array_t filters; /* List of filters */ char *psz_capability; /* Capability of all the filters in the chain */ es_format_t fmt_in; /* Input format (read only) */ es_format_t fmt_out; /* Output format (writable depending on ... */ bool b_allow_fmt_out_change; /* allow changing fmt_out if true */ int (* pf_buffer_allocation_init)( filter_t *, void *p_data ); /* Callback called once filter allocation has succeeded to initialize the filter's buffer allocation callbacks. This function is responsible for setting p_owner if needed. */ void (* pf_buffer_allocation_clear)( filter_t * ); /* Callback called on filter removal from chain to clean up buffer allocation callbacks data (ie p_owner) */ void *p_buffer_allocation_data; /* Data for pf_buffer_allocation_init */};/** * Local prototypes */static filter_t *filter_chain_AppendFilterInternal( filter_chain_t *, const char *, config_chain_t *, const es_format_t *, const es_format_t * );static int filter_chain_AppendFromStringInternal( filter_chain_t *, const char * );static int filter_chain_DeleteFilterInternal( filter_chain_t *, filter_t * );static int UpdateBufferFunctions( filter_chain_t * );static picture_t *VideoBufferNew( filter_t * );static void VideoBufferDelete( filter_t *, picture_t * );/** * Filter chain initialisation */filter_chain_t *__filter_chain_New( vlc_object_t *p_this, const char *psz_capability, bool b_allow_fmt_out_change, int (*pf_buffer_allocation_init)( filter_t *, void * ), void (*pf_buffer_allocation_clear)( filter_t * ), void *p_buffer_allocation_data ){ filter_chain_t *p_chain = (filter_chain_t *) malloc( sizeof( filter_chain_t ) ); if( !p_chain ) return NULL; p_chain->p_this = p_this; vlc_array_init( &p_chain->filters ); p_chain->psz_capability = strdup( psz_capability ); if( !p_chain->psz_capability ) { free( p_chain ); return NULL; } es_format_Init( &p_chain->fmt_in, UNKNOWN_ES, 0 ); es_format_Init( &p_chain->fmt_out, UNKNOWN_ES, 0 ); p_chain->b_allow_fmt_out_change = b_allow_fmt_out_change; p_chain->pf_buffer_allocation_init = pf_buffer_allocation_init; p_chain->pf_buffer_allocation_clear = pf_buffer_allocation_clear; p_chain->p_buffer_allocation_data = p_buffer_allocation_data; return p_chain;}/** * Filter chain destruction */void filter_chain_Delete( filter_chain_t *p_chain ){ while( p_chain->filters.i_count ) filter_chain_DeleteFilterInternal( p_chain, (filter_t*)p_chain->filters.pp_elems[0] ); vlc_array_clear( &p_chain->filters ); free( p_chain->psz_capability ); es_format_Clean( &p_chain->fmt_in ); es_format_Clean( &p_chain->fmt_out ); free( p_chain );}/** * Filter chain reinitialisation */void filter_chain_Reset( filter_chain_t *p_chain, const es_format_t *p_fmt_in, const es_format_t *p_fmt_out ){ while( p_chain->filters.i_count ) filter_chain_DeleteFilterInternal( p_chain, (filter_t*)p_chain->filters.pp_elems[0] ); if( p_fmt_in ) { es_format_Clean( &p_chain->fmt_in ); es_format_Copy( &p_chain->fmt_in, p_fmt_in ); } if( p_fmt_out ) { es_format_Clean( &p_chain->fmt_out ); es_format_Copy( &p_chain->fmt_out, p_fmt_out ); }}/** * Modifying the filter chain */static filter_t *filter_chain_AppendFilterInternal( filter_chain_t *p_chain, const char *psz_name, config_chain_t *p_cfg, const es_format_t *p_fmt_in, const es_format_t *p_fmt_out ){ static const char typename[] = "filter"; filter_t *p_filter = vlc_custom_create( p_chain->p_this, sizeof(filter_t), VLC_OBJECT_GENERIC, typename ); if( !p_filter ) return NULL; vlc_object_attach( p_filter, p_chain->p_this ); if( !p_fmt_in ) { if( p_chain->filters.i_count ) p_fmt_in = &((filter_t*)p_chain->filters.pp_elems[p_chain->filters.i_count-1])->fmt_out; else p_fmt_in = &p_chain->fmt_in; } if( !p_fmt_out ) { p_fmt_out = &p_chain->fmt_out; } es_format_Copy( &p_filter->fmt_in, p_fmt_in ); es_format_Copy( &p_filter->fmt_out, p_fmt_out ); p_filter->p_cfg = p_cfg; p_filter->b_allow_fmt_out_change = p_chain->b_allow_fmt_out_change; p_filter->p_module = module_Need( p_filter, p_chain->psz_capability, psz_name, psz_name ? true : false ); if( !p_filter->p_module ) goto error; if( p_filter->b_allow_fmt_out_change ) { es_format_Clean( &p_chain->fmt_out ); es_format_Copy( &p_chain->fmt_out, &p_filter->fmt_out ); } if( p_chain->pf_buffer_allocation_init( p_filter, p_chain->p_buffer_allocation_data ) != VLC_SUCCESS ) goto error; vlc_array_append( &p_chain->filters, p_filter ); msg_Dbg( p_chain->p_this, "Filter '%s' (%p) appended to chain", psz_name?:p_filter->psz_object_name, p_filter ); return p_filter; error: if( psz_name ) msg_Err( p_chain->p_this, "Failed to create %s '%s'", p_chain->psz_capability, psz_name ); else msg_Err( p_chain->p_this, "Failed to create %s", p_chain->psz_capability ); if( p_filter->p_module ) module_Unneed( p_filter, p_filter->p_module ); es_format_Clean( &p_filter->fmt_in ); es_format_Clean( &p_filter->fmt_out ); vlc_object_detach( p_filter ); vlc_object_release( p_filter ); return NULL;}filter_t *filter_chain_AppendFilter( filter_chain_t *p_chain, const char *psz_name, config_chain_t *p_cfg, const es_format_t *p_fmt_in, const es_format_t *p_fmt_out ){ filter_t *p_filter = filter_chain_AppendFilterInternal( p_chain, psz_name, p_cfg, p_fmt_in, p_fmt_out ); if( UpdateBufferFunctions( p_chain ) < 0 ) msg_Err( p_filter, "Woah! This doesn't look good." ); return p_filter;}static int filter_chain_AppendFromStringInternal( filter_chain_t *p_chain, const char *psz_string ){ config_chain_t *p_cfg = NULL; char *psz_name = NULL; char* psz_new_string; if( !psz_string || !*psz_string ) return 0; psz_new_string = config_ChainCreate( &psz_name, &p_cfg, psz_string ); filter_t *p_filter = filter_chain_AppendFilterInternal( p_chain, psz_name, p_cfg, NULL, NULL ); if( !p_filter ) { msg_Err( p_chain->p_this, "Failed while trying to append '%s' " "to filter chain", psz_name ); free( psz_name ); free( p_cfg ); free( psz_new_string ); return -1; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -