[vlc-devel] commit: visual: save again some allocation/deallocation cycles. ( Rémi Duraffort )
git version control
git at videolan.org
Fri Nov 20 10:11:03 CET 2009
vlc | branch: master | Rémi Duraffort <ivoire at videolan.org> | Fri Nov 20 10:04:03 2009 +0100| [60b30f42e92b46726b4647d9a5d8bb3e3b670e59] | committer: Rémi Duraffort
visual: save again some allocation/deallocation cycles.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=60b30f42e92b46726b4647d9a5d8bb3e3b670e59
---
modules/visualization/visual/effects.c | 51 +++++++++++++++++++------------
modules/visualization/visual/visual.c | 5 +++
modules/visualization/visual/visual.h | 7 ++++
3 files changed, 43 insertions(+), 20 deletions(-)
diff --git a/modules/visualization/visual/effects.c b/modules/visualization/visual/effects.c
index 473cd41..7a6440f 100644
--- a/modules/visualization/visual/effects.c
+++ b/modules/visualization/visual/effects.c
@@ -396,11 +396,38 @@ int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
int16_t *p_buffs; /* int16_t converted buffer */
int16_t *p_s16_buff; /* int16_t converted buffer */
- p_s16_buff = malloc( p_buffer->i_nb_samples * p_effect->i_nb_chans * sizeof(int16_t) );
- if( !p_s16_buff )
- return -1;
+ /* Create the data struct if needed */
+ spectrometer_data *p_data = p_effect->p_data;
+ if( !p_data )
+ {
+ p_data = malloc( sizeof(spectrometer_data) );
+ if( !p_data )
+ return -1;
+ p_data->peaks = calloc( 80, sizeof(int) );
+ if( !p_data->peaks )
+ {
+ free( p_data );
+ return -1;
+ }
+ p_data->i_prev_nb_samples = 0;
+ p_data->p_prev_s16_buff = NULL;
+ p_effect->p_data = (void*)p_data;
+ }
+ peaks = p_data->peaks;
+
+ /* Allocate the buffer only if the number of samples change */
+ if( p_buffer->i_nb_samples != p_data->i_prev_nb_samples )
+ {
+ free( p_data->p_prev_s16_buff );
+ p_data->p_prev_s16_buff = malloc( p_buffer->i_nb_samples *
+ p_effect->i_nb_chans *
+ sizeof(int16_t));
+ p_data->i_prev_nb_samples = p_buffer->i_nb_samples;
+ if( !p_data->p_prev_s16_buff )
+ return -1;
+ }
+ p_buffs = p_s16_buff = p_data->p_prev_s16_buff;
- p_buffs = p_s16_buff;
i_original = config_GetInt ( p_aout, "spect-show-original" );
i_80_bands = config_GetInt ( p_aout, "spect-80-bands" );
i_separ = config_GetInt ( p_aout, "spect-separ" );
@@ -425,23 +452,9 @@ int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
i_nb_bands = 20;
}
- if( !p_effect->p_data )
- {
- p_effect->p_data = calloc( 80, sizeof(int) );
- if( !p_effect->p_data )
- {
- free( p_s16_buff );
- return -1;
- }
- }
- peaks =(int *)p_effect->p_data;
-
height = malloc( i_nb_bands * sizeof(int) );
if( !height)
- {
- free( p_s16_buff );
return -1;
- }
/* Convert the buffer to int16_t */
/* Pasted from float32tos16.c */
@@ -460,7 +473,6 @@ int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
{
msg_Err(p_aout,"unable to initialize FFT transform");
free( height );
- free( p_s16_buff );
return -1;
}
p_buffs = p_s16_buff;
@@ -772,7 +784,6 @@ int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
fft_close( p_state );
- free( p_s16_buff );
free( height );
return 0;
diff --git a/modules/visualization/visual/visual.c b/modules/visualization/visual/visual.c
index 212c4de..ee69dee 100644
--- a/modules/visualization/visual/visual.c
+++ b/modules/visualization/visual/visual.c
@@ -399,6 +399,11 @@ static void Close( vlc_object_t *p_this )
free( ( ( spectrum_data * )p_effect->p_data )->prev_heights );
free( ( ( spectrum_data * )p_effect->p_data )->p_prev_s16_buff );
}
+ if( !strncmp( p_effect->psz_name, "spectrometer", strlen( "spectrometer" ) ) )
+ {
+ free( ((spectrometer_data*)p_effect->p_data)->peaks );
+ free( ((spectrometer_data*)p_effect->p_data)->p_prev_s16_buff );
+ }
free( p_effect->p_data );
free( p_effect->psz_args );
free( p_effect );
diff --git a/modules/visualization/visual/visual.h b/modules/visualization/visual/visual.h
index f811385..d1b20c4 100644
--- a/modules/visualization/visual/visual.h
+++ b/modules/visualization/visual/visual.h
@@ -47,6 +47,13 @@ typedef struct spectrum_data
int16_t *p_prev_s16_buff;
} spectrum_data;
+typedef struct
+{
+ int *peaks;
+
+ unsigned i_prev_nb_samples;
+ int16_t *p_prev_s16_buff;
+} spectrometer_data;
/*****************************************************************************
* aout_filter_sys_t: visualizer audio filter method descriptor
More information about the vlc-devel
mailing list