From eccc9db9235cb5a57443686e3787d07da4a18364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Paul=20K=C3=BChne?= Date: Mon, 31 Mar 2014 17:54:01 +0200 Subject: [PATCH 20/20] libvlc: add preliminary code path to modify quartztext variables on-the-fly --- include/vlc/libvlc_media_player.h | 21 +++++++++++++ lib/libvlc.sym | 4 +++ lib/media_player.c | 6 ++++ lib/video.c | 47 +++++++++++++++++++++++++++++ modules/text_renderer/quartztext.c | 61 ++++++++++++++++++++++++++++++++------ 5 files changed, 130 insertions(+), 9 deletions(-) diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h index 4b2f449..59beb48 100644 --- a/include/vlc/libvlc_media_player.h +++ b/include/vlc/libvlc_media_player.h @@ -1382,6 +1382,27 @@ LIBVLC_API float libvlc_video_get_adjust_float( libvlc_media_player_t *p_mi, 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 index c0c66dd..7810ed7 100644 --- a/lib/libvlc.sym +++ b/lib/libvlc.sym @@ -217,6 +217,8 @@ libvlc_video_get_spu_count 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 @@ -241,6 +243,8 @@ libvlc_video_set_spu 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 index 968a0e8..5c88620 100644 --- a/lib/media_player.c +++ b/lib/media_player.c @@ -560,6 +560,12 @@ libvlc_media_player_new( libvlc_instance_t *instance ) 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 index c8b3711..cda3c35 100644 --- a/lib/video.c +++ b/lib/video.c @@ -903,3 +903,50 @@ float libvlc_video_get_adjust_float( libvlc_media_player_t *p_mi, { 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 index ceb97a6..4cce93f 100644 --- 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; @@ -229,6 +242,16 @@ static void Destroy(vlc_object_t *p_this) { 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 ); + + var_Destroy( p_filter, "quartztext-font" ) ; + var_Destroy( p_filter, "quartztext-fontsize" ); + var_Destroy( p_filter, "quartztext-color" ); + #ifndef TARGET_OS_IPHONE if (p_sys->p_fonts) { for (int k = 0; k < p_sys->i_fonts; k++) { @@ -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); } @@ -957,12 +980,12 @@ static int GetFontSize(filter_t *p_filter) { int i_size = 0; - int i_ratio = var_CreateGetInteger( p_filter, "quartztext-rel-fontsize" ); + int i_ratio = var_CreateGetIntegerCommand( p_filter, "quartztext-fontsize" ); + if( i_ratio > 0 ) i_size = (int)p_filter->fmt_out.video.i_height / i_ratio; - if( i_size <= 0 ) - { + if( i_size <= 0 ) { msg_Warn( p_filter, "invalid fontsize, using 12" ); i_size = 12; } @@ -1048,3 +1071,23 @@ static int RenderYUVA(filter_t *p_filter, subpicture_region_t *p_region, 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; +} -- 1.9.3 (Apple Git-50)