Line data Source code
1 : /* 2 : * Copyright (C) 2004-2026 Savoir-faire Linux Inc. 3 : * 4 : * This program is free software: you can redistribute it and/or modify 5 : * it under the terms of the GNU General Public License as published by 6 : * the Free Software Foundation, either version 3 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * This program is distributed in the hope that it will be useful, 10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : * GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License 15 : * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 : */ 17 : 18 : #ifndef __PREFERENCE_H__ 19 : #define __PREFERENCE_H__ 20 : 21 : #include "config/serializable.h" 22 : #include "client/jami_signal.h" 23 : #include <string> 24 : #include <map> 25 : #include <set> 26 : #include <vector> 27 : #include <chrono> 28 : 29 : namespace YAML { 30 : class Emitter; 31 : class Node; 32 : } // namespace YAML 33 : 34 : extern "C" { 35 : struct pjsip_msg; 36 : } 37 : 38 : namespace jami { 39 : 40 : class AudioLayer; 41 : 42 : class Preferences : public Serializable 43 : { 44 : public: 45 : static const char* const DFT_ZONE; 46 : static const char* const REGISTRATION_EXPIRE_KEY; 47 : 48 : Preferences(); 49 : 50 : void serialize(YAML::Emitter& out) const override; 51 : void unserialize(const YAML::Node& in) override; 52 : 53 3645 : const std::string& getAccountOrder() const { return accountOrder_; } 54 : 55 : // flush invalid accountIDs from account order 56 : void verifyAccountOrder(const std::vector<std::string>& accounts); 57 : 58 : void addAccount(const std::string& acc); 59 : void removeAccount(const std::string& acc); 60 : 61 0 : void setAccountOrder(const std::string& ord) { accountOrder_ = ord; } 62 : 63 : bool isAccountPending(const std::string& accountId) const; 64 : bool addPendingAccountId(const std::string& accountId); 65 : bool removePendingAccountId(const std::string& accountId); 66 : 67 0 : int getHistoryLimit() const { return historyLimit_; } 68 : 69 0 : void setHistoryLimit(int lim) { historyLimit_ = lim; } 70 : 71 95 : std::chrono::seconds getRingingTimeout() const { return std::chrono::seconds(ringingTimeout_); } 72 : 73 0 : void setRingingTimeout(std::chrono::seconds timeout) { ringingTimeout_ = timeout.count(); } 74 : 75 : int getHistoryMaxCalls() const { return historyMaxCalls_; } 76 : 77 : void setHistoryMaxCalls(int max) { historyMaxCalls_ = max; } 78 : 79 31 : std::string getZoneToneChoice() const { return zoneToneChoice_; } 80 : 81 : void setZoneToneChoice(const std::string& str) { zoneToneChoice_ = str; } 82 : 83 : int getPortNum() const { return portNum_; } 84 : 85 : void setPortNum(int port) { portNum_ = port; } 86 : 87 : bool getSearchBarDisplay() const { return searchBarDisplay_; } 88 : 89 : void setSearchBarDisplay(bool search) { searchBarDisplay_ = search; } 90 : 91 9 : bool getMd5Hash() const { return md5Hash_; } 92 : void setMd5Hash(bool md5) { md5Hash_ = md5; } 93 : 94 : private: 95 : std::string accountOrder_; 96 : int historyLimit_; 97 : int historyMaxCalls_; 98 : int ringingTimeout_; 99 : std::string zoneToneChoice_; 100 : int portNum_; 101 : bool searchBarDisplay_; 102 : bool md5Hash_; 103 : std::set<std::string> pendingAccountIds_; 104 : constexpr static const char* const CONFIG_LABEL = "preferences"; 105 : }; 106 : 107 : class VoipPreference : public Serializable 108 : { 109 : public: 110 : VoipPreference(); 111 : 112 : void serialize(YAML::Emitter& out) const override; 113 : void unserialize(const YAML::Node& in) override; 114 : 115 0 : bool getPlayDtmf() const { return playDtmf_; } 116 : 117 0 : void setPlayDtmf(bool dtmf) { playDtmf_ = dtmf; } 118 : 119 581 : bool getPlayTones() const { return playTones_; } 120 : 121 : void setPlayTones(bool tone) { playTones_ = tone; } 122 : 123 0 : int getPulseLength() const { return pulseLength_; } 124 : 125 : void setPulseLength(int length) { pulseLength_ = length; } 126 : 127 : private: 128 : bool playDtmf_; 129 : bool playTones_; 130 : int pulseLength_; 131 : constexpr static const char* const CONFIG_LABEL = "voipPreferences"; 132 : }; 133 : 134 : class AudioPreference : public Serializable 135 : { 136 : public: 137 : AudioPreference(); 138 : AudioLayer* createAudioLayer(); 139 : 140 : static std::vector<std::string> getSupportedAudioManagers(); 141 : 142 0 : const std::string& getAudioApi() const { return audioApi_; } 143 : 144 0 : void setAudioApi(const std::string& api) { audioApi_ = api; } 145 : 146 : void serialize(YAML::Emitter& out) const override; 147 : 148 : void unserialize(const YAML::Node& in) override; 149 : 150 : // alsa preference 151 31 : int getAlsaCardin() const { return alsaCardin_; } 152 : 153 0 : void setAlsaCardin(int c) { alsaCardin_ = c; } 154 : 155 31 : int getAlsaCardout() const { return alsaCardout_; } 156 : 157 0 : void setAlsaCardout(int c) { alsaCardout_ = c; } 158 : 159 31 : int getAlsaCardRingtone() const { return alsaCardRingtone_; } 160 : 161 0 : void setAlsaCardRingtone(int c) { alsaCardRingtone_ = c; } 162 : 163 31 : const std::string& getAlsaPlugin() const { return alsaPlugin_; } 164 : 165 0 : void setAlsaPlugin(const std::string& p) { alsaPlugin_ = p; } 166 : 167 : int getAlsaSmplrate() const { return alsaSmplrate_; } 168 : 169 : void setAlsaSmplrate(int r) { alsaSmplrate_ = r; } 170 : 171 : // pulseaudio preference 172 0 : const std::string& getPulseDevicePlayback() const { return pulseDevicePlayback_; } 173 : 174 0 : void setPulseDevicePlayback(const std::string& p) { pulseDevicePlayback_ = p; } 175 : 176 0 : const std::string& getPulseDeviceRecord() const { return pulseDeviceRecord_; } 177 0 : void setPulseDeviceRecord(const std::string& r) { pulseDeviceRecord_ = r; } 178 : 179 0 : const std::string& getPulseDeviceRingtone() const { return pulseDeviceRingtone_; } 180 : 181 0 : void setPulseDeviceRingtone(const std::string& r) { pulseDeviceRingtone_ = r; } 182 : 183 : // portaudio preference 184 : const std::string& getPortAudioDevicePlayback() const { return portaudioDevicePlayback_; } 185 : 186 : void setPortAudioDevicePlayback(const std::string& p) { portaudioDevicePlayback_ = p; } 187 : 188 : const std::string& getPortAudioDeviceRecord() const { return portaudioDeviceRecord_; } 189 : 190 : void setPortAudioDeviceRecord(const std::string& r) { portaudioDeviceRecord_ = r; } 191 : 192 : const std::string& getPortAudioDeviceRingtone() const { return portaudioDeviceRingtone_; } 193 : 194 : void setPortAudioDeviceRingtone(const std::string& r) { portaudioDeviceRingtone_ = r; } 195 : 196 : // general preference 197 2 : const std::string& getRecordPath() const { return recordpath_; } 198 : 199 : // Returns true if directory is writeable 200 : bool setRecordPath(const std::string& r); 201 : 202 170 : bool getIsAlwaysRecording() const { return alwaysRecording_; } 203 : 204 0 : void setIsAlwaysRecording(bool rec) { alwaysRecording_ = rec; } 205 : 206 34 : double getVolumemic() const { return volumemic_; } 207 2390 : void setVolumemic(double m) { volumemic_ = m; } 208 : 209 34 : double getVolumespkr() const { return volumespkr_; } 210 2390 : void setVolumespkr(double s) { volumespkr_ = s; } 211 : 212 34 : bool isAGCEnabled() const { return agcEnabled_; } 213 : 214 0 : void setAGCState(bool enabled) { agcEnabled_ = enabled; } 215 : 216 34 : const std::string& getNoiseReduce() const { return denoise_; } 217 : 218 0 : void setNoiseReduce(const std::string& enabled) { denoise_ = enabled; } 219 : 220 34 : bool getCaptureMuted() const { return captureMuted_; } 221 : 222 2390 : void setCaptureMuted(bool muted) { captureMuted_ = muted; } 223 : 224 34 : bool getPlaybackMuted() const { return playbackMuted_; } 225 : 226 2390 : void setPlaybackMuted(bool muted) { playbackMuted_ = muted; } 227 : 228 34 : const std::string& getAudioProcessor() const { return audioProcessor_; } 229 : 230 : void setAudioProcessor(const std::string& ap) { audioProcessor_ = ap; } 231 : 232 34 : bool getVadEnabled() const { return vadEnabled_; } 233 : 234 0 : void setVad(bool enable) { vadEnabled_ = enable; } 235 : 236 34 : const std::string& getEchoCanceller() const { return echoCanceller_; } 237 : 238 0 : void setEchoCancel(const std::string& canceller) { echoCanceller_ = canceller; } 239 : 240 : private: 241 : std::string audioApi_; 242 : 243 : // alsa preference 244 : int alsaCardin_; 245 : int alsaCardout_; 246 : int alsaCardRingtone_; 247 : std::string alsaPlugin_; 248 : int alsaSmplrate_; 249 : 250 : // pulseaudio preference 251 : std::string pulseDevicePlayback_; 252 : std::string pulseDeviceRecord_; 253 : std::string pulseDeviceRingtone_; 254 : 255 : // portaudio preference 256 : std::string portaudioDevicePlayback_; 257 : std::string portaudioDeviceRecord_; 258 : std::string portaudioDeviceRingtone_; 259 : 260 : // general preference 261 : std::string recordpath_; 262 : bool alwaysRecording_; 263 : double volumemic_; 264 : double volumespkr_; 265 : 266 : // audio processor preferences 267 : std::string audioProcessor_; 268 : std::string denoise_; 269 : bool agcEnabled_; 270 : bool vadEnabled_; 271 : std::string echoCanceller_; 272 : 273 : bool captureMuted_; 274 : bool playbackMuted_; 275 : constexpr static const char* const CONFIG_LABEL = "audio"; 276 : }; 277 : 278 : #ifdef ENABLE_VIDEO 279 : class VideoPreferences : public Serializable 280 : { 281 : public: 282 : VideoPreferences(); 283 : 284 : void serialize(YAML::Emitter& out) const override; 285 : void unserialize(const YAML::Node& in) override; 286 : 287 308 : bool getDecodingAccelerated() const { return decodingAccelerated_; } 288 : 289 0 : bool setDecodingAccelerated(bool decodingAccelerated) 290 : { 291 0 : if (decodingAccelerated_ != decodingAccelerated) { 292 0 : decodingAccelerated_ = decodingAccelerated; 293 0 : emitSignal<libjami::ConfigurationSignal::HardwareDecodingChanged>(decodingAccelerated_); 294 0 : return true; 295 : } 296 0 : return false; 297 : } 298 : 299 725 : bool getEncodingAccelerated() const { return encodingAccelerated_; } 300 : 301 0 : bool setEncodingAccelerated(bool encodingAccelerated) 302 : { 303 0 : if (encodingAccelerated_ != encodingAccelerated) { 304 0 : encodingAccelerated_ = encodingAccelerated; 305 0 : emitSignal<libjami::ConfigurationSignal::HardwareEncodingChanged>(encodingAccelerated_); 306 0 : return true; 307 : } 308 0 : return false; 309 : } 310 : 311 0 : bool getRecordPreview() const { return recordPreview_; } 312 : 313 0 : void setRecordPreview(bool rec) { recordPreview_ = rec; } 314 : 315 2 : int getRecordQuality() const { return recordQuality_; } 316 : 317 0 : void setRecordQuality(int rec) { recordQuality_ = rec; } 318 : 319 37 : const std::string& getConferenceResolution() const { return conferenceResolution_; } 320 : 321 : void setConferenceResolution(const std::string& res) { conferenceResolution_ = res; } 322 : 323 : private: 324 : bool decodingAccelerated_; 325 : bool encodingAccelerated_; 326 : bool recordPreview_; 327 : int recordQuality_; 328 : std::string conferenceResolution_; 329 : constexpr static const char* const CONFIG_LABEL = "video"; 330 : }; 331 : #endif // ENABLE_VIDEO 332 : 333 : #ifdef ENABLE_PLUGIN 334 : class PluginPreferences : public Serializable 335 : { 336 : public: 337 : PluginPreferences(); 338 : 339 : void serialize(YAML::Emitter& out) const override; 340 : void unserialize(const YAML::Node& in) override; 341 : 342 34 : bool getPluginsEnabled() const { return pluginsEnabled_; } 343 : 344 0 : void setPluginsEnabled(bool pluginsEnabled) { pluginsEnabled_ = pluginsEnabled; } 345 : 346 8 : std::vector<std::string> getLoadedPlugins() const 347 : { 348 8 : std::vector<std::string> v(loadedPlugins_.begin(), loadedPlugins_.end()); 349 8 : return v; 350 : } 351 : 352 0 : std::vector<std::string> getInstalledPlugins() const 353 : { 354 0 : return std::vector<std::string>(installedPlugins_.begin(), installedPlugins_.end()); 355 : } 356 : 357 0 : void saveStateLoadedPlugins(std::string plugin, bool loaded) 358 : { 359 0 : if (loaded) { 360 0 : if (loadedPlugins_.find(plugin) != loadedPlugins_.end()) 361 0 : return; 362 0 : loadedPlugins_.emplace(plugin); 363 : } else { 364 0 : auto it = loadedPlugins_.find(plugin); 365 0 : if (it != loadedPlugins_.end()) 366 0 : loadedPlugins_.erase(it); 367 : } 368 : } 369 : 370 : private: 371 : bool pluginsEnabled_; 372 : std::set<std::string> installedPlugins_; 373 : std::set<std::string> loadedPlugins_; 374 : constexpr static const char* const CONFIG_LABEL = "plugins"; 375 : }; 376 : #endif // ENABLE_PLUGIN 377 : 378 : } // namespace jami 379 : 380 : #endif