[vlc-devel] [PATCH] Remove libvlc equalizer implementation from the audio output core.
Mark Lee
mark.lee at capricasoftware.co.uk
Tue Sep 18 19:11:34 CEST 2012
Rather than using callbacks in the core, the audio equalizer is simply directly applied (when enabled) to the aout:
1. each time an aout is created;
2. each time the equalizer is set on the media player.
This is similar, in part, to how libvlc_set_fullscreen is implemented.
---
lib/media_player.c | 31 +++++++++++++++++++++++++++----
src/audio_output/common.c | 15 ---------------
2 files changed, 27 insertions(+), 19 deletions(-)
diff --git a/lib/media_player.c b/lib/media_player.c
index b9b2a11..b468f96 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -32,6 +32,7 @@
#include <vlc_demux.h>
#include <vlc_input.h>
+#include <vlc_aout.h>
#include <vlc_vout.h>
#include <vlc_keys.h>
#include <vlc_aout_intf.h>
@@ -191,6 +192,21 @@ static void set_state( libvlc_media_player_t *p_mi, libvlc_state_t state,
}
}
+static void apply_equalizer( input_thread_t *p_input, libvlc_media_player_t *p_mi )
+{
+ audio_output_t *p_aout;
+ if( input_Control( p_input, INPUT_GET_AOUT, &p_aout ) == VLC_SUCCESS )
+ {
+ var_SetString( p_aout, "equalizer-bands", var_GetString( p_mi, "equalizer-bands" ) );
+ var_SetFloat( p_aout, "equalizer-preamp", var_GetFloat( p_mi, "equalizer-preamp" ) );
+
+ if( strlen( var_GetString( p_mi, "equalizer-bands" ) ) > 0 )
+ aout_EnableFilter( p_mi, "equalizer", true );
+
+ vlc_object_release( p_aout );
+ }
+}
+
static int
input_seekable_changed( vlc_object_t * p_this, char const * psz_cmd,
vlc_value_t oldval, vlc_value_t newval,
@@ -335,6 +351,8 @@ input_event_changed( vlc_object_t * p_this, char const * psz_cmd,
event.u.media_player_vout.new_count = i_vout;
libvlc_event_send( p_mi->p_event_manager, &event );
}
+ else if( newval.i_int == INPUT_EVENT_AOUT )
+ apply_equalizer( p_input, p_mi );
return VLC_SUCCESS;
}
@@ -751,9 +769,6 @@ int libvlc_media_player_play( libvlc_media_player_t *p_mi )
p_mi->input.p_thread = p_input_thread;
unlock_input(p_mi);
- if( strlen( var_GetString( p_mi, "equalizer-bands" ) ) > 0 )
- aout_EnableFilter( p_mi, "equalizer", true );
-
return 0;
}
@@ -1420,6 +1435,8 @@ void libvlc_media_player_next_frame( libvlc_media_player_t *p_mi )
int libvlc_media_player_set_equalizer( libvlc_media_player_t *p_mi, libvlc_equalizer_t *p_equalizer )
{
+ input_thread_t *p_input_thread;
+
if ( !p_equalizer )
{
aout_EnableFilter( p_mi, "equalizer", false );
@@ -1444,6 +1461,12 @@ int libvlc_media_player_set_equalizer( libvlc_media_player_t *p_mi, libvlc_equal
var_SetString( p_mi, "equalizer-bands", psz_bands );
free( psz_bands );
- aout_EnableFilter( p_mi, "equalizer", true );
+ p_input_thread = libvlc_get_input_thread( p_mi );
+ if ( !p_input_thread )
+ return 0;
+
+ apply_equalizer( p_input_thread, p_mi );
+
+ vlc_object_release( p_input_thread );
return 0;
}
diff --git a/src/audio_output/common.c b/src/audio_output/common.c
index 949d3b5..f839d02 100644
--- a/src/audio_output/common.c
+++ b/src/audio_output/common.c
@@ -177,15 +177,6 @@ audio_output_t *aout_New( vlc_object_t * p_parent )
&val, &text);
}
- if (var_Type (p_parent, "equalizer-bands"))
- {
- var_Create (aout, "equalizer-preamp", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT);
- var_Create (aout, "equalizer-bands", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
-
- var_AddCallback (p_parent, "equalizer-preamp", var_Copy, aout);
- var_AddCallback (p_parent, "equalizer-bands", var_Copy, aout);
- }
-
return aout;
}
@@ -200,12 +191,6 @@ void aout_Destroy (audio_output_t *aout)
var_SetFloat (aout, "volume", -1.f);
var_DelCallback (aout, "volume", var_Copy, aout->p_parent);
- if (var_Type (aout->p_parent, "equalizer-bands"))
- {
- var_DelCallback (aout->p_parent, "equalizer-preamp", var_Copy, aout);
- var_DelCallback (aout->p_parent, "equalizer-bands", var_Copy, aout);
- }
-
vlc_object_release (aout);
}
--
1.7.9.5
More information about the vlc-devel
mailing list