diff --git a/src/client/configurationmanager.cpp b/src/client/configurationmanager.cpp index a4ae58ee5d05e2f853c1d682d9858f22048bc868..17ac9789b08e5e7a2f67725206f67cec02cbacab 100644 --- a/src/client/configurationmanager.cpp +++ b/src/client/configurationmanager.cpp @@ -406,30 +406,35 @@ setCodecDetails(const std::string& accountID, return false; } - if (codec->systemCodecInfo.mediaType & ring::MEDIA_AUDIO) { - if (auto foundCodec = std::static_pointer_cast<ring::AccountAudioCodecInfo>(codec)) { - foundCodec->setCodecSpecifications(details); - ring::emitSignal<ConfigurationSignal::MediaParametersChanged>(accountID); - return true; + try { + if (codec->systemCodecInfo.mediaType & ring::MEDIA_AUDIO) { + if (auto foundCodec = std::static_pointer_cast<ring::AccountAudioCodecInfo>(codec)) { + foundCodec->setCodecSpecifications(details); + ring::emitSignal<ConfigurationSignal::MediaParametersChanged>(accountID); + return true; + } } - } - if (codec->systemCodecInfo.mediaType & ring::MEDIA_VIDEO) { - if (auto foundCodec = std::static_pointer_cast<ring::AccountVideoCodecInfo>(codec)) { - foundCodec->setCodecSpecifications(details); - RING_WARN("parameters for %s changed ", - foundCodec->systemCodecInfo.name.c_str()); - if (auto call = ring::Manager::instance().getCurrentCall()) { - if (call->useVideoCodec(foundCodec.get())) { - RING_WARN("%s running. Need to restart encoding", - foundCodec->systemCodecInfo.name.c_str()); - call->restartMediaSender(); + if (codec->systemCodecInfo.mediaType & ring::MEDIA_VIDEO) { + if (auto foundCodec = std::static_pointer_cast<ring::AccountVideoCodecInfo>(codec)) { + foundCodec->setCodecSpecifications(details); + RING_WARN("parameters for %s changed ", + foundCodec->systemCodecInfo.name.c_str()); + if (auto call = ring::Manager::instance().getCurrentCall()) { + if (call->useVideoCodec(foundCodec.get())) { + RING_WARN("%s running. Need to restart encoding", + foundCodec->systemCodecInfo.name.c_str()); + call->restartMediaSender(); + } } + ring::emitSignal<ConfigurationSignal::MediaParametersChanged>(accountID); + return true; } - ring::emitSignal<ConfigurationSignal::MediaParametersChanged>(accountID); - return true; } + } catch (const std::exception& e) { + RING_ERR("Cannot set codec specifications: %s", e.what()); } + return false; } diff --git a/src/media/media_codec.cpp b/src/media/media_codec.cpp index 6af478e776b9c9624333cf7ec2a525cba8477446..4922f3ecc95891f0b5c9398663b48b3939608c51 100644 --- a/src/media/media_codec.cpp +++ b/src/media/media_codec.cpp @@ -126,10 +126,8 @@ SystemVideoCodecInfo::getCodecSpecifications() }; } -AccountCodecInfo::AccountCodecInfo(const SystemCodecInfo& sysCodecInfo) +AccountCodecInfo::AccountCodecInfo(const SystemCodecInfo& sysCodecInfo) noexcept : systemCodecInfo(sysCodecInfo) - , order(0) - , isActive(true) , payloadType(sysCodecInfo.payloadType) , bitrate(sysCodecInfo.bitrate) { @@ -139,8 +137,31 @@ AccountCodecInfo::AccountCodecInfo(const SystemCodecInfo& sysCodecInfo) quality = SystemCodecInfo::DEFAULT_NO_QUALITY; } -AccountCodecInfo::~AccountCodecInfo() -{} +AccountCodecInfo& +AccountCodecInfo::operator=(AccountCodecInfo&& o) +{ + if (&systemCodecInfo != &o.systemCodecInfo) + throw std::runtime_error("cannot assign codec info object pointing to another codec."); + order = o.order; + isActive = o.isActive; + payloadType = o.payloadType; + bitrate = o.bitrate; + quality = o.quality; + return *this; +} + +AccountCodecInfo& +AccountCodecInfo::operator=(const AccountCodecInfo& o) +{ + if (&systemCodecInfo != &o.systemCodecInfo) + throw std::runtime_error("cannot assign codec info object pointing to another codec."); + order = o.order; + isActive = o.isActive; + payloadType = o.payloadType; + bitrate = o.bitrate; + quality = o.quality; + return *this; +} AccountAudioCodecInfo::AccountAudioCodecInfo(const SystemAudioCodecInfo& sysCodecInfo) : AccountCodecInfo(sysCodecInfo) @@ -156,23 +177,19 @@ AccountAudioCodecInfo::getCodecSpecifications() {DRing::Account::ConfProperties::CodecInfo::BITRATE, to_string(bitrate)}, {DRing::Account::ConfProperties::CodecInfo::SAMPLE_RATE, to_string(audioformat.sample_rate)}, {DRing::Account::ConfProperties::CodecInfo::CHANNEL_NUMBER, to_string(audioformat.nb_channels)} - }; + }; } void AccountAudioCodecInfo::setCodecSpecifications(const std::map<std::string, std::string>& details) { - auto it = details.find(DRing::Account::ConfProperties::CodecInfo::BITRATE); - if (it != details.end()) - bitrate = ring::stoi(it->second); - - it = details.find(DRing::Account::ConfProperties::CodecInfo::SAMPLE_RATE); - if (it != details.end()) - audioformat.sample_rate = ring::stoi(it->second); + decltype(bitrate) tmp_bitrate = ring::stoi(details.at(DRing::Account::ConfProperties::CodecInfo::BITRATE)); + decltype(audioformat) tmp_audioformat = audioformat; + tmp_audioformat.sample_rate = ring::stoi(details.at(DRing::Account::ConfProperties::CodecInfo::SAMPLE_RATE)); - it = details.find(DRing::Account::ConfProperties::CodecInfo::CHANNEL_NUMBER); - if (it != details.end()) - audioformat.nb_channels = ring::stoi(it->second); + // copy back if no exception was raised + bitrate = tmp_bitrate; + audioformat = tmp_audioformat; } bool @@ -181,10 +198,6 @@ AccountAudioCodecInfo::isPCMG722() const return systemCodecInfo.avcodecId == AV_CODEC_ID_ADPCM_G722; } - -AccountAudioCodecInfo::~AccountAudioCodecInfo() -{} - AccountVideoCodecInfo::AccountVideoCodecInfo(const SystemVideoCodecInfo& sysCodecInfo) : AccountCodecInfo(sysCodecInfo) , frameRate(sysCodecInfo.frameRate) @@ -205,30 +218,32 @@ AccountVideoCodecInfo::getCodecSpecifications() {DRing::Account::ConfProperties::CodecInfo::MIN_QUALITY, to_string(systemCodecInfo.minQuality)}, {DRing::Account::ConfProperties::CodecInfo::FRAME_RATE, to_string(frameRate)}, {DRing::Account::ConfProperties::CodecInfo::AUTO_QUALITY_ENABLED, bool_to_str(isAutoQualityEnabled)} - }; + }; } void AccountVideoCodecInfo::setCodecSpecifications(const std::map<std::string, std::string>& details) { + auto copy = *this; + auto it = details.find(DRing::Account::ConfProperties::CodecInfo::BITRATE); if (it != details.end()) - bitrate = ring::stoi(it->second); + copy.bitrate = ring::stoi(it->second); it = details.find(DRing::Account::ConfProperties::CodecInfo::FRAME_RATE); if (it != details.end()) - frameRate = ring::stoi(it->second); + copy.frameRate = ring::stoi(it->second); it = details.find(DRing::Account::ConfProperties::CodecInfo::QUALITY); if (it != details.end()) - quality = ring::stoi(it->second); + copy.quality = ring::stoi(it->second); it = details.find(DRing::Account::ConfProperties::CodecInfo::AUTO_QUALITY_ENABLED); if (it != details.end()) - isAutoQualityEnabled = (it->second == TRUE_STR) ? true : false; -} + copy.isAutoQualityEnabled = (it->second == TRUE_STR) ? true : false; -AccountVideoCodecInfo::~AccountVideoCodecInfo() -{} + // copy back if no exception was raised + *this = std::move(copy); +} } // namespace ring diff --git a/src/media/media_codec.h b/src/media/media_codec.h index 810059e49dec6c951c9ff20258fac02b1b7021e7..0aac1d3720f9de41e09498be517035f45ee83edb 100644 --- a/src/media/media_codec.h +++ b/src/media/media_codec.h @@ -152,12 +152,15 @@ struct SystemVideoCodecInfo : SystemCodecInfo */ struct AccountCodecInfo { - AccountCodecInfo(const SystemCodecInfo& sysCodecInfo); - ~AccountCodecInfo(); + AccountCodecInfo(const SystemCodecInfo& sysCodecInfo) noexcept; + AccountCodecInfo(const AccountCodecInfo&) noexcept = default; + AccountCodecInfo(AccountCodecInfo&&) noexcept = default; + AccountCodecInfo& operator=(const AccountCodecInfo&); + AccountCodecInfo& operator=(AccountCodecInfo&&); const SystemCodecInfo& systemCodecInfo; - unsigned order; /*used to define prefered codec list order in UI*/ - bool isActive; + unsigned order {0}; /*used to define prefered codec list order in UI*/ + bool isActive {true}; /* account custom values */ unsigned payloadType; unsigned bitrate; @@ -169,7 +172,6 @@ struct AccountCodecInfo struct AccountAudioCodecInfo : AccountCodecInfo { AccountAudioCodecInfo(const SystemAudioCodecInfo& sysCodecInfo); - ~AccountAudioCodecInfo(); std::map<std::string, std::string> getCodecSpecifications(); void setCodecSpecifications(const std::map<std::string, std::string>& details); @@ -182,7 +184,6 @@ struct AccountAudioCodecInfo : AccountCodecInfo struct AccountVideoCodecInfo : AccountCodecInfo { AccountVideoCodecInfo(const SystemVideoCodecInfo& sysCodecInfo); - ~AccountVideoCodecInfo(); void setCodecSpecifications(const std::map<std::string, std::string>& details); std::map<std::string, std::string> getCodecSpecifications();