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 <vlc/vlc.h>
00029 #include <vlc/vout.h>
00030 #include "audio_output.h"
00031 #include "aout_internal.h"
00032
00033 #include "visual.h"
00034
00035
00036
00037
00038 #define ELIST_TEXT N_( "Effects list" )
00039 #define ELIST_LONGTEXT N_( \
00040 "A list of visual effect, separated by commas.\n" \
00041 "Current effects include: dummy, scope, spectrum" )
00042
00043 #define WIDTH_TEXT N_( "Video width" )
00044 #define WIDTH_LONGTEXT N_( \
00045 "The width of the effects video window, in pixels." )
00046
00047 #define HEIGHT_TEXT N_( "Video height" )
00048 #define HEIGHT_LONGTEXT N_( \
00049 "The height of the effects video window, in pixels." )
00050
00051 #define NBBANDS_TEXT N_( "Number of bands" )
00052 #define NBBANDS_LONGTEXT N_( \
00053 "Number of bands used by spectrum analyzer, should be 20 or 80." )
00054 #define SPNBBANDS_LONGTEXT N_( \
00055 "Number of bands used by the spectrOmeter, from 20 to 80." )
00056
00057 #define SEPAR_TEXT N_( "Band separator" )
00058 #define SEPAR_LONGTEXT N_( \
00059 "Number of blank pixels between bands.")
00060
00061 #define AMP_TEXT N_( "Amplification" )
00062 #define AMP_LONGTEXT N_( \
00063 "This is a coefficient that modifies the height of the bands.")
00064
00065 #define PEAKS_TEXT N_( "Enable peaks" )
00066 #define PEAKS_LONGTEXT N_( \
00067 "Defines whether to draw peaks." )
00068
00069 #define ORIG_TEXT N_( "Enable original graphic spectrum" )
00070 #define ORIG_LONGTEXT N_( \
00071 "Defines whether to draw the original spectrum graphic routine." )
00072
00073 #define BANDS_TEXT N_( "Enable bands" )
00074 #define BANDS_LONGTEXT N_( \
00075 "Defines whether to draw the bands." )
00076
00077 #define BASE_TEXT N_( "Enable base" )
00078 #define BASE_LONGTEXT N_( \
00079 "Defines whether to draw the base of the bands." )
00080
00081 #define RADIUS_TEXT N_( "Base pixel radius" )
00082 #define RADIUS_LONGTEXT N_( \
00083 "Defines radius size in pixels, of base of bands(beginning)." )
00084
00085 #define SECT_TEXT N_( "Spectral sections" )
00086 #define SECT_LONGTEXT N_( \
00087 "Determines how many sections of spectrum will exist." )
00088
00089 #define PEAK_HEIGHT_TEXT N_( "Peak height" )
00090 #define PEAK_HEIGHT_LONGTEXT N_( \
00091 "This is the total pixel height of the peak items." )
00092
00093 #define PEAK_WIDTH_TEXT N_( "Peak extra width" )
00094 #define PEAK_WIDTH_LONGTEXT N_( \
00095 "Additions or subtractions of pixels on the peak width." )
00096
00097 #define COLOR1_TEXT N_( "V-plane color" )
00098 #define COLOR1_LONGTEXT N_( \
00099 "YUV-Color cube shifting across the V-plane ( 0 - 127 )." )
00100
00101 #define STARS_TEXT N_( "Number of stars" )
00102 #define STARS_LONGTEXT N_( \
00103 "Defines the number of stars to draw with random effect." )
00104
00105 static int Open ( vlc_object_t * );
00106 static void Close ( vlc_object_t * );
00107
00108 vlc_module_begin();
00109 set_shortname( _("Visualizer"));
00110 set_category( CAT_AUDIO );
00111 set_subcategory( SUBCAT_AUDIO_VISUAL );
00112 set_description( _("Visualizer filter") );
00113 set_section( N_( "General") , NULL );
00114 add_string("effect-list", "spectrum", NULL,
00115 ELIST_TEXT, ELIST_LONGTEXT, VLC_TRUE );
00116 add_integer("effect-width",VOUT_WIDTH,NULL,
00117 WIDTH_TEXT, WIDTH_LONGTEXT, VLC_FALSE );
00118 add_integer("effect-height" , VOUT_HEIGHT , NULL,
00119 HEIGHT_TEXT, HEIGHT_LONGTEXT, VLC_FALSE );
00120 set_section( N_("Spectrum analyser") , NULL );
00121 add_integer("visual-nbbands", 80, NULL,
00122 NBBANDS_TEXT, NBBANDS_LONGTEXT, VLC_TRUE );
00123 add_integer("visual-separ", 1, NULL,
00124 SEPAR_TEXT, SEPAR_LONGTEXT, VLC_TRUE );
00125 add_integer("visual-amp", 3, NULL,
00126 AMP_TEXT, AMP_LONGTEXT, VLC_TRUE );
00127 add_bool("visual-peaks", VLC_TRUE, NULL,
00128 PEAKS_TEXT, PEAKS_LONGTEXT, VLC_TRUE );
00129 set_section( N_("Spectrometer") , NULL );
00130 add_bool("spect-show-original", VLC_FALSE, NULL,
00131 ORIG_TEXT, ORIG_LONGTEXT, VLC_TRUE );
00132 add_bool("spect-show-base", VLC_TRUE, NULL,
00133 BASE_TEXT, BASE_LONGTEXT, VLC_TRUE );
00134 add_integer("spect-radius", 42, NULL,
00135 RADIUS_TEXT, RADIUS_LONGTEXT, VLC_TRUE );
00136 add_integer("spect-sections", 3, NULL,
00137 SECT_TEXT, SECT_LONGTEXT, VLC_TRUE );
00138 add_integer("spect-color", 80, NULL,
00139 COLOR1_TEXT, COLOR1_LONGTEXT, VLC_TRUE );
00140 add_bool("spect-show-bands", VLC_TRUE, NULL,
00141 BANDS_TEXT, BANDS_LONGTEXT, VLC_TRUE );
00142 add_integer("spect-nbbands", 32, NULL,
00143 NBBANDS_TEXT, SPNBBANDS_LONGTEXT, VLC_TRUE );
00144 add_integer("spect-separ", 1, NULL,
00145 SEPAR_TEXT, SEPAR_LONGTEXT, VLC_TRUE );
00146 add_integer("spect-amp", 8, NULL,
00147 AMP_TEXT, AMP_LONGTEXT, VLC_TRUE );
00148 add_bool("spect-show-peaks", VLC_TRUE, NULL,
00149 PEAKS_TEXT, PEAKS_LONGTEXT, VLC_TRUE );
00150 add_integer("spect-peak-width", 61, NULL,
00151 PEAK_WIDTH_TEXT, PEAK_WIDTH_LONGTEXT, VLC_TRUE );
00152 add_integer("spect-peak-height", 1, NULL,
00153 PEAK_HEIGHT_TEXT, PEAK_HEIGHT_LONGTEXT, VLC_TRUE );
00154 set_capability( "visualization", 0 );
00155 set_callbacks( Open, Close );
00156 add_shortcut( "visualizer");
00157 vlc_module_end();
00158
00159
00160
00161
00162
00163 static void DoWork( aout_instance_t *, aout_filter_t *,
00164 aout_buffer_t *, aout_buffer_t * );
00165 static int FilterCallback( vlc_object_t *, char const *,
00166 vlc_value_t, vlc_value_t, void * );
00167 static struct
00168 {
00169 char *psz_name;
00170 int (*pf_run)( visual_effect_t *, aout_instance_t *,
00171 aout_buffer_t *, picture_t *);
00172 } pf_effect_run[]=
00173 {
00174 { "scope", scope_Run },
00175 { "spectrum", spectrum_Run },
00176 { "spectrometer", spectrometer_Run },
00177 { "dummy", dummy_Run},
00178 { NULL, dummy_Run}
00179 };
00180
00181
00182
00183
00184 static int Open( vlc_object_t *p_this )
00185 {
00186 aout_filter_t *p_filter = (aout_filter_t *)p_this;
00187 aout_filter_sys_t *p_sys;
00188 vlc_value_t val;
00189
00190 char *psz_effects, *psz_parser;
00191 video_format_t fmt = {0};
00192
00193 if( ( p_filter->input.i_format != VLC_FOURCC('f','l','3','2') &&
00194 p_filter->input.i_format != VLC_FOURCC('f','i','3','2') ) )
00195 {
00196 return VLC_EGENERIC;
00197 }
00198
00199 p_sys = p_filter->p_sys = malloc( sizeof( aout_filter_sys_t ) );
00200 if( p_sys == NULL )
00201 {
00202 msg_Err( p_filter, "out of memory" );
00203 return VLC_EGENERIC;
00204 }
00205
00206 p_sys->i_height = config_GetInt( p_filter , "effect-height");
00207 p_sys->i_width = config_GetInt( p_filter , "effect-width");
00208
00209 if( p_sys->i_height < 20 ) p_sys->i_height = 20;
00210 if( p_sys->i_width < 20 ) p_sys->i_width = 20;
00211 if( (p_sys->i_height % 2 ) != 0 ) p_sys->i_height--;
00212 if( (p_sys->i_width % 2 ) != 0 ) p_sys->i_width--;
00213
00214 p_sys->i_effect = 0;
00215 p_sys->effect = NULL;
00216
00217
00218 var_Create( p_filter, "effect-list", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
00219 var_Get( p_filter, "effect-list", &val);
00220 psz_parser = psz_effects = strdup( val.psz_string );
00221 free( val.psz_string );
00222
00223 var_AddCallback( p_filter, "effect-list", FilterCallback, NULL );
00224
00225 while( psz_parser && *psz_parser != '\0' )
00226 {
00227 visual_effect_t *p_effect;
00228 int i;
00229
00230 p_effect = malloc( sizeof( visual_effect_t ) );
00231 p_effect->i_width = p_sys->i_width;
00232 p_effect->i_height= p_sys->i_height;
00233 p_effect->i_nb_chans = aout_FormatNbChannels( &p_filter->input);
00234 p_effect->psz_args = NULL;
00235 p_effect->p_data = NULL;
00236
00237 p_effect->pf_run = NULL;
00238 p_effect->psz_name = NULL;
00239
00240 for( i = 0; pf_effect_run[i].psz_name != NULL; i++ )
00241 {
00242 if( !strncasecmp( psz_parser,
00243 pf_effect_run[i].psz_name,
00244 strlen( pf_effect_run[i].psz_name ) ) )
00245 {
00246 p_effect->pf_run = pf_effect_run[i].pf_run;
00247 p_effect->psz_name = strdup( pf_effect_run[i].psz_name );
00248 break;
00249 }
00250 }
00251
00252 if( p_effect->psz_name )
00253 {
00254 psz_parser += strlen( p_effect->psz_name );
00255
00256 if( *psz_parser == '{' )
00257 {
00258 char *psz_eoa;
00259
00260 psz_parser++;
00261
00262 if( ( psz_eoa = strchr( psz_parser, '}') ) == NULL )
00263 {
00264 msg_Err( p_filter, "Unable to parse effect list. Aborting");
00265 break;
00266 }
00267 p_effect->psz_args =
00268 strndup( psz_parser, psz_eoa - psz_parser);
00269 }
00270 TAB_APPEND( p_sys->i_effect, p_sys->effect, p_effect );
00271 }
00272 else
00273 {
00274 msg_Err( p_filter, "unknown visual effect: %s", psz_parser );
00275 free( p_effect );
00276 }
00277
00278 if( strchr( psz_parser, ',' ) )
00279 {
00280 psz_parser = strchr( psz_parser, ',' ) + 1;
00281 }
00282 else if( strchr( psz_parser, ':' ) )
00283 {
00284 psz_parser = strchr( psz_parser, ':' ) + 1;
00285 }
00286 else
00287 {
00288 break;
00289 }
00290 }
00291
00292 if( psz_effects )
00293 {
00294 free( psz_effects );
00295 }
00296
00297 if( !p_sys->i_effect )
00298 {
00299 msg_Err( p_filter, "no effects found" );
00300 free( p_sys );
00301 return VLC_EGENERIC;
00302 }
00303
00304
00305 fmt.i_width = fmt.i_visible_width = p_sys->i_width;
00306 fmt.i_height = fmt.i_visible_height = p_sys->i_height;
00307 fmt.i_chroma = VLC_FOURCC('I','4','2','0');
00308 fmt.i_aspect = VOUT_ASPECT_FACTOR * p_sys->i_width/p_sys->i_height;
00309 fmt.i_sar_num = fmt.i_sar_den = 1;
00310
00311 p_sys->p_vout = vout_Request( p_filter, NULL, &fmt );
00312 if( p_sys->p_vout == NULL )
00313 {
00314 msg_Err( p_filter, "no suitable vout module" );
00315 free( p_sys );
00316 return VLC_EGENERIC;
00317 }
00318
00319 p_filter->pf_do_work = DoWork;
00320 p_filter->b_in_place= 1;
00321
00322 msg_Dbg( p_filter,"Visualizer initialized");
00323 return VLC_SUCCESS;
00324 }
00325
00326
00327
00328
00329
00330
00331 static void DoWork( aout_instance_t *p_aout, aout_filter_t *p_filter,
00332 aout_buffer_t *p_in_buf, aout_buffer_t *p_out_buf )
00333 {
00334 aout_filter_sys_t *p_sys = p_filter->p_sys;
00335 picture_t *p_outpic;
00336 int i;
00337
00338 p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
00339 p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes *
00340 aout_FormatNbChannels( &p_filter->output ) /
00341 aout_FormatNbChannels( &p_filter->input );
00342
00343
00344 while( ( p_outpic = vout_CreatePicture( p_sys->p_vout, 0, 0, 3 ) ) == NULL)
00345 {
00346 if( p_aout->b_die )
00347 {
00348 return;
00349 }
00350 msleep( VOUT_OUTMEM_SLEEP );
00351 }
00352
00353
00354 for( i = 0 ; i < p_outpic->i_planes ; i++ )
00355 {
00356 memset( p_outpic->p[i].p_pixels, i > 0 ? 0x80 : 0x00,
00357 p_outpic->p[i].i_visible_lines * p_outpic->p[i].i_pitch );
00358 }
00359
00360
00361 for( i = 0; i < p_sys->i_effect; i++ )
00362 {
00363 #define p_effect p_sys->effect[i]
00364 if( p_effect->pf_run )
00365 {
00366 p_effect->pf_run( p_effect, p_aout, p_out_buf, p_outpic );
00367 }
00368 #undef p_effect
00369 }
00370
00371 vout_DatePicture( p_sys->p_vout, p_outpic,
00372 ( p_in_buf->start_date + p_in_buf->end_date ) / 2 );
00373
00374 vout_DisplayPicture( p_sys->p_vout, p_outpic );
00375 }
00376
00377
00378
00379
00380 static void Close( vlc_object_t *p_this )
00381 {
00382 aout_filter_t * p_filter = (aout_filter_t *)p_this;
00383 aout_filter_sys_t *p_sys = p_filter->p_sys;
00384
00385 int i;
00386
00387 if( p_filter->p_sys->p_vout )
00388 {
00389 vout_Request( p_filter, p_filter->p_sys->p_vout, 0 );
00390 }
00391
00392
00393 for( i = 0; i < p_sys->i_effect; i++ )
00394 {
00395 #define p_effect p_sys->effect[i]
00396 if( p_effect->psz_name )
00397 {
00398 free( p_effect->psz_name );
00399 }
00400 if( p_effect->psz_args )
00401 {
00402 free( p_effect->psz_args );
00403 }
00404 free( p_effect );
00405 #undef p_effect
00406 }
00407
00408 if( p_sys->effect )
00409 {
00410 free( p_sys->effect );
00411 }
00412
00413 free( p_filter->p_sys );
00414 }
00415
00416
00417
00418
00419 static int FilterCallback( vlc_object_t *p_this, char const *psz_cmd,
00420 vlc_value_t oldval, vlc_value_t newval,
00421 void *p_data )
00422 {
00423 aout_filter_t *p_filter = (aout_filter_t *)p_this;
00424
00425 msg_Dbg( p_filter, "We should restart the visual filter" );
00426 return VLC_SUCCESS;
00427 }
00428