Example #1
0
/*****************************************************************************
 * aout_VolumeDown : lower the output volume
 *****************************************************************************
 * If pi_volume != NULL, *pi_volume will contain the volume at the end of the
 * function.
 *****************************************************************************/
int __aout_VolumeDown( vlc_object_t * p_object, int i_nb_steps,
                       audio_volume_t * pi_volume )
{
    vlc_value_t val;
    aout_instance_t * p_aout = vlc_object_find( p_object, VLC_OBJECT_AOUT,
                               FIND_ANYWHERE );
    int i_result = 0, i_volume = 0, i_volume_step = 0;

    i_volume_step = config_GetInt( p_object->p_libvlc, "volume-step" );
    i_volume = config_GetInt( p_object, "volume" );
    i_volume -= i_volume_step * i_nb_steps;
    if ( i_volume < AOUT_VOLUME_MIN )
    {
        i_volume = AOUT_VOLUME_MIN;
    }
    config_PutInt( p_object, "volume", i_volume );
    var_Create( p_object->p_libvlc, "saved-volume", VLC_VAR_INTEGER );
    var_SetInteger( p_object->p_libvlc, "saved-volume", (audio_volume_t) i_volume );
    if ( pi_volume != NULL ) *pi_volume = (audio_volume_t) i_volume;

    val.b_bool = true;
    var_Set( p_object->p_libvlc, "volume-change", val );

    if ( p_aout == NULL ) return 0;

    aout_lock_mixer( p_aout );
    if ( !p_aout->mixer.b_error )
    {
        i_result = p_aout->output.pf_volume_set( p_aout, (audio_volume_t) i_volume );
    }
    aout_unlock_mixer( p_aout );

    vlc_object_release( p_aout );
    return i_result;
}
Example #2
0
/*****************************************************************************
 * aout_VolumeGet : get the volume of the output device
 *****************************************************************************/
int __aout_VolumeGet( vlc_object_t * p_object, audio_volume_t * pi_volume )
{
    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 )
    {
        *pi_volume = (audio_volume_t)config_GetInt( p_object, "volume" );
        return 0;
    }

    aout_lock_mixer( p_aout );
    if ( !p_aout->mixer.b_error )
    {
        i_result = p_aout->output.pf_volume_get( p_aout, pi_volume );
    }
    else
    {
        *pi_volume = (audio_volume_t)config_GetInt( p_object, "volume" );
    }
    aout_unlock_mixer( p_aout );

    vlc_object_release( p_aout );
    return i_result;
}
Example #3
0
File: intf.c Project: paa/vlc
/*****************************************************************************
 * aout_VolumeGet : get the volume of the output device
 *****************************************************************************/
int aout_VolumeGet( vlc_object_t * p_object, audio_volume_t * pi_volume )
{
    int i_result = 0;
    aout_instance_t * p_aout = findAout( p_object );

    if ( pi_volume == NULL ) return -1;

    if ( p_aout == NULL )
    {
        *pi_volume = (audio_volume_t)config_GetInt( p_object, "volume" );
        return 0;
    }

    aout_lock_volume( p_aout );
    aout_lock_mixer( p_aout );
    if ( p_aout->p_mixer )
    {
        i_result = p_aout->output.pf_volume_get( p_aout, pi_volume );
    }
    else
    {
        *pi_volume = (audio_volume_t)config_GetInt( p_object, "volume" );
    }
    aout_unlock_mixer( p_aout );
    aout_unlock_volume( p_aout );

    vlc_object_release( p_aout );
    return i_result;
}
Example #4
0
static int ReplayGainCallback( vlc_object_t *p_this, char const *psz_cmd,
                               vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
    VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
    VLC_UNUSED(newval); VLC_UNUSED(p_data);
    aout_instance_t *p_aout = (aout_instance_t *)p_this;
    int i;

    aout_lock_mixer( p_aout );
    for( i = 0; i < p_aout->i_nb_inputs; i++ )
        ReplayGainSelect( p_aout, p_aout->pp_inputs[i] );

    /* Restart the mixer (a trivial mixer may be in use) */
    if( p_aout->p_mixer )
        aout_MixerMultiplierSet( p_aout, p_aout->mixer_multiplier );
    aout_unlock_mixer( p_aout );

    return VLC_SUCCESS;
}
Example #5
0
/*****************************************************************************
 * aout_VolumeInfos : get the boundary pi_soft
 *****************************************************************************/
int __aout_VolumeInfos( vlc_object_t * p_object, audio_volume_t * pi_soft )
{
    aout_instance_t * p_aout = vlc_object_find( p_object, VLC_OBJECT_AOUT,
                               FIND_ANYWHERE );
    int i_result;

    if ( p_aout == NULL ) return 0;

    aout_lock_mixer( p_aout );
    if ( p_aout->mixer.b_error )
    {
        /* The output module is destroyed. */
        i_result = -1;
    }
    else
    {
        i_result = p_aout->output.pf_volume_infos( p_aout, pi_soft );
    }
    aout_unlock_mixer( p_aout );

    vlc_object_release( p_aout );
    return i_result;
}
Example #6
0
/*****************************************************************************
 * aout_VolumeSet : set the volume of the output device
 *****************************************************************************/
int __aout_VolumeSet( vlc_object_t * p_object, audio_volume_t i_volume )
{
    vlc_value_t val;
    aout_instance_t *p_aout = vlc_object_find( p_object, VLC_OBJECT_AOUT, FIND_ANYWHERE );
    int i_result = 0;

    config_PutInt( p_object, "volume", i_volume );

    val.b_bool = true;
    var_Set( p_object->p_libvlc, "volume-change", val );

    if ( p_aout == NULL ) return 0;

    aout_lock_mixer( p_aout );
    if ( !p_aout->mixer.b_error )
    {
        i_result = p_aout->output.pf_volume_set( p_aout, i_volume );
    }
    aout_unlock_mixer( p_aout );

    var_Set( p_aout, "intf-change", val );
    vlc_object_release( p_aout );
    return i_result;
}
Example #7
0
/*****************************************************************************
 * aout_Restart : re-open the output device and rebuild the input and output
 *                pipelines
 *****************************************************************************
 * This function is used whenever the parameters of the output plug-in are
 * changed (eg. selecting S/PDIF or PCM).
 *****************************************************************************/
static int aout_Restart( aout_instance_t * p_aout )
{
    int i;
    bool b_error = 0;

    aout_lock_mixer( p_aout );

    if ( p_aout->i_nb_inputs == 0 )
    {
        aout_unlock_mixer( p_aout );
        msg_Err( p_aout, "no decoder thread" );
        return -1;
    }

    /* Lock all inputs. */
    aout_lock_input_fifos( p_aout );

    for ( i = 0; i < p_aout->i_nb_inputs; i++ )
    {
        aout_lock_input( p_aout, p_aout->pp_inputs[i] );
        aout_InputDelete( p_aout, p_aout->pp_inputs[i] );
    }

    aout_MixerDelete( p_aout );

    /* Re-open the output plug-in. */
    aout_OutputDelete( p_aout );

    if ( aout_OutputNew( p_aout, &p_aout->pp_inputs[0]->input ) == -1 )
    {
        /* Release all locks and report the error. */
        for ( i = 0; i < p_aout->i_nb_inputs; i++ )
        {
            vlc_mutex_unlock( &p_aout->pp_inputs[i]->lock );
        }
        aout_unlock_input_fifos( p_aout );
        aout_unlock_mixer( p_aout );
        return -1;
    }

    if ( aout_MixerNew( p_aout ) == -1 )
    {
        aout_OutputDelete( p_aout );
        for ( i = 0; i < p_aout->i_nb_inputs; i++ )
        {
            vlc_mutex_unlock( &p_aout->pp_inputs[i]->lock );
        }
        aout_unlock_input_fifos( p_aout );
        aout_unlock_mixer( p_aout );
        return -1;
    }

    /* Re-open all inputs. */
    for ( i = 0; i < p_aout->i_nb_inputs; i++ )
    {
        aout_input_t * p_input = p_aout->pp_inputs[i];
        b_error |= aout_InputNew( p_aout, p_input );
        p_input->b_changed = 1;
        aout_unlock_input( p_aout, p_input );
    }

    aout_unlock_input_fifos( p_aout );
    aout_unlock_mixer( p_aout );

    return b_error;
}
Example #8
0
File: intf.c Project: paa/vlc
/*****************************************************************************
 * doVolumeChanges : handle all volume changes. Internal use only to ease
 *                   variables locking.
 *****************************************************************************/
static
int doVolumeChanges( unsigned action, vlc_object_t * p_object, int i_nb_steps,
                audio_volume_t i_volume, audio_volume_t * i_return_volume,
                bool b_mute )
{
    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 )
    {
        if ( p_aout )
        {
            aout_unlock_volume( p_aout );
            vlc_object_release( p_aout );
        }
        return i_result;
    }

    /* On UnMute */
    if ( b_unmute_condition )
    {
        /* Restore saved volume */
        i_volume = var_GetInteger( p_object, "saved-volume" );
        var_SetBool( p_object, "volume-muted", false );
    }
    else if ( b_mute_condition )
    {
        /* We need an initial value to backup later */
        i_volume = config_GetInt( p_object, "volume" );
    }

    if ( action == INCREMENT_VOLUME )
    {
        i_volume_step = var_InheritInteger( p_object, "volume-step" );

        if ( !b_unmute_condition )
            i_volume = config_GetInt( p_object, "volume" );

        i_new_volume = (int) i_volume + i_volume_step * i_nb_steps;

        if ( i_new_volume > AOUT_VOLUME_MAX )
            i_volume = AOUT_VOLUME_MAX;
        else if ( i_new_volume < AOUT_VOLUME_MIN )
            i_volume = AOUT_VOLUME_MIN;
        else
            i_volume = i_new_volume;
    }

    var_SetInteger( p_object, "saved-volume" , i_volume );

    /* On Mute */
    if ( b_mute_condition )
    {
        i_volume = AOUT_VOLUME_MIN;
        var_SetBool( p_object, "volume-muted", true );
    }

    /* Commit volume changes */
    config_PutInt( p_object, "volume", i_volume );

    if ( p_aout )
    {
        aout_lock_mixer( p_aout );
        aout_lock_input_fifos( p_aout );
            if ( p_aout->p_mixer )
                i_result = p_aout->output.pf_volume_set( p_aout, i_volume );
        aout_unlock_input_fifos( p_aout );
        aout_unlock_mixer( p_aout );
    }

    /* trigger callbacks */
    var_TriggerCallback( p_object, "volume-change" );
    if ( p_aout )
    {
        var_SetBool( p_aout, "intf-change", true );
        aout_unlock_volume( p_aout );
        vlc_object_release( p_aout );
    }

    if ( i_return_volume != NULL )
         *i_return_volume = i_volume;
    return i_result;
}