Skip to content
Snippets Groups Projects
Commit 2fa53a3d authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

Plug the sflphone playback volume control to the pulseaudio volume manager

No support for modifyng the volume of source outputs in pa
parent 2b49a15c
No related branches found
No related tags found
No related merge requests found
...@@ -770,4 +770,3 @@ AlsaLayer::adjustVolume( void* buffer , int len, int stream ) ...@@ -770,4 +770,3 @@ AlsaLayer::adjustVolume( void* buffer , int len, int stream )
return src ; return src ;
} }
void AlsaLayer::setPlaybackVolume( double volume UNUSED){}
...@@ -204,7 +204,8 @@ class AlsaLayer : public AudioLayer { ...@@ -204,7 +204,8 @@ class AlsaLayer : public AudioLayer {
/** /**
* UNUSED in ALSA layer * UNUSED in ALSA layer
*/ */
void setPlaybackVolume( double volume ); void setPlaybackVolume( UNUSED int volume ){}
void setCaptureVolume( UNUSED int volume ){}
/** /**
* Callback used for asynchronous playback. * Callback used for asynchronous playback.
......
...@@ -197,7 +197,8 @@ class AudioLayer { ...@@ -197,7 +197,8 @@ class AudioLayer {
virtual void reducePulseAppsVolume( void ) = 0; virtual void reducePulseAppsVolume( void ) = 0;
virtual void restorePulseAppsVolume( 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 * Write accessor to the error state
......
...@@ -28,7 +28,7 @@ AudioStream::AudioStream( pa_context* context, int type, std::string desc, doubl ...@@ -28,7 +28,7 @@ AudioStream::AudioStream( pa_context* context, int type, std::string desc, doubl
sample_spec.rate = 44100; sample_spec.rate = 44100;
sample_spec.channels = 1; sample_spec.channels = 1;
channel_map.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 ); _audiostream = createStream( context );
} }
...@@ -93,7 +93,6 @@ AudioStream::createStream( pa_context* c ) ...@@ -93,7 +93,6 @@ AudioStream::createStream( pa_context* c )
pa_stream_connect_playback( s , NULL , attributes, pa_stream_connect_playback( s , NULL , attributes,
PA_STREAM_INTERPOLATE_TIMING, PA_STREAM_INTERPOLATE_TIMING,
&_volume, NULL); &_volume, NULL);
//pa_cvolume_set(&cv, sample_spec.channels , PA_VOLUME_NORM) , NULL );
} }
else if( _streamType == CAPTURE_STREAM ){ else if( _streamType == CAPTURE_STREAM ){
......
...@@ -384,46 +384,71 @@ static void retrieve_client_list(pa_context *c, const pa_client_info *i, int eol ...@@ -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; PulseLayer* pulse = (PulseLayer*) userdata;
AudioStream* s = pulse->getPlaybackStream();
if( !eol ){ if( !eol ){
_debug("Sink Info: index : %i\n" , i->index); //_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\tClient : %i\n" , i->client); //_debug("\t\tVolume : %i\n" , i->volume.values[0]);
_debug("\t\tVolume : %i\n" , i->volume.values[0]); //_debug("\t\tChannels : %i\n" , i->volume.channels);
_debug("\t\tChannels : %i\n" , i->volume.channels);
if( strcmp( i->name , PLAYBACK_STREAM_NAME ) != 0) 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; PulseLayer* pulse = (PulseLayer*) userdata;
//AudioStream* s = pulse->getPlaybackStream();
if( !eol ){ if( !eol ){
_debug("Sink Info: index : %i\n" , i->index); //_debug("Sink Info: index : %i\n" , i->index);
_debug("\t\tSink name : -%s-\n" , i->name); //_debug("\t\tSink name : -%s-\n" , i->name);
_debug("\t\tClient : %i\n" , i->client); //_debug("\t\tClient : %i\n" , i->client);
_debug("\t\tVolume : %i\n" , i->volume.values[0]); //_debug("\t\tVolume : %i\n" , i->volume.values[0]);
_debug("\t\tChannels : %i\n" , i->volume.channels); //_debug("\t\tChannels : %i\n" , i->volume.channels);
if( strcmp( i->name , PLAYBACK_STREAM_NAME ) != 0) 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 void
PulseLayer::reducePulseAppsVolume( 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 void
PulseLayer::restorePulseAppsVolume( 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 void
...@@ -432,41 +457,41 @@ PulseLayer::serverinfo( void ) ...@@ -432,41 +457,41 @@ PulseLayer::serverinfo( void )
pa_context_get_server_info( context , retrieve_server_info , NULL ); 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 void PulseLayer::setSinkVolume( int index, int channels, int volume )
PulseLayer::reduceAppVolume( int index , int channels )
{ {
pa_cvolume volume;
pa_volume_t vol = PA_VOLUME_NORM;
vol /= 10;
pa_cvolume_set( &volume , channels , vol); pa_cvolume cvolume;
_debug("Mute Index %i\n" , index); pa_volume_t vol = PA_VOLUME_NORM * ((double)volume / 100) ;
pa_context_set_sink_input_volume( context, index, &volume, on_success, this) ;
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) ;
} }
void void PulseLayer::setSourceVolume( int index, int channels, int volume )
PulseLayer::restoreAppVolume( int index, int channels )
{ {
pa_cvolume volume;
pa_volume_t vol = PA_VOLUME_NORM;
pa_cvolume_set( &volume , channels , vol); pa_cvolume cvolume;
_debug("Restore Index %i\n" , index); pa_volume_t vol = PA_VOLUME_NORM * ((double)volume / 100) ;
pa_context_set_sink_input_volume( context, index, &volume, on_success, this) ;
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);
} }
void
PulseLayer::setPlaybackVolume( double volume ) void PulseLayer::setPlaybackVolume( int volume )
{ {
//value between 0 and 100 setSpkrVolume( volume );
AudioStream* s = getPlaybackStream(); pa_context_get_sink_input_info_list( context , set_playback_volume_cb , this );
s->setVolume( volume );
} }
void PulseLayer::setCaptureVolume( int volume )
{
setMicVolume( volume );
pa_context_get_source_output_info_list( context , set_capture_volume_cb , this );
}
...@@ -143,18 +143,16 @@ class PulseLayer : public AudioLayer { ...@@ -143,18 +143,16 @@ class PulseLayer : public AudioLayer {
void restorePulseAppsVolume( void ); void restorePulseAppsVolume( void );
/** /**
* Reduce volume of one particular application * Set the volume of a sink.
* @param index The index of the stream * @param index The index of the stream
* @param channels The stream's number of channels * @param channels The stream's number of channels
* @param volume The new volume (between 0 and 100)
*/ */
void reduceAppVolume( int index , int channels ); void setSinkVolume( int index, int channels, int volume );
void setSourceVolume( int index, int channels, int volume );
/** void setPlaybackVolume( int volume );
* Restore to PA_VOLUME_NORM the volume of one particular application void setCaptureVolume( int volume );
* @param index The index of the stream
* @param channels The stream's number of channels
*/
void restoreAppVolume( int index , int channels );
/** /**
* Accessor * Accessor
...@@ -168,11 +166,11 @@ class PulseLayer : public AudioLayer { ...@@ -168,11 +166,11 @@ class PulseLayer : public AudioLayer {
*/ */
AudioStream* getRecordStream(){ return record;} AudioStream* getRecordStream(){ return record;}
/** int getSpkrVolume( void ) { return spkrVolume; }
* Set the speaker volume to a new value ( between 0 and 100 ) void setSpkrVolume( int value ) { spkrVolume = value; }
* @param volume The new value
*/ int getMicVolume( void ) { return micVolume; }
void setPlaybackVolume( double volume ); void setMicVolume( int value ) { micVolume = value; }
private: private:
// Copy Constructor // Copy Constructor
...@@ -181,6 +179,7 @@ class PulseLayer : public AudioLayer { ...@@ -181,6 +179,7 @@ class PulseLayer : public AudioLayer {
// Assignment Operator // Assignment Operator
PulseLayer& operator=( const PulseLayer& rh); PulseLayer& operator=( const PulseLayer& rh);
/** /**
* Drop the pending frames and close the capture device * Drop the pending frames and close the capture device
*/ */
...@@ -252,6 +251,10 @@ class PulseLayer : public AudioLayer { ...@@ -252,6 +251,10 @@ class PulseLayer : public AudioLayer {
* A stream object to handle the pulseaudio upload stream * A stream object to handle the pulseaudio upload stream
*/ */
AudioStream* cache; AudioStream* cache;
int spkrVolume;
int micVolume;
}; };
#endif // _PULSE_LAYER_H_ #endif // _PULSE_LAYER_H_
......
...@@ -1766,6 +1766,32 @@ ManagerImpl::initVolume() ...@@ -1766,6 +1766,32 @@ ManagerImpl::initVolume()
setMicVolume(getConfigInt(AUDIO, VOLUME_MICRO)); 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 * configuration function requests
* Main Thread * Main Thread
......
...@@ -722,7 +722,7 @@ class ManagerImpl { ...@@ -722,7 +722,7 @@ class ManagerImpl {
* Write by main thread only * Write by main thread only
* @param spkr_vol The volume value * @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 * Inline functions to manage mic volume control
...@@ -738,7 +738,7 @@ class ManagerImpl { ...@@ -738,7 +738,7 @@ class ManagerImpl {
* Write by main thread only * Write by main thread only
* @param mic_vol The volume value * @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 // Manage information about firewall
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment