00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdlib.h>
00028 #include <string.h>
00029 #include <vlc/vlc.h>
00030 #include <vlc/input.h>
00031
00032 #include <vlc_filter.h>
00033 #include <vlc_video.h>
00034
00035 #include <vlc_osd.h>
00036
00037
00038
00039
00040
00041
00042 #define OSD_FILE_TEXT N_("OSD menu configuration file")
00043 #define OSD_FILE_LONGTEXT N_( \
00044 "An OSD menu configuration file that menu actions with button images" )
00045
00046 #define OSD_PATH_TEXT N_("Path to OSD menu images")
00047 #define OSD_PATH_LONGTEXT N_( \
00048 "Specify another path to the OSD menu images. This will override the path as defined in the " \
00049 "OSD configuration file." )
00050
00051 #define POSX_TEXT N_("X coordinate of the OSD menu")
00052 #define POSX_LONGTEXT N_("You can move the OSD menu by left-clicking on it." )
00053
00054 #define POSY_TEXT N_("Y coordinate of the OSD menu")
00055 #define POSY_LONGTEXT N_("You can move the OSD menu by left-clicking on it." )
00056
00057 #define POS_TEXT N_("OSD menu position")
00058 #define POS_LONGTEXT N_( \
00059 "You can enforce the OSD menu position on the video " \
00060 "(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \
00061 "also use combinations of these values).")
00062
00063 #define TIMEOUT_TEXT N_("Timeout of OSD menu")
00064 #define TIMEOUT_LONGTEXT N_( \
00065 "OSD menu pictures get a default timeout of 15 seconds added to their remaining time." \
00066 "This will ensure that they are at least the specified time visible.")
00067
00068 #define OSD_UPDATE_TEXT N_("Update speed of OSD menu")
00069 #define OSD_UPDATE_LONGTEXT N_( \
00070 "Update the OSD menu picture every 200ms (default). Shorten the update time for " \
00071 "environments that experience transmissions errors. Be carefull with this option " \
00072 "because encoding OSD menu pictures is very computing intensive. The range is 0 - 1000 ms." )
00073
00074 static int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
00075 static char *ppsz_pos_descriptions[] =
00076 { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
00077 N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
00078
00079
00080 static int CreateFilter ( vlc_object_t * );
00081 static void DestroyFilter( vlc_object_t * );
00082 static subpicture_t *Filter( filter_t *, mtime_t );
00083 static int OSDMenuUpdateEvent( vlc_object_t *, char const *,
00084 vlc_value_t, vlc_value_t, void * );
00085 static int OSDMenuVisibleEvent( vlc_object_t *, char const *,
00086 vlc_value_t, vlc_value_t, void * );
00087
00088 #define OSD_CFG "osdmenu-"
00089
00090 #if defined( WIN32 ) || defined( UNDER_CE )
00091 #define OSD_DEFAULT_CFG "osdmenu/default.cfg"
00092 #else
00093 #define OSD_DEFAULT_CFG "share/osdmenu/default.cfg"
00094 #endif
00095
00096 #define OSD_UPDATE_MIN 0
00097 #define OSD_UPDATE_DEFAULT 200
00098 #define OSD_UPDATE_MAX 1000
00099
00100 vlc_module_begin();
00101 add_integer( OSD_CFG "x", -1, NULL, POSX_TEXT, POSX_LONGTEXT, VLC_FALSE );
00102 add_integer( OSD_CFG "y", -1, NULL, POSY_TEXT, POSY_LONGTEXT, VLC_FALSE );
00103 add_integer( OSD_CFG "position", 8, NULL, POS_TEXT, POS_LONGTEXT, VLC_FALSE );
00104 change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
00105 add_string( OSD_CFG "file", OSD_DEFAULT_CFG, NULL, OSD_FILE_TEXT,
00106 OSD_FILE_LONGTEXT, VLC_FALSE );
00107 add_string( OSD_CFG "file-path", NULL, NULL, OSD_PATH_TEXT,
00108 OSD_PATH_LONGTEXT, VLC_FALSE );
00109 add_integer( OSD_CFG "timeout", 15, NULL, TIMEOUT_TEXT,
00110 TIMEOUT_LONGTEXT, VLC_FALSE );
00111 add_integer_with_range( OSD_CFG "update", OSD_UPDATE_DEFAULT,
00112 OSD_UPDATE_MIN, OSD_UPDATE_MAX, NULL, OSD_UPDATE_TEXT,
00113 OSD_UPDATE_LONGTEXT, VLC_TRUE );
00114
00115 set_capability( "sub filter", 100 );
00116 set_description( N_("On Screen Display menu subfilter") );
00117 set_shortname( N_("OSD menu") );
00118 add_shortcut( "osdmenu" );
00119
00120
00121
00122
00123 set_callbacks( CreateFilter, DestroyFilter );
00124 vlc_module_end();
00125
00126
00127
00128
00129
00130
00131
00132
00133 struct filter_sys_t
00134 {
00135 vlc_mutex_t lock;
00136
00137 int position;
00138 mtime_t i_last_date;
00139 mtime_t i_timeout;
00140
00141 vlc_bool_t b_absolute;
00142 vlc_bool_t b_update;
00143 vlc_bool_t b_visible;
00144 mtime_t i_update;
00145 mtime_t i_end_date;
00146
00147 char *psz_file;
00148 osd_menu_t *p_menu;
00149 };
00150
00151
00152
00153
00154 static int CreateFilter ( vlc_object_t *p_this )
00155 {
00156 filter_t *p_filter = (filter_t *)p_this;
00157 vlc_value_t val;
00158 int i_posx, i_posy;
00159
00160 p_filter->p_sys = (filter_sys_t *) malloc( sizeof( filter_sys_t ) );
00161 if( !p_filter->p_sys )
00162 {
00163 msg_Err( p_filter, "out of memory" );
00164 return VLC_ENOMEM;
00165 }
00166
00167
00168 p_filter->p_sys->p_menu = NULL;
00169 p_filter->p_sys->psz_file = NULL;
00170
00171 vlc_mutex_init( p_filter, &p_filter->p_sys->lock );
00172
00173 p_filter->p_sys->psz_file = config_GetPsz( p_filter, OSD_CFG "file" );
00174 if( p_filter->p_sys->psz_file == NULL || *p_filter->p_sys->psz_file == '\0' )
00175 {
00176 msg_Err( p_filter, "unable to get filename" );
00177 goto error;
00178 }
00179
00180 var_Create( p_this, OSD_CFG "position", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00181 var_Get( p_this, OSD_CFG "position", &val );
00182 p_filter->p_sys->position = val.i_int;
00183 var_Create( p_this, OSD_CFG "x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00184 var_Get( p_this, OSD_CFG "x", &val );
00185 i_posx = val.i_int;
00186 var_Create( p_this, OSD_CFG "y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00187 var_Get( p_this, OSD_CFG "y", &val );
00188 i_posy = val.i_int;
00189
00190
00191 var_Create( p_this, OSD_CFG "timeout", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00192 var_Get( p_this, OSD_CFG "timeout", &val );
00193 p_filter->p_sys->i_timeout = (mtime_t)(val.i_int * 1000000) >> 2;
00194 var_Create( p_this, OSD_CFG "update", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00195 var_Get( p_this, OSD_CFG "update", &val );
00196 p_filter->p_sys->i_update = (mtime_t)(val.i_int * 1000);
00197
00198
00199 p_filter->p_sys->p_menu = osd_MenuCreate( p_this, p_filter->p_sys->psz_file );
00200 if( p_filter->p_sys->p_menu == NULL )
00201 goto error;
00202
00203
00204 p_filter->p_sys->b_absolute = VLC_TRUE;
00205 if( i_posx < 0 || i_posy < 0)
00206 {
00207 p_filter->p_sys->b_absolute = VLC_FALSE;
00208 p_filter->p_sys->p_menu->i_x = 0;
00209 p_filter->p_sys->p_menu->i_y = 0;
00210 }
00211 else if( i_posx >= 0 || i_posy >= 0 )
00212 {
00213 p_filter->p_sys->p_menu->i_x = i_posx;
00214 p_filter->p_sys->p_menu->i_y = i_posy;
00215 }
00216 else if( p_filter->p_sys->p_menu->i_x < 0 || p_filter->p_sys->p_menu->i_y < 0 )
00217 {
00218 p_filter->p_sys->b_absolute = VLC_FALSE;
00219 p_filter->p_sys->p_menu->i_x = 0;
00220 p_filter->p_sys->p_menu->i_y = 0;
00221 }
00222
00223
00224 p_filter->p_sys->i_last_date = mdate();
00225
00226
00227 p_filter->p_sys->b_update = VLC_FALSE;
00228 p_filter->p_sys->b_visible = VLC_FALSE;
00229
00230 var_AddCallback( p_filter->p_sys->p_menu, "osd-menu-update", OSDMenuUpdateEvent, p_filter );
00231 var_AddCallback( p_filter->p_sys->p_menu, "osd-menu-visible", OSDMenuVisibleEvent, p_filter );
00232
00233
00234 p_filter->pf_sub_filter = Filter;
00235
00236 es_format_Init( &p_filter->fmt_out, SPU_ES, VLC_FOURCC( 's','p','u',' ' ) );
00237 p_filter->fmt_out.i_priority = 0;
00238
00239 msg_Dbg( p_filter, "successfully loaded osdmenu filter" );
00240 return VLC_SUCCESS;
00241
00242 error:
00243 msg_Err( p_filter, "osdmenu filter discarded" );
00244 vlc_mutex_destroy( &p_filter->p_sys->lock );
00245 if( p_filter->p_sys->p_menu )
00246 {
00247 osd_MenuDelete( p_this, p_filter->p_sys->p_menu );
00248 p_filter->p_sys->p_menu = NULL;
00249 }
00250 if( p_filter->p_sys->psz_file ) free( p_filter->p_sys->psz_file );
00251 if( p_filter->p_sys ) free( p_filter->p_sys );
00252 return VLC_EGENERIC;
00253 }
00254
00255
00256
00257
00258 static void DestroyFilter( vlc_object_t *p_this )
00259 {
00260 filter_t *p_filter = (filter_t*)p_this;
00261 filter_sys_t *p_sys = p_filter->p_sys;
00262
00263 var_Destroy( p_this, OSD_CFG "file" );
00264 var_Destroy( p_this, OSD_CFG "x" );
00265 var_Destroy( p_this, OSD_CFG "y" );
00266 var_Destroy( p_this, OSD_CFG "position" );
00267 var_Destroy( p_this, OSD_CFG "timeout" );
00268 var_Destroy( p_this, OSD_CFG "update" );
00269
00270 var_DelCallback( p_sys->p_menu, "osd-menu-update", OSDMenuUpdateEvent, p_filter );
00271 var_DelCallback( p_sys->p_menu, "osd-menu-visible", OSDMenuVisibleEvent, p_filter );
00272
00273 osd_MenuDelete( p_filter, p_sys->p_menu );
00274
00275 vlc_mutex_destroy( &p_filter->p_sys->lock );
00276 if( p_sys->psz_file) free( p_sys->psz_file );
00277 if( p_sys ) free( p_sys );
00278
00279 msg_Dbg( p_filter, "osdmenu filter destroyed" );
00280 }
00281
00282
00283
00284
00285 static int OSDMenuVisibleEvent( vlc_object_t *p_this, char const *psz_var,
00286 vlc_value_t oldval, vlc_value_t newval, void *p_data )
00287 {
00288 filter_t *p_filter = (filter_t *) p_data;
00289
00290 p_filter->p_sys->b_visible = VLC_TRUE;
00291 return VLC_SUCCESS;
00292 }
00293
00294 static int OSDMenuUpdateEvent( vlc_object_t *p_this, char const *psz_var,
00295 vlc_value_t oldval, vlc_value_t newval, void *p_data )
00296 {
00297 filter_t *p_filter = (filter_t *) p_data;
00298
00299 p_filter->p_sys->b_update = VLC_TRUE;
00300 p_filter->p_sys->i_end_date = (mtime_t) 0;
00301 return VLC_SUCCESS;
00302 }
00303
00304 #if 0
00305
00306
00307
00308 static subpicture_region_t *create_text_region( filter_t *p_filter, subpicture_t *p_spu,
00309 int i_width, int i_height, const char *psz_text )
00310 {
00311 subpicture_region_t *p_region;
00312 video_format_t fmt;
00313
00314
00315 memset( &fmt, 0, sizeof(video_format_t) );
00316 fmt.i_chroma = VLC_FOURCC( 'T','E','X','T' );
00317 fmt.i_aspect = VOUT_ASPECT_FACTOR;
00318 fmt.i_sar_num = fmt.i_sar_den = 1;
00319 fmt.i_width = fmt.i_visible_width = i_width;
00320 fmt.i_height = fmt.i_visible_height = i_height;
00321 fmt.i_x_offset = fmt.i_y_offset = 0;
00322 p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt );
00323 if( !p_region )
00324 {
00325 msg_Err( p_filter, "cannot allocate another SPU region" );
00326 return NULL;
00327 }
00328 p_region->psz_text = strdup( psz_text );
00329 p_region->i_x = 0;
00330 p_region->i_y = 40;
00331 #if 1
00332 msg_Dbg( p_filter, "SPU text region position (%d,%d) (%d,%d) [%s]",
00333 p_region->i_x, p_region->i_y,
00334 p_region->fmt.i_width, p_region->fmt.i_height, p_region->psz_text );
00335 #endif
00336 return p_region;
00337 }
00338 #endif
00339
00340
00341
00342
00343 static subpicture_region_t *create_picture_region( filter_t *p_filter, subpicture_t *p_spu,
00344 int i_width, int i_height, picture_t *p_pic )
00345 {
00346 subpicture_region_t *p_region;
00347 video_format_t fmt;
00348
00349 if( !p_spu ) return NULL;
00350
00351
00352 memset( &fmt, 0, sizeof(video_format_t) );
00353 fmt.i_chroma = (p_pic == NULL) ? VLC_FOURCC('Y','U','V','P') : VLC_FOURCC('Y','U','V','A');
00354 fmt.i_aspect = VOUT_ASPECT_FACTOR;
00355 fmt.i_sar_num = fmt.i_sar_den = 1;
00356 fmt.i_width = fmt.i_visible_width = i_width;
00357 fmt.i_height = fmt.i_visible_height = i_height;
00358 fmt.i_x_offset = fmt.i_y_offset = 0;
00359 p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt );
00360 if( !p_region )
00361 {
00362 msg_Err( p_filter, "cannot allocate SPU region" );
00363 p_filter->pf_sub_buffer_del( p_filter, p_spu );
00364 return NULL;
00365 }
00366 if( !p_pic && ( fmt.i_chroma == VLC_FOURCC('Y','U','V','P') ) )
00367 {
00368 p_region->fmt.p_palette->i_entries = 0;
00369 p_region->fmt.i_width = p_region->fmt.i_visible_width = 0;
00370 p_region->fmt.i_height = p_region->fmt.i_visible_height = 0;
00371 }
00372 if( p_pic != NULL )
00373 vout_CopyPicture( p_filter, &p_region->picture, p_pic );
00374
00375 p_region->i_x = 0;
00376 p_region->i_y = 0;
00377 #if 0
00378 msg_Dbg( p_filter, "SPU picture region position (%d,%d) (%d,%d) [%p]",
00379 p_region->i_x, p_region->i_y,
00380 p_region->fmt.i_width, p_region->fmt.i_height, p_pic );
00381 #endif
00382 return p_region;
00383 }
00384
00385
00386
00387
00388
00389
00390 static subpicture_t *Filter( filter_t *p_filter, mtime_t i_date )
00391 {
00392 filter_sys_t *p_sys = p_filter->p_sys;
00393 subpicture_t *p_spu;
00394 subpicture_region_t *p_region;
00395
00396 if( !p_sys->b_update )
00397 return NULL;
00398
00399
00400 if( ( ( p_sys->i_last_date + p_sys->i_update ) > i_date ) &&
00401 ( p_sys->i_end_date > 0 ) )
00402 return NULL;
00403
00404
00405 p_spu = p_filter->pf_sub_buffer_new( p_filter );
00406 if( !p_spu ) return NULL;
00407 p_spu->b_ephemer = VLC_TRUE;
00408 p_spu->b_fade = VLC_TRUE;
00409 p_spu->b_absolute = p_sys->b_absolute;
00410 p_spu->i_flags = p_sys->position;
00411
00412
00413 if( p_sys->i_end_date > 0 )
00414 {
00415
00416 p_spu->i_stop = p_sys->i_end_date - i_date;
00417 if( ( i_date + p_sys->i_update ) >= p_sys->i_end_date )
00418 p_sys->b_update = VLC_FALSE;
00419 }
00420 else
00421 {
00422
00423 p_spu->i_stop = i_date + p_sys->i_timeout;
00424 p_sys->i_end_date = p_spu->i_stop;
00425 }
00426
00427 p_sys->i_last_date = i_date;
00428 p_spu->i_start = p_sys->i_last_date = i_date;
00429
00430
00431
00432
00433 if( !p_filter->p_sys->p_menu->p_state->p_pic ||
00434 ( p_filter->p_sys->b_visible == VLC_FALSE ) )
00435 {
00436
00437 p_region = create_picture_region( p_filter, p_spu,
00438 p_filter->p_sys->p_menu->p_state->i_width,
00439 p_filter->p_sys->p_menu->p_state->i_height,
00440 NULL );
00441
00442
00443 p_spu->i_x = p_filter->p_sys->p_menu->p_state->i_x;
00444 p_spu->i_y = p_filter->p_sys->p_menu->p_state->i_y;
00445 p_spu->p_region = p_region;
00446 p_spu->i_alpha = 0xFF;
00447 return p_spu;
00448 }
00449
00450
00451 p_region = create_picture_region( p_filter, p_spu,
00452 p_filter->p_sys->p_menu->p_state->i_width,
00453 p_filter->p_sys->p_menu->p_state->i_height,
00454 p_filter->p_sys->p_menu->p_state->p_pic );
00455 #if 0
00456 p_region->p_next = create_text_region( p_filter, p_spu,
00457 p_filter->p_sys->p_menu->p_state->i_width, p_filter->p_sys->p_menu->p_state->i_height,
00458 p_filter->p_sys->p_menu->p_state->p_visible->psz_action );
00459 #endif
00460
00461
00462 p_spu->i_x = p_filter->p_sys->p_menu->p_state->i_x;
00463 p_spu->i_y = p_filter->p_sys->p_menu->p_state->i_y;
00464 p_spu->p_region = p_region;
00465 return p_spu;
00466 }