From 28ef0fe16c33c2e314654aed350dfaf60a980ebf Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Thu, 7 Apr 2011 23:36:00 +0300 Subject: [PATCH] Pass mute flag to aout_output_t.pf_volume_set This improves mute flag handling in the PulseAudio output: We do not blindly reset the mute flag. --- include/vlc_aout.h | 2 +- modules/audio_output/pulse.c | 5 ++- modules/audio_output/waveout.c | 8 +++-- src/audio_output/aout_internal.h | 4 --- src/audio_output/intf.c | 53 +++++++++++++------------------- 5 files changed, 29 insertions(+), 43 deletions(-) diff --git a/include/vlc_aout.h b/include/vlc_aout.h index 20bc45586c..3bb3265c16 100644 --- a/include/vlc_aout.h +++ b/include/vlc_aout.h @@ -198,7 +198,7 @@ typedef struct aout_output_t struct module_t * p_module; struct aout_sys_t * p_sys; void (* pf_play)( aout_instance_t * ); - int (* pf_volume_set )( aout_instance_t *, audio_volume_t ); + int (* pf_volume_set )( aout_instance_t *, audio_volume_t, bool ); int i_nb_samples; /* Current volume for the output - it's just a placeholder, the plug-in diff --git a/modules/audio_output/pulse.c b/modules/audio_output/pulse.c index 809f0f626b..b212d95ee0 100644 --- a/modules/audio_output/pulse.c +++ b/modules/audio_output/pulse.c @@ -258,7 +258,7 @@ static void Play(aout_instance_t *aout) pa_threaded_mainloop_unlock(sys->mainloop); } -static int VolumeSet(aout_instance_t *aout, audio_volume_t vol) +static int VolumeSet(aout_instance_t *aout, audio_volume_t vol, bool mute) { aout_sys_t *sys = aout->output.p_sys; pa_threaded_mainloop *mainloop = sys->mainloop; @@ -278,8 +278,7 @@ static int VolumeSet(aout_instance_t *aout, audio_volume_t vol) op = pa_context_set_sink_input_volume(sys->context, idx, &cvolume, NULL, NULL); if (likely(op != NULL)) pa_operation_unref(op); - op = pa_context_set_sink_input_mute(sys->context, idx, volume == PA_VOLUME_MUTED, - NULL, NULL); + op = pa_context_set_sink_input_mute(sys->context, idx, mute, NULL, NULL); if (likely(op != NULL)) pa_operation_unref(op); pa_threaded_mainloop_unlock(mainloop); diff --git a/modules/audio_output/waveout.c b/modules/audio_output/waveout.c index 36b8ae431b..a5f6e0411e 100644 --- a/modules/audio_output/waveout.c +++ b/modules/audio_output/waveout.c @@ -1019,8 +1019,12 @@ static void* WaveOutThread( vlc_object_t *p_this ) return NULL; } -static int VolumeSet( aout_instance_t * p_aout, audio_volume_t i_volume ) +static int VolumeSet( aout_instance_t * p_aout, audio_volume_t i_volume, + bool mute ) { + if( mute ) + i_volume = AOUT_VOLUME_MIN; + unsigned long i_waveout_vol = i_volume * 0xFFFF * 2 / AOUT_VOLUME_MAX; i_waveout_vol |= (i_waveout_vol << 16); @@ -1029,8 +1033,6 @@ static int VolumeSet( aout_instance_t * p_aout, audio_volume_t i_volume ) #else waveOutSetVolume( p_aout->output.p_sys->h_waveout, i_waveout_vol ); #endif - - p_aout->output.i_volume = i_volume; return 0; } diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h index 8a648eb43c..004eed35c5 100644 --- a/src/audio_output/aout_internal.h +++ b/src/audio_output/aout_internal.h @@ -140,10 +140,6 @@ void aout_FifoDestroy( aout_instance_t * p_aout, aout_fifo_t * p_fifo ); void aout_FormatsPrint( aout_instance_t * p_aout, const char * psz_text, const audio_sample_format_t * p_format1, const audio_sample_format_t * p_format2 ); bool aout_ChangeFilterString( vlc_object_t *, aout_instance_t *, const char *psz_variable, const char *psz_name, bool b_add ); -/* From intf.c :*/ -int aout_VolumeSoftSet( aout_instance_t *, audio_volume_t ); -int aout_VolumeNoneSet( aout_instance_t *, audio_volume_t ); - /* From dec.c */ aout_input_t *aout_DecNew( aout_instance_t *, audio_sample_format_t *, const audio_replay_gain_t *, const aout_request_vout_t * ); diff --git a/src/audio_output/intf.c b/src/audio_output/intf.c index 8265d184bd..776e11ffb3 100644 --- a/src/audio_output/intf.c +++ b/src/audio_output/intf.c @@ -81,8 +81,6 @@ static int commitVolume (vlc_object_t *obj, aout_instance_t *aout, int ret = 0; var_SetInteger (obj, "volume", volume); - if (mute) - volume = AOUT_VOLUME_MIN; var_SetBool (obj, "mute", mute); if (aout != NULL) @@ -90,7 +88,7 @@ static int commitVolume (vlc_object_t *obj, aout_instance_t *aout, aout_lock_mixer (aout); aout_lock_input_fifos (aout); if (aout->p_mixer != NULL) - ret = aout->output.pf_volume_set (aout, volume); + ret = aout->output.pf_volume_set (aout, volume, mute); aout_unlock_input_fifos (aout); aout_unlock_mixer (aout); @@ -229,43 +227,41 @@ int aout_SetMute (vlc_object_t *obj, audio_volume_t *volp, bool mute) return ret; } + /* * The next functions are not supposed to be called by the interface, but * are placeholders for software-only scaling. */ +static int aout_VolumeSoftSet (aout_instance_t *aout, audio_volume_t volume, + bool mute) +{ + float f = mute ? 0. : (volume / (float)AOUT_VOLUME_DEFAULT); + aout_MixerMultiplierSet (aout, f); + aout->output.i_volume = volume; + return 0; +} /* Meant to be called by the output plug-in's Open(). */ -void aout_VolumeSoftInit( aout_instance_t * p_aout ) +void aout_VolumeSoftInit (aout_instance_t *aout) { - int i_volume; - - p_aout->output.pf_volume_set = aout_VolumeSoftSet; - - i_volume = var_InheritInteger( p_aout, "volume" ); - if ( i_volume < AOUT_VOLUME_MIN ) - { - i_volume = AOUT_VOLUME_DEFAULT; - } - else if ( i_volume > AOUT_VOLUME_MAX ) - { - i_volume = AOUT_VOLUME_MAX; - } + audio_volume_t volume = var_InheritInteger (aout, "volume"); + bool mute = var_InheritBool (aout, "mute"); - aout_VolumeSoftSet( p_aout, (audio_volume_t)i_volume ); + aout->output.pf_volume_set = aout_VolumeSoftSet; + aout_VolumeSoftSet (aout, volume, mute); } -/* Placeholder for pf_volume_set(). */ -int aout_VolumeSoftSet( aout_instance_t * p_aout, audio_volume_t i_volume ) -{ - aout_MixerMultiplierSet( p_aout, (float)i_volume / AOUT_VOLUME_DEFAULT ); - p_aout->output.i_volume = i_volume; - return 0; -} /* * The next functions are not supposed to be called by the interface, but * are placeholders for unsupported scaling. */ +static int aout_VolumeNoneSet (aout_instance_t *aout, audio_volume_t volume, + bool mute) +{ + (void)aout; (void)volume; (void)mute; + return -1; +} /* Meant to be called by the output plug-in's Open(). */ void aout_VolumeNoneInit( aout_instance_t * p_aout ) @@ -273,13 +269,6 @@ void aout_VolumeNoneInit( aout_instance_t * p_aout ) p_aout->output.pf_volume_set = aout_VolumeNoneSet; } -/* Placeholder for pf_volume_set(). */ -int aout_VolumeNoneSet( aout_instance_t * p_aout, audio_volume_t i_volume ) -{ - (void)p_aout; (void)i_volume; - return -1; -} - /* * Pipelines management -- 2.39.5