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