[vlc-devel] [PATCH 1/2] [RFC] filters: add mode to add a filter including conversion filters

Steve Lhomme robux4 at videolabs.io
Fri May 5 10:14:02 CEST 2017


This is useful to add CPU filters when using hardware decoding.

The shortcut is used by the conversion chain filter to know the actual filter requested.
---
 include/vlc_filter.h                 |  5 ++++-
 modules/stream_out/transcode/video.c |  4 ++--
 modules/video_chroma/chain.c         |  2 +-
 src/misc/filter_chain.c              | 15 +++++++++------
 src/video_output/video_output.c      |  2 +-
 5 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/include/vlc_filter.h b/include/vlc_filter.h
index 5743cac21e..41b86432d9 100644
--- a/include/vlc_filter.h
+++ b/include/vlc_filter.h
@@ -77,6 +77,8 @@ struct filter_t
     es_format_t         fmt_out;
     bool                b_allow_fmt_out_change;
 
+    const char *shortcut;
+
     /* Filter configuration */
     config_chain_t *    p_cfg;
 
@@ -316,11 +318,12 @@ VLC_API void filter_chain_Reset( filter_chain_t *, const es_format_t *, const es
  * \param name filter name
  * \param fmt_in filter input format
  * \param fmt_out filter output format
+ * \param strict do not try to add conversion filters in the middle
  * \return a pointer to the filter or NULL on error
  */
 VLC_API filter_t *filter_chain_AppendFilter(filter_chain_t *chain,
     const char *name, config_chain_t *cfg, const es_format_t *fmt_in,
-    const es_format_t *fmt_out);
+    const es_format_t *fmt_out, bool strict);
 
 /**
  * Append a conversion to the chain.
diff --git a/modules/stream_out/transcode/video.c b/modules/stream_out/transcode/video.c
index 47491f1cda..7550f1c83d 100644
--- a/modules/stream_out/transcode/video.c
+++ b/modules/stream_out/transcode/video.c
@@ -329,7 +329,7 @@ static void transcode_video_filter_init( sout_stream_t *p_stream,
                                    p_stream->p_sys->psz_deinterlace,
                                    p_stream->p_sys->p_deinterlace_cfg,
                                    &id->p_decoder->fmt_out,
-                                   &id->p_decoder->fmt_out );
+                                   &id->p_decoder->fmt_out, true );
 
         p_fmt_out = filter_chain_GetFmtOut( id->p_f_chain );
     }
@@ -339,7 +339,7 @@ static void transcode_video_filter_init( sout_stream_t *p_stream,
                                    "fps",
                                    NULL,
                                    p_fmt_out,
-                                   &id->p_encoder->fmt_in );
+                                   &id->p_encoder->fmt_in, true );
 
         p_fmt_out = filter_chain_GetFmtOut( id->p_f_chain );
     }
diff --git a/modules/video_chroma/chain.c b/modules/video_chroma/chain.c
index 6bc7af35f6..39b52a07b3 100644
--- a/modules/video_chroma/chain.c
+++ b/modules/video_chroma/chain.c
@@ -349,7 +349,7 @@ static filter_t * AppendTransform( filter_chain_t *p_chain, es_format_t *p_fmt1,
     snprintf( config, 100, "transform{type=%s}", type );
     char *next = config_ChainCreate( &name, &cfg, config );
 
-    filter_t *p_filter = filter_chain_AppendFilter( p_chain, name, cfg, p_fmt1, p_fmt2 );
+    filter_t *p_filter = filter_chain_AppendFilter( p_chain, name, cfg, p_fmt1, p_fmt2, true );
 
     config_ChainDestroy(cfg);
     free(name);
diff --git a/src/misc/filter_chain.c b/src/misc/filter_chain.c
index ae0316af73..96a3cf50b2 100644
--- a/src/misc/filter_chain.c
+++ b/src/misc/filter_chain.c
@@ -180,7 +180,7 @@ void filter_chain_Reset( filter_chain_t *p_chain, const es_format_t *p_fmt_in,
 
 static filter_t *filter_chain_AppendInner( filter_chain_t *chain,
     const char *name, const char *capability, config_chain_t *cfg,
-    const es_format_t *fmt_in, const es_format_t *fmt_out )
+    const es_format_t *fmt_in, const es_format_t *fmt_out, bool strict )
 {
     vlc_object_t *parent = chain->callbacks.sys;
     chained_filter_t *chained =
@@ -211,7 +211,10 @@ static filter_t *filter_chain_AppendInner( filter_chain_t *chain,
 
     assert( capability != NULL );
 
-    filter->p_module = module_need( filter, capability, name, name != NULL );
+
+    strict &= name != NULL;
+    filter->shortcut = strict ? NULL : name;
+    filter->p_module = module_need( filter, capability, name, strict );
     if( filter->p_module == NULL )
         goto error;
 
@@ -257,17 +260,17 @@ error:
 
 filter_t *filter_chain_AppendFilter( filter_chain_t *chain,
     const char *name, config_chain_t *cfg,
-    const es_format_t *fmt_in, const es_format_t *fmt_out )
+    const es_format_t *fmt_in, const es_format_t *fmt_out, bool strict )
 {
     return filter_chain_AppendInner( chain, name, chain->filter_cap, cfg,
-                                     fmt_in, fmt_out );
+                                     fmt_in, fmt_out, strict );
 }
 
 int filter_chain_AppendConverter( filter_chain_t *chain,
     const es_format_t *fmt_in, const es_format_t *fmt_out )
 {
     return filter_chain_AppendInner( chain, NULL, chain->conv_cap, NULL,
-                                     fmt_in, fmt_out ) != NULL ? 0 : -1;
+                                     fmt_in, fmt_out, true ) != NULL ? 0 : -1;
 }
 
 void filter_chain_DeleteFilter( filter_chain_t *chain, filter_t *filter )
@@ -327,7 +330,7 @@ int filter_chain_AppendFromString( filter_chain_t *chain, const char *str )
         buf = next;
 
         filter_t *filter = filter_chain_AppendFilter( chain, name, cfg,
-                                                      NULL, NULL );
+                                                      NULL, NULL, true );
         if( cfg )
             config_ChainDestroy( cfg );
 
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index e6a36f9828..1744eb7562 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -770,7 +770,7 @@ static void ThreadChangeFilters(vout_thread_t *vout,
         for (size_t i = 0; i < vlc_array_count(array); i++) {
             vout_filter_t *e = vlc_array_item_at_index(array, i);
             msg_Dbg(vout, "Adding '%s' as %s", e->name, a == 0 ? "static" : "interactive");
-            if (!filter_chain_AppendFilter(chain, e->name, e->cfg, NULL, NULL)) {
+            if (!filter_chain_AppendFilter(chain, e->name, e->cfg, NULL, NULL, false)) {
                 msg_Err(vout, "Failed to add filter '%s'", e->name);
                 config_ChainDestroy(e->cfg);
             }
-- 
2.12.1



More information about the vlc-devel mailing list