X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvisualization%2Fvisual%2Fvisual.c;h=98b4ab3b06c16865197c61d69fa901951f6876f5;hb=41b8c2e1f660c767ee7a96ab69204b94b1470ca8;hp=a0570bd976d5f49808e220c38d0d5b0693f7ebe6;hpb=56b5483c5684b5e91e56fdbc7429b264728e2e77;p=vlc diff --git a/modules/visualization/visual/visual.c b/modules/visualization/visual/visual.c index a0570bd976..98b4ab3b06 100644 --- a/modules/visualization/visual/visual.c +++ b/modules/visualization/visual/visual.c @@ -1,10 +1,10 @@ /***************************************************************************** * visual.c : Visualisation system ***************************************************************************** - * Copyright (C) 2002 VideoLAN + * Copyright (C) 2002-2009 the VideoLAN team * $Id$ * - * Authors: Clément Stenac + * Authors: Clément Stenac * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,17 +18,21 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ -#include -#include -#include "audio_output.h" -#include "aout_internal.h" +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include +#include #include "visual.h" @@ -38,7 +42,8 @@ #define ELIST_TEXT N_( "Effects list" ) #define ELIST_LONGTEXT N_( \ "A list of visual effect, separated by commas.\n" \ - "Current effects include: dummy, random, scope, spectrum" ) + "Current effects include: dummy, scope, spectrum, "\ + "spectrometer and vuMeter." ) #define WIDTH_TEXT N_( "Video width" ) #define WIDTH_LONGTEXT N_( \ @@ -48,9 +53,11 @@ #define HEIGHT_LONGTEXT N_( \ "The height of the effects video window, in pixels." ) -#define NBBANDS_TEXT N_( "Number of bands" ) +#define NBBANDS_TEXT N_( "More bands : 80 / 20" ) #define NBBANDS_LONGTEXT N_( \ - "Number of bands used by spectrum analyzer, should be 20 or 80." ) + "More bands for the spectrum analyzer : 80 if enabled else 20." ) +#define SPNBBANDS_LONGTEXT N_( \ + "More bands for the spectrometer : 80 if enabled else 20." ) #define SEPAR_TEXT N_( "Band separator" ) #define SEPAR_LONGTEXT N_( \ @@ -62,58 +69,114 @@ #define PEAKS_TEXT N_( "Enable peaks" ) #define PEAKS_LONGTEXT N_( \ - "Defines whether to draw peaks." ) + "Draw \"peaks\" in the spectrum analyzer." ) + +#define ORIG_TEXT N_( "Enable original graphic spectrum" ) +#define ORIG_LONGTEXT N_( \ + "Enable the \"flat\" spectrum analyzer in the spectrometer." ) + +#define BANDS_TEXT N_( "Enable bands" ) +#define BANDS_LONGTEXT N_( \ + "Draw bands in the spectrometer." ) + +#define BASE_TEXT N_( "Enable base" ) +#define BASE_LONGTEXT N_( \ + "Defines whether to draw the base of the bands." ) + +#define RADIUS_TEXT N_( "Base pixel radius" ) +#define RADIUS_LONGTEXT N_( \ + "Defines radius size in pixels, of base of bands(beginning)." ) + +#define SSECT_TEXT N_( "Spectral sections" ) +#define SSECT_LONGTEXT N_( \ + "Determines how many sections of spectrum will exist." ) + +#define PEAK_HEIGHT_TEXT N_( "Peak height" ) +#define PEAK_HEIGHT_LONGTEXT N_( \ + "Total pixel height of the peak items." ) -#define STARS_TEXT N_( "Number of stars" ) -#define STARS_LONGTEXT N_( \ - "Defines the number of stars to draw with random effect." ) +#define PEAK_WIDTH_TEXT N_( "Peak extra width" ) +#define PEAK_WIDTH_LONGTEXT N_( \ + "Additions or subtractions of pixels on the peak width." ) + +#define COLOR1_TEXT N_( "V-plane color" ) +#define COLOR1_LONGTEXT N_( \ + "YUV-Color cube shifting across the V-plane ( 0 - 127 )." ) static int Open ( vlc_object_t * ); static void Close ( vlc_object_t * ); -vlc_module_begin(); - set_description( _("visualizer filter") ); +vlc_module_begin () + set_shortname( N_("Visualizer")) + set_category( CAT_AUDIO ) + set_subcategory( SUBCAT_AUDIO_VISUAL ) + set_description( N_("Visualizer filter") ) + set_section( N_( "General") , NULL ) add_string("effect-list", "spectrum", NULL, - ELIST_TEXT, ELIST_LONGTEXT, VLC_TRUE ); + ELIST_TEXT, ELIST_LONGTEXT, true ) add_integer("effect-width",VOUT_WIDTH,NULL, - WIDTH_TEXT, WIDTH_LONGTEXT, VLC_FALSE ); + WIDTH_TEXT, WIDTH_LONGTEXT, false ) add_integer("effect-height" , VOUT_HEIGHT , NULL, - HEIGHT_TEXT, HEIGHT_LONGTEXT, VLC_FALSE ); - add_integer("visual-nbbands", 80, NULL, - NBBANDS_TEXT, NBBANDS_LONGTEXT, VLC_FALSE ); - add_integer("visual-separ", 1, NULL, - SEPAR_TEXT, SEPAR_LONGTEXT, VLC_FALSE ); - add_integer("visual-amp", 3, NULL, - AMP_TEXT, AMP_LONGTEXT, VLC_FALSE ); - add_bool("visual-peaks", VLC_TRUE, NULL, - PEAKS_TEXT, PEAKS_LONGTEXT, VLC_FALSE ); - add_integer("visual-stars", 200, NULL, - STARS_TEXT, STARS_LONGTEXT, VLC_FALSE ); - set_capability( "audio filter", 0 ); - set_callbacks( Open, Close ); - add_shortcut( "visualizer"); -vlc_module_end(); + HEIGHT_TEXT, HEIGHT_LONGTEXT, false ) + set_section( N_("Spectrum analyser") , NULL ) + add_obsolete_integer( "visual-nbbands" ) /* Since 1.0.0 */ + add_bool("visual-80-bands", true, NULL, + NBBANDS_TEXT, NBBANDS_LONGTEXT, true ); + add_obsolete_integer( "visual-separ" ) /* Since 1.0.0 */ + add_obsolete_integer( "visual-amp" ) /* Since 1.0.0 */ + add_bool("visual-peaks", true, NULL, + PEAKS_TEXT, PEAKS_LONGTEXT, true ) + set_section( N_("Spectrometer") , NULL ) + add_bool("spect-show-original", false, NULL, + ORIG_TEXT, ORIG_LONGTEXT, true ) + add_bool("spect-show-base", true, NULL, + BASE_TEXT, BASE_LONGTEXT, true ) + add_integer("spect-radius", 42, NULL, + RADIUS_TEXT, RADIUS_LONGTEXT, true ) + add_integer("spect-sections", 3, NULL, + SSECT_TEXT, SSECT_LONGTEXT, true ) + add_integer("spect-color", 80, NULL, + COLOR1_TEXT, COLOR1_LONGTEXT, true ) + add_bool("spect-show-bands", true, NULL, + BANDS_TEXT, BANDS_LONGTEXT, true ); + add_obsolete_integer( "spect-nbbands" ) /* Since 1.0.0 */ + add_bool("spect-80-bands", true, NULL, + NBBANDS_TEXT, SPNBBANDS_LONGTEXT, true ) + add_integer("spect-separ", 1, NULL, + SEPAR_TEXT, SEPAR_LONGTEXT, true ) + add_integer("spect-amp", 8, NULL, + AMP_TEXT, AMP_LONGTEXT, true ) + add_bool("spect-show-peaks", true, NULL, + PEAKS_TEXT, PEAKS_LONGTEXT, true ) + add_integer("spect-peak-width", 61, NULL, + PEAK_WIDTH_TEXT, PEAK_WIDTH_LONGTEXT, true ) + add_integer("spect-peak-height", 1, NULL, + PEAK_HEIGHT_TEXT, PEAK_HEIGHT_LONGTEXT, true ) + set_capability( "visualization2", 0 ) + set_callbacks( Open, Close ) + add_shortcut( "visualizer") +vlc_module_end () /***************************************************************************** * Local prototypes *****************************************************************************/ -static void DoWork( aout_instance_t *, aout_filter_t *, - aout_buffer_t *, aout_buffer_t * ); +static block_t *DoWork( filter_t *, block_t * ); static int FilterCallback( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * ); -static struct +static const struct { - char *psz_name; - int (*pf_run)( visual_effect_t *, aout_instance_t *, - aout_buffer_t *, picture_t *); + const char *psz_name; + int (*pf_run)( visual_effect_t *, vlc_object_t *, + const block_t *, picture_t *); } pf_effect_run[]= { - { "scope", scope_Run }, - { "spectrum", spectrum_Run }, - { "random", random_Run}, - { "dummy", dummy_Run}, - { NULL, dummy_Run} + { "scope", scope_Run }, + { "vuMeter", vuMeter_Run }, + { "spectrum", spectrum_Run }, + { "spectrometer", spectrometer_Run }, + { "dummy", dummy_Run}, + { NULL, dummy_Run} }; /***************************************************************************** @@ -121,30 +184,27 @@ static struct *****************************************************************************/ static int Open( vlc_object_t *p_this ) { - aout_filter_t *p_filter = (aout_filter_t *)p_this; - aout_filter_sys_t *p_sys; - vlc_value_t val; + filter_t *p_filter = (filter_t *)p_this; + filter_sys_t *p_sys; char *psz_effects, *psz_parser; + video_format_t fmt; - if( ( p_filter->input.i_format != VLC_FOURCC('f','l','3','2') && - p_filter->input.i_format != VLC_FOURCC('f','i','3','2') ) ) + if( ( p_filter->fmt_in.audio.i_format != VLC_CODEC_FL32 && + p_filter->fmt_in.audio.i_format != VLC_CODEC_FI32 ) ) { return VLC_EGENERIC; } - p_sys = p_filter->p_sys = malloc( sizeof( aout_filter_sys_t ) ); + p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) ); if( p_sys == NULL ) - { - msg_Err( p_filter, "out of memory" ); return VLC_EGENERIC; - } - p_sys->i_height = config_GetInt( p_filter , "effect-height"); - p_sys->i_width = config_GetInt( p_filter , "effect-width"); + p_sys->i_height = var_InheritInteger( p_filter , "effect-height"); + p_sys->i_width = var_InheritInteger( p_filter , "effect-width"); - if( p_sys->i_height < 20 ) p_sys->i_height = 20; - if( p_sys->i_width < 20 ) p_sys->i_width = 20; + if( p_sys->i_height < 400 ) p_sys->i_height = 400; + if( p_sys->i_width < 532 ) p_sys->i_width = 532; if( (p_sys->i_height % 2 ) != 0 ) p_sys->i_height--; if( (p_sys->i_width % 2 ) != 0 ) p_sys->i_width--; @@ -152,12 +212,7 @@ static int Open( vlc_object_t *p_this ) p_sys->effect = NULL; /* Parse the effect list */ - var_Create( p_filter, "effect-list", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); - var_Get( p_filter, "effect-list", &val); - psz_parser = psz_effects = strdup( val.psz_string ); - free( val.psz_string ); - msg_Dbg( p_filter , "Building list of effects" ); - + psz_parser = psz_effects = var_CreateGetString( p_filter, "effect-list" ); var_AddCallback( p_filter, "effect-list", FilterCallback, NULL ); while( psz_parser && *psz_parser != '\0' ) @@ -166,9 +221,14 @@ static int Open( vlc_object_t *p_this ) int i; p_effect = malloc( sizeof( visual_effect_t ) ); + if( !p_effect ) + break; p_effect->i_width = p_sys->i_width; p_effect->i_height= p_sys->i_height; - p_effect->i_nb_chans = aout_FormatNbChannels( &p_filter->input); + p_effect->i_nb_chans = aout_FormatNbChannels( &p_filter->fmt_in.audio); + p_effect->i_idx_left = 0; + p_effect->i_idx_right = __MIN( 1, p_effect->i_nb_chans-1 ); + p_effect->psz_args = NULL; p_effect->p_data = NULL; @@ -182,7 +242,7 @@ static int Open( vlc_object_t *p_this ) strlen( pf_effect_run[i].psz_name ) ) ) { p_effect->pf_run = pf_effect_run[i].pf_run; - p_effect->psz_name = strdup( pf_effect_run[i].psz_name ); + p_effect->psz_name = pf_effect_run[i].psz_name; break; } } @@ -199,7 +259,8 @@ static int Open( vlc_object_t *p_this ) if( ( psz_eoa = strchr( psz_parser, '}') ) == NULL ) { - msg_Err( p_filter, "Unable to parse effect list. Aborting"); + msg_Err( p_filter, "unable to parse effect list. Aborting"); + free( p_effect ); break; } p_effect->psz_args = @@ -227,10 +288,7 @@ static int Open( vlc_object_t *p_this ) } } - if( psz_effects ) - { - free( psz_effects ); - } + free( psz_effects ); if( !p_sys->i_effect ) { @@ -240,23 +298,29 @@ static int Open( vlc_object_t *p_this ) } /* Open the video output */ - p_sys->p_vout = - vout_Request( p_filter, NULL, - p_sys->i_width, p_sys->i_height, - VLC_FOURCC('I','4','2','0'), - VOUT_ASPECT_FACTOR * p_sys->i_width/p_sys->i_height ); + memset( &fmt, 0, sizeof(video_format_t) ); + + fmt.i_width = fmt.i_visible_width = p_sys->i_width; + fmt.i_height = fmt.i_visible_height = p_sys->i_height; + fmt.i_chroma = VLC_CODEC_I420; + fmt.i_sar_num = fmt.i_sar_den = 1; + p_sys->p_vout = aout_filter_RequestVout( p_filter, NULL, &fmt ); if( p_sys->p_vout == NULL ) { msg_Err( p_filter, "no suitable vout module" ); + for( int i = 0; i < p_sys->i_effect; i++ ) + { + free( p_sys->effect[i]->psz_args ); + free( p_sys->effect[i] ); + } + free( p_sys->effect ); free( p_sys ); return VLC_EGENERIC; } - p_filter->pf_do_work = DoWork; - p_filter->b_in_place= 1; + p_filter->pf_audio_filter = DoWork; - msg_Dbg( p_filter,"Visualizer initialized"); return VLC_SUCCESS; } @@ -265,25 +329,18 @@ static int Open( vlc_object_t *p_this ) ***************************************************************************** * Audio part pasted from trivial.c ****************************************************************************/ -static void DoWork( aout_instance_t *p_aout, aout_filter_t *p_filter, - aout_buffer_t *p_in_buf, aout_buffer_t *p_out_buf ) +static block_t *DoWork( filter_t *p_filter, block_t *p_in_buf ) { - aout_filter_sys_t *p_sys = p_filter->p_sys; + filter_sys_t *p_sys = p_filter->p_sys; picture_t *p_outpic; int i; - p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; - p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes * - aout_FormatNbChannels( &p_filter->output ) / - aout_FormatNbChannels( &p_filter->input ); - /* First, get a new picture */ - while( ( p_outpic = vout_CreatePicture( p_sys->p_vout, 0, 0, 3 ) ) == NULL) - { - if( p_aout->b_die ) - { - return; - } + while( ( p_outpic = vout_GetPicture( p_sys->p_vout ) ) == NULL) + { /* XXX: This looks like a bad idea. Don't run to me for sympathy if it + * dead locks... */ + if( !vlc_object_alive (p_sys->p_vout) ) + return NULL; msleep( VOUT_OUTMEM_SLEEP ); } @@ -300,15 +357,16 @@ static void DoWork( aout_instance_t *p_aout, aout_filter_t *p_filter, #define p_effect p_sys->effect[i] if( p_effect->pf_run ) { - p_effect->pf_run( p_effect, p_aout, p_out_buf, p_outpic ); + p_effect->pf_run( p_effect, VLC_OBJECT(p_filter), + p_in_buf, p_outpic ); } #undef p_effect } - vout_DatePicture( p_sys->p_vout, p_outpic, - ( p_in_buf->start_date + p_in_buf->end_date ) / 2 ); + p_outpic->date = p_in_buf->i_pts + (p_in_buf->i_length / 2); - vout_DisplayPicture( p_sys->p_vout, p_outpic ); + vout_PutPicture( p_sys->p_vout, p_outpic ); + return p_in_buf; } /***************************************************************************** @@ -316,37 +374,40 @@ static void DoWork( aout_instance_t *p_aout, aout_filter_t *p_filter, *****************************************************************************/ static void Close( vlc_object_t *p_this ) { - aout_filter_t * p_filter = (aout_filter_t *)p_this; - aout_filter_sys_t *p_sys = p_filter->p_sys; + filter_t * p_filter = (filter_t *)p_this; + filter_sys_t *p_sys = p_filter->p_sys; int i; if( p_filter->p_sys->p_vout ) { - vout_Request( p_filter, p_filter->p_sys->p_vout, 0, 0, 0, 0 ); + aout_filter_RequestVout( p_filter, p_filter->p_sys->p_vout, 0 ); } /* Free the list */ for( i = 0; i < p_sys->i_effect; i++ ) { #define p_effect p_sys->effect[i] - if( p_effect->psz_name ) + if( !strncmp( p_effect->psz_name, "spectrum", strlen( "spectrum" ) ) ) { - free( p_effect->psz_name ); + spectrum_data *p_data = p_effect->p_data; + free( p_data->peaks ); + free( p_data->prev_heights ); + free( p_data->p_prev_s16_buff ); } - if( p_effect->psz_args ) + if( !strncmp( p_effect->psz_name, "spectrometer", strlen( "spectrometer" ) ) ) { - free( p_effect->psz_args ); + spectrometer_data *p_data = p_effect->p_data; + free( p_data->peaks ); + free( p_data->p_prev_s16_buff ); } + free( p_effect->p_data ); + free( p_effect->psz_args ); free( p_effect ); #undef p_effect } - if( p_sys->effect ) - { - free( p_sys->effect ); - } - + free( p_sys->effect ); free( p_filter->p_sys ); } @@ -357,9 +418,11 @@ static int FilterCallback( vlc_object_t *p_this, char const *psz_cmd, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { + VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); + VLC_UNUSED(p_data); VLC_UNUSED(newval); aout_filter_t *p_filter = (aout_filter_t *)p_this; /* restart this baby */ - msg_Dbg( p_filter, "We should restart the visual filter" ); + msg_Dbg( p_filter, "we should restart the visual filter" ); return VLC_SUCCESS; }