1 /*****************************************************************************
\r
2 * marq.c : marquee display video plugin for vlc
\r
3 *****************************************************************************
\r
4 * Copyright (C) 2003-2005 VideoLAN
\r
5 * $Id: time.c 8751 2004-09-20 21:51:41Z gbazin $
\r
7 * Authors: Mark Moriarty
\r
9 * This program is free software; you can redistribute it and/or modify
\r
10 * it under the terms of the GNU General Public License as published by
\r
11 * the Free Software Foundation; either version 2 of the License, or
\r
12 * (at your option) any later version.
\r
14 * This program is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU General Public License for more details.
\r
19 * You should have received a copy of the GNU General Public License
\r
20 * along with this program; if not, write to the Free Software
\r
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
\r
22 *****************************************************************************/
\r
24 /*****************************************************************************
\r
26 *****************************************************************************/
\r
27 #include <stdlib.h> /* malloc(), free() */
\r
30 #include <vlc/vlc.h>
\r
31 #include <vlc/vout.h>
\r
33 #include "vlc_filter.h"
\r
34 #include "vlc_block.h"
\r
37 /*****************************************************************************
\r
39 *****************************************************************************/
\r
40 static int CreateFilter ( vlc_object_t * );
\r
41 static void DestroyFilter( vlc_object_t * );
\r
42 static subpicture_t *Filter( filter_t *, mtime_t );
\r
45 static int MarqueeCallback( vlc_object_t *p_this, char const *psz_var,
\r
46 vlc_value_t oldval, vlc_value_t newval,
\r
48 static int pi_color_values[] = { 0xf0000000, 0x00000000, 0x00808080, 0x00C0C0C0,
\r
49 0x00FFFFFF, 0x00800000, 0x00FF0000, 0x00FF00FF, 0x00FFFF00,
\r
50 0x00808000, 0x00008000, 0x00008080, 0x0000FF00, 0x00800080,
\r
51 0x00000080, 0x000000FF, 0x0000FFFF};
\r
52 static char *ppsz_color_descriptions[] = { N_("Default"), N_("Black"),
\r
53 N_("Gray"), N_("Silver"), N_("White"), N_("Maroon"), N_("Red"),
\r
54 N_("Fuchsia"), N_("Yellow"), N_("Olive"), N_("Green"),
\r
55 N_("Teal"), N_("Lime"), N_("Purple"), N_("Navy"), N_("Blue"),
\r
58 /*****************************************************************************
\r
59 * filter_sys_t: marquee filter descriptor
\r
60 *****************************************************************************/
\r
63 int i_xoff, i_yoff; /* offsets for the display string in the video window */
\r
64 int i_pos; /* permit relative positioning (top, bottom, left, right, center) */
\r
67 char *psz_marquee; /* marquee string */
\r
69 int i_font_color, i_font_opacity, i_font_size; /* font control */
\r
72 vlc_bool_t b_absolute; /* position control, relative vs. absolute */
\r
74 vlc_bool_t b_need_update;
\r
77 #define MSG_TEXT N_("Marquee text")
\r
78 #define MSG_LONGTEXT N_("Marquee text to display")
\r
79 #define POSX_TEXT N_("X offset, from left")
\r
80 #define POSX_LONGTEXT N_("X offset, from the left screen edge" )
\r
81 #define POSY_TEXT N_("Y offset, from the top")
\r
82 #define POSY_LONGTEXT N_("Y offset, down from the top" )
\r
83 #define TIMEOUT_TEXT N_("Marquee timeout")
\r
84 #define TIMEOUT_LONGTEXT N_("Defines the time the marquee must remain " \
\r
85 "displayed, in milliseconds. Default value is " \
\r
86 "0 (remain forever).")
\r
87 #define OPACITY_TEXT N_("Opacity, -1..255")
\r
88 #define OPACITY_LONGTEXT N_("The opacity (inverse of transparency) of overlay text. " \
\r
89 "-1 = use freetype-opacity, 0 = transparent, 255 = totally opaque. " )
\r
90 #define SIZE_TEXT N_("Font size, pixels")
\r
91 #define SIZE_LONGTEXT N_("Specify the font size, in pixels, " \
\r
92 "with -1 = use freetype-fontsize" )
\r
94 #define COLOR_TEXT N_("Text Default Color")
\r
95 #define COLOR_LONGTEXT N_("The color of overlay text. 1 byte for each color, hexadecimal." \
\r
96 "-1 = use freetype-color, #000000 = all colors off, " \
\r
97 "0xFF0000 = just Red, 0xFFFFFF = all color on [White]" )
\r
99 #define POS_TEXT N_("Marquee position")
\r
100 #define POS_LONGTEXT N_( \
\r
101 "You can enforce the marquee position on the video " \
\r
102 "(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \
\r
103 "also use combinations of these values by adding them).")
\r
105 static int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
\r
106 static char *ppsz_pos_descriptions[] =
\r
107 { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
\r
108 N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
\r
110 /*****************************************************************************
\r
111 * Module descriptor
\r
112 *****************************************************************************/
\r
113 vlc_module_begin();
\r
114 set_capability( "sub filter", 0 );
\r
115 set_shortname( N_("Marquee" ));
\r
116 set_callbacks( CreateFilter, DestroyFilter );
\r
117 set_category( CAT_VIDEO );
\r
118 set_subcategory( SUBCAT_VIDEO_SUBPIC );
\r
119 add_string( "marq-marquee", "Marquee", NULL, MSG_TEXT, MSG_LONGTEXT, VLC_FALSE );
\r
120 add_integer( "marq-x", -1, NULL, POSX_TEXT, POSX_LONGTEXT, VLC_FALSE );
\r
121 add_integer( "marq-y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, VLC_FALSE );
\r
122 add_integer( "marq-timeout", 0, NULL, TIMEOUT_TEXT, TIMEOUT_LONGTEXT,
\r
124 add_integer( "marq-position", 5, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
\r
125 /* 5 sets the default to top [1] left [4] */
\r
126 change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
\r
127 add_integer_with_range( "marq-opacity", -1, -1, 255, NULL,
\r
128 OPACITY_TEXT, OPACITY_LONGTEXT, VLC_FALSE );
\r
129 add_integer( "marq-color", -1, NULL, COLOR_TEXT, COLOR_LONGTEXT, VLC_TRUE );
\r
130 change_integer_list( pi_color_values, ppsz_color_descriptions, 0 );
\r
131 add_integer( "marq-size", -1, NULL, SIZE_TEXT, SIZE_LONGTEXT, VLC_FALSE );
\r
133 set_description( _("Marquee display sub filter") );
\r
134 add_shortcut( "marq" );
\r
137 /*****************************************************************************
\r
138 * CreateFilter: allocates marquee video filter
\r
139 *****************************************************************************/
\r
140 static int CreateFilter( vlc_object_t *p_this )
\r
142 filter_t *p_filter = (filter_t *)p_this;
\r
143 filter_sys_t *p_sys;
\r
144 vlc_object_t *p_input;
\r
146 /* Allocate structure */
\r
147 p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
\r
148 if( p_sys == NULL )
\r
150 msg_Err( p_filter, "out of memory" );
\r
154 /* Hook used for callback variables */
\r
155 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
\r
161 p_sys->i_xoff = var_CreateGetInteger( p_input->p_libvlc , "marq-x" );
\r
162 p_sys->i_yoff = var_CreateGetInteger( p_input->p_libvlc , "marq-y" );
\r
163 p_sys->i_timeout = var_CreateGetInteger( p_input->p_libvlc , "marq-timeout" );
\r
164 p_sys->i_pos = var_CreateGetInteger( p_input->p_libvlc , "marq-position" );
\r
165 p_sys->psz_marquee = var_CreateGetString( p_input->p_libvlc, "marq-marquee" );
\r
166 var_Create( p_input->p_libvlc, "marq-opacity", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
\r
167 p_sys->i_font_opacity = var_CreateGetInteger( p_input->p_libvlc , "marq-opacity" );
\r
168 p_sys->i_font_color = var_CreateGetInteger( p_input->p_libvlc , "marq-color" );
\r
169 p_sys->i_font_size = var_CreateGetInteger( p_input->p_libvlc , "marq-size" );
\r
171 var_AddCallback( p_input->p_libvlc, "marq-x", MarqueeCallback, p_sys );
\r
172 var_AddCallback( p_input->p_libvlc, "marq-y", MarqueeCallback, p_sys );
\r
173 var_AddCallback( p_input->p_libvlc, "marq-marquee", MarqueeCallback, p_sys );
\r
174 var_AddCallback( p_input->p_libvlc, "marq-timeout", MarqueeCallback, p_sys );
\r
175 var_AddCallback( p_input->p_libvlc, "marq-position", MarqueeCallback, p_sys );
\r
176 var_AddCallback( p_input->p_libvlc, "marq-color", MarqueeCallback, p_sys );
\r
177 var_AddCallback( p_input->p_libvlc, "marq-opacity", MarqueeCallback, p_sys );
\r
178 var_AddCallback( p_input->p_libvlc, "marq-size", MarqueeCallback, p_sys );
\r
180 vlc_object_release( p_input );
\r
184 p_filter->pf_sub_filter = Filter;
\r
185 p_sys->last_time = ((time_t)-1);
\r
186 p_sys->b_need_update = VLC_TRUE;
\r
188 return VLC_SUCCESS;
\r
190 /*****************************************************************************
\r
191 * DestroyFilter: destroy marquee video filter
\r
192 *****************************************************************************/
\r
193 static void DestroyFilter( vlc_object_t *p_this )
\r
195 filter_t *p_filter = (filter_t *)p_this;
\r
196 filter_sys_t *p_sys = p_filter->p_sys;
\r
197 vlc_object_t *p_input;
\r
199 if( p_sys->psz_marquee ) free( p_sys->psz_marquee );
\r
202 /* Delete the marquee variables */
\r
203 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
\r
208 var_Destroy( p_input->p_libvlc , "marq-marquee" );
\r
209 var_Destroy( p_input->p_libvlc , "marq-x" );
\r
210 var_Destroy( p_input->p_libvlc , "marq-y" );
\r
211 var_Destroy( p_input->p_libvlc , "marq-timeout" );
\r
212 var_Destroy( p_input->p_libvlc , "marq-position" );
\r
213 var_Destroy( p_input->p_libvlc , "marq-color");
\r
214 var_Destroy( p_input->p_libvlc , "marq-opacity");
\r
215 var_Destroy( p_input->p_libvlc , "marq-size");
\r
217 vlc_object_release( p_input );
\r
220 /****************************************************************************
\r
221 * Filter: the whole thing
\r
222 ****************************************************************************
\r
223 * This function outputs subpictures at regular time intervals.
\r
224 ****************************************************************************/
\r
225 static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
\r
227 filter_sys_t *p_sys = p_filter->p_sys;
\r
228 subpicture_t *p_spu;
\r
229 video_format_t fmt;
\r
232 if( p_sys->last_time == time( NULL ) )
\r
237 if( p_sys->b_need_update == VLC_FALSE )
\r
242 p_sys->b_absolute = VLC_TRUE;
\r
243 if( p_sys->i_xoff < 0 || p_sys->i_yoff < 0 )
\r
245 p_sys->b_absolute = VLC_FALSE;
\r
248 p_spu = p_filter->pf_sub_buffer_new( p_filter );
\r
249 if( !p_spu ) return NULL;
\r
251 p_spu->b_absolute = p_sys->b_absolute;
\r
252 memset( &fmt, 0, sizeof(video_format_t) );
\r
253 fmt.i_chroma = VLC_FOURCC('T','E','X','T');
\r
255 fmt.i_width = fmt.i_height = 0;
\r
256 fmt.i_x_offset = 0;
\r
257 fmt.i_y_offset = 0;
\r
258 p_spu->p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt );
\r
259 if( !p_spu->p_region )
\r
261 p_filter->pf_sub_buffer_del( p_filter, p_spu );
\r
265 t = p_sys->last_time = time( NULL );
\r
267 p_spu->p_region->psz_text = strdup(p_sys->psz_marquee);
\r
268 p_spu->i_start = date;
\r
269 p_spu->i_stop = p_sys->i_timeout == 0 ? 0 : date + p_sys->i_timeout * 1000;
\r
270 p_spu->b_ephemer = VLC_TRUE;
\r
271 p_spu->i_x = p_sys->i_xoff;
\r
272 p_spu->i_y = p_sys->i_yoff;
\r
273 p_spu->p_region->i_font_color = p_sys->i_font_color;
\r
274 p_spu->p_region->i_font_opacity = p_sys->i_font_opacity;
\r
275 p_spu->p_region->i_font_size = p_sys->i_font_size;
\r
277 p_spu->i_flags = p_sys->i_pos;
\r
279 p_sys->b_need_update = VLC_FALSE;
\r
283 /**********************************************************************
\r
284 * Callback to update params on the fly
\r
285 **********************************************************************/
\r
286 static int MarqueeCallback( vlc_object_t *p_this, char const *psz_var,
\r
287 vlc_value_t oldval, vlc_value_t newval,
\r
290 filter_sys_t *p_sys = (filter_sys_t *) p_data;
\r
292 if( !strncmp( psz_var, "marq-marquee", 7 ) )
\r
294 if( p_sys->psz_marquee ) free( p_sys->psz_marquee );
\r
295 p_sys->psz_marquee = strdup( newval.psz_string );
\r
297 else if ( !strncmp( psz_var, "marq-x", 6 ) )
\r
299 p_sys->i_xoff = newval.i_int;
\r
301 else if ( !strncmp( psz_var, "marq-y", 6 ) )
\r
303 p_sys->i_yoff = newval.i_int;
\r
305 else if ( !strncmp( psz_var, "marq-color", 8 ) ) /* "marq-col" */
\r
307 p_sys->i_font_color = newval.i_int;
\r
309 else if ( !strncmp( psz_var, "marq-opacity", 8 ) ) /* "marq-opa" */
\r
311 p_sys->i_font_opacity = newval.i_int;
\r
313 else if ( !strncmp( psz_var, "marq-size", 6 ) )
\r
315 p_sys->i_font_size = newval.i_int;
\r
317 else if ( !strncmp( psz_var, "marq-timeout", 12 ) )
\r
319 p_sys->i_timeout = newval.i_int;
\r
321 else if ( !strncmp( psz_var, "marq-position", 8 ) )
\r
322 /* willing to accept a match against marq-pos */
\r
324 p_sys->i_pos = newval.i_int;
\r
325 p_sys->i_xoff = -1; /* force to relative positioning */
\r
327 p_sys->b_need_update = VLC_TRUE;
\r
328 return VLC_SUCCESS;
\r