Commit 4c21af6b authored by Tristan Matthews's avatar Tristan Matthews

* #11269: video: fix codec per account management

parent 2debe703
......@@ -88,7 +88,7 @@ void Account::loadDefaultCodecs()
result.push_back("111");
result.push_back("112");
setActiveCodecs(result);
setActiveAudioCodecs(result);
#ifdef SFL_VIDEO
setActiveVideoCodecs(sfl_video::getCodecList());
#endif
......@@ -97,11 +97,15 @@ void Account::loadDefaultCodecs()
void Account::setActiveVideoCodecs(const std::vector<std::string> &list)
{
#ifdef SFL_VIDEO
// first clear the previously stored codecs
videoCodecList_.clear();
videoCodecList_ = !list.empty() ? list : sfl_video::getCodecList();
// update the codec string according to new codec selection
videoCodecStr_ = ManagerImpl::join_string(list);
#endif
}
void Account::setActiveCodecs(const std::vector<std::string> &list)
void Account::setActiveAudioCodecs(const std::vector<std::string> &list)
{
// first clear the previously stored codecs
audioCodecList_.clear();
......
......@@ -244,7 +244,7 @@ class Account : public Serializable {
/* Accessor to data structures
* @return CodecOrder& The list that reflects the user's choice
*/
std::vector<int> getActiveCodecs() const {
std::vector<int> getActiveAudioCodecs() const {
return audioCodecList_;
}
......@@ -252,7 +252,7 @@ class Account : public Serializable {
* Update both the codec order structure and the codec string used for
* SDP offer and configuration respectively
*/
void setActiveCodecs(const std::vector<std::string>& list);
void setActiveAudioCodecs(const std::vector<std::string>& list);
void setActiveVideoCodecs(const std::vector<std::string>& list);
std::string getRingtonePath() const {
......@@ -289,7 +289,6 @@ class Account : public Serializable {
/**
* Helper function used to load the default codec order from the codec factory
* setActiveCodecs is called to sync both codecList_ and codecStr_
*/
void loadDefaultCodecs();
......
......@@ -78,7 +78,7 @@ AudioCodecFactory::getCodecName(int payload) const
return "";
}
std::vector<int32_t >
std::vector<int32_t>
AudioCodecFactory::getAudioCodecList() const
{
std::vector<int32_t> list;
......
......@@ -191,14 +191,14 @@ std::vector<std::string> ConfigurationManager::getAudioCodecDetails(const int32_
std::vector<int32_t> ConfigurationManager::getActiveAudioCodecList(const std::string& accountID)
{
std::vector<int32_t> v;
Account *acc = Manager::instance().getAccount(accountID);
if (acc)
return acc->getActiveCodecs();
return v;
return acc->getActiveAudioCodecs();
else {
ERROR("Could not find account %s", accountID.c_str());
return std::vector<int32_t>();
}
}
void ConfigurationManager::setActiveAudioCodecList(const std::vector<std::string>& list, const std::string& accountID)
......@@ -206,7 +206,7 @@ void ConfigurationManager::setActiveAudioCodecList(const std::vector<std::string
Account *acc = Manager::instance().getAccount(accountID);
if (acc) {
acc->setActiveCodecs(list);
acc->setActiveAudioCodecs(list);
Manager::instance().saveConfig();
}
}
......
......@@ -87,10 +87,10 @@ VideoControls::setActiveCodecList(const std::vector<std::string>& list, const st
{
Account *acc = Manager::instance().getAccount(accountID);
if (acc != NULL)
acc->setActiveCodecs(list);
Manager::instance().saveConfig();
if (acc != NULL) {
acc->setActiveVideoCodecs(list);
Manager::instance().saveConfig();
}
}
std::vector<std::string> VideoControls::getInputDeviceList()
......
......@@ -93,7 +93,7 @@ void IAXAccount::unserialize(const Conf::MappingNode &map)
map.getValue(AUDIO_CODECS_KEY, &audioCodecStr_);
// Update codec list which one is used for SDP offer
setActiveCodecs(ManagerImpl::split_string(audioCodecStr_));
setActiveAudioCodecs(ManagerImpl::split_string(audioCodecStr_));
map.getValue(DISPLAY_NAME_KEY, &displayName_);
}
......
......@@ -72,7 +72,7 @@ int IAXCall::getSupportedFormat(const std::string &accountID) const
int format_mask = 0;
if (account) {
vector<int> codecs(account->getActiveCodecs());
vector<int> codecs(account->getActiveAudioCodecs());
for (vector<int>::const_iterator i = codecs.begin(); i != codecs.end(); ++i)
format_mask |= codecToASTFormat(*i);
......@@ -88,7 +88,7 @@ int IAXCall::getFirstMatchingFormat(int needles, const std::string &accountID) c
Account *account = Manager::instance().getAccount(accountID);
if (account != NULL) {
vector<int> codecs(account->getActiveCodecs());
vector<int> codecs(account->getActiveAudioCodecs());
for (vector<int>::const_iterator i = codecs.begin(); i != codecs.end(); ++i) {
int format_mask = codecToASTFormat(*i);
......
......@@ -717,12 +717,6 @@ class ManagerImpl {
*/
int32_t getMailNotify() const;
/**
* Get the list of the active codecs
* @return std::vector< ::std::string > The list of active codecs
*/
std::vector<std::string> getActiveCodecList() const;
/**
* Change a specific value in the configuration tree.
* This value will then be saved in the user config file sflphonedrc
......
......@@ -141,14 +141,11 @@ void SIPAccount::serialize(Conf::YamlEmitter &emitter)
ScalarNode publishPort(publicportstr.str());
ScalarNode sameasLocal(publishedSameasLocal_);
DEBUG("%s", audioCodecStr_.c_str());
ScalarNode audioCodecs(audioCodecStr_);
#ifdef SFL_VIDEO
for (vector<string>::const_iterator i = videoCodecList_.begin();
i != videoCodecList_.end(); ++i)
DEBUG("%s", i->c_str());
DEBUG("%s", Manager::instance().join_string(videoCodecList_).c_str());
ScalarNode videoCodecs(Manager::instance().join_string(videoCodecList_));
DEBUG("%s", videoCodecStr_.c_str());
ScalarNode videoCodecs(videoCodecStr_);
#endif
ScalarNode ringtonePath(ringtonePath_);
......@@ -283,12 +280,12 @@ void SIPAccount::unserialize(const Conf::MappingNode &map)
map.getValue(ACCOUNT_ENABLE_KEY, &enabled_);
map.getValue(MAILBOX_KEY, &mailBox_);
map.getValue(AUDIO_CODECS_KEY, &audioCodecStr_);
// Update codec list which one is used for SDP offer
setActiveAudioCodecs(ManagerImpl::split_string(audioCodecStr_));
#ifdef SFL_VIDEO
map.getValue(VIDEO_CODECS_KEY, &videoCodecStr_);
setActiveVideoCodecs(ManagerImpl::split_string(videoCodecStr_));
#endif
// Update codec list which one is used for SDP offer
setActiveCodecs(ManagerImpl::split_string(audioCodecStr_));
map.getValue(RINGTONE_PATH_KEY, &ringtonePath_);
map.getValue(RINGTONE_ENABLED_KEY, &ringtoneEnabled_);
......
......@@ -241,7 +241,7 @@ pj_bool_t transaction_request_cb(pjsip_rx_data *rdata)
if (!body || pjmedia_sdp_parse(rdata->tp_info.pool, (char*) body->data, body->len, &r_sdp) != PJ_SUCCESS)
r_sdp = NULL;
if (account->getActiveCodecs().empty()) {
if (account->getActiveAudioCodecs().empty()) {
pjsip_endpt_respond_stateless(endpt_, rdata,
PJSIP_SC_NOT_ACCEPTABLE_HERE, NULL, NULL,
NULL);
......@@ -323,9 +323,9 @@ pj_bool_t transaction_request_cb(pjsip_rx_data *rdata)
}
#ifdef SFL_VIDEO
call->getLocalSDP()->receiveOffer(r_sdp, account->getActiveCodecs(), account->getActiveVideoCodecs());
call->getLocalSDP()->receiveOffer(r_sdp, account->getActiveAudioCodecs(), account->getActiveVideoCodecs());
#else
call->getLocalSDP()->receiveOffer(r_sdp, account->getActiveCodecs());
call->getLocalSDP()->receiveOffer(r_sdp, account->getActiveAudioCodecs());
#endif
sfl::AudioCodec* ac = dynamic_cast<sfl::AudioCodec*>(Manager::instance().audioCodecFactory.instantiateCodec(PAYLOAD_CODEC_ULAW));
......@@ -751,9 +751,9 @@ Call *SIPVoIPLink::SIPNewIpToIpCall(const std::string& id, const std::string& to
// Building the local SDP offer
call->getLocalSDP()->setLocalIP(localAddress);
#ifdef SFL_VIDEO
call->getLocalSDP()->createOffer(account->getActiveCodecs(), account->getActiveVideoCodecs());
call->getLocalSDP()->createOffer(account->getActiveAudioCodecs(), account->getActiveVideoCodecs());
#else
call->getLocalSDP()->createOffer(account->getActiveCodecs());
call->getLocalSDP()->createOffer(account->getActiveAudioCodecs());
#endif
if (!SIPStartCall(call)) {
......@@ -824,9 +824,9 @@ Call *SIPVoIPLink::newRegisteredAccountCall(const std::string& id, const std::st
call->getLocalSDP()->setLocalIP(addrSdp);
#ifdef SFL_VIDEO
call->getLocalSDP()->createOffer(account->getActiveCodecs(), account->getActiveVideoCodecs());
call->getLocalSDP()->createOffer(account->getActiveAudioCodecs(), account->getActiveVideoCodecs());
#else
call->getLocalSDP()->createOffer(account->getActiveCodecs());
call->getLocalSDP()->createOffer(account->getActiveAudioCodecs());
#endif
if (!SIPStartCall(call)) {
......@@ -1385,9 +1385,9 @@ void sdp_request_offer_cb(pjsip_inv_session *inv, const pjmedia_sdp_session *off
return;
#ifdef SFL_VIDEO
call->getLocalSDP()->receiveOffer(offer, account->getActiveCodecs(), account->getActiveVideoCodecs());
call->getLocalSDP()->receiveOffer(offer, account->getActiveAudioCodecs(), account->getActiveVideoCodecs());
#else
call->getLocalSDP()->receiveOffer(offer, account->getActiveCodecs());
call->getLocalSDP()->receiveOffer(offer, account->getActiveAudioCodecs());
#endif
call->getLocalSDP()->startNegotiation();
......@@ -1418,9 +1418,9 @@ void sdp_create_offer_cb(pjsip_inv_session *inv, pjmedia_sdp_session **p_offer)
call->getLocalSDP()->setLocalIP(addrSdp);
#ifdef SFL_VIDEO
call->getLocalSDP()->createOffer(account->getActiveCodecs(), account->getActiveVideoCodecs());
call->getLocalSDP()->createOffer(account->getActiveAudioCodecs(), account->getActiveVideoCodecs());
#else
call->getLocalSDP()->createOffer(account->getActiveCodecs());
call->getLocalSDP()->createOffer(account->getActiveAudioCodecs());
#endif
*p_offer = call->getLocalSDP()->getLocalSdpSession();
......
......@@ -909,26 +909,29 @@ sflphone_mute_call()
static void
sflphone_fill_video_codec_list_per_account(account_t *account)
{
gchar **order = dbus_get_active_video_codec_list(account->accountID);
if (!account->vcodecs)
account->vcodecs = g_queue_new();
GQueue* vcodecs = get_video_codecs_list();
else
g_queue_clear(account->vcodecs);
/* First add the active codecs for this account */
GQueue* system_vcodecs = get_video_codecs_list();
gchar **order = dbus_get_active_video_codec_list(account->accountID);
for (gchar **pl = order; *pl; pl++) {
codec_t *orig = codec_list_get_by_name(*pl, vcodecs);
codec_t *orig = codec_list_get_by_name(*pl, system_vcodecs);
codec_t *c = codec_create_new_from_caps(orig);
if (c)
g_queue_push_tail(account->vcodecs, c);
else
ERROR ("SFLphone: Couldn't find codec %s %p", *pl, orig);
ERROR("Couldn't find codec %s %p", *pl, orig);
g_free(*pl);
}
g_free(order);
g_queue_clear(account->vcodecs);
guint caps_size = g_queue_get_length(vcodecs);
/* Here we add installed codecs that aren't active for the account */
guint caps_size = g_queue_get_length(system_vcodecs);
for (guint i = 0; i < caps_size; ++i) {
codec_t * vcodec = g_queue_peek_nth(vcodecs, i);
codec_t * vcodec = g_queue_peek_nth(system_vcodecs, i);
if (codec_list_get_by_name(vcodec->name, account->vcodecs) == NULL) {
vcodec->is_active = FALSE;
g_queue_push_tail(account->vcodecs, vcodec);
......@@ -942,27 +945,28 @@ sflphone_fill_audio_codec_list_per_account(account_t *account)
{
if (!account->acodecs)
account->acodecs = g_queue_new();
else
g_queue_clear(account->acodecs);
/* First add the active codecs for this account */
GArray *order = dbus_get_active_audio_codec_list(account->accountID);
GQueue* acodecs = get_audio_codecs_list();
GQueue *system_acodecs = get_audio_codecs_list();
for (guint i = 0; i < order->len; i++) {
gint payload = g_array_index(order, gint, i);
codec_t *orig = codec_list_get_by_payload(payload, acodecs);
codec_t *orig = codec_list_get_by_payload(payload, system_acodecs);
codec_t *c = codec_create_new_from_caps(orig);
if (c)
g_queue_push_tail(account->acodecs, c);
else
ERROR ("SFLphone: Couldn't find codec %d %p", payload, orig);
ERROR("Couldn't find codec %d %p", payload, orig);
}
g_array_unref(order);
g_queue_clear(account->acodecs);
guint caps_size = g_queue_get_length(acodecs);
/* Here we add installed codecs that aren't active for the account */
guint caps_size = g_queue_get_length(system_acodecs);
for (guint i = 0; i < caps_size; ++i) {
codec_t * acodec = g_queue_peek_nth(acodecs, i);
codec_t * acodec = g_queue_peek_nth(system_acodecs, i);
if (codec_list_get_by_payload(acodec->payload, account->acodecs) == NULL) {
acodec->is_active = FALSE;
g_queue_push_tail(account->acodecs, acodec);
......
......@@ -60,13 +60,13 @@ static codec_t *codec_create(gint payload, gchar **specs)
}
codec->payload = payload;
codec->name = specs[0];
codec->bitrate = specs[1];
codec->name = g_strdup(specs[0]);
codec->bitrate = g_strdup(specs[1]);
codec->sample_rate = specs[2] ? atoi(specs[2]) : 0;
codec->is_active = TRUE;
free(specs[2]);
free(specs);
g_free(specs[2]);
g_free(specs);
return codec;
}
......@@ -175,7 +175,7 @@ codec_t *codec_create_new_from_caps(codec_t *original)
if (original) {
codec = g_new0(codec_t, 1);
codec->payload = original->payload;
codec->is_active = TRUE;
codec->is_active = original->is_active;
codec->name = g_strdup(original->name);
codec->sample_rate = original->sample_rate;
codec->bitrate = g_strdup(original->bitrate);
......
......@@ -81,25 +81,31 @@ preferences_dialog_fill_codec_list(const account_t *account)
GtkListStore *codecStore = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(codecTreeView)));
gtk_list_store_clear(codecStore);
GQueue *list = account ? account->acodecs : get_audio_codecs_list();
GQueue *list;
if (!account) {
DEBUG("Account is NULL, using global codec list");
list = get_audio_codecs_list();
} else {
list = account->acodecs;
}
// Insert codecs
for (size_t i = 0; i < list->length; ++i) {
codec_t *c = g_queue_peek_nth (list, i);
codec_t *c = g_queue_peek_nth(list, i);
if (c) {
DEBUG ("%s", c->name);
DEBUG("%s is %sactive", c->name, c->is_active ? "" : "not ");
GtkTreeIter iter;
gtk_list_store_append (codecStore, &iter);
gchar *samplerate = g_strdup_printf ("%d kHz", c->sample_rate);
gchar *bitrate = g_strdup_printf ("%s kbps", c->bitrate);
gtk_list_store_set (codecStore, &iter,
COLUMN_CODEC_ACTIVE, c->is_active,
COLUMN_CODEC_NAME, c->name,
COLUMN_CODEC_FREQUENCY, samplerate,
COLUMN_CODEC_BITRATE, bitrate,
-1);
gtk_list_store_append(codecStore, &iter);
gchar *samplerate = g_strdup_printf("%d kHz", c->sample_rate);
gchar *bitrate = g_strdup_printf("%s kbps", c->bitrate);
gtk_list_store_set(codecStore, &iter,
COLUMN_CODEC_ACTIVE, c->is_active,
COLUMN_CODEC_NAME, c->name,
COLUMN_CODEC_FREQUENCY, samplerate,
COLUMN_CODEC_BITRATE, bitrate,
-1);
g_free(samplerate);
g_free(bitrate);
}
......@@ -536,10 +542,10 @@ GtkWidget* audiocodecs_box(const account_t *account)
gtk_box_pack_start(GTK_BOX(audiocodecs_hbox), scrolledWindow, TRUE, TRUE, 0);
GtkListStore *codecStore = gtk_list_store_new(CODEC_COLUMN_COUNT,
G_TYPE_BOOLEAN, /* Active */
G_TYPE_STRING, /* Name */
G_TYPE_STRING, /* Frequency */
G_TYPE_STRING, /* Bit rate */
G_TYPE_STRING /* Bandwith */);
G_TYPE_STRING, /* Name */
G_TYPE_STRING, /* Frequency */
G_TYPE_STRING, /* Bitrate */
G_TYPE_STRING /* Bandwidth */);
// Create codec tree view with list store
codecTreeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(codecStore));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment