[vlc-commits] filters: use macro to set the typed Open callback for text renderer filters

Steve Lhomme git at videolan.org
Tue Oct 13 11:07:09 CEST 2020


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Fri Oct  9 11:24:26 2020 +0200| [b027f1a6c792da764bec4290b2510bbc14dc18a3] | committer: Steve Lhomme

filters: use macro to set the typed Open callback for text renderer filters

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b027f1a6c792da764bec4290b2510bbc14dc18a3
---

 include/vlc_filter.h                        | 11 ++++++++++-
 modules/text_renderer/freetype/freetype.c   | 12 +++++-------
 modules/text_renderer/nsspeechsynthesizer.m |  8 +++-----
 modules/text_renderer/sapi.cpp              | 18 ++++++++----------
 modules/text_renderer/svg.c                 |  9 +++------
 modules/text_renderer/tdummy.c              |  8 +++-----
 6 files changed, 32 insertions(+), 34 deletions(-)

diff --git a/include/vlc_filter.h b/include/vlc_filter.h
index 63763e0231..6b3c395d7d 100644
--- a/include/vlc_filter.h
+++ b/include/vlc_filter.h
@@ -100,7 +100,7 @@ struct vlc_filter_operations
         /** Filter a subpicture (sub filter) */
         subpicture_t *(*filter_sub)(filter_t *, subpicture_t *);
 
-        /** Render text (text render) */
+        /** Render text (text renderer) */
         int (*render)(filter_t *, subpicture_region_t *,
                       subpicture_region_t *, const vlc_fourcc_t *);
     };
@@ -143,6 +143,7 @@ struct vlc_filter_operations
 typedef int (*vlc_open_deinterlace)(filter_t *);
 typedef int (*vlc_video_converter_open)(filter_t *);
 typedef int (*vlc_video_filter_open)(filter_t *);
+typedef int (*vlc_video_text_renderer_open)(filter_t *);
 
 
 #define set_deinterlace_callback( activate )     \
@@ -170,6 +171,14 @@ typedef int (*vlc_video_filter_open)(filter_t *);
     }                                                      \
     set_capability( "video converter", priority )
 
+#define set_callback_text_renderer( activate, priority )   \
+    {                                                      \
+        vlc_video_text_renderer_open open__ = activate;    \
+        (void) open__;                                     \
+        set_callback(activate)                             \
+    }                                                      \
+    set_capability( "text renderer", priority )
+
 /** Structure describing a filter
  * @warning BIG FAT WARNING : the code relies on the first 4 members of
  * filter_t and decoder_t to be the same, so if you have anything to add,
diff --git a/modules/text_renderer/freetype/freetype.c b/modules/text_renderer/freetype/freetype.c
index a866b99d72..d9044ca54c 100644
--- a/modules/text_renderer/freetype/freetype.c
+++ b/modules/text_renderer/freetype/freetype.c
@@ -53,7 +53,7 @@
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-static int  Create ( vlc_object_t * );
+static int  Create ( filter_t * );
 static void Destroy( filter_t * );
 
 #define FONT_TEXT N_("Font")
@@ -204,9 +204,8 @@ vlc_module_begin ()
         change_safe()
 #endif
 
-    set_capability( "text renderer", 100 )
     add_shortcut( "text" )
-    set_callback( Create )
+    set_callback_text_renderer( Create, 100 )
 vlc_module_end ()
 
 /* */
@@ -1169,9 +1168,8 @@ static const struct vlc_filter_operations filter_ops =
  *****************************************************************************
  * This function allocates and initializes a Clone vout method.
  *****************************************************************************/
-static int Create( vlc_object_t *p_this )
+static int Create( filter_t *p_filter )
 {
-    filter_t      *p_filter         = ( filter_t * ) p_this;
     filter_sys_t  *p_sys            = NULL;
 
     /* Allocate structure */
@@ -1193,8 +1191,8 @@ static int Create( vlc_object_t *p_this )
         p_sys->p_stroker = NULL;
     }
 
-    p_sys->ftcache = vlc_ftcache_New( p_this, p_sys->p_library,
-                            var_InheritInteger( p_this, "freetype-cache-size" ) );
+    p_sys->ftcache = vlc_ftcache_New( VLC_OBJECT(p_filter), p_sys->p_library,
+                            var_InheritInteger( p_filter, "freetype-cache-size" ) );
     if( !p_sys->ftcache )
         goto error;
 
diff --git a/modules/text_renderer/nsspeechsynthesizer.m b/modules/text_renderer/nsspeechsynthesizer.m
index f3b7d7e151..5d8a683ec4 100644
--- a/modules/text_renderer/nsspeechsynthesizer.m
+++ b/modules/text_renderer/nsspeechsynthesizer.m
@@ -35,7 +35,7 @@
 
 #import <Cocoa/Cocoa.h>
 
-static int Create (vlc_object_t *);
+static int Create (filter_t *);
 static void Destroy(filter_t *);
 static int RenderText(filter_t *,
                       subpicture_region_t *,
@@ -47,8 +47,7 @@ set_description(N_("Speech synthesis for Mac OS X"))
 set_category(CAT_VIDEO)
 set_subcategory(SUBCAT_VIDEO_SUBPIC)
 
-set_capability("text renderer", 0)
-set_callback(Create)
+set_callback_text_renderer(Create, 0)
 vlc_module_end ()
 
 typedef struct filter_sys_t
@@ -62,9 +61,8 @@ static const struct vlc_filter_operations filter_ops = {
     .render = RenderText, .close = Destroy,
 };
 
-static int  Create (vlc_object_t *p_this)
+static int  Create (filter_t *p_filter)
 {
-    filter_t *p_filter = (filter_t *)p_this;
     filter_sys_t *p_sys;
 
     p_filter->p_sys = p_sys = malloc(sizeof(filter_sys_t));
diff --git a/modules/text_renderer/sapi.cpp b/modules/text_renderer/sapi.cpp
index f12961ecef..d735b8c512 100644
--- a/modules/text_renderer/sapi.cpp
+++ b/modules/text_renderer/sapi.cpp
@@ -44,7 +44,7 @@
 #include <sapi.h>
 #include <sphelper.h>
 
-static int Create (vlc_object_t *);
+static int Create (filter_t *);
 static void Destroy(filter_t *);
 static int RenderText(filter_t *,
                       subpicture_region_t *,
@@ -57,8 +57,7 @@ vlc_module_begin ()
  set_category(CAT_VIDEO)
  set_subcategory(SUBCAT_VIDEO_SUBPIC)
 
- set_capability("text renderer", 0)
- set_callback(Create)
+ set_callback_text_renderer(Create, 0)
  add_integer("sapi-voice", -1, "Voice Index", "Voice index", false)
 vlc_module_end ()
 
@@ -102,13 +101,12 @@ static const struct FilterOperationInitializer {
     };
 } filter_ops;
 
-static int Create (vlc_object_t *p_this)
+static int Create (filter_t *p_filter)
 {
-    filter_t *p_filter = (filter_t *)p_this;
     filter_sys_t *p_sys;
     HRESULT hr;
 
-    if (TryEnterMTA(p_this))
+    if (TryEnterMTA(p_filter))
         return VLC_EGENERIC;
 
     p_filter->p_sys = p_sys = (filter_sys_t*) malloc(sizeof(filter_sys_t));
@@ -131,7 +129,7 @@ static int Create (vlc_object_t *p_this)
             hr = cpEnum->GetCount(&ulCount);
             if (SUCCEEDED (hr))
             {
-                int voiceIndex = var_InheritInteger(p_this, "sapi-voice");
+                int voiceIndex = var_InheritInteger(p_filter, "sapi-voice");
                 if (voiceIndex > -1)
                 {
                     if ((unsigned)voiceIndex < ulCount) {
@@ -139,17 +137,17 @@ static int Create (vlc_object_t *p_this)
                         if (SUCCEEDED(hr)) {
                             hr = p_sys->cpVoice->SetVoice(cpVoiceToken);
                             if (SUCCEEDED(hr)) {
-                                msg_Dbg(p_this, "Selected voice %d", voiceIndex);
+                                msg_Dbg(p_filter, "Selected voice %d", voiceIndex);
                             }
                             else {
-                                msg_Err(p_this, "Failed to set voice %d", voiceIndex);
+                                msg_Err(p_filter, "Failed to set voice %d", voiceIndex);
                             }
                             cpVoiceToken->Release();
                             cpVoiceToken = NULL;
                         }
                     }
                     else
-                        msg_Err(p_this, "Voice index exceeds available count");
+                        msg_Err(p_filter, "Voice index exceeds available count");
                 }
             }
             cpEnum->Release();
diff --git a/modules/text_renderer/svg.c b/modules/text_renderer/svg.c
index fbb55f6beb..39907a39e7 100644
--- a/modules/text_renderer/svg.c
+++ b/modules/text_renderer/svg.c
@@ -47,7 +47,7 @@
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int  Create    ( vlc_object_t * );
+static int  Create    ( filter_t * );
 static void Destroy   ( filter_t * );
 static int  RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
                         subpicture_region_t *p_region_in,
@@ -73,10 +73,9 @@ typedef struct
 vlc_module_begin ()
     set_category( CAT_INPUT )
     set_subcategory( SUBCAT_INPUT_SCODEC )
-    set_capability( "text renderer", 99 )
     add_shortcut( "svg" )
     add_string( "svg-template-file", "", TEMPLATE_TEXT, TEMPLATE_LONGTEXT, true )
-    set_callback( Create )
+    set_callback_text_renderer( Create, 99 )
 vlc_module_end ()
 
 static void svg_RescaletoFit  ( filter_t *, int *width, int *height, float * );
@@ -179,10 +178,8 @@ static const struct vlc_filter_operations filter_ops = {
  * This function allocates and initializes a  vout method.
  *****************************************************************************/
 
-static int Create( vlc_object_t *p_this )
+static int Create( filter_t *p_filter )
 {
-    filter_t *p_filter = ( filter_t * )p_this;
-
     filter_sys_t *p_sys = calloc( 1, sizeof(*p_sys) );
     if( !p_sys )
         return VLC_ENOMEM;
diff --git a/modules/text_renderer/tdummy.c b/modules/text_renderer/tdummy.c
index 4fd996674c..dc330605f1 100644
--- a/modules/text_renderer/tdummy.c
+++ b/modules/text_renderer/tdummy.c
@@ -28,13 +28,12 @@
 #include <vlc_plugin.h>
 #include <vlc_filter.h>
 
-static int OpenRenderer( vlc_object_t * );
+static int OpenRenderer( filter_t * );
 
 vlc_module_begin ()
     set_shortname( N_("Dummy") )
     set_description( N_("Dummy font renderer") )
-    set_capability( "text renderer", 1 )
-    set_callback( OpenRenderer )
+    set_callback_text_renderer( OpenRenderer, 1 )
 vlc_module_end ()
 
 
@@ -51,9 +50,8 @@ static const struct vlc_filter_operations filter_ops = {
     .render = RenderText,
 };
 
-static int OpenRenderer( vlc_object_t *p_this )
+static int OpenRenderer( filter_t *p_filter )
 {
-    filter_t *p_filter = (filter_t *)p_this;
     p_filter->ops = &filter_ops;
     return VLC_SUCCESS;
 }



More information about the vlc-commits mailing list