- int i_result = 0;
- aout_instance_t * p_aout = vlc_object_find( p_object, VLC_OBJECT_AOUT,
- FIND_ANYWHERE );
-
- if ( pi_volume == NULL ) return -1;
-
- if ( p_aout == NULL )
+ int i_result = VLC_SUCCESS;
+ int i_volume_step = 1, i_new_volume = 0;
+ bool b_var_mute = false;
+ aout_instance_t *p_aout = findAout( p_object );
+
+ if ( p_aout ) aout_lock_volume( p_aout );
+
+ b_var_mute = var_GetBool( p_object, "volume-muted");
+
+ const bool b_unmute_condition = ( b_var_mute
+ && ( /* Unmute: on increments */
+ ( action == INCREMENT_VOLUME )
+ || /* On explicit unmute */
+ ( ( action == SET_MUTE ) && !b_mute )
+ || /* On toggle from muted */
+ ( action == TOGGLE_MUTE )
+ ));
+
+ const bool b_mute_condition = ( !b_var_mute
+ && ( /* explicit */
+ ( ( action == SET_MUTE ) && b_mute )
+ || /* or toggle */
+ ( action == TOGGLE_MUTE )
+ ));
+
+ /* If muting or unmuting when play hasn't started */
+ if ( action == SET_MUTE && !b_unmute_condition && !b_mute_condition )