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 )
return src ;
}
void AlsaLayer::setPlaybackVolume( double volume UNUSED){}
......@@ -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.
......
......@@ -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
......
......@@ -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 ){
......
......@@ -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 );
}
......@@ -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_
......
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment