diff --git a/src/audio/alsalayer.cpp b/src/audio/alsalayer.cpp index 9a77daaf59c7a83f37f524f5630e45fda6888c1f..33a14637b4cd39c1b64116fbf3069a7117250020 100644 --- a/src/audio/alsalayer.cpp +++ b/src/audio/alsalayer.cpp @@ -770,4 +770,3 @@ AlsaLayer::adjustVolume( void* buffer , int len, int stream ) return src ; } -void AlsaLayer::setPlaybackVolume( double volume UNUSED){} diff --git a/src/audio/alsalayer.h b/src/audio/alsalayer.h index 8d7aceafe4c2f15287753459d9234d1437c987cd..c9dfa016d2cf8d61d68df15d815d7cc8f13eb088 100644 --- a/src/audio/alsalayer.h +++ b/src/audio/alsalayer.h @@ -204,7 +204,8 @@ class AlsaLayer : public AudioLayer { /** * UNUSED in ALSA layer */ - void setPlaybackVolume( double volume ); + void setPlaybackVolume( UNUSED int volume ){} + void setCaptureVolume( UNUSED int volume ){} /** * Callback used for asynchronous playback. diff --git a/src/audio/audiolayer.h b/src/audio/audiolayer.h index 62883100aa8b27511a1ca387ab7d8ceda0f59a05..658ac3825deaad2d14fec6c31e547d60648d4ed3 100644 --- a/src/audio/audiolayer.h +++ b/src/audio/audiolayer.h @@ -197,7 +197,8 @@ class AudioLayer { virtual void reducePulseAppsVolume( void ) = 0; virtual void restorePulseAppsVolume( void ) = 0; - virtual void setPlaybackVolume( double volume ) = 0; + virtual void setPlaybackVolume( int volume ) = 0; + virtual void setCaptureVolume( int volume ) = 0; /** * Write accessor to the error state diff --git a/src/audio/audiostream.cpp b/src/audio/audiostream.cpp index 8bffb2463a5ad02ba31bd3feeedb6262f1e626cf..254f8ae19e42b18bb7b2ce5ef38ff12063a768c1 100644 --- a/src/audio/audiostream.cpp +++ b/src/audio/audiostream.cpp @@ -28,7 +28,7 @@ AudioStream::AudioStream( pa_context* context, int type, std::string desc, doubl sample_spec.rate = 44100; sample_spec.channels = 1; channel_map.channels = 1; - pa_cvolume_set( &_volume , 1 , PA_VOLUME_NORM ) ; // * vol / 100 ; + pa_cvolume_set( &_volume , 1 , PA_VOLUME_MUTED ) ; // * vol / 100 ; _audiostream = createStream( context ); } @@ -93,7 +93,6 @@ AudioStream::createStream( pa_context* c ) pa_stream_connect_playback( s , NULL , attributes, PA_STREAM_INTERPOLATE_TIMING, &_volume, NULL); - //pa_cvolume_set(&cv, sample_spec.channels , PA_VOLUME_NORM) , NULL ); } else if( _streamType == CAPTURE_STREAM ){ diff --git a/src/audio/pulselayer.cpp b/src/audio/pulselayer.cpp index b4718928360b2a74a1b47a2a3d4cff6c5138be1d..9f7c5a78a6c7d702dd1575c236fff600d477d7dc 100644 --- a/src/audio/pulselayer.cpp +++ b/src/audio/pulselayer.cpp @@ -384,46 +384,71 @@ static void retrieve_client_list(pa_context *c, const pa_client_info *i, int eol } */ -static void reduce_sink_list(pa_context *c UNUSED, const pa_sink_input_info *i, int eol, void *userdata) +static void reduce_sink_list_cb(pa_context *c UNUSED, const pa_sink_input_info *i, int eol, void *userdata) { PulseLayer* pulse = (PulseLayer*) userdata; - AudioStream* s = pulse->getPlaybackStream(); if( !eol ){ - _debug("Sink Info: index : %i\n" , i->index); - _debug("\t\tSink name : -%s-%s-\n" , i->name, s->getStreamName().c_str()); - _debug("\t\tClient : %i\n" , i->client); - _debug("\t\tVolume : %i\n" , i->volume.values[0]); - _debug("\t\tChannels : %i\n" , i->volume.channels); + //_debug("Sink Info: index : %i\n" , i->index); + //_debug("\t\tClient : %i\n" , i->client); + //_debug("\t\tVolume : %i\n" , i->volume.values[0]); + //_debug("\t\tChannels : %i\n" , i->volume.channels); if( strcmp( i->name , PLAYBACK_STREAM_NAME ) != 0) - pulse->reduceAppVolume( i->index , i->volume.channels); + pulse->setSinkVolume( i->index , i->volume.channels, 10 ); } } -static void restore_sink_list(pa_context *c UNUSED, const pa_sink_input_info *i, int eol, void *userdata) +static void restore_sink_list_cb(pa_context *c UNUSED, const pa_sink_input_info *i, int eol, void *userdata) { PulseLayer* pulse = (PulseLayer*) userdata; - //AudioStream* s = pulse->getPlaybackStream(); if( !eol ){ - _debug("Sink Info: index : %i\n" , i->index); - _debug("\t\tSink name : -%s-\n" , i->name); - _debug("\t\tClient : %i\n" , i->client); - _debug("\t\tVolume : %i\n" , i->volume.values[0]); - _debug("\t\tChannels : %i\n" , i->volume.channels); + //_debug("Sink Info: index : %i\n" , i->index); + //_debug("\t\tSink name : -%s-\n" , i->name); + //_debug("\t\tClient : %i\n" , i->client); + //_debug("\t\tVolume : %i\n" , i->volume.values[0]); + //_debug("\t\tChannels : %i\n" , i->volume.channels); if( strcmp( i->name , PLAYBACK_STREAM_NAME ) != 0) - pulse->restoreAppVolume( i->index , i->volume.channels); + pulse->setSinkVolume( i->index , i->volume.channels, 100); } } +static void set_playback_volume_cb(pa_context *c UNUSED, const pa_sink_input_info *i, int eol, void *userdata) +{ + PulseLayer* pulse; + int volume; + + pulse = (PulseLayer*) userdata; + volume = pulse->getSpkrVolume(); + + if( !eol ){ + if( strcmp( i->name , PLAYBACK_STREAM_NAME ) == 0) + pulse->setSinkVolume( i->index , i->volume.channels, volume ); + } +} + +static void set_capture_volume_cb(pa_context *c UNUSED, const pa_source_output_info *i, int eol, void *userdata) +{ + PulseLayer* pulse; + int volume; + + pulse = (PulseLayer*) userdata; + volume = pulse->getMicVolume(); + + if( !eol ){ + if( strcmp( i->name , CAPTURE_STREAM_NAME ) == 0) + pulse->setSourceVolume( i->index , i->channel_map.channels, volume ); + } +} + void PulseLayer::reducePulseAppsVolume( void ) { - pa_context_get_sink_input_info_list( context , reduce_sink_list , this ); + pa_context_get_sink_input_info_list( context , reduce_sink_list_cb , this ); } void PulseLayer::restorePulseAppsVolume( void ) { - pa_context_get_sink_input_info_list( context , restore_sink_list , this ); + pa_context_get_sink_input_info_list( context , restore_sink_list_cb , this ); } void @@ -432,41 +457,41 @@ PulseLayer::serverinfo( void ) pa_context_get_server_info( context , retrieve_server_info , NULL ); } -static void on_success(pa_context *c UNUSED, int success UNUSED, void *userdata UNUSED) -{ - _debug("Operation successfull \n"); -} - void -PulseLayer::reduceAppVolume( int index , int channels ) +void PulseLayer::setSinkVolume( int index, int channels, int volume ) { - pa_cvolume volume; - pa_volume_t vol = PA_VOLUME_NORM; - vol /= 10; + + pa_cvolume cvolume; + pa_volume_t vol = PA_VOLUME_NORM * ((double)volume / 100) ; + + pa_cvolume_set( &cvolume , channels , vol); + _debug("Set sink volume of index %i\n" , index); + pa_context_set_sink_input_volume( context, index, &cvolume, NULL, NULL) ; - pa_cvolume_set( &volume , channels , vol); - _debug("Mute Index %i\n" , index); - pa_context_set_sink_input_volume( context, index, &volume, on_success, this) ; } - void -PulseLayer::restoreAppVolume( int index, int channels ) +void PulseLayer::setSourceVolume( int index, int channels, int volume ) { - pa_cvolume volume; - pa_volume_t vol = PA_VOLUME_NORM; + + pa_cvolume cvolume; + pa_volume_t vol = PA_VOLUME_NORM * ((double)volume / 100) ; + + pa_cvolume_set( &cvolume , channels , vol); + _debug("Set source volume of index %i\n" , index); + pa_context_set_source_volume_by_index(context, index, &cvolume, NULL, NULL); - pa_cvolume_set( &volume , channels , vol); - _debug("Restore Index %i\n" , index); - pa_context_set_sink_input_volume( context, index, &volume, on_success, this) ; } - void -PulseLayer::setPlaybackVolume( double volume ) + +void PulseLayer::setPlaybackVolume( int volume ) { - //value between 0 and 100 - AudioStream* s = getPlaybackStream(); - s->setVolume( volume ); + setSpkrVolume( volume ); + pa_context_get_sink_input_info_list( context , set_playback_volume_cb , this ); } - +void PulseLayer::setCaptureVolume( int volume ) +{ + setMicVolume( volume ); + pa_context_get_source_output_info_list( context , set_capture_volume_cb , this ); +} diff --git a/src/audio/pulselayer.h b/src/audio/pulselayer.h index 24a98478b0ccbc251ca70c4df2d2fb0964d3bdfb..5dcd31a5f91cb71499b8a475a47e3de808a4e3fa 100644 --- a/src/audio/pulselayer.h +++ b/src/audio/pulselayer.h @@ -141,20 +141,18 @@ class PulseLayer : public AudioLayer { * Restore the volume of every audio applications connected to the same sink to PA_VOLUME_NORM */ void restorePulseAppsVolume( void ); - - /** - * Reduce volume of one particular application - * @param index The index of the stream - * @param channels The stream's number of channels - */ - void reduceAppVolume( int index , int channels ); - + /** - * Restore to PA_VOLUME_NORM the volume of one particular application + * Set the volume of a sink. * @param index The index of the stream * @param channels The stream's number of channels + * @param volume The new volume (between 0 and 100) */ - void restoreAppVolume( int index , int channels ); + void setSinkVolume( int index, int channels, int volume ); + void setSourceVolume( int index, int channels, int volume ); + + void setPlaybackVolume( int volume ); + void setCaptureVolume( int volume ); /** * Accessor @@ -168,11 +166,11 @@ class PulseLayer : public AudioLayer { */ AudioStream* getRecordStream(){ return record;} - /** - * Set the speaker volume to a new value ( between 0 and 100 ) - * @param volume The new value - */ - void setPlaybackVolume( double volume ); + int getSpkrVolume( void ) { return spkrVolume; } + void setSpkrVolume( int value ) { spkrVolume = value; } + + int getMicVolume( void ) { return micVolume; } + void setMicVolume( int value ) { micVolume = value; } private: // Copy Constructor @@ -181,6 +179,7 @@ class PulseLayer : public AudioLayer { // Assignment Operator PulseLayer& operator=( const PulseLayer& rh); + /** * Drop the pending frames and close the capture device */ @@ -252,6 +251,10 @@ class PulseLayer : public AudioLayer { * A stream object to handle the pulseaudio upload stream */ AudioStream* cache; + + int spkrVolume; + int micVolume; + }; #endif // _PULSE_LAYER_H_ diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index 746bf3bf9c5947da1e0dbdf1bf8f9b0167ca1ecf..204f3c088875e26cb14ae9933baf4922c159daba 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -1766,6 +1766,32 @@ ManagerImpl::initVolume() setMicVolume(getConfigInt(AUDIO, VOLUME_MICRO)); } + +void ManagerImpl::setSpkrVolume(unsigned short spkr_vol) +{ + AudioLayer *audiolayer = NULL; + + _spkr_volume = spkr_vol; + audiolayer = getAudioDriver(); + if( audiolayer ) + { + audiolayer->setPlaybackVolume( spkr_vol ); + } + +} + +void ManagerImpl::setMicVolume(unsigned short mic_vol) +{ + //AudioLayer *audiolayer = NULL; + + _mic_volume = mic_vol; + //audiolayer = getAudioDriver(); + //if( audiolayer ) + //{ + // audiolayer->setCaptureVolume( mic_vol ); + //} +} + /** * configuration function requests * Main Thread diff --git a/src/managerimpl.h b/src/managerimpl.h index 6f5dac3fb737feaa5f6f0e6d14ecd6ff8fc458ff..1d06bd331fc5f39e3ac2f0220a58921d9cb02cd0 100644 --- a/src/managerimpl.h +++ b/src/managerimpl.h @@ -722,7 +722,7 @@ class ManagerImpl { * Write by main thread only * @param spkr_vol The volume value */ - void setSpkrVolume(unsigned short spkr_vol) { _spkr_volume = spkr_vol; } + void setSpkrVolume(unsigned short spkr_vol); /* * Inline functions to manage mic volume control @@ -738,7 +738,7 @@ class ManagerImpl { * Write by main thread only * @param mic_vol The volume value */ - void setMicVolume(unsigned short mic_vol) { _mic_volume = mic_vol; } + void setMicVolume(unsigned short mic_vol); // Manage information about firewall