[vlc-devel] commit: visual: save a huge number of allocation/deallocation. ( Rémi Duraffort )
git version control
git at videolan.org
Thu Nov 19 10:05:39 CET 2009
vlc | branch: master | Rémi Duraffort <ivoire at videolan.org> | Thu Nov 19 10:04:42 2009 +0100| [68dd76f1cd8ec68e2caeeabe325593ffb93b750c] | committer: Rémi Duraffort
visual: save a huge number of allocation/deallocation.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=68dd76f1cd8ec68e2caeeabe325593ffb93b750c
---
modules/visualization/visual/effects.c | 52 ++++++++++++++++++-------------
modules/visualization/visual/visual.c | 1 +
modules/visualization/visual/visual.h | 3 ++
3 files changed, 34 insertions(+), 22 deletions(-)
diff --git a/modules/visualization/visual/effects.c b/modules/visualization/visual/effects.c
index f2043e6..23c9e47 100644
--- a/modules/visualization/visual/effects.c
+++ b/modules/visualization/visual/effects.c
@@ -100,25 +100,7 @@ int spectrum_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;
-
- p_buffs = p_s16_buff;
- i_80_bands = config_GetInt ( p_aout, "visual-80-bands" );
- i_peak = config_GetInt ( p_aout, "visual-peaks" );
-
- if( i_80_bands != 0)
- {
- xscale = xscale2;
- i_nb_bands = 80;
- }
- else
- {
- xscale = xscale1;
- i_nb_bands = 20;
- }
-
+ /* Create p_data if needed */
if( !p_data )
{
p_effect->p_data = p_data = malloc( sizeof( spectrum_data ) );
@@ -130,15 +112,43 @@ int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
p_data->peaks = calloc( 80, sizeof(int) );
p_data->prev_heights = calloc( 80, sizeof(int) );
+
+ p_data->i_prev_nb_samples = 0;
+ p_data->p_prev_s16_buff = NULL;
}
peaks = (int *)p_data->peaks;
prev_heights = (int *)p_data->prev_heights;
+ /* 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;
+
+ i_80_bands = config_GetInt ( p_aout, "visual-80-bands" );
+ i_peak = config_GetInt ( p_aout, "visual-peaks" );
+
+ if( i_80_bands != 0)
+ {
+ xscale = xscale2;
+ i_nb_bands = 80;
+ }
+ else
+ {
+ xscale = xscale1;
+ i_nb_bands = 20;
+ }
height = malloc( i_nb_bands * sizeof(int) );
if( !height )
{
- free( p_s16_buff );
return -1;
}
/* Convert the buffer to int16_t */
@@ -157,7 +167,6 @@ int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
if( !p_state)
{
free( height );
- free( p_s16_buff );
msg_Err(p_aout,"unable to initialize FFT transform");
return -1;
}
@@ -321,7 +330,6 @@ int spectrum_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 2b8ca4d..212c4de 100644
--- a/modules/visualization/visual/visual.c
+++ b/modules/visualization/visual/visual.c
@@ -397,6 +397,7 @@ static void Close( vlc_object_t *p_this )
{
free( ( ( spectrum_data * )p_effect->p_data )->peaks );
free( ( ( spectrum_data * )p_effect->p_data )->prev_heights );
+ free( ( ( spectrum_data * )p_effect->p_data )->p_prev_s16_buff );
}
free( p_effect->p_data );
free( p_effect->psz_args );
diff --git a/modules/visualization/visual/visual.h b/modules/visualization/visual/visual.h
index aadb7a8..f811385 100644
--- a/modules/visualization/visual/visual.h
+++ b/modules/visualization/visual/visual.h
@@ -42,6 +42,9 @@ typedef struct spectrum_data
{
int *peaks;
int *prev_heights;
+
+ unsigned i_prev_nb_samples;
+ int16_t *p_prev_s16_buff;
} spectrum_data;
More information about the vlc-devel
mailing list