Commit 3a375752 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

DBus communication for audio codecs settings

parent 8ba45b53
......@@ -580,21 +580,89 @@ sflphone_set_default_account( )
void
sflphone_fill_codec_list()
{
int i=0;
codec_list_clear();
gchar** codecs = (gchar**)dbus_codec_list();
while(codecs[i]!=NULL)
gchar** details;
gchar** pl;
for(pl=codecs; *codecs; codecs++)
{
printf("%s\n", codecs[i]);
codec_t * c = g_new0(codec_t, 1);
c->name = codecs[i];
codec_set_active(codecs[i]); // active by default
c->_payload = atoi(*codecs);
//codec_set_active(*codecs); // active by default
codec_list_add(c);
i++;
details = (gchar **)dbus_codec_details(c->_payload);
printf("Codec details: %s / %s / %s / %s\n",details[0],details[1],details[2],details[3]);
c->name = details[0];
c->sample_rate = atoi(details[1]);
printf("sample rate = %i\n", atoi(details[1]));
c->_bitrate = (gdouble)(atoi(details[2]));
printf("bitrate = %d\n", (double)atoi(details[2]));
c->_bandwidth = (gdouble)(atoi(details[3]));
printf("bandwidth = %d\n", (double)atoi(details[3]));
}
//g_strfreev(codecs);
/*
int i;
gchar ** details;
for( i = 0 ; i < codec_list_get_size() ; i++)
{
codec_t * c = codec_list_get_nth(i);
details = (gchar **)dbus_codec_details(c->_payload);
printf("%s\n", details[0]);
c->name = details[0];
c->sample_rate = (guint)details[1];
//c->_bitrate = (gdouble)details[2];
//c->_bandwidth = (gdouble)details[3];
}*/
}
/*
account_list_clear ( );
gchar ** array = (gchar **)dbus_account_list();
gchar ** accountID;
for (accountID = array; *accountID; accountID++)
{
account_t * a = g_new0(account_t,1);
a->accountID = g_strdup(*accountID);
account_list_add(a);
}
g_strfreev (array);
int i;
for( i = 0; i < account_list_get_size(); i++)
{
account_t * a = account_list_get_nth (i);
GHashTable * details = (GHashTable *) dbus_account_details(a->accountID);
a->properties = details;
gchar * status = g_hash_table_lookup(details, "Status");
if(strcmp(status, "REGISTERED") == 0)
{
a->state = ACCOUNT_STATE_REGISTERED;
}
else if(strcmp(status, "UNREGISTERED") == 0)
{
a->state = ACCOUNT_STATE_UNREGISTERED;
}
else if(strcmp(status, "TRYING") == 0)
{
a->state = ACCOUNT_STATE_TRYING;
}
else if(strcmp(status, "ERROR") == 0)
{
a->state = ACCOUNT_STATE_ERROR;
}
*/
......
......@@ -39,6 +39,13 @@ codec_list_init()
codecQueue = g_queue_new();
}
void
codec_list_clear ()
{
g_queue_free (codecQueue);
codecQueue = g_queue_new();
}
void
codec_list_add(codec_t * c)
{
......
......@@ -26,12 +26,16 @@
*/
typedef struct {
gchar * name;
guint sample_rate;
int _payload;
gboolean is_active;
gchar * name;
int sample_rate;
gdouble _bitrate;
gdouble _bandwidth;
}codec_t;
void codec_list_init();
void codec_list_clear();
void codec_list_add(codec_t * c);
void codec_set_active(gchar * codec_name);
void codec_set_inactive(gchar * codec_name);
......
......@@ -661,13 +661,13 @@ dbus_unregister(int pid)
}
gchar **
gchar**
dbus_codec_list()
{
g_print("Before");
GError *error = NULL;
char ** array;
gchar** array;
org_sflphone_SFLphone_ConfigurationManager_get_codec_list (
configurationManagerProxy,
&array,
......@@ -688,6 +688,35 @@ dbus_codec_list()
return array;
}
gchar**
dbus_codec_details( int payload )
{
g_print("Before");
GError *error = NULL;
gchar ** array;
org_sflphone_SFLphone_ConfigurationManager_get_codec_details (
configurationManagerProxy,
payload,
&array,
&error);
g_print("After");
if (error)
{
g_printerr ("Failed to call get_codec_details() on ConfigurationManager: %s\n",
error->message);
g_error_free (error);
}
else
{
g_print ("DBus called get_codec_details() on ConfigurationManager\n");
}
return array;
}
gchar **
dbus_default_codec_list()
{
......
......@@ -54,6 +54,7 @@ void dbus_play_dtmf(const gchar * key);
gchar* dbus_get_default_account();
void dbus_set_default_account(gchar * accountID);
gchar** dbus_codec_list();
gchar** dbus_codec_details(int payload);
gchar** dbus_default_codec_list();
gchar** dbus_get_sample_rate_list();
......
......@@ -36,9 +36,7 @@ CodecDescriptor::CodecDescriptor()
#ifdef HAVE_SPEEX
_codecMap[PAYLOAD_CODEC_SPEEX] = new CodecSpeex(PAYLOAD_CODEC_SPEEX); // TODO: this is a variable payload!
#endif
// theses one are not implemented yet..
// _codecMap[PAYLOAD_CODEC_ILBC_20] = "iLBC";
// _codecMap[PAYLOAD_CODEC_SPEEX] = Speex();
_codecMap[PAYLOAD_CODEC_ILBC_20] = "iLBC";
}
void
......@@ -47,7 +45,7 @@ CodecDescriptor::init()
_codecMap[PAYLOAD_CODEC_ULAW] = "PCMU";
_codecMap[PAYLOAD_CODEC_GSM] = "GSM";
_codecMap[PAYLOAD_CODEC_ALAW] = "PCMA";
// _codecMap[PAYLOAD_CODEC_ILBC_20] = "iLBC";
_codecMap[PAYLOAD_CODEC_ILBC_20] = "iLBC";
}
std::string&
......@@ -57,7 +55,7 @@ CodecDescriptor::getCodecName(CodecType payload)
if (iter!=_codecMap.end()) {
return (iter->second);
}
//return ;
//return std::string("");
}
bool
......@@ -100,7 +98,9 @@ double
CodecDescriptor::getBitRate(CodecType payload)
{
switch(payload){
case PAYLOAD_CODEC_ULAW | PAYLOAD_CODEC_ALAW:
case PAYLOAD_CODEC_ULAW:
return 64;
case PAYLOAD_CODEC_ALAW:
return 64;
case PAYLOAD_CODEC_GSM:
return 13.3;
......@@ -117,7 +117,9 @@ double
CodecDescriptor::getBandwidthPerCall(CodecType payload)
{
switch(payload){
case PAYLOAD_CODEC_ULAW | PAYLOAD_CODEC_ALAW:
case PAYLOAD_CODEC_ULAW:
return 80;
case PAYLOAD_CODEC_ALAW:
return 80;
case PAYLOAD_CODEC_GSM:
return 28.6;
......@@ -132,14 +134,40 @@ int
CodecDescriptor::getSampleRate(CodecType payload)
{
switch(payload){
case PAYLOAD_CODEC_ULAW | PAYLOAD_CODEC_ALAW | PAYLOAD_CODEC_GSM | PAYLOAD_CODEC_ILBC_20:
case PAYLOAD_CODEC_ULAW:
printf("PAYLOAD = %i\n", payload);
return 8000;
case PAYLOAD_CODEC_ALAW:
printf("PAYLOAD = %i\n", payload);
return 8000;
case PAYLOAD_CODEC_GSM:
printf("PAYLOAD = %i\n", payload);
return 8000;
case PAYLOAD_CODEC_ILBC_20:
printf("PAYLOAD = %i\n", payload);
return 8000;
default:
return -1;
}
return -1;
return -1;
}
/*
int
CodecDescriptor::getSampleRate(CodecType payload)
{
std::string name = getCodecName(payload);
switch(name){
case "PCMU":
return 8000;
case "PCMA":
return 8000;
case "GSM":
return 8000;
case "iLBC":
return 8000;
}
}
*/
......
......@@ -25,6 +25,7 @@
#include <string>
#include <map>
#include <vector>
#include "../global.h"
typedef enum {
......@@ -51,6 +52,7 @@ typedef enum {
/* A codec is identified by its payload. A payload is associated with a name. */
typedef std::map<CodecType, std::string> CodecMap;
typedef std::vector<CodecType> CodecOrder;
class CodecDescriptor {
public:
......@@ -60,6 +62,7 @@ public:
CodecDescriptor();
~CodecDescriptor() {};
CodecMap& getCodecMap() { return _codecMap; }
CodecOrder& getCodecOrder() { return _codecOrder; }
/**
* Get codec with is associated payload
......@@ -116,6 +119,7 @@ public:
int getSampleRate(CodecType payload);
private:
CodecMap _codecMap;
CodecOrder _codecOrder;
};
#endif // __CODEC_DESCRIPTOR_H__
......@@ -25,18 +25,22 @@ public:
register_method(ConfigurationManager, addAccount, _addAccount_stub);
register_method(ConfigurationManager, removeAccount, _removeAccount_stub);
register_method(ConfigurationManager, getAccountList, _getAccountList_stub);
register_method(ConfigurationManager, getDefaultAccount, _getDefaultAccount_stub);
register_method(ConfigurationManager, setDefaultAccount, _setDefaultAccount_stub);
register_method(ConfigurationManager, getToneLocaleList, _getToneLocaleList_stub);
register_method(ConfigurationManager, getVersion, _getVersion_stub);
register_method(ConfigurationManager, getRingtoneList, _getRingtoneList_stub);
register_method(ConfigurationManager, getSampleRateList, _getSampleRateList_stub);
register_method(ConfigurationManager, getPlaybackDeviceList, _getPlaybackDeviceList_stub);
register_method(ConfigurationManager, getRecordDeviceList, _getRecordDeviceList_stub);
register_method(ConfigurationManager, getCodecList, _getCodecList_stub);
register_method(ConfigurationManager, getCodecDetails, _getCodecDetails_stub);
register_method(ConfigurationManager, getDefaultCodecList, _getDefaultCodecList_stub);
register_method(ConfigurationManager, getToneLocaleList, _getToneLocaleList_stub);
register_method(ConfigurationManager, setCodecPreferedOrder, _setCodecPreferedOrder_stub);
register_method(ConfigurationManager, getCodecPreferedOrder, _getCodecPreferedOrder_stub);
register_method(ConfigurationManager, getPlaybackDeviceList, _getPlaybackDeviceList_stub);
register_method(ConfigurationManager, getRecordDeviceList, _getRecordDeviceList_stub);
register_method(ConfigurationManager, getSampleRateList, _getSampleRateList_stub);
register_method(ConfigurationManager, getDefaultAccount, _getDefaultAccount_stub);
register_method(ConfigurationManager, setDefaultAccount, _setDefaultAccount_stub);
register_method(ConfigurationManager, getCodecBitRate, _getCodecBitRate_stub);
register_method(ConfigurationManager, getCodecBandwidth, _getCodecBandwidth_stub);
register_method(ConfigurationManager, getCodecClockRate, _getCodecClockRate_stub);
}
::DBus::IntrospectedInterface* const introspect() const
......@@ -68,6 +72,21 @@ public:
{ "list", "as", false },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument getDefaultAccount_args[] =
{
{ "accountID", "s", false },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument setDefaultAccount_args[] =
{
{ "accountID", "s", true },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument getToneLocaleList_args[] =
{
{ "list", "as", false },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument getVersion_args[] =
{
{ "version", "s", false },
......@@ -78,54 +97,63 @@ public:
{ "list", "as", false },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument getCodecList_args[] =
static ::DBus::IntrospectedArgument getSampleRateList_args[] =
{
{ "list", "as", false },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument getDefaultCodecList_args[] =
static ::DBus::IntrospectedArgument getPlaybackDeviceList_args[] =
{
{ "list", "as", false },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument getToneLocaleList_args[] =
static ::DBus::IntrospectedArgument getRecordDeviceList_args[] =
{
{ "list", "as", false },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument setCodecPreferedOrder_args[] =
static ::DBus::IntrospectedArgument getCodecList_args[] =
{
{ "codec_name", "s", true },
{ "list", "as", false },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument getCodecPreferedOrder_args[] =
static ::DBus::IntrospectedArgument getCodecDetails_args[] =
{
{ "codec_name", "s", false },
{ "payload", "i", true },
{ "details", "as", false },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument getPlaybackDeviceList_args[] =
static ::DBus::IntrospectedArgument getDefaultCodecList_args[] =
{
{ "list", "as", false },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument getRecordDeviceList_args[] =
static ::DBus::IntrospectedArgument setCodecPreferedOrder_args[] =
{
{ "list", "as", false },
{ "codec_name", "s", true },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument getSampleRateList_args[] =
static ::DBus::IntrospectedArgument getCodecPreferedOrder_args[] =
{
{ "list", "as", false },
{ "codec_name", "s", false },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument getDefaultAccount_args[] =
static ::DBus::IntrospectedArgument getCodecBitRate_args[] =
{
{ "accountID", "s", false },
{ "codec_name", "s", true },
{ "bitrate", "s", false },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument setDefaultAccount_args[] =
static ::DBus::IntrospectedArgument getCodecBandwidth_args[] =
{
{ "accountID", "s", true },
{ "codec_name", "s", true },
{ "bandwidth", "s", false },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument getCodecClockRate_args[] =
{
{ "codec_name", "s", true },
{ "clockrate", "s", false },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument parametersChanged_args[] =
......@@ -144,18 +172,22 @@ public:
{ "addAccount", addAccount_args },
{ "removeAccount", removeAccount_args },
{ "getAccountList", getAccountList_args },
{ "getDefaultAccount", getDefaultAccount_args },
{ "setDefaultAccount", setDefaultAccount_args },
{ "getToneLocaleList", getToneLocaleList_args },
{ "getVersion", getVersion_args },
{ "getRingtoneList", getRingtoneList_args },
{ "getSampleRateList", getSampleRateList_args },
{ "getPlaybackDeviceList", getPlaybackDeviceList_args },
{ "getRecordDeviceList", getRecordDeviceList_args },
{ "getCodecList", getCodecList_args },
{ "getCodecDetails", getCodecDetails_args },
{ "getDefaultCodecList", getDefaultCodecList_args },
{ "getToneLocaleList", getToneLocaleList_args },
{ "setCodecPreferedOrder", setCodecPreferedOrder_args },
{ "getCodecPreferedOrder", getCodecPreferedOrder_args },
{ "getPlaybackDeviceList", getPlaybackDeviceList_args },
{ "getRecordDeviceList", getRecordDeviceList_args },
{ "getSampleRateList", getSampleRateList_args },
{ "getDefaultAccount", getDefaultAccount_args },
{ "setDefaultAccount", setDefaultAccount_args },
{ "getCodecBitRate", getCodecBitRate_args },
{ "getCodecBandwidth", getCodecBandwidth_args },
{ "getCodecClockRate", getCodecClockRate_args },
{ 0, 0 }
};
static ::DBus::IntrospectedMethod ConfigurationManager_signals[] =
......@@ -194,18 +226,22 @@ public:
virtual void addAccount( const std::map< ::DBus::String, ::DBus::String >& details ) = 0;
virtual void removeAccount( const ::DBus::String& accoundID ) = 0;
virtual std::vector< ::DBus::String > getAccountList( ) = 0;
virtual ::DBus::String getDefaultAccount( ) = 0;
virtual void setDefaultAccount( const ::DBus::String& accountID ) = 0;
virtual std::vector< ::DBus::String > getToneLocaleList( ) = 0;
virtual ::DBus::String getVersion( ) = 0;
virtual std::vector< ::DBus::String > getRingtoneList( ) = 0;
virtual std::vector< ::DBus::String > getSampleRateList( ) = 0;
virtual std::vector< ::DBus::String > getPlaybackDeviceList( ) = 0;
virtual std::vector< ::DBus::String > getRecordDeviceList( ) = 0;
virtual std::vector< ::DBus::String > getCodecList( ) = 0;
virtual std::vector< ::DBus::String > getCodecDetails( const ::DBus::Int32& payload ) = 0;
virtual std::vector< ::DBus::String > getDefaultCodecList( ) = 0;
virtual std::vector< ::DBus::String > getToneLocaleList( ) = 0;
virtual void setCodecPreferedOrder( const ::DBus::String& codec_name ) = 0;
virtual ::DBus::String getCodecPreferedOrder( ) = 0;
virtual std::vector< ::DBus::String > getPlaybackDeviceList( ) = 0;
virtual std::vector< ::DBus::String > getRecordDeviceList( ) = 0;
virtual std::vector< ::DBus::String > getSampleRateList( ) = 0;
virtual ::DBus::String getDefaultAccount( ) = 0;
virtual void setDefaultAccount( const ::DBus::String& accountID ) = 0;
virtual ::DBus::String getCodecBitRate( const ::DBus::String& codec_name ) = 0;
virtual ::DBus::String getCodecBandwidth( const ::DBus::String& codec_name ) = 0;
virtual ::DBus::String getCodecClockRate( const ::DBus::String& codec_name ) = 0;
public:
......@@ -277,6 +313,35 @@ private:
wi << argout1;
return reply;
}
::DBus::Message _getDefaultAccount_stub( const ::DBus::CallMessage& call )
{
::DBus::MessageIter ri = call.reader();
::DBus::String argout1 = getDefaultAccount();
::DBus::ReturnMessage reply(call);
::DBus::MessageIter wi = reply.writer();
wi << argout1;
return reply;
}
::DBus::Message _setDefaultAccount_stub( const ::DBus::CallMessage& call )
{
::DBus::MessageIter ri = call.reader();
::DBus::String argin1; ri >> argin1;
setDefaultAccount(argin1);
::DBus::ReturnMessage reply(call);
return reply;
}
::DBus::Message _getToneLocaleList_stub( const ::DBus::CallMessage& call )
{
::DBus::MessageIter ri = call.reader();
std::vector< ::DBus::String > argout1 = getToneLocaleList();
::DBus::ReturnMessage reply(call);
::DBus::MessageIter wi = reply.writer();
wi << argout1;
return reply;
}
::DBus::Message _getVersion_stub( const ::DBus::CallMessage& call )
{
::DBus::MessageIter ri = call.reader();
......@@ -297,102 +362,117 @@ private:
wi << argout1;
return reply;
}
::DBus::Message _getCodecList_stub( const ::DBus::CallMessage& call )
::DBus::Message _getSampleRateList_stub( const ::DBus::CallMessage& call )
{
::DBus::MessageIter ri = call.reader();
std::vector< ::DBus::String > argout1 = getCodecList();
std::vector< ::DBus::String > argout1 = getSampleRateList();
::DBus::ReturnMessage reply(call);
::DBus::MessageIter wi = reply.writer();
wi << argout1;
return reply;
}
::DBus::Message _getDefaultCodecList_stub( const ::DBus::CallMessage& call )
::DBus::Message _getPlaybackDeviceList_stub( const ::DBus::CallMessage& call )
{
::DBus::MessageIter ri = call.reader();
std::vector< ::DBus::String > argout1 = getDefaultCodecList();
std::vector< ::DBus::String > argout1 = getPlaybackDeviceList();
::DBus::ReturnMessage reply(call);
::DBus::MessageIter wi = reply.writer();
wi << argout1;
return reply;
}
::DBus::Message _getToneLocaleList_stub( const ::DBus::CallMessage& call )
::DBus::Message _getRecordDeviceList_stub( const ::DBus::CallMessage& call )
{
::DBus::MessageIter ri = call.reader();
std::vector< ::DBus::String > argout1 = getToneLocaleList();
std::vector< ::DBus::String > argout1 = getRecordDeviceList();
::DBus::ReturnMessage reply(call);
::DBus::MessageIter wi = reply.writer();
wi << argout1;
return reply;
}
::DBus::Message _setCodecPreferedOrder_stub( const ::DBus::CallMessage& call )
::DBus::Message _getCodecList_stub( const ::DBus::CallMessage& call )
{
::DBus::MessageIter ri = call.reader();
::DBus::String argin1; ri >> argin1;
setCodecPreferedOrder(argin1);
std::vector< ::DBus::String > argout1 = getCodecList();
::DBus::ReturnMessage reply(call);
::DBus::MessageIter wi = reply.writer();
wi << argout1;
return reply;
}
::DBus::Message _getCodecPreferedOrder_stub( const ::DBus::CallMessage& call )
::DBus::Message _getCodecDetails_stub( const ::DBus::CallMessage& call )
{
::DBus::MessageIter ri = call.reader();
::DBus::String argout1 = getCodecPreferedOrder();
::DBus::Int32 argin1; ri >> argin1;
std::vector< ::DBus::String > argout1 = getCodecDetails(argin1);
::DBus::ReturnMessage reply(call);
::DBus::MessageIter wi = reply.writer();
wi << argout1;
return reply;