Commit 6299a511 authored by Adrien Béraud's avatar Adrien Béraud

account: prevent all codecs from being disabled

All codecs being disabled prevents Ring from making any call.
If all codecs are disabled for audio or video, re-enable all codecs
of this kind.

Tuleap: #394
Change-Id: Ib65e0e878686b2580b312202482b9ddbce298590
parent b1120dc1
......@@ -203,7 +203,7 @@ join_string(const std::vector<unsigned> &v)
void
Account::serialize(YAML::Emitter& out)
{
const auto& activeCodecs = join_string(getActiveAccountCodecInfoIdList(MEDIA_ALL));
const auto& activeCodecs = join_string(getActiveCodecs(MEDIA_ALL));
out << YAML::Key << ID_KEY << YAML::Value << accountID_;
out << YAML::Key << ALIAS_KEY << YAML::Value << alias_;
......@@ -309,10 +309,13 @@ Account::getVolatileAccountDetails() const
};
}
std::vector<unsigned>
Account::getActiveCodecs() const
bool
Account::hasActiveCodec(MediaType mediaType) const
{
return getActiveAccountCodecInfoIdList(MEDIA_ALL);
for (auto& codecIt: accountCodecInfoList_)
if ((codecIt->systemCodecInfo.mediaType & mediaType) && codecIt->isActive)
return true;
return false;
}
void
......@@ -320,7 +323,7 @@ Account::setActiveCodecs(const std::vector<unsigned>& list)
{
// first clear the previously stored codecs
// TODO: mutex to protect isActive
desactivateAllMedia(MEDIA_ALL);
setAllCodecsActive(MEDIA_ALL, false);
// list contains the ordered payload of active codecs picked by the user for this account
// we used the codec vector to save the order.
......@@ -339,6 +342,15 @@ Account::setActiveCodecs(const std::vector<unsigned>& list)
std::shared_ptr<AccountCodecInfo> b) {
return a->order < b->order;
});
if (!hasActiveCodec(MEDIA_AUDIO)) {
RING_WARN("All audio codecs disabled, enabling all");
setAllCodecsActive(MEDIA_AUDIO, true);
}
if (!hasActiveCodec(MEDIA_VIDEO)) {
RING_WARN("All video codecs disabled, enabling all");
setAllCodecsActive(MEDIA_VIDEO, true);
}
}
std::string
......@@ -483,7 +495,7 @@ Account::searchCodecByPayload(unsigned payload, MediaType mediaType)
}
std::vector<unsigned>
Account::getActiveAccountCodecInfoIdList(MediaType mediaType) const
Account::getActiveCodecs(MediaType mediaType) const
{
if (mediaType == MEDIA_NONE)
return {};
......@@ -513,14 +525,13 @@ Account::getAccountCodecInfoIdList(MediaType mediaType) const
}
void
Account::desactivateAllMedia(MediaType mediaType)
Account::setAllCodecsActive(MediaType mediaType, bool active)
{
if (mediaType == MEDIA_NONE)
return;
for (auto& codecIt: accountCodecInfoList_) {
if (codecIt->systemCodecInfo.mediaType & mediaType)
codecIt->isActive = false;
codecIt->isActive = active;
}
}
......
......@@ -217,7 +217,8 @@ class Account : public Serializable, public std::enable_shared_from_this<Account
/* Accessor to data structures
* @return The list that reflects the user's choice
*/
std::vector<unsigned> getActiveCodecs() const;
std::vector<unsigned> getActiveCodecs(MediaType mediaType = MEDIA_ALL) const;
bool hasActiveCodec(MediaType mediaType) const;
/**
* Update both the codec order structure and the codec string used for
......@@ -225,7 +226,6 @@ class Account : public Serializable, public std::enable_shared_from_this<Account
*/
void setActiveCodecs(const std::vector<unsigned>& list);
std::shared_ptr<AccountCodecInfo> searchCodecById(unsigned codecId, MediaType mediaType);
std::vector<unsigned> getActiveAccountCodecInfoIdList(MediaType mediaType) const;
std::vector<std::shared_ptr<AccountCodecInfo>> getActiveAccountCodecInfoList(MediaType mediaType) const;
std::shared_ptr<AccountCodecInfo> searchCodecByPayload(unsigned payload, MediaType mediaType);
......@@ -453,8 +453,7 @@ class Account : public Serializable, public std::enable_shared_from_this<Account
*/
std::shared_ptr<AccountCodecInfo> searchCodecByName(std::string name, MediaType mediaType);
std::vector<unsigned> getAccountCodecInfoIdList(MediaType mediaType) const;
void desactivateAllMedia(MediaType mediaType);
void setAllCodecsActive(MediaType mediaType, bool active);
};
} // namespace ring
......
......@@ -79,7 +79,7 @@ IAXCall::getSupportedFormat(const std::string &accountID) const
int format_mask = 0;
if (account) {
std::vector<unsigned> codecs{account->getActiveAccountCodecInfoIdList(MEDIA_AUDIO)};
std::vector<unsigned> codecs{account->getActiveCodecs(MEDIA_AUDIO)};
for (const auto &i : codecs)
format_mask |= codecToASTFormat(i);
......@@ -95,7 +95,7 @@ IAXCall::getFirstMatchingFormat(int needles, const std::string &accountID) const
const auto account = Manager::instance().getAccount(accountID);
if (account != NULL) {
std::vector<unsigned> codecs{account->getActiveAccountCodecInfoIdList(MEDIA_AUDIO)};
std::vector<unsigned> codecs{account->getActiveCodecs(MEDIA_AUDIO)};
for (const auto &i : codecs) {
int format_mask = codecToASTFormat(i);
......
......@@ -262,7 +262,7 @@ 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->getActiveAccountCodecInfoIdList(MEDIA_AUDIO).empty()) {
if (not account->hasActiveCodec(MEDIA_AUDIO)) {
try_respond_stateless(endpt_, rdata, PJSIP_SC_NOT_ACCEPTABLE_HERE, NULL, NULL, NULL);
return PJ_FALSE;
......
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