[vlc-devel] [PATCH 1/4] sub-filter2 support
Yuval Tze
yuvaltze at gmail.com
Thu Mar 24 23:22:49 CET 2011
new filter type for processing subtitles.
---
include/vlc_filter.h | 15 ++++++++
src/libvlccore.sym | 1 +
src/misc/filter_chain.c | 14 +++++++
src/video_output/vout_intf.c | 3 +-
src/video_output/vout_subpictures.c | 65 ++++++++++++++++++++++++++++++++++-
5 files changed, 96 insertions(+), 2 deletions(-)
diff --git a/include/vlc_filter.h b/include/vlc_filter.h
index ea24344..453f08d 100644
--- a/include/vlc_filter.h
+++ b/include/vlc_filter.h
@@ -118,6 +118,12 @@ struct filter_t
struct
{
+ subpicture_t * (*pf_filter) ( filter_t *, subpicture_t * );
+ } sub2;
+#define pf_sub_filter2 u.sub2.pf_filter
+
+ struct
+ {
int (*pf_text) ( filter_t *, subpicture_region_t *,
subpicture_region_t * );
int (*pf_html) ( filter_t *, subpicture_region_t *,
@@ -402,6 +408,15 @@ VLC_EXPORT( block_t *, filter_chain_AudioFilter, ( filter_chain_t *, block_t * )
VLC_EXPORT( void, filter_chain_SubFilter, ( filter_chain_t *, mtime_t ) );
/**
+ * Apply filter2 chain to subpictures.
+ *
+ * \param p_chain pointer to filter2 chain
+ * \param p_subpicture subpicture to apply filters on
+ * \return modified subpicture after applying all subpicture filters
+ */
+VLC_EXPORT( subpicture_t *, filter_chain_SubFilter2, ( filter_chain_t *, subpicture_t * ) );
+
+/**
* Apply the filter chain to a mouse state.
*
* It will be applied from the output to the input. It makes sense only
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 30173a5..965c387 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -134,6 +134,7 @@ filter_chain_MouseEvent
filter_chain_New
filter_chain_Reset
filter_chain_SubFilter
+filter_chain_SubFilter2
filter_chain_VideoFilter
filter_chain_VideoFlush
filter_ConfigureBlend
diff --git a/src/misc/filter_chain.c b/src/misc/filter_chain.c
index cb9be4a..a69d762 100644
--- a/src/misc/filter_chain.c
+++ b/src/misc/filter_chain.c
@@ -306,6 +306,20 @@ void filter_chain_SubFilter( filter_chain_t *p_chain,
}
}
+subpicture_t *filter_chain_SubFilter2( filter_chain_t *p_chain, subpicture_t *p_subpic )
+{
+ for( chained_filter_t *f = p_chain->first; f != NULL; f = f->next )
+ {
+ filter_t *p_filter = &f->filter;
+
+ p_subpic = p_filter->pf_sub_filter2( p_filter, p_subpic );
+
+ if( !p_subpic )
+ break;
+ }
+ return p_subpic;
+}
+
int filter_chain_MouseFilter( filter_chain_t *p_chain, vlc_mouse_t *p_dst, const vlc_mouse_t *p_src )
{
vlc_mouse_t current = *p_src;
diff --git a/src/video_output/vout_intf.c b/src/video_output/vout_intf.c
index 2f33731..8ce337d 100644
--- a/src/video_output/vout_intf.c
+++ b/src/video_output/vout_intf.c
@@ -466,7 +466,8 @@ void vout_EnableFilter( vout_thread_t *p_vout, const char *psz_name,
{
psz_filter_type = "video-filter";
}
- else if( module_provides( p_obj, "sub filter" ) )
+ else if( module_provides( p_obj, "sub filter" ) ||
+ module_provides( p_obj, "sub filter2" ) )
{
psz_filter_type = "sub-filter";
}
diff --git a/src/video_output/vout_subpictures.c b/src/video_output/vout_subpictures.c
index dc21fa7..9f8ab69 100644
--- a/src/video_output/vout_subpictures.c
+++ b/src/video_output/vout_subpictures.c
@@ -86,6 +86,7 @@ struct spu_private_t
char *psz_chain_update;
vlc_mutex_t chain_lock;
filter_chain_t *p_chain;
+ filter_chain_t *p_chain2;
/* */
mtime_t i_last_sort_date;
@@ -1277,6 +1278,56 @@ static void SubFilterAllocationClean( filter_t *p_filter )
free( p_filter->p_owner );
}
+
+/*****************************************************************************
+ * Append subfilters to appropriate chain
+ *****************************************************************************/
+static void AppendSubfiltersByCapability( char *psz_filters,
+ filter_chain_t *p_subfilter_chain,
+ filter_chain_t *p_subfilter2_chain )
+{
+ module_t *p_module;
+ config_chain_t *p_cfg;
+ const char *psz_capability;
+ char *psz_name;
+ char *psz_next;
+ filter_chain_t *p_chain;
+
+ char *psz_current = psz_filters ? strdup( psz_filters ) : NULL;
+
+ while( psz_current )
+ {
+ psz_next = config_ChainCreate( &psz_name, &p_cfg, psz_current );
+
+ p_module = module_find( psz_name );
+
+ if( p_module )
+ {
+ psz_capability = module_get_capability( p_module );
+
+ if( !strcmp( psz_capability, "sub filter" ) )
+ {
+ p_chain = p_subfilter_chain;
+ }
+ else /* psz_capability == "sub filter2" */
+ {
+ p_chain = p_subfilter2_chain;
+ }
+
+ filter_chain_AppendFilter( p_chain, psz_name, p_cfg, NULL, NULL );
+ }
+ else
+ {
+ config_ChainDestroy( p_cfg );
+ }
+
+ free( psz_name );
+ free( psz_current );
+ psz_current = psz_next;
+ }
+}
+
+
/*****************************************************************************
* Public API
*****************************************************************************/
@@ -1322,6 +1373,11 @@ spu_t *spu_Create( vlc_object_t *p_this )
SubFilterAllocationClean,
p_spu );
+ p_sys->p_chain2 = filter_chain_New( p_spu, "sub filter2", false,
+ NULL,
+ NULL,
+ p_spu );
+
/* Load text and scale module */
p_sys->p_text = SpuRenderCreateAndLoadText( p_spu );
@@ -1360,6 +1416,7 @@ void spu_Destroy( spu_t *p_spu )
FilterRelease( p_sys->p_scale );
filter_chain_Delete( p_sys->p_chain );
+ filter_chain_Delete( p_sys->p_chain2 );
vlc_mutex_destroy( &p_sys->chain_lock );
free( p_sys->psz_chain_update );
@@ -1434,6 +1491,9 @@ void spu_PutSubpicture( spu_t *p_spu, subpicture_t *p_subpic )
{
spu_private_t *p_sys = p_spu->p;
+ /* Run filter chain on the new subpicture */
+ p_subpic = filter_chain_SubFilter2(p_spu->p->p_chain2, p_subpic);
+
/* SPU_DEFAULT_CHANNEL always reset itself */
if( p_subpic->i_channel == SPU_DEFAULT_CHANNEL )
spu_ClearChannel( p_spu, SPU_DEFAULT_CHANNEL );
@@ -1474,8 +1534,11 @@ subpicture_t *spu_Render( spu_t *p_spu,
if( psz_chain_update )
{
filter_chain_Reset( p_sys->p_chain, NULL, NULL );
+ filter_chain_Reset( p_sys->p_chain2, NULL, NULL );
- filter_chain_AppendFromString( p_spu->p->p_chain, psz_chain_update );
+ AppendSubfiltersByCapability( psz_chain_update,
+ p_spu->p->p_chain,
+ p_spu->p->p_chain2 );
free( psz_chain_update );
}
--
1.7.1
More information about the vlc-devel
mailing list