From f055f01f00d6a5744e67fc6b240f1641779033c0 Mon Sep 17 00:00:00 2001 From: Christophe Massiot Date: Sun, 9 Feb 2003 01:13:43 +0000 Subject: [PATCH] * aout_Volume* functions now do their own vlc_object_find() on the audio output. Consequently, the first argument can be any vlc_object_t. * modules/gui/macosx/*: greatly simplified volume functions ; you can now call aout_Volume* even when there is no audio output, and the volume will be saved for later use. --- include/aout_internal.h | 4 +- include/audio_output.h | 20 ++-- modules/control/rc/rc.c | 19 +--- modules/gui/macosx/controls.m | 101 +++-------------- modules/gui/macosx/intf.m | 28 ++--- src/audio_output/intf.c | 197 +++++++++++++--------------------- src/libvlc.h | 13 ++- 7 files changed, 128 insertions(+), 254 deletions(-) diff --git a/include/aout_internal.h b/include/aout_internal.h index 2978bd1a91..d05d338070 100644 --- a/include/aout_internal.h +++ b/include/aout_internal.h @@ -2,7 +2,7 @@ * aout_internal.h : internal defines for audio output ***************************************************************************** * Copyright (C) 2002 VideoLAN - * $Id: aout_internal.h,v 1.37 2003/01/23 17:13:28 massiot Exp $ + * $Id: aout_internal.h,v 1.38 2003/02/09 01:13:43 massiot Exp $ * * Authors: Christophe Massiot * @@ -200,8 +200,6 @@ typedef struct aout_output_t /* Current volume for the output - it's just a placeholder, the plug-in * may or may not use it. */ audio_volume_t i_volume; - /* Saved volume for aout_VolumeMute(). */ - audio_volume_t i_saved_volume; /* If b_error == 1, there is no audio output pipeline. */ vlc_bool_t b_error; diff --git a/include/audio_output.h b/include/audio_output.h index dd04ea57b2..95534c702d 100644 --- a/include/audio_output.h +++ b/include/audio_output.h @@ -2,7 +2,7 @@ * audio_output.h : audio output interface ***************************************************************************** * Copyright (C) 2002 VideoLAN - * $Id: audio_output.h,v 1.77 2003/02/06 15:14:41 massiot Exp $ + * $Id: audio_output.h,v 1.78 2003/02/09 01:13:43 massiot Exp $ * * Authors: Christophe Massiot * @@ -175,12 +175,18 @@ VLC_EXPORT( void, aout_DecDeleteBuffer, ( aout_instance_t *, aout_input_t *, aou VLC_EXPORT( int, aout_DecPlay, ( aout_instance_t *, aout_input_t *, aout_buffer_t * ) ); /* From intf.c : */ -VLC_EXPORT( int, aout_VolumeGet, ( aout_instance_t *, audio_volume_t * ) ); -VLC_EXPORT( int, aout_VolumeSet, ( aout_instance_t *, audio_volume_t ) ); -VLC_EXPORT( int, aout_VolumeInfos, ( aout_instance_t *, audio_volume_t * ) ); -VLC_EXPORT( int, aout_VolumeUp, ( aout_instance_t *, int, audio_volume_t * ) ); -VLC_EXPORT( int, aout_VolumeDown, ( aout_instance_t *, int, audio_volume_t * ) ); -VLC_EXPORT( int, aout_VolumeMute, ( aout_instance_t *, audio_volume_t * ) ); +#define aout_VolumeGet(a, b) __aout_VolumeGet(VLC_OBJECT(a), b) +VLC_EXPORT( int, __aout_VolumeGet, ( vlc_object_t *, audio_volume_t * ) ); +#define aout_VolumeSet(a, b) __aout_VolumeSet(VLC_OBJECT(a), b) +VLC_EXPORT( int, __aout_VolumeSet, ( vlc_object_t *, audio_volume_t ) ); +#define aout_VolumeInfos(a, b) __aout_VolumeInfos(VLC_OBJECT(a), b) +VLC_EXPORT( int, __aout_VolumeInfos, ( vlc_object_t *, audio_volume_t * ) ); +#define aout_VolumeUp(a, b, c) __aout_VolumeUp(VLC_OBJECT(a), b, c) +VLC_EXPORT( int, __aout_VolumeUp, ( vlc_object_t *, int, audio_volume_t * ) ); +#define aout_VolumeDown(a, b, c) __aout_VolumeDown(VLC_OBJECT(a), b, c) +VLC_EXPORT( int, __aout_VolumeDown, ( vlc_object_t *, int, audio_volume_t * ) ); +#define aout_VolumeMute(a, b) __aout_VolumeMute(VLC_OBJECT(a), b) +VLC_EXPORT( int, __aout_VolumeMute, ( vlc_object_t *, audio_volume_t * ) ); VLC_EXPORT( int, aout_Restart, ( aout_instance_t * p_aout ) ); VLC_EXPORT( void, aout_FindAndRestart, ( vlc_object_t * p_this ) ); VLC_EXPORT( int, aout_ChannelsRestart, ( vlc_object_t *, const char *, vlc_value_t, vlc_value_t, void * ) ); diff --git a/modules/control/rc/rc.c b/modules/control/rc/rc.c index 1ed405ce65..e49417b06b 100644 --- a/modules/control/rc/rc.c +++ b/modules/control/rc/rc.c @@ -2,7 +2,7 @@ * rc.c : remote control stdin/stdout plugin for vlc ***************************************************************************** * Copyright (C) 2001 VideoLAN - * $Id: rc.c,v 1.24 2003/02/06 23:59:40 sam Exp $ + * $Id: rc.c,v 1.25 2003/02/09 01:13:43 massiot Exp $ * * Authors: Peter Surda * @@ -681,10 +681,7 @@ static int Intf( vlc_object_t *p_this, char const *psz_cmd, static int Volume( vlc_object_t *p_this, char const *psz_cmd, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { - aout_instance_t * p_aout; int i_error; - p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE ); - if ( p_aout == NULL ) return VLC_ENOOBJ; if ( *newval.psz_string ) { @@ -696,13 +693,13 @@ static int Volume( vlc_object_t *p_this, char const *psz_cmd, AOUT_VOLUME_MAX ); i_error = VLC_EBADVAR; } - else i_error = aout_VolumeSet( p_aout, i_volume ); + else i_error = aout_VolumeSet( p_this, i_volume ); } else { /* Get. */ audio_volume_t i_volume; - if ( aout_VolumeGet( p_aout, &i_volume ) < 0 ) + if ( aout_VolumeGet( p_this, &i_volume ) < 0 ) { i_error = VLC_EGENERIC; } @@ -712,7 +709,6 @@ static int Volume( vlc_object_t *p_this, char const *psz_cmd, i_error = VLC_SUCCESS; } } - vlc_object_release( (vlc_object_t *)p_aout ); return i_error; } @@ -720,7 +716,6 @@ static int Volume( vlc_object_t *p_this, char const *psz_cmd, static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { - aout_instance_t * p_aout; audio_volume_t i_volume; int i_nb_steps = atoi(newval.psz_string); int i_error = VLC_SUCCESS; @@ -730,20 +725,16 @@ static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd, i_nb_steps = 1; } - p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE ); - if ( p_aout == NULL ) return VLC_ENOOBJ; - if ( !strcmp(psz_cmd, "volup") ) { - if ( aout_VolumeUp( p_aout, i_nb_steps, &i_volume ) < 0 ) + if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 ) i_error = VLC_EGENERIC; } else { - if ( aout_VolumeDown( p_aout, i_nb_steps, &i_volume ) < 0 ) + if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 ) i_error = VLC_EGENERIC; } - vlc_object_release( (vlc_object_t *)p_aout ); if ( !i_error ) printf( "Volume is %d\n", i_volume ); return i_error; diff --git a/modules/gui/macosx/controls.m b/modules/gui/macosx/controls.m index 1ecc85bb16..6e91dc426e 100644 --- a/modules/gui/macosx/controls.m +++ b/modules/gui/macosx/controls.m @@ -2,7 +2,7 @@ * controls.m: MacOS X interface plugin ***************************************************************************** * Copyright (C) 2002 VideoLAN - * $Id: controls.m,v 1.23 2003/02/08 19:10:21 massiot Exp $ + * $Id: controls.m,v 1.24 2003/02/09 01:13:43 massiot Exp $ * * Authors: Jon Lech Johansen * Christophe Massiot @@ -279,17 +279,11 @@ { intf_thread_t * p_intf = [NSApp getIntf]; - aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT, - FIND_ANYWHERE ); - if( p_aout != NULL ) - { - if( p_intf->p_sys->b_mute ) - { - [self mute: nil]; - } + aout_VolumeUp( p_intf, 1, NULL ); - aout_VolumeUp( p_aout, 1, NULL ); - vlc_object_release( (vlc_object_t *)p_aout ); + if( p_intf->p_sys->b_mute ) + { + [self mute: nil]; } [self updateVolumeSlider]; @@ -299,17 +293,11 @@ { intf_thread_t * p_intf = [NSApp getIntf]; - aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT, - FIND_ANYWHERE ); - if( p_aout != NULL ) - { - if( p_intf->p_sys->b_mute ) - { - [self mute: nil]; - } + aout_VolumeDown( p_intf, 1, NULL ); - aout_VolumeDown( p_aout, 1, NULL ); - vlc_object_release( (vlc_object_t *)p_aout ); + if( p_intf->p_sys->b_mute ) + { + [self mute: nil]; } [self updateVolumeSlider]; @@ -318,19 +306,10 @@ - (IBAction)mute:(id)sender { intf_thread_t * p_intf = [NSApp getIntf]; + audio_volume_t i_volume; - aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT, - FIND_ANYWHERE ); - - if ( p_aout != NULL ) - { - audio_volume_t i_volume; - - aout_VolumeMute( p_aout, &i_volume ); - vlc_object_release( (vlc_object_t *)p_aout ); - - p_intf->p_sys->b_mute = ( i_volume == 0 ); - } + aout_VolumeMute( p_intf, &i_volume ); + p_intf->p_sys->b_mute = ( i_volume == 0 ); [self updateVolumeSlider]; } @@ -338,36 +317,19 @@ - (IBAction)volumeSliderUpdated:(id)sender { intf_thread_t * p_intf = [NSApp getIntf]; + audio_volume_t i_volume = (audio_volume_t)[sender intValue]; - aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT, - FIND_ANYWHERE ); - if( p_aout != NULL ) - { - audio_volume_t i_volume; - - i_volume = (audio_volume_t)[sender intValue]; - - aout_VolumeSet( p_aout, i_volume * AOUT_VOLUME_STEP ); - vlc_object_release( (vlc_object_t *)p_aout ); - } + aout_VolumeSet( p_intf, i_volume * AOUT_VOLUME_STEP ); } - (void)updateVolumeSlider { intf_thread_t * p_intf = [NSApp getIntf]; + audio_volume_t i_volume; - aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT, - FIND_ANYWHERE ); - - if ( p_aout != NULL ) - { - audio_volume_t i_volume; - - aout_VolumeGet( p_aout, &i_volume ); - vlc_object_release( (vlc_object_t *)p_aout ); + aout_VolumeGet( p_intf, &i_volume ); - [o_volumeslider setFloatValue: (float)(i_volume / AOUT_VOLUME_STEP)]; - } + [o_volumeslider setFloatValue: (float)(i_volume / AOUT_VOLUME_STEP)]; } - (IBAction)halfWindow:(id)sender @@ -718,37 +680,8 @@ [o_mi setState: i_state]; } - else if( [[o_mi title] isEqualToString: _NS("Volume Up")] || - [[o_mi title] isEqualToString: _NS("Volume Down")] ) - { - aout_instance_t * p_aout; - - p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT, - FIND_ANYWHERE ); - if( p_aout != NULL ) - { - vlc_object_release( (vlc_object_t *)p_aout ); - } - else - { - bEnabled = FALSE; - } - } else if( [[o_mi title] isEqualToString: _NS("Mute")] ) { - aout_instance_t * p_aout; - - p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT, - FIND_ANYWHERE ); - if( p_aout != NULL ) - { - vlc_object_release( (vlc_object_t *)p_aout ); - } - else - { - bEnabled = FALSE; - } - [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState]; } else if( [[o_mi title] isEqualToString: _NS("Fullscreen")] || diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m index 49f50a50be..380d9b4bb7 100644 --- a/modules/gui/macosx/intf.m +++ b/modules/gui/macosx/intf.m @@ -2,7 +2,7 @@ * intf.m: MacOS X interface plugin ***************************************************************************** * Copyright (C) 2002-2003 VideoLAN - * $Id: intf.m,v 1.50 2003/02/08 20:32:44 massiot Exp $ + * $Id: intf.m,v 1.51 2003/02/09 01:13:43 massiot Exp $ * * Authors: Jon Lech Johansen * Christophe Massiot @@ -459,6 +459,8 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg ) if( !p_input->b_die ) { + audio_volume_t i_volume; + /* New input or stream map change */ if( p_input->stream.b_changed ) { @@ -479,7 +481,6 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg ) if( p_aout != NULL ) { vlc_value_t val; - audio_volume_t i_volume; if( var_Get( (vlc_object_t *)p_aout, "intf-change", &val ) >= 0 && val.b_bool ) @@ -487,12 +488,10 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg ) p_intf->p_sys->b_aout_update = 1; b_need_menus = VLC_TRUE; } - - aout_VolumeGet( p_aout, &i_volume ); vlc_object_release( (vlc_object_t *)p_aout ); - - p_intf->p_sys->b_mute = ( i_volume == 0 ); } + aout_VolumeGet( p_intf, &i_volume ); + p_intf->p_sys->b_mute = ( i_volume == 0 ); p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE ); @@ -834,25 +833,12 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg ) - (void)manageVolumeSlider { audio_volume_t i_volume; - vlc_bool_t b_audio = VLC_FALSE; intf_thread_t * p_intf = [NSApp getIntf]; - aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT, - FIND_ANYWHERE ); - if( p_aout != NULL ) - { - b_audio = VLC_TRUE; - - aout_VolumeGet( p_aout, &i_volume ); - vlc_object_release( (vlc_object_t *)p_aout ); - } - else - { - i_volume = (audio_volume_t)config_GetInt( p_intf, "volume" ); - } + aout_VolumeGet( p_intf, &i_volume ); [o_volumeslider setFloatValue: (float)i_volume / AOUT_VOLUME_STEP]; - [o_volumeslider setEnabled: b_audio]; + [o_volumeslider setEnabled: 1]; p_intf->p_sys->b_mute = ( i_volume == 0 ); } diff --git a/src/audio_output/intf.c b/src/audio_output/intf.c index 1c6bf14308..5ec9a2c8d3 100644 --- a/src/audio_output/intf.c +++ b/src/audio_output/intf.c @@ -2,7 +2,7 @@ * intf.c : audio output API towards the interface modules ***************************************************************************** * Copyright (C) 2002 VideoLAN - * $Id: intf.c,v 1.15 2003/01/21 10:29:12 massiot Exp $ + * $Id: intf.c,v 1.16 2003/02/09 01:13:43 massiot Exp $ * * Authors: Christophe Massiot * @@ -59,71 +59,64 @@ /***************************************************************************** * aout_VolumeGet : get the volume of the output device *****************************************************************************/ -int aout_VolumeGet( aout_instance_t * p_aout, audio_volume_t * pi_volume ) +int __aout_VolumeGet( vlc_object_t * p_object, audio_volume_t * pi_volume ) { - int i_result; - - vlc_mutex_lock( &p_aout->mixer_lock ); - - if ( p_aout->mixer.b_error ) - { - int i; - /* The output module is destroyed. */ - vlc_mutex_unlock( &p_aout->mixer_lock ); - i = config_GetInt( p_aout, "volume" ); - if (pi_volume != NULL ) *pi_volume = (audio_volume_t)i; - return 0; - } + int i; - i_result = p_aout->output.pf_volume_get( p_aout, pi_volume ); + i = config_GetInt( p_object, "volume" ); + if ( pi_volume != NULL ) *pi_volume = (audio_volume_t)i; - vlc_mutex_unlock( &p_aout->mixer_lock ); - return i_result; + return 0; } /***************************************************************************** * aout_VolumeSet : set the volume of the output device *****************************************************************************/ -int aout_VolumeSet( aout_instance_t * p_aout, audio_volume_t i_volume ) +int __aout_VolumeSet( vlc_object_t * p_object, audio_volume_t i_volume ) { - int i_result; + aout_instance_t * p_aout = vlc_object_find( p_object, VLC_OBJECT_AOUT, + FIND_ANYWHERE ); + int i_result = 0; - vlc_mutex_lock( &p_aout->mixer_lock ); + config_PutInt( p_object, "volume", i_volume ); - if ( p_aout->mixer.b_error ) + if ( p_aout == NULL ) return 0; + + vlc_mutex_lock( &p_aout->mixer_lock ); + if ( !p_aout->mixer.b_error ) { - /* The output module is destroyed. */ - vlc_mutex_unlock( &p_aout->mixer_lock ); - config_PutInt( p_aout, "volume", i_volume ); - return 0; + i_result = p_aout->output.pf_volume_set( p_aout, i_volume ); } - - i_result = p_aout->output.pf_volume_set( p_aout, i_volume ); - vlc_mutex_unlock( &p_aout->mixer_lock ); + + vlc_object_release( p_aout ); return i_result; } /***************************************************************************** * aout_VolumeInfos : get the boundary pi_soft *****************************************************************************/ -int aout_VolumeInfos( aout_instance_t * p_aout, audio_volume_t * 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; - vlc_mutex_lock( &p_aout->mixer_lock ); + if ( p_aout == NULL ) return 0; + vlc_mutex_lock( &p_aout->mixer_lock ); if ( p_aout->mixer.b_error ) { /* The output module is destroyed. */ - vlc_mutex_unlock( &p_aout->mixer_lock ); - msg_Err( p_aout, "VolumeInfos called without output module" ); - return -1; + i_result = -1; + } + else + { + i_result = p_aout->output.pf_volume_infos( p_aout, pi_soft ); } - - i_result = p_aout->output.pf_volume_infos( p_aout, pi_soft ); - vlc_mutex_unlock( &p_aout->mixer_lock ); + + vlc_object_release( p_aout ); return i_result; } @@ -133,44 +126,32 @@ int aout_VolumeInfos( aout_instance_t * p_aout, audio_volume_t * pi_soft ) * If pi_volume != NULL, *pi_volume will contain the volume at the end of the * function. *****************************************************************************/ -int aout_VolumeUp( aout_instance_t * p_aout, int i_nb_steps, +int __aout_VolumeUp( vlc_object_t * p_object, int i_nb_steps, audio_volume_t * pi_volume ) { - int i_result; - audio_volume_t i_volume; - - vlc_mutex_lock( &p_aout->mixer_lock ); + aout_instance_t * p_aout = vlc_object_find( p_object, VLC_OBJECT_AOUT, + FIND_ANYWHERE ); + int i_result = 0, i; - if ( p_aout->mixer.b_error ) + i = config_GetInt( p_object, "volume" ); + i += AOUT_VOLUME_STEP * i_nb_steps; + if ( i > AOUT_VOLUME_MAX ) { - int i; - /* The output module is destroyed. */ - vlc_mutex_unlock( &p_aout->mixer_lock ); - i = config_GetInt( p_aout, "volume" ); - i += AOUT_VOLUME_STEP * i_nb_steps; - if ( i > AOUT_VOLUME_MAX ) - { - i = AOUT_VOLUME_MAX; - } - config_PutInt( p_aout, "volume", i ); - if ( pi_volume != NULL ) *pi_volume = (audio_volume_t)i; - return 0; + i = AOUT_VOLUME_MAX; } + config_PutInt( p_object, "volume", i ); + if ( pi_volume != NULL ) *pi_volume = (audio_volume_t)i; + + if ( p_aout == NULL ) return 0; - if ( p_aout->output.pf_volume_get( p_aout, &i_volume ) ) + vlc_mutex_lock( &p_aout->mixer_lock ); + if ( !p_aout->mixer.b_error ) { - vlc_mutex_unlock( &p_aout->mixer_lock ); - return -1; + i_result = p_aout->output.pf_volume_set( p_aout, (audio_volume_t)i ); } - - i_volume += AOUT_VOLUME_STEP * i_nb_steps; - if ( i_volume > AOUT_VOLUME_MAX ) i_volume = AOUT_VOLUME_MAX; - - i_result = p_aout->output.pf_volume_set( p_aout, i_volume ); - vlc_mutex_unlock( &p_aout->mixer_lock ); - if ( pi_volume != NULL ) *pi_volume = i_volume; + vlc_object_release( p_aout ); return i_result; } @@ -180,46 +161,32 @@ int aout_VolumeUp( aout_instance_t * p_aout, int i_nb_steps, * If pi_volume != NULL, *pi_volume will contain the volume at the end of the * function. *****************************************************************************/ -int aout_VolumeDown( aout_instance_t * p_aout, int i_nb_steps, +int __aout_VolumeDown( vlc_object_t * p_object, int i_nb_steps, audio_volume_t * pi_volume ) { - int i_result; - audio_volume_t i_volume; - - vlc_mutex_lock( &p_aout->mixer_lock ); + aout_instance_t * p_aout = vlc_object_find( p_object, VLC_OBJECT_AOUT, + FIND_ANYWHERE ); + int i_result = 0, i; - if ( p_aout->mixer.b_error ) + i = config_GetInt( p_object, "volume" ); + i -= AOUT_VOLUME_STEP * i_nb_steps; + if ( i < AOUT_VOLUME_MIN ) { - int i; - /* The output module is destroyed. */ - vlc_mutex_unlock( &p_aout->mixer_lock ); - i = config_GetInt( p_aout, "volume" ); - i -= AOUT_VOLUME_STEP * i_nb_steps; - if ( i < 0 ) - { - i = AOUT_VOLUME_MAX; - } - config_PutInt( p_aout, "volume", i ); - if ( pi_volume != NULL ) *pi_volume = (audio_volume_t)i; - return 0; + i = AOUT_VOLUME_MIN; } + config_PutInt( p_object, "volume", i ); + if ( pi_volume != NULL ) *pi_volume = (audio_volume_t)i; + + if ( p_aout == NULL ) return 0; - if ( p_aout->output.pf_volume_get( p_aout, &i_volume ) ) + vlc_mutex_lock( &p_aout->mixer_lock ); + if ( !p_aout->mixer.b_error ) { - vlc_mutex_unlock( &p_aout->mixer_lock ); - return -1; + i_result = p_aout->output.pf_volume_set( p_aout, (audio_volume_t)i ); } - - if ( i_volume < AOUT_VOLUME_STEP * i_nb_steps ) - i_volume = 0; - else - i_volume -= AOUT_VOLUME_STEP * i_nb_steps; - - i_result = p_aout->output.pf_volume_set( p_aout, i_volume ); - vlc_mutex_unlock( &p_aout->mixer_lock ); - if ( pi_volume != NULL ) *pi_volume = i_volume; + vlc_object_release( p_aout ); return i_result; } @@ -229,43 +196,27 @@ int aout_VolumeDown( aout_instance_t * p_aout, int i_nb_steps, * If pi_volume != NULL, *pi_volume will contain the volume at the end of the * function (muted => 0). *****************************************************************************/ -int aout_VolumeMute( aout_instance_t * p_aout, audio_volume_t * pi_volume ) +int __aout_VolumeMute( vlc_object_t * p_object, audio_volume_t * pi_volume ) { int i_result; audio_volume_t i_volume; - vlc_mutex_lock( &p_aout->mixer_lock ); - - if ( p_aout->mixer.b_error ) - { - /* The output module is destroyed. */ - vlc_mutex_unlock( &p_aout->mixer_lock ); - config_PutInt( p_aout, "volume", 0 ); - if ( pi_volume != NULL ) *pi_volume = 0; - return 0; - } - - if ( p_aout->output.pf_volume_get( p_aout, &i_volume ) ) + i_volume = (audio_volume_t)config_GetInt( p_object, "volume" ); + if ( i_volume != 0 ) { - vlc_mutex_unlock( &p_aout->mixer_lock ); - return -1; - } - - if ( i_volume == 0 ) - { - i_volume = p_aout->output.i_saved_volume; + /* Mute */ + i_result = aout_VolumeSet( p_object, AOUT_VOLUME_MIN ); + config_PutInt( p_object, "saved-volume", (int)i_volume ); + if ( pi_volume != NULL ) *pi_volume = AOUT_VOLUME_MIN; } else { - p_aout->output.i_saved_volume = i_volume; - i_volume = 0; + /* Un-mute */ + i_volume = (audio_volume_t)config_GetInt( p_object, "saved-volume" ); + i_result = aout_VolumeSet( p_object, i_volume ); + if ( pi_volume != NULL ) *pi_volume = i_volume; } - i_result = p_aout->output.pf_volume_set( p_aout, i_volume ); - - vlc_mutex_unlock( &p_aout->mixer_lock ); - - if ( pi_volume != NULL ) *pi_volume = i_volume; return i_result; } @@ -284,7 +235,7 @@ void aout_VolumeSoftInit( aout_instance_t * p_aout ) p_aout->output.pf_volume_set = aout_VolumeSoftSet; i_volume = config_GetInt( p_aout, "volume" ); - if ( i_volume < 0 ) + if ( i_volume < AOUT_VOLUME_MIN ) { i_volume = AOUT_VOLUME_DEFAULT; } diff --git a/src/libvlc.h b/src/libvlc.h index 375d4bfaf3..2bf3552b44 100644 --- a/src/libvlc.h +++ b/src/libvlc.h @@ -2,7 +2,7 @@ * libvlc.h: main libvlc header ***************************************************************************** * Copyright (C) 1998-2002 VideoLAN - * $Id: libvlc.h,v 1.41 2003/02/08 19:10:22 massiot Exp $ + * $Id: libvlc.h,v 1.42 2003/02/09 01:13:43 massiot Exp $ * * Authors: Vincent Seguin * Samuel Hocevar @@ -89,6 +89,10 @@ static char *ppsz_sout_vcodec[] = { "", "mpeg1", "mpeg2", "mpeg4", NULL }; "You can set the default audio output volume here, in a range from 0 to " \ "1024.") +#define VOLUME_SAVE_TEXT N_("audio output saved volume") +#define VOLUME_SAVE_LONGTEXT N_( \ + "This saves the audio output volume when you select mute.") + #define AOUT_RATE_TEXT N_("audio output frequency (Hz)") #define AOUT_RATE_LONGTEXT N_( \ "You can force the audio output frequency here. Common values are " \ @@ -438,7 +442,12 @@ vlc_module_begin(); add_module_with_short( "aout", 'A', "audio output", NULL, NULL, AOUT_TEXT, AOUT_LONGTEXT ); add_bool( "audio", 1, NULL, AUDIO_TEXT, AUDIO_LONGTEXT ); - add_integer_with_range( "volume", 256, 0, 1024, NULL, VOLUME_TEXT, VOLUME_LONGTEXT ); + add_integer_with_range( "volume", AOUT_VOLUME_DEFAULT, AOUT_VOLUME_MIN, + AOUT_VOLUME_MAX, NULL, VOLUME_TEXT, + VOLUME_LONGTEXT ); + add_integer_with_range( "saved-volume", AOUT_VOLUME_DEFAULT, + AOUT_VOLUME_MIN, AOUT_VOLUME_MAX, NULL, + VOLUME_SAVE_TEXT, VOLUME_SAVE_LONGTEXT ); add_integer( "aout-rate", -1, NULL, AOUT_RATE_TEXT, AOUT_RATE_LONGTEXT ); add_integer( "desync", 0, NULL, DESYNC_TEXT, DESYNC_LONGTEXT ); add_bool( "headphone", 0, NULL, HEADPHONE_TEXT, HEADPHONE_LONGTEXT ); -- 2.39.2