1 /*****************************************************************************
2 * marq.c : marquee display video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2003-2008 the VideoLAN team
7 * Authors: Mark Moriarty
8 * Sigmund Augdal Helberg <dnumgis@videolan.org>
9 * Antoine Cellerier <dionoea . videolan \ org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
37 #include <vlc_filter.h>
38 #include <vlc_block.h>
41 #include <vlc_strings.h>
43 /*****************************************************************************
45 *****************************************************************************/
46 static int CreateFilter ( vlc_object_t * );
47 static void DestroyFilter( vlc_object_t * );
48 static subpicture_t *Filter( filter_t *, mtime_t );
51 static int MarqueeCallback( vlc_object_t *p_this, char const *psz_var,
52 vlc_value_t oldval, vlc_value_t newval,
54 static const int pi_color_values[] = {
55 0xf0000000, 0x00000000, 0x00808080, 0x00C0C0C0,
56 0x00FFFFFF, 0x00800000, 0x00FF0000, 0x00FF00FF, 0x00FFFF00,
57 0x00808000, 0x00008000, 0x00008080, 0x0000FF00, 0x00800080,
58 0x00000080, 0x000000FF, 0x0000FFFF};
59 static const char *const ppsz_color_descriptions[] = {
60 N_("Default"), N_("Black"), N_("Gray"),
61 N_("Silver"), N_("White"), N_("Maroon"), N_("Red"),
62 N_("Fuchsia"), N_("Yellow"), N_("Olive"), N_("Green"),
63 N_("Teal"), N_("Lime"), N_("Purple"), N_("Navy"), N_("Blue"),
66 /*****************************************************************************
67 * filter_sys_t: marquee filter descriptor
68 *****************************************************************************/
73 int i_xoff, i_yoff; /* offsets for the display string in the video window */
74 int i_pos; /* permit relative positioning (top, bottom, left, right, center) */
77 char *psz_marquee; /* marquee string */
79 text_style_t *p_style; /* font control */
87 #define MSG_TEXT N_("Text")
88 #define MSG_LONGTEXT N_( \
89 "Marquee text to display. " \
90 "(Available format strings: " \
91 "Time related: %Y = year, %m = month, %d = day, %H = hour, " \
92 "%M = minute, %S = second, ... " \
93 "Meta data related: $a = artist, $b = album, $c = copyright, " \
94 "$d = description, $e = encoded by, $g = genre, " \
95 "$l = language, $n = track num, $p = now playing, " \
96 "$r = rating, $s = subtitles language, $t = title, "\
97 "$u = url, $A = date, " \
98 "$B = audio bitrate (in kb/s), $C = chapter," \
99 "$D = duration, $F = full name with path, $I = title, "\
101 "$N = name, $O = audio language, $P = position (in %), $R = rate, " \
102 "$S = audio sample rate (in kHz), " \
103 "$T = time, $U = publisher, $V = volume, $_ = new line) ")
104 #define POSX_TEXT N_("X offset")
105 #define POSX_LONGTEXT N_("X offset, from the left screen edge." )
106 #define POSY_TEXT N_("Y offset")
107 #define POSY_LONGTEXT N_("Y offset, down from the top." )
108 #define TIMEOUT_TEXT N_("Timeout")
109 #define TIMEOUT_LONGTEXT N_("Number of milliseconds the marquee must remain " \
110 "displayed. Default value is " \
111 "0 (remains forever).")
112 #define REFRESH_TEXT N_("Refresh period in ms")
113 #define REFRESH_LONGTEXT N_("Number of milliseconds between string updates. " \
114 "This is mainly useful when using meta data " \
115 "or time format string sequences.")
116 #define OPACITY_TEXT N_("Opacity")
117 #define OPACITY_LONGTEXT N_("Opacity (inverse of transparency) of " \
118 "overlayed text. 0 = transparent, 255 = totally opaque. " )
119 #define SIZE_TEXT N_("Font size, pixels")
120 #define SIZE_LONGTEXT N_("Font size, in pixels. Default is -1 (use default " \
123 #define COLOR_TEXT N_("Color")
124 #define COLOR_LONGTEXT N_("Color of the text that will be rendered on "\
125 "the video. This must be an hexadecimal (like HTML colors). The first two "\
126 "chars are for red, then green, then blue. #000000 = black, #FF0000 = red,"\
127 " #00FF00 = green, #FFFF00 = yellow (red + green), #FFFFFF = white" )
129 #define POS_TEXT N_("Marquee position")
130 #define POS_LONGTEXT N_( \
131 "You can enforce the marquee position on the video " \
132 "(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \
133 "also use combinations of these values, eg 6 = top-right).")
135 static const int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
136 static const char *const ppsz_pos_descriptions[] =
137 { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
138 N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
140 #define CFG_PREFIX "marq-"
142 #define MARQUEE_HELP N_("Display text above the video")
144 /*****************************************************************************
146 *****************************************************************************/
148 set_capability( "sub filter", 0 )
149 set_shortname( N_("Marquee" ))
150 set_description( N_("Marquee display") )
151 set_help(MARQUEE_HELP)
152 set_callbacks( CreateFilter, DestroyFilter )
153 set_category( CAT_VIDEO )
154 set_subcategory( SUBCAT_VIDEO_SUBPIC )
155 add_string( CFG_PREFIX "marquee", "VLC", NULL, MSG_TEXT, MSG_LONGTEXT,
158 set_section( N_("Position"), NULL )
159 add_integer( CFG_PREFIX "x", 0, NULL, POSX_TEXT, POSX_LONGTEXT, true )
160 add_integer( CFG_PREFIX "y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, true )
161 add_integer( CFG_PREFIX "position", -1, NULL, POS_TEXT, POS_LONGTEXT, false )
162 change_integer_list( pi_pos_values, ppsz_pos_descriptions, NULL )
164 set_section( N_("Font"), NULL )
165 /* 5 sets the default to top [1] left [4] */
166 add_integer_with_range( CFG_PREFIX "opacity", 255, 0, 255, NULL,
167 OPACITY_TEXT, OPACITY_LONGTEXT, false )
168 add_integer( CFG_PREFIX "color", 0xFFFFFF, NULL, COLOR_TEXT, COLOR_LONGTEXT,
170 change_integer_list( pi_color_values, ppsz_color_descriptions, NULL )
171 add_integer( CFG_PREFIX "size", -1, NULL, SIZE_TEXT, SIZE_LONGTEXT,
174 set_section( N_("Misc"), NULL )
175 add_integer( CFG_PREFIX "timeout", 0, NULL, TIMEOUT_TEXT, TIMEOUT_LONGTEXT,
177 add_integer( CFG_PREFIX "refresh", 1000, NULL, REFRESH_TEXT,
178 REFRESH_LONGTEXT, false )
180 add_shortcut( "time" )
181 add_obsolete_string( "time-format" )
182 add_obsolete_string( "time-x" )
183 add_obsolete_string( "time-y" )
184 add_obsolete_string( "time-position" )
185 add_obsolete_string( "time-opacity" )
186 add_obsolete_string( "time-color" )
187 add_obsolete_string( "time-size" )
190 static const char *const ppsz_filter_options[] = {
191 "marquee", "x", "y", "position", "color", "size", "timeout", "refresh",
195 /*****************************************************************************
196 * CreateFilter: allocates marquee video filter
197 *****************************************************************************/
198 static int CreateFilter( vlc_object_t *p_this )
200 filter_t *p_filter = (filter_t *)p_this;
203 /* Allocate structure */
204 p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
208 vlc_mutex_init( &p_sys->lock );
209 p_sys->p_style = text_style_New();
211 config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
215 #define CREATE_VAR( stor, type, var ) \
216 p_sys->stor = var_CreateGet##type##Command( p_filter, var ); \
217 var_AddCallback( p_filter, var, MarqueeCallback, p_sys );
219 p_sys->b_need_update = true;
220 CREATE_VAR( i_xoff, Integer, "marq-x" );
221 CREATE_VAR( i_yoff, Integer, "marq-y" );
222 CREATE_VAR( i_timeout,Integer, "marq-timeout" );
223 p_sys->i_refresh = 1000 * var_CreateGetIntegerCommand( p_filter,
225 var_AddCallback( p_filter, "marq-refresh", MarqueeCallback, p_sys );
226 CREATE_VAR( i_pos, Integer, "marq-position" );
227 CREATE_VAR( psz_marquee, String, "marq-marquee" );
228 p_sys->p_style->i_font_alpha = 255 - var_CreateGetIntegerCommand( p_filter,
230 var_AddCallback( p_filter, "marq-opacity", MarqueeCallback, p_sys );
231 CREATE_VAR( p_style->i_font_color, Integer, "marq-color" );
232 CREATE_VAR( p_style->i_font_size, Integer, "marq-size" );
235 p_filter->pf_sub_filter = Filter;
236 p_sys->last_time = 0;
240 /*****************************************************************************
241 * DestroyFilter: destroy marquee video filter
242 *****************************************************************************/
243 static void DestroyFilter( vlc_object_t *p_this )
245 filter_t *p_filter = (filter_t *)p_this;
246 filter_sys_t *p_sys = p_filter->p_sys;
248 /* Delete the marquee variables */
249 #define DEL_VAR(var) \
250 var_DelCallback( p_filter, var, MarqueeCallback, p_sys ); \
251 var_Destroy( p_filter, var );
254 DEL_VAR( "marq-timeout" );
255 DEL_VAR( "marq-refresh" );
256 DEL_VAR( "marq-position" );
257 DEL_VAR( "marq-marquee" );
258 DEL_VAR( "marq-opacity" );
259 DEL_VAR( "marq-color" );
260 DEL_VAR( "marq-size" );
262 vlc_mutex_destroy( &p_sys->lock );
263 text_style_Delete( p_sys->p_style );
264 free( p_sys->psz_marquee );
268 /****************************************************************************
269 * Filter: the whole thing
270 ****************************************************************************
271 * This function outputs subpictures at regular time intervals.
272 ****************************************************************************/
273 static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
275 filter_sys_t *p_sys = p_filter->p_sys;
276 subpicture_t *p_spu = NULL;
279 vlc_mutex_lock( &p_sys->lock );
280 if( p_sys->last_time + p_sys->i_refresh > date )
282 if( p_sys->b_need_update == false )
285 p_spu = filter_NewSubpicture( p_filter );
289 memset( &fmt, 0, sizeof(video_format_t) );
290 fmt.i_chroma = VLC_CODEC_TEXT;
291 fmt.i_width = fmt.i_height = 0;
294 p_spu->p_region = subpicture_region_New( &fmt );
295 if( !p_spu->p_region )
297 p_filter->pf_sub_buffer_del( p_filter, p_spu );
302 p_sys->last_time = date;
304 if( !strchr( p_sys->psz_marquee, '%' )
305 && !strchr( p_sys->psz_marquee, '$' ) )
306 p_sys->b_need_update = false;
308 p_spu->p_region->psz_text = str_format( p_filter, p_sys->psz_marquee );
309 p_spu->i_start = date;
310 p_spu->i_stop = p_sys->i_timeout == 0 ? 0 : date + p_sys->i_timeout * 1000;
311 p_spu->b_ephemer = true;
313 /* where to locate the string: */
314 if( p_sys->i_pos < 0 )
315 { /* set to an absolute xy */
316 p_spu->p_region->i_align = SUBPICTURE_ALIGN_LEFT | SUBPICTURE_ALIGN_TOP;
317 p_spu->b_absolute = true;
320 { /* set to one of the 9 relative locations */
321 p_spu->p_region->i_align = p_sys->i_pos;
322 p_spu->b_absolute = false;
325 p_spu->p_region->i_x = p_sys->i_xoff;
326 p_spu->p_region->i_y = p_sys->i_yoff;
328 p_spu->p_region->p_style = text_style_Duplicate( p_sys->p_style );
331 vlc_mutex_unlock( &p_sys->lock );
335 /**********************************************************************
336 * Callback to update params on the fly
337 **********************************************************************/
338 static int MarqueeCallback( vlc_object_t *p_this, char const *psz_var,
339 vlc_value_t oldval, vlc_value_t newval,
342 filter_sys_t *p_sys = (filter_sys_t *) p_data;
347 vlc_mutex_lock( &p_sys->lock );
348 if( !strncmp( psz_var, "marq-marquee", 7 ) )
350 free( p_sys->psz_marquee );
351 p_sys->psz_marquee = strdup( newval.psz_string );
353 else if ( !strncmp( psz_var, "marq-x", 6 ) )
355 p_sys->i_xoff = newval.i_int;
357 else if ( !strncmp( psz_var, "marq-y", 6 ) )
359 p_sys->i_yoff = newval.i_int;
361 else if ( !strncmp( psz_var, "marq-color", 8 ) ) /* "marq-col" */
363 p_sys->p_style->i_font_color = newval.i_int;
365 else if ( !strncmp( psz_var, "marq-opacity", 8 ) ) /* "marq-opa" */
367 p_sys->p_style->i_font_alpha = 255 - newval.i_int;
369 else if ( !strncmp( psz_var, "marq-size", 6 ) )
371 p_sys->p_style->i_font_size = newval.i_int;
373 else if ( !strncmp( psz_var, "marq-timeout", 12 ) )
375 p_sys->i_timeout = newval.i_int;
377 else if ( !strncmp( psz_var, "marq-refresh", 12 ) )
379 p_sys->i_refresh = newval.i_int * 1000;
381 else if ( !strncmp( psz_var, "marq-position", 8 ) )
382 /* willing to accept a match against marq-pos */
384 p_sys->i_pos = newval.i_int;
385 p_sys->i_xoff = -1; /* force to relative positioning */
387 p_sys->b_need_update = true;
388 vlc_mutex_unlock( &p_sys->lock );