Commit 3364219c authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

visual: clean up clean up code

parent 032bbe05
...@@ -56,9 +56,24 @@ static int dummy_Run( visual_effect_t * p_effect, vlc_object_t *p_aout, ...@@ -56,9 +56,24 @@ static int dummy_Run( visual_effect_t * p_effect, vlc_object_t *p_aout,
return 0; return 0;
} }
static void dummy_Free( void *data )
{
VLC_UNUSED(data);
}
/***************************************************************************** /*****************************************************************************
* spectrum_Run: spectrum analyser * spectrum_Run: spectrum analyser
*****************************************************************************/ *****************************************************************************/
typedef struct spectrum_data
{
int *peaks;
int *prev_heights;
unsigned i_prev_nb_samples;
int16_t *p_prev_s16_buff;
} spectrum_data;
static int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout, static int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
const block_t * p_buffer , picture_t * p_picture) const block_t * p_buffer , picture_t * p_picture)
{ {
...@@ -332,10 +347,31 @@ static int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout, ...@@ -332,10 +347,31 @@ static int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
return 0; return 0;
} }
static void spectrum_Free( void *data )
{
spectrum_data *p_data = data;
if( p_data != NULL )
{
free( p_data->peaks );
free( p_data->prev_heights );
free( p_data->p_prev_s16_buff );
free( p_data );
}
}
/***************************************************************************** /*****************************************************************************
* spectrometer_Run: derivative spectrum analysis * spectrometer_Run: derivative spectrum analysis
*****************************************************************************/ *****************************************************************************/
typedef struct
{
int *peaks;
unsigned i_prev_nb_samples;
int16_t *p_prev_s16_buff;
} spectrometer_data;
static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout, static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
const block_t * p_buffer , picture_t * p_picture) const block_t * p_buffer , picture_t * p_picture)
{ {
...@@ -789,6 +825,18 @@ static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout, ...@@ -789,6 +825,18 @@ static int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
return 0; return 0;
} }
static void spectrometer_Free( void *data )
{
spectrometer_data *p_data = data;
if( p_data != NULL )
{
free( p_data->peaks );
free( p_data->p_prev_s16_buff );
free( p_data );
}
}
/***************************************************************************** /*****************************************************************************
* scope_Run: scope effect * scope_Run: scope effect
...@@ -988,10 +1036,10 @@ static int vuMeter_Run(visual_effect_t * p_effect, vlc_object_t *p_aout, ...@@ -988,10 +1036,10 @@ static int vuMeter_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
/* Table of effects */ /* Table of effects */
const struct visual_cb_t effectv[] = { const struct visual_cb_t effectv[] = {
{ "scope", scope_Run }, { "scope", scope_Run, dummy_Free },
{ "vuMeter", vuMeter_Run }, { "vuMeter", vuMeter_Run, dummy_Free },
{ "spectrum", spectrum_Run }, { "spectrum", spectrum_Run, spectrum_Free },
{ "spectrometer", spectrometer_Run }, { "spectrometer", spectrometer_Run, spectrometer_Free },
{ "dummy", dummy_Run }, { "dummy", dummy_Run, dummy_Free },
}; };
const unsigned effectc = sizeof (effectv) / sizeof (effectv[0]); const unsigned effectc = sizeof (effectv) / sizeof (effectv[0]);
...@@ -209,9 +209,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -209,9 +209,7 @@ static int Open( vlc_object_t *p_this )
p_effect->i_idx_right = __MIN( 1, p_effect->i_nb_chans-1 ); p_effect->i_idx_right = __MIN( 1, p_effect->i_nb_chans-1 );
p_effect->p_data = NULL; p_effect->p_data = NULL;
p_effect->pf_run = NULL; p_effect->pf_run = NULL;
p_effect->psz_name = NULL;
for( unsigned i = 0; i < effectc; i++ ) for( unsigned i = 0; i < effectc; i++ )
{ {
...@@ -219,15 +217,14 @@ static int Open( vlc_object_t *p_this ) ...@@ -219,15 +217,14 @@ static int Open( vlc_object_t *p_this )
strlen( effectv[i].name ) ) ) strlen( effectv[i].name ) ) )
{ {
p_effect->pf_run = effectv[i].run_cb; p_effect->pf_run = effectv[i].run_cb;
p_effect->psz_name = effectv[i].name; p_effect->pf_free = effectv[i].free_cb;
psz_parser += strlen( effectv[i].name );
break; break;
} }
} }
if( p_effect->psz_name ) if( p_effect->pf_run != NULL )
{ {
psz_parser += strlen( p_effect->psz_name );
if( *psz_parser == '{' ) if( *psz_parser == '{' )
{ {
char *psz_eoa; char *psz_eoa;
...@@ -355,28 +352,12 @@ static void Close( vlc_object_t *p_this ) ...@@ -355,28 +352,12 @@ static void Close( vlc_object_t *p_this )
/* Free the list */ /* Free the list */
for( int i = 0; i < p_sys->i_effect; i++ ) for( int i = 0; i < p_sys->i_effect; i++ )
{ {
#define p_effect p_sys->effect[i] #define p_effect (p_sys->effect[i])
if( p_effect->p_data != NULL ) p_effect->pf_free( p_effect->p_data );
{
if( !strncmp( p_effect->psz_name, "spectrum", strlen( "spectrum" ) ) )
{
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( !strncmp( p_effect->psz_name, "spectrometer", strlen( "spectrometer" ) ) )
{
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 ); free( p_effect );
#undef p_effect #undef p_effect
} }
free( p_sys->effect ); free( p_sys->effect );
free( p_filter->p_sys ); free( p_sys );
} }
...@@ -21,12 +21,15 @@ ...@@ -21,12 +21,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
typedef struct visual_effect_t typedef struct visual_effect_t visual_effect_t;
{ typedef int (*visual_run_t)(visual_effect_t *, vlc_object_t *,
const char *psz_name; /* Filter name*/ const block_t *, picture_t *);
typedef void (*visual_free_t)(void *);
int (*pf_run)( struct visual_effect_t * , vlc_object_t *, struct visual_effect_t
const block_t *, picture_t *); {
visual_run_t pf_run;
visual_free_t pf_free;
void * p_data; /* The effect stores whatever it wants here */ void * p_data; /* The effect stores whatever it wants here */
int i_width; int i_width;
int i_height; int i_height;
...@@ -35,30 +38,12 @@ typedef struct visual_effect_t ...@@ -35,30 +38,12 @@ typedef struct visual_effect_t
/* Channels index */ /* Channels index */
int i_idx_left; int i_idx_left;
int i_idx_right; int i_idx_right;
} visual_effect_t ; };
typedef struct spectrum_data
{
int *peaks;
int *prev_heights;
unsigned i_prev_nb_samples;
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;
typedef int (*visual_run_t)(visual_effect_t *, vlc_object_t *,
const block_t *, picture_t *);
extern const struct visual_cb_t extern const struct visual_cb_t
{ {
char name[16]; char name[16];
visual_run_t run_cb; visual_run_t run_cb;
visual_free_t free_cb;
} effectv[]; } effectv[];
extern const unsigned effectc; extern const unsigned effectc;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment