Commit cb35f874 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

#5809: Add configuration parameters

parent 9c2b4bc1
......@@ -781,6 +781,23 @@ active_noise_suppress (void)
dbus_set_noise_suppress_state (newstate);
}
void
active_echo_cancel(void)
{
gchar *state;
gchar *newstate;
state = dbus_get_echo_cancel_state();
if(strcmp(state, "enabled") == 0) {
newstate = "disabled";
} else {
newstate = "enabled";
}
dbus_set_echo_cancel_state(newstate);
}
void
active_is_always_recording (void)
{
......@@ -927,7 +944,9 @@ GtkWidget* create_audio_configuration()
// Sub boxes
GtkWidget *frame;
GtkWidget *enableNoiseReduction;
GtkWidget *enableEchoCancel;
gboolean noisesuppressActive;
gboolean echoCancelActive;
gchar *state;
ret = gtk_vbox_new (FALSE, 10);
......@@ -1015,6 +1034,19 @@ GtkWidget* create_audio_configuration()
g_signal_connect (G_OBJECT (enableNoiseReduction), "clicked", active_noise_suppress, NULL);
gtk_table_attach (GTK_TABLE (table), enableNoiseReduction, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
enableEchoCancel = gtk_check_button_new_with_mnemonic(_("_Echo Cancellation"));
// state = dbus_get_echo_cancel_state();
echoCancelActive = FALSE;
if (strcmp(state, "enabled") == 0) {
echoCancelActive = TRUE;
}
else {
echoCancelActive = FALSE;
}
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enableEchoCancel), echoCancelActive);
g_signal_connect(G_OBJECT(enableEchoCancel), "clicked", active_echo_cancel, NULL);
gtk_table_attach(GTK_TABLE(table), enableEchoCancel, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show_all (ret);
if (!pulse_audio) {
......
......@@ -563,7 +563,54 @@
</arg>
</method>
<method name="getNoiseSuppressState" tp:name-for-bindings="getNoiseSuppressState">
<method name="getEchoCancelState" tp:name-for-bindings="getNoiseSuppressState">
<tp:docstring>
</tp:docstring>
<arg type="s" name="state" direction="out">
<tp:docstring>
</tp:docstring>
</arg>
</method>
<method name="setEchoCancelState" tp:name-for-binding="setEchoCancelState">
<arg type="s" name="state" direction="in">
</arg>
</method>
<method name="setEchoCancelTailLength" tp:name-for-binding="setEchoCancelTailLength">
<tp:docstring>
</tp:docstring>
<arg type="i" name="index" direction="in">
<tp:docstring>
</tp:docstring>
</arg>
</method>
<method name="getEchoCancelTailLength" tp:name-for-binding="getEchoCancelTailLength">
<tp:docstring>
</tp:docstring>
<arg type="i" name="index" direction="out">
<tp:docstring>
</tp:docstring>
</arg>
</method>
<method name="setEchoCancelDelay" tp:name-for-binding="setEchoCancelTailLength">
<tp:docstring>
</tp:docstring>
<arg type="i" name="index" direction="in">
</arg>
</method>
<method name="getEchoCancelDelay" tp:name-for-binding="getEchoCancelTailLength">
<tp:docstring>
</tp:docstring>
<arg type="i" name="index" direction="out">
</arg>
</method>
<method name="getNoiseSuppressState" tp:name-for-bindings="getEchoCancelState">
<tp:docstring>
</tp:docstring>
<arg type="s" name="state" direction="out">
......
......@@ -1512,6 +1512,89 @@ dbus_set_noise_suppress_state (gchar* state)
}
}
gchar *
dbus_get_echo_cancel_state(void)
{
GError *error = NULL;
gchar *state = "";
org_sflphone_SFLphone_ConfigurationManager_get_echo_cancel_state(configurationManagerProxy, &state, &error);
if(error) {
ERROR("DBus: Failed to call get_echo_cancel_state() on ConfigurationManager: %s", error->message);
g_error_free(error);
}
return state;
}
void
dbus_set_echo_cancel_state(gchar *state)
{
GError *error = NULL;
org_sflphone_SFLphone_ConfigurationManager_set_echo_cancel_state(configurationManagerProxy, state, &error);
if(error) {
ERROR("DBus: Failed to call set_echo_cancel_state() on ConfigurationManager: %s", error->message);
g_error_free(error);
}
}
int
dbus_get_echo_cancel_tail_length(void)
{
GError *error = NULL;
int length;
org_sflphone_SFLphone_ConfigurationManager_get_echo_cancel_tail_length(configurationManagerProxy, &length, &error);
if(error) {
ERROR("DBus: Failed to call get_echo_cancel_tail_length() on ConfigurationManager: %s", error->message);
g_error_free(error);
}
return length;
}
void
dbus_set_echo_cancel_tail_length(int length)
{
GError *error = NULL;
org_sflphone_SFLphone_ConfigurationManager_set_echo_cancel_tail_length(configurationManagerProxy, length, &error);
if(error) {
ERROR("DBus: Failed to call get_echo_cancel_state() on ConfigurationManager: %s", error->message);
g_error_free(error);
}
}
int
dbus_get_echo_cancel_delay(void)
{
GError *error = NULL;
int delay;
org_sflphone_SFLphone_ConfigurationManager_get_echo_cancel_delay(configurationManagerProxy, &delay, &error);
if(error) {
ERROR("DBus: Failed to call get_echo_cancel_tail_length() on ConfigurationManager: %s", error->message);
g_error_free(error);
}
return delay;
}
void
dbus_set_echo_cancel_delay(int delay)
{
GError *error = NULL;
org_sflphone_SFLphone_ConfigurationManager_set_echo_cancel_delay(configurationManagerProxy, delay, &error);
if(error) {
ERROR("DBus: Failed to call get_echo_cancel_delay() on ConfigurationManager: %s", error->message);
g_error_free(error);
}
}
gchar*
dbus_get_ringtone_choice (const gchar *accountID)
......
......@@ -335,6 +335,25 @@ gchar *dbus_get_noise_suppress_state (void);
*/
void dbus_set_noise_suppress_state (gchar *state);
/**
* ConfigurationManager - Get the current echo cancel state
* @return gchar* The state (enabled/disabled)
*/
gchar *dbus_get_echo_cancel_state(void);
/**
* ConfigurationManager - Set the current echo cancel state
* @param gchar* The state (enabled/disabled)
*/
void dbus_set_echo_cancel_state(gchar *state);
int dbus_get_echo_cancel_tail_length(void);
void dbus_set_echo_cancel_tail_length(int length);
int dbus_get_echo_cancel_delay(void);
void dbus_set_echo_cancel_delay(int delay);
/**
* ConfigurationManager - Query to server to
......
......@@ -185,7 +185,6 @@ void AudioRtpRecordHandler::initBuffers()
_audioRtpRecord._converter = new SamplerateConverter ();
int nbSamplesMax = (int) ( (getCodecSampleRate() * getCodecFrameSize() / 1000));
_debug("============================================================= getCodecFrameSize() %d", getCodecFrameSize());
_audioRtpRecord._micData = new SFLDataFormat[nbSamplesMax];
_audioRtpRecord._micDataConverted = new SFLDataFormat[nbSamplesMax];
_audioRtpRecord._micDataEchoCancelled = new SFLDataFormat[nbSamplesMax];
......@@ -251,8 +250,6 @@ ofstream teststream("test_process_data_encode.raw");
int AudioRtpRecordHandler::processDataEncode (void)
{
_debug("AudioRtp: Process data encode");
SFLDataFormat *micData = _audioRtpRecord._micData;
unsigned char *micDataEncoded = _audioRtpRecord._micDataEncoded;
SFLDataFormat *micDataEchoCancelled = _audioRtpRecord._micDataEchoCancelled;
......@@ -317,8 +314,6 @@ int AudioRtpRecordHandler::processDataEncode (void)
_audioRtpRecord.audioProcessMutex.enter();
_debug("------------------------------------------------------ process encode!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
echoCanceller.process(micData, micDataEchoCancelled, nbSample * sizeof(SFLDataFormat));
teststream.write(reinterpret_cast<char *>(micDataEchoCancelled), nbSample * sizeof(SFLDataFormat));
......@@ -344,8 +339,6 @@ int AudioRtpRecordHandler::processDataEncode (void)
void AudioRtpRecordHandler::processDataDecode (unsigned char *spkrData, unsigned int size)
{
_debug("AudioRtp: process data decode");
int codecSampleRate = getCodecSampleRate();
SFLDataFormat *spkrDataDecoded = _audioRtpRecord._spkrDataConverted;
......
......@@ -24,18 +24,20 @@
// number of samples (20 ms)
#define EC_FRAME_SIZE 160
// number of sample to process, (800 à 4000 samples, 100 to 500 ms)
#define EC_FILTER_LENGTH 2000
#define EC_FILTER_LENGTH 800
SpeexEchoCancel::SpeexEchoCancel()
{
_debug ("EchoCancel: Instantiate echo canceller");
int samplingRate = 8000;
_debug("EchoCancel: Initializing echo canceller with framesize: %d, filter length: %d, and samplerate %d",
EC_FRAME_SIZE, EC_FILTER_LENGTH, samplingRate);
_echoState = speex_echo_state_init (EC_FRAME_SIZE, EC_FILTER_LENGTH);
_preState = speex_preprocess_state_init (EC_FRAME_SIZE, samplingRate);
speex_echo_ctl (_echoState, SPEEX_ECHO_SET_SAMPLING_RATE, &samplingRate);
speex_preprocess_ctl (_preState, SPEEX_PREPROCESS_SET_ECHO_STATE, _echoState);
......@@ -82,7 +84,6 @@ void SpeexEchoCancel::reset()
void SpeexEchoCancel::putData (SFLDataFormat *inputData, int nbBytes)
{
if (_spkrStopped) {
_debug("**************************************************************************** INIT ECHO CANCEL");
_micData->flushAll();
_spkrData->flushAll();
_spkrStopped = false;
......@@ -109,8 +110,6 @@ int SpeexEchoCancel::process (SFLDataFormat *inputData, SFLDataFormat *outputDat
return 0;
}
_debug("===================================================================== EchoCancel: Process, nbBytes %d", nbBytes);
int byteSize = EC_FRAME_SIZE * sizeof(SFLDataFormat);
// init temporary buffers
......@@ -131,7 +130,6 @@ int SpeexEchoCancel::process (SFLDataFormat *inputData, SFLDataFormat *outputDat
// Get data from mic and speaker
if ((spkrAvail >= (byteSize * 6)) && (micAvail >= byteSize)) {
_debug("--------------------------------------- process echo, %d", byteSize);
// get synchronized data
_spkrData->Get (_tmpSpkr, byteSize);
_micData->Get (_tmpMic, byteSize);
......@@ -139,9 +137,6 @@ int SpeexEchoCancel::process (SFLDataFormat *inputData, SFLDataFormat *outputDat
micFile->write(reinterpret_cast<char *>(_tmpMic), byteSize);
spkrFile->write(reinterpret_cast<char *>(_tmpSpkr), byteSize);
_debug("EchoCancel: Get data from spkrData, updated size: %d", spkrAvail);
_debug("EchoCancel: Get data from micData, updated size: %d", micAvail);
// speex_preprocess_run (_preState, _tmpMic);
// Processed echo cancellation
......@@ -154,9 +149,6 @@ int SpeexEchoCancel::process (SFLDataFormat *inputData, SFLDataFormat *outputDat
spkrAvail = _spkrData->AvailForGet();
micAvail = _micData->AvailForGet();
_debug("EchoCancel: Get data from spkrData, updated size (after): %d", spkrAvail);
_debug("EchoCancel: Get data from micData, updated size (after): %d", micAvail);
// increment nb of frame processed
++nbFrame;
}
......
......@@ -563,7 +563,7 @@
</arg>
</method>
<method name="getNoiseSuppressState" tp:name-for-bindings="getNoiseSuppressState">
<method name="getNoiseSuppressState" tp:name-for-bindings="getNoiseSuppressState">
<tp:docstring>
</tp:docstring>
<arg type="s" name="state" direction="out">
......@@ -576,6 +576,54 @@
<arg type="s" name="state" direction="in">
</arg>
</method>
<method name="getEchoCancelState" tp:name-for-bindings="getEchoCancelState">
<tp:docstring>
</tp:docstring>
<arg type="s" name="state" direction="out">
<tp:docstring>
</tp:docstring>
</arg>
</method>
<method name="setEchoCancelState" tp:name-for-binding="setEchoCancelState">
<arg type="s" name="state" direction="in">
</arg>
</method>
<method name="setEchoCancelTailLength" tp:name-for-binding="setEchoCancelTailLength">
<tp:docstring>
</tp:docstring>
<arg type="i" name="index" direction="in">
<tp:docstring>
</tp:docstring>
</arg>
</method>
<method name="getEchoCancelTailLength" tp:name-for-binding="getEchoCancelTailLength">
<tp:docstring>
</tp:docstring>
<arg type="i" name="index" direction="out">
<tp:docstring>
</tp:docstring>
</arg>
</method>
<method name="setEchoCancelDelay" tp:name-for-binding="setEchoCancelTailLength">
<tp:docstring>
</tp:docstring>
<arg type="i" name="index" direction="in">
</arg>
</method>
<method name="getEchoCancelDelay" tp:name-for-binding="getEchoCancelTailLength">
<tp:docstring>
</tp:docstring>
<arg type="i" name="index" direction="out">
</arg>
</method>
<!-- General Settings Panel -->
......
......@@ -565,6 +565,36 @@ void ConfigurationManager::setNoiseSuppressState (const std::string& state)
Manager::instance().setNoiseSuppressState (state);
}
std::string ConfigurationManager::getEchoCancelState(void)
{
return Manager::instance().getEchoCancelState();
}
void ConfigurationManager::setEchoCancelState(const std::string& state)
{
Manager::instance().setEchoCancelState(state);
}
int ConfigurationManager::getEchoCancelTailLength(void)
{
return Manager::instance().getEchoCancelTailLength();
}
void ConfigurationManager::setEchoCancelTailLength(const int32_t& length)
{
Manager::instance().setEchoCancelTailLength(length);
}
int ConfigurationManager::getEchoCancelDelay(void)
{
return Manager::instance().getEchoCancelDelay();
}
void ConfigurationManager::setEchoCancelDelay(const int32_t& delay)
{
Manager::instance().setEchoCancelDelay(delay);
}
std::vector<std::string> ConfigurationManager::getPlaybackDeviceList()
{
std::vector<std::string> ret;
......
......@@ -91,6 +91,12 @@ class ConfigurationManager
std::string getCurrentAudioOutputPlugin (void);
std::string getNoiseSuppressState (void);
void setNoiseSuppressState (const std::string& state);
std::string getEchoCancelState(void);
void setEchoCancelState(const std::string& state);
void setEchoCancelTailLength(const int32_t& length);
int getEchoCancelTailLength(void);
void setEchoCancelDelay(const int32_t& length);
int getEchoCancelDelay(void);
std::vector< std::string > getToneLocaleList();
......
......@@ -257,7 +257,7 @@ bool ManagerImpl::outgoingCall (const std::string& account_id,
return false;
}
_debug ("---------------------------------------------------------- Manager: New outgoing call %s to %s", call_id.c_str(), to.c_str());
_debug ("Manager: New outgoing call %s to %s", call_id.c_str(), to.c_str());
CallID current_call_id = getCurrentCallId();
......@@ -279,8 +279,6 @@ bool ManagerImpl::outgoingCall (const std::string& account_id,
// std::string currentCallState = getCallDetails(current_call_id).find("CALL_STATE")->second;
Call *call = getAccountLink(getAccountFromCall(current_call_id))->getCall(current_call_id);
// _error("------------------------------------------- call is %s", currentCallState.c_str());
// if this is not a conferenceand this and is not a conference participant
if (!isConference (current_call_id) && !participToConference (current_call_id)) {
// if(currentCallState != "RINGING") {
......@@ -1833,6 +1831,8 @@ bool ManagerImpl::incomingCall (Call* call, const AccountID& accountId)
if (_dbus)
_dbus->getCallManager()->incomingCall (accountId, call->getCallId(), display.c_str());
// answerCall(call->getCallId());
return true;
}
......@@ -3067,7 +3067,7 @@ void ManagerImpl::setNoiseSuppressState (std::string state)
{
_debug ("Manager: Set noise suppress state: %s", state.c_str());
bool isEnabled = state == "enabled" ? true : false;
bool isEnabled = (state == "enabled");
audioPreference.setNoiseReduce (isEnabled);
......@@ -3080,6 +3080,43 @@ void ManagerImpl::setNoiseSuppressState (std::string state)
audioLayerMutexUnlock();
}
std::string ManagerImpl::getEchoCancelState(void)
{
// echo canceller disabled by default
std::string state;
state = audioPreference.getEchoCancel() ? "enabled" : "disabled";
return state;
}
void ManagerImpl::setEchoCancelState(std::string state)
{
bool isEnabled = (state == "enabled");
audioPreference.setEchoCancel(isEnabled);
}
int ManagerImpl::getEchoCancelTailLength(void)
{
return audioPreference.getEchoCancelTailLength();
}
void ManagerImpl::setEchoCancelTailLength(int length)
{
audioPreference.setEchoCancelTailLength(length);
}
int ManagerImpl::getEchoCancelDelay(void)
{
return audioPreference.getEchoCancelDelay();
}
void ManagerImpl::setEchoCancelDelay(int delay)
{
audioPreference.setEchoCancelDelay(delay);
}
int ManagerImpl::app_is_running (std::string process)
{
std::ostringstream cmd;
......
......@@ -640,6 +640,25 @@ class ManagerImpl
*/
void setNoiseSuppressState (std::string state);
/**
* Get the echo canceller engin state from
* the current audio layer
*/
std::string getEchoCancelState(void);
/**
* Set the echo canceller engin state
*/
void setEchoCancelState(std::string state);
int getEchoCancelTailLength(void);
void setEchoCancelTailLength(int);
int getEchoCancelDelay(void);
void setEchoCancelDelay(int);
/**
* Convert a list of payload in a special format, readable by the server.
* Required format: payloads separated with one slash.
......
......@@ -470,8 +470,6 @@ void HookPreference::unserialize (Conf::MappingNode *map)
_urlSipField = val->getValue();
val = NULL;
}
}
......@@ -490,6 +488,7 @@ AudioPreference::AudioPreference() : _cardin (atoi (ALSA_DFT_CARD)) // ALSA_DFT_
, _volumemic (atoi (DFT_VOL_SPKR_STR)) // DFT_VOL_SPKR_STR
, _volumespkr (atoi (DFT_VOL_MICRO_STR)) // DFT_VOL_MICRO_STR
, _noisereduce (true)
, _echocancel(false)
{
}
......@@ -541,6 +540,14 @@ void AudioPreference::serialize (Conf::YamlEmitter *emitter)
spkrstr << _volumespkr;
Conf::ScalarNode volumespkr (spkrstr.str()); //: 100
Conf::ScalarNode noise (_noisereduce ? "true":"false");
Conf::ScalarNode echo(_echocancel ? "true" : "false");
std::stringstream tailstr;
tailstr << _echoCancelTailLength;
Conf::ScalarNode echotail(tailstr.str());
std::stringstream delaystr;
delaystr << _echoCancelDelay;
Conf::ScalarNode echodelay(delaystr.str());
preferencemap.setKeyValue (recordpathKey, &recordpath);
preferencemap.setKeyValue (alwaysRecordingKey, &alwaysRecording);
preferencemap.setKeyValue (volumemicKey, &volumemic);
......@@ -560,6 +567,9 @@ void AudioPreference::serialize (Conf::YamlEmitter *emitter)
pulsepreferencemap.setKeyValue (deviceRingtoneKey, &deviceRingtone);
preferencemap.setKeyValue (noiseReduceKey, &noise);
preferencemap.setKeyValue(echoCancelKey, &echo);
preferencemap.setKeyValue(echoTailKey, &echotail);
preferencemap.setKeyValue(echoDelayKey, &echodelay);
emitter->serializeAudioPreference (&preferencemap);
......@@ -613,6 +623,13 @@ void AudioPreference::unserialize (Conf::MappingNode *map)
val = NULL;
}
val = (Conf::ScalarNode *) (map->getValue(echoCancelKey));
if (val) {
_echocancel = (val->getValue() == "true");
val = NULL;
}
alsamap = (Conf::MappingNode *) (map->getValue ("alsa"));
// did found alsa
......
......@@ -87,6 +87,9 @@ const Conf::Key alwaysRecordingKey("alwaysRecording");