0015-libvlc-add-preliminary-code-path-to-modify-quartztex.patch 10.2 KB
Newer Older
1
From d85d2e1dc4ac7eb95e1ba32aca38667c573b1abb Mon Sep 17 00:00:00 2001
2 3
From: =?UTF-8?q?Felix=20Paul=20K=C3=BChne?= <fkuehne@videolan.org>
Date: Mon, 31 Mar 2014 17:54:01 +0200
Felix Paul Kühne's avatar
Felix Paul Kühne committed
4
Subject: [PATCH 15/16] libvlc: add preliminary code path to modify quartztext
5 6 7
 variables on-the-fly

---
Felix Paul Kühne's avatar
Felix Paul Kühne committed
8
 include/vlc/libvlc_media_player.h  | 21 +++++++++++++
9
 lib/libvlc.sym                     |  4 +++
Felix Paul Kühne's avatar
Felix Paul Kühne committed
10 11 12 13
 lib/media_player.c                 |  6 ++++
 lib/video.c                        | 47 +++++++++++++++++++++++++++++
 modules/text_renderer/quartztext.c | 61 ++++++++++++++++++++++++++++++++------
 5 files changed, 130 insertions(+), 9 deletions(-)
14 15

diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
16
index 94bf7e8..c55e85d 100644
17 18
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
19
@@ -1383,6 +1383,27 @@ LIBVLC_API float libvlc_video_get_adjust_float( libvlc_media_player_t *p_mi,
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
 LIBVLC_API void libvlc_video_set_adjust_float( libvlc_media_player_t *p_mi,
                                                    unsigned option, float value );
 
+/** option values for libvlc_video_{get,set}_adjust_{int,float,bool} */
+enum libvlc_video_textrenderer_option_t {
+    libvlc_textrender_font = 0,
+    libvlc_textrender_fontsize,
+    libvlc_textrender_fontcolor,
+};
+
+LIBVLC_API int libvlc_video_get_textrenderer_int( libvlc_media_player_t *p_mi,
+                                                  unsigned option );
+
+LIBVLC_API void libvlc_video_set_textrenderer_int( libvlc_media_player_t *p_mi,
+                                                   unsigned option, int value );
+
+LIBVLC_API char *libvlc_video_get_textrenderer_string( libvlc_media_player_t *p_mi,
+                                                          unsigned option );
+
+LIBVLC_API void libvlc_video_set_textrenderer_string( libvlc_media_player_t *p_mi,
+                                                      unsigned option,
+                                                      const char *psz_text );
+
+
 /** @} video */
 
 /** \defgroup libvlc_audio LibVLC audio controls
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
48
index c0c66dd..7810ed7 100644
49 50
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
51
@@ -217,6 +217,8 @@ libvlc_video_get_spu_count
52 53 54 55 56 57 58 59
 libvlc_video_get_spu_delay
 libvlc_video_get_spu_description
 libvlc_video_get_teletext
+libvlc_video_get_text_renderer_int
+libvlc_video_get_text_renderer_string
 libvlc_video_get_title_description
 libvlc_video_get_track
 libvlc_video_get_track_count
60
@@ -241,6 +243,8 @@ libvlc_video_set_spu
61 62 63 64 65 66 67 68 69
 libvlc_video_set_spu_delay
 libvlc_video_set_subtitle_file
 libvlc_video_set_teletext
+libvlc_video_set_text_renderer_int
+libvlc_video_set_text_renderer_string
 libvlc_video_set_track
 libvlc_video_take_snapshot
 libvlc_vlm_add_broadcast
diff --git a/lib/media_player.c b/lib/media_player.c
70
index 5691345..3ca1e10 100644
71 72
--- a/lib/media_player.c
+++ b/lib/media_player.c
73
@@ -465,6 +465,12 @@ libvlc_media_player_new( libvlc_instance_t *instance )
74 75 76 77 78 79 80 81 82 83 84 85 86
     var_Create (mp, "saturation", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);
     var_Create (mp, "gamma", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);
 
+#ifdef __APPLE__
+    var_Create (mp, "quartztext-font", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
+    var_Create (mp, "quartztext-fontsize", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+    var_Create (mp, "quartztext-color", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+#endif
+
      /* Audio */
     var_Create (mp, "aout", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
     var_Create (mp, "mute", VLC_VAR_BOOL);
diff --git a/lib/video.c b/lib/video.c
87
index 19065fb..8988069 100644
88 89
--- a/lib/video.c
+++ b/lib/video.c
90
@@ -934,3 +934,50 @@ float libvlc_video_get_adjust_float( libvlc_media_player_t *p_mi,
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
 {
     return get_float( p_mi, "adjust", adjust_option_bynumber(option) );
 }
+
+
+static const opt_t *
+textrenderer_option_bynumber( unsigned option )
+{
+    static const opt_t optlist[] =
+    {
+        { "quartztext-font",            VLC_VAR_STRING },
+        { "quartztext-fontsize",    VLC_VAR_INTEGER },
+        { "quartztext-color",           VLC_VAR_INTEGER },
+    };
+    enum { num_opts = sizeof(optlist) / sizeof(*optlist) };
+
+    const opt_t *r = option < num_opts ? optlist+option : NULL;
+    if( !r )
+        libvlc_printerr( "Unknown quartztext option" );
+    return r;
+}
+
+/* basic text renderer support */
+
+void libvlc_video_set_textrenderer_int( libvlc_media_player_t *p_mi,
+                                 unsigned option, int value )
+{
+    set_int( p_mi, "quartztext", textrenderer_option_bynumber(option), value );
+}
+
+
+int libvlc_video_get_textrenderer_int( libvlc_media_player_t *p_mi,
+                                unsigned option )
+{
+    return get_int( p_mi, "quartztext", textrenderer_option_bynumber(option) );
+}
+
+
+void libvlc_video_set_textrenderer_string( libvlc_media_player_t *p_mi,
+                                   unsigned option, const char *psz_value )
+{
+    set_string( p_mi, "quartztext", textrenderer_option_bynumber(option), psz_value );
+}
+
+
+char * libvlc_video_get_textrenderer_string( libvlc_media_player_t *p_mi,
+                                    unsigned option )
+{
+    return get_string( p_mi, "quartztext", textrenderer_option_bynumber(option) );
+}
diff --git a/modules/text_renderer/quartztext.c b/modules/text_renderer/quartztext.c
142
index 8de1081..112e952 100644
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
--- a/modules/text_renderer/quartztext.c
+++ b/modules/text_renderer/quartztext.c
@@ -65,6 +65,10 @@
 static int  Create (vlc_object_t *);
 static void Destroy(vlc_object_t *);
 
+static int QuartztextCallback( vlc_object_t *p_this, char const *psz_var,
+                               vlc_value_t oldval, vlc_value_t newval,
+                               void *p_data );
+
 static int LoadFontsFromAttachments(filter_t *p_filter);
 
 static int RenderText(filter_t *, subpicture_region_t *,
@@ -128,14 +132,17 @@ vlc_module_begin ()
 
     add_string("quartztext-font", DEFAULT_FONT, FONT_TEXT, FONT_LONGTEXT,
               false)
-    add_integer("quartztext-rel-fontsize", DEFAULT_REL_FONT_SIZE, FONTSIZER_TEXT,
+        change_safe()
+    add_integer("quartztext-fontsize", DEFAULT_REL_FONT_SIZE, FONTSIZER_TEXT,
                  FONTSIZER_LONGTEXT, false)
+        change_safe()
         change_integer_list(pi_sizes, ppsz_sizes_text)
     add_integer("quartztext-color", 0x00FFFFFF, COLOR_TEXT,
                  COLOR_LONGTEXT, false)
+        change_safe()
         change_integer_list(pi_color_values, ppsz_color_descriptions)
     set_capability("text renderer", 50)
-    add_shortcut("text")
+    add_shortcut("quartztext")
     set_callbacks(Create, Destroy)
 vlc_module_end ()
 
@@ -177,7 +184,8 @@ struct offscreen_bitmap_t
  *****************************************************************************/
 struct filter_sys_t
 {
-    char          *psz_font_name;
+    vlc_mutex_t    lock;
+    char           *psz_font_name;
     uint8_t        i_font_opacity;
     int            i_font_color;
     int            i_font_size;
@@ -202,9 +210,9 @@ static int Create(vlc_object_t *p_this)
     p_filter->p_sys = p_sys = malloc(sizeof(filter_sys_t));
     if (!p_sys)
         return VLC_ENOMEM;
-    p_sys->psz_font_name  = var_CreateGetString(p_this, "quartztext-font");
+    p_sys->psz_font_name  = var_CreateGetStringCommand(p_this, "quartztext-font");
     p_sys->i_font_opacity = 255;
-    p_sys->i_font_color = VLC_CLIP(var_CreateGetInteger(p_this, "quartztext-color") , 0, 0xFFFFFF);
+    p_sys->i_font_color = VLC_CLIP(var_CreateGetIntegerCommand(p_this, "quartztext-color") , 0, 0xFFFFFF);
     p_sys->i_font_size = GetFontSize(p_filter);
 
     p_filter->pf_render_text = RenderText;
@@ -215,6 +223,11 @@ static int Create(vlc_object_t *p_this)
     p_sys->i_fonts = 0;
 #endif
 
+    vlc_mutex_init( &p_sys->lock );
+    var_AddCallback( p_filter, "quartztext-font", QuartztextCallback, p_sys );
+    var_AddCallback( p_filter, "quartztext-fontsize", QuartztextCallback, p_sys );
+    var_AddCallback( p_filter, "quartztext-color", QuartztextCallback, p_sys );
+
     LoadFontsFromAttachments(p_filter);
 
     return VLC_SUCCESS;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
210
@@ -229,6 +242,16 @@ static void Destroy(vlc_object_t *p_this)
211 212 213 214 215 216 217 218
 {
     filter_t *p_filter = (filter_t *)p_this;
     filter_sys_t *p_sys = p_filter->p_sys;
+
+    var_DelCallback( p_filter, "quartztext-font", QuartztextCallback, p_sys );
+    var_DelCallback( p_filter, "quartztext-fontsize", QuartztextCallback, p_sys );
+    var_DelCallback( p_filter, "quartztext-color", QuartztextCallback, p_sys );
+    vlc_mutex_destroy( &p_sys->lock );
Felix Paul Kühne's avatar
Felix Paul Kühne committed
219 220 221 222
+
+    var_Destroy( p_filter, "quartztext-font" ) ;
+    var_Destroy( p_filter, "quartztext-fontsize" );
+    var_Destroy( p_filter, "quartztext-color" );
223 224 225 226
+
 #ifndef TARGET_OS_IPHONE
     if (p_sys->p_fonts) {
         for (int k = 0; k < p_sys->i_fonts; k++) {
Felix Paul Kühne's avatar
Felix Paul Kühne committed
227 228 229 230 231 232 233 234 235 236
@@ -236,8 +259,8 @@ static void Destroy(vlc_object_t *p_this)
 
         free(p_sys->p_fonts);
     }
-#endif
     free(p_sys->psz_font_name);
+#endif
     free(p_sys);
 }
 
237
@@ -949,12 +972,12 @@ static int GetFontSize(filter_t *p_filter)
238 239 240 241 242
 {
     int i_size = 0;
 
-    int i_ratio = var_CreateGetInteger( p_filter, "quartztext-rel-fontsize" );
+    int i_ratio = var_CreateGetIntegerCommand( p_filter, "quartztext-fontsize" );
Felix Paul Kühne's avatar
Felix Paul Kühne committed
243
+
244 245 246
     if( i_ratio > 0 )
         i_size = (int)p_filter->fmt_out.video.i_height / i_ratio;
 
Felix Paul Kühne's avatar
Felix Paul Kühne committed
247 248 249 250 251 252
-    if( i_size <= 0 )
-    {
+    if( i_size <= 0 ) {
         msg_Warn( p_filter, "invalid fontsize, using 12" );
         i_size = 12;
     }
253
@@ -1041,3 +1064,23 @@ static int RenderYUVA(filter_t *p_filter, subpicture_region_t *p_region,
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
 
     return VLC_SUCCESS;
 }
+
+static int QuartztextCallback( vlc_object_t *p_this, char const *psz_var,
+                              vlc_value_t oldval, vlc_value_t newval,
+                              void *p_data )
+{
+    VLC_UNUSED(oldval);
+    filter_t *p_filter = (filter_t *)p_this;
+    filter_sys_t *p_sys = (filter_sys_t *)p_data;
+
+    vlc_mutex_lock( &p_sys->lock );
+    if( !strcmp( psz_var, "quartztext-font" ) )
+        p_sys->psz_font_name = newval.psz_string;
+    else if( !strcmp( psz_var, "quartztext-fontsize" ) )
+        p_sys->i_font_size = (int)p_filter->fmt_out.video.i_height / newval.i_int;
+    else if( !strcmp( psz_var, "quartztext-color" ) )
+        p_sys->i_font_color = VLC_CLIP(newval.i_int, 0, 0xFFFFFF);
+    vlc_mutex_unlock( &p_sys->lock );
+
+    return VLC_SUCCESS;
+}
-- 
278
2.3.0
279