File: window-basic-settings.hpp

package info (click to toggle)
obs-studio 30.2.3%2Bdfsg-3.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,928 kB
  • sloc: ansic: 202,137; cpp: 112,403; makefile: 868; python: 599; sh: 275; javascript: 19
file content (537 lines) | stat: -rw-r--r-- 15,117 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
/******************************************************************************
    Copyright (C) 2023 by Lain Bailey <lain@obsproject.com>
                          Philippe Groarke <philippe.groarke@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#pragma once

#include <util/util.hpp>
#include <QDialog>
#include <QPointer>
#include <memory>
#include <string>

#include <obs.hpp>

#include "auth-base.hpp"
#include "ffmpeg-utils.hpp"
#include "obs-app-theming.hpp"

class OBSBasic;
class QAbstractButton;
class QRadioButton;
class QComboBox;
class QCheckBox;
class QLabel;
class QButtonGroup;
class OBSPropertiesView;
class OBSHotkeyWidget;

#include "ui_OBSBasicSettings.h"

#define VOLUME_METER_DECAY_FAST 23.53
#define VOLUME_METER_DECAY_MEDIUM 11.76
#define VOLUME_METER_DECAY_SLOW 8.57

class SilentUpdateCheckBox : public QCheckBox {
	Q_OBJECT

public slots:
	void setCheckedSilently(bool checked)
	{
		bool blocked = blockSignals(true);
		setChecked(checked);
		blockSignals(blocked);
	}
};

class SilentUpdateSpinBox : public QSpinBox {
	Q_OBJECT

public slots:
	void setValueSilently(int val)
	{
		bool blocked = blockSignals(true);
		setValue(val);
		blockSignals(blocked);
	}
};

std::string DeserializeConfigText(const char *value);

class OBSBasicSettings : public QDialog {
	Q_OBJECT
	Q_PROPERTY(QIcon generalIcon READ GetGeneralIcon WRITE SetGeneralIcon
			   DESIGNABLE true)
	Q_PROPERTY(QIcon appearanceIcon READ GetAppearanceIcon WRITE
			   SetAppearanceIcon DESIGNABLE true)
	Q_PROPERTY(QIcon streamIcon READ GetStreamIcon WRITE SetStreamIcon
			   DESIGNABLE true)
	Q_PROPERTY(QIcon outputIcon READ GetOutputIcon WRITE SetOutputIcon
			   DESIGNABLE true)
	Q_PROPERTY(QIcon audioIcon READ GetAudioIcon WRITE SetAudioIcon
			   DESIGNABLE true)
	Q_PROPERTY(QIcon videoIcon READ GetVideoIcon WRITE SetVideoIcon
			   DESIGNABLE true)
	Q_PROPERTY(QIcon hotkeysIcon READ GetHotkeysIcon WRITE SetHotkeysIcon
			   DESIGNABLE true)
	Q_PROPERTY(QIcon accessibilityIcon READ GetAccessibilityIcon WRITE
			   SetAccessibilityIcon DESIGNABLE true)
	Q_PROPERTY(QIcon advancedIcon READ GetAdvancedIcon WRITE SetAdvancedIcon
			   DESIGNABLE true)

	enum Pages {
		GENERAL,
		APPEARANCE,
		STREAM,
		OUTPUT,
		AUDIO,
		VIDEO,
		HOTKEYS,
		ACCESSIBILITY,
		ADVANCED,
		NUM_PAGES
	};

private:
	OBSBasic *main;

	std::unique_ptr<Ui::OBSBasicSettings> ui;

	std::shared_ptr<Auth> auth;

	bool generalChanged = false;
	bool stream1Changed = false;
	bool outputsChanged = false;
	bool audioChanged = false;
	bool videoChanged = false;
	bool hotkeysChanged = false;
	bool a11yChanged = false;
	bool appearanceChanged = false;
	bool advancedChanged = false;
	int pageIndex = 0;
	bool loading = true;
	bool forceAuthReload = false;
	bool forceUpdateCheck = false;
	int sampleRateIndex = 0;
	int channelIndex = 0;
	bool llBufferingEnabled = false;
	bool hotkeysLoaded = false;

	int lastSimpleRecQualityIdx = 0;
	int lastServiceIdx = -1;
	int lastIgnoreRecommended = -1;
	int lastChannelSetupIdx = 0;

	static constexpr uint32_t ENCODER_HIDE_FLAGS =
		(OBS_ENCODER_CAP_DEPRECATED | OBS_ENCODER_CAP_INTERNAL);

	OBSTheme *savedTheme = nullptr;

	std::vector<FFmpegFormat> formats;

	OBSPropertiesView *streamProperties = nullptr;
	OBSPropertiesView *streamEncoderProps = nullptr;
	OBSPropertiesView *recordEncoderProps = nullptr;

	QPointer<QLabel> advOutRecWarning;
	QPointer<QLabel> simpleOutRecWarning;

	QString curPreset;
	QString curQSVPreset;
	QString curNVENCPreset;
	QString curAMDPreset;
	QString curAMDAV1Preset;

	QString curAdvStreamEncoder;
	QString curAdvRecordEncoder;

	using AudioSource_t =
		std::tuple<OBSWeakSource, QPointer<QCheckBox>,
			   QPointer<QSpinBox>, QPointer<QCheckBox>,
			   QPointer<QSpinBox>>;
	std::vector<AudioSource_t> audioSources;
	std::vector<OBSSignal> audioSourceSignals;
	OBSSignal sourceCreated;
	OBSSignal channelChanged;

	std::vector<std::pair<bool, QPointer<OBSHotkeyWidget>>> hotkeys;
	OBSSignal hotkeyRegistered;
	OBSSignal hotkeyUnregistered;

	uint32_t outputCX = 0;
	uint32_t outputCY = 0;

	QPointer<QCheckBox> simpleVodTrack;

	QPointer<QCheckBox> vodTrackCheckbox;
	QPointer<QWidget> vodTrackContainer;
	QPointer<QRadioButton> vodTrack[MAX_AUDIO_MIXES];

	QIcon hotkeyConflictIcon;

	void SaveCombo(QComboBox *widget, const char *section,
		       const char *value);
	void SaveComboData(QComboBox *widget, const char *section,
			   const char *value);
	void SaveCheckBox(QAbstractButton *widget, const char *section,
			  const char *value, bool invert = false);
	void SaveGroupBox(QGroupBox *widget, const char *section,
			  const char *value);
	void SaveEdit(QLineEdit *widget, const char *section,
		      const char *value);
	void SaveSpinBox(QSpinBox *widget, const char *section,
			 const char *value);
	void SaveText(QPlainTextEdit *widget, const char *section,
		      const char *value);
	void SaveFormat(QComboBox *combo);
	void SaveEncoder(QComboBox *combo, const char *section,
			 const char *value);

	bool ResFPSValid(obs_service_resolution *res_list, size_t res_count,
			 int max_fps);
	void ClosestResFPS(obs_service_resolution *res_list, size_t res_count,
			   int max_fps, int &new_cx, int &new_cy, int &new_fps);

	inline bool Changed() const
	{
		return generalChanged || appearanceChanged || outputsChanged ||
		       stream1Changed || audioChanged || videoChanged ||
		       advancedChanged || hotkeysChanged || a11yChanged;
	}

	inline void EnableApplyButton(bool en)
	{
		ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(en);
	}

	inline void ClearChanged()
	{
		generalChanged = false;
		stream1Changed = false;
		outputsChanged = false;
		audioChanged = false;
		videoChanged = false;
		hotkeysChanged = false;
		a11yChanged = false;
		advancedChanged = false;
		appearanceChanged = false;
		EnableApplyButton(false);
	}

	template<typename Widget, typename WidgetParent, typename... SignalArgs,
		 typename... SlotArgs>
	void HookWidget(Widget *widget,
			void (WidgetParent::*signal)(SignalArgs...),
			void (OBSBasicSettings::*slot)(SlotArgs...))
	{
		QObject::connect(widget, signal, this, slot);
		widget->setProperty("changed", QVariant(false));
	}

	bool QueryChanges();
	bool QueryAllowedToClose();

	void ResetEncoders(bool streamOnly = false);
	void LoadColorRanges();
	void LoadColorSpaces();
	void LoadColorFormats();
	void LoadFormats();
	void ReloadCodecs(const FFmpegFormat &format);

	void UpdateColorFormatSpaceWarning();

	void LoadGeneralSettings();
	void LoadStream1Settings();
	void LoadOutputSettings();
	void LoadAudioSettings();
	void LoadVideoSettings();
	void
	LoadHotkeySettings(obs_hotkey_id ignoreKey = OBS_INVALID_HOTKEY_ID);
	void LoadA11ySettings(bool presetChange = false);
	void LoadAppearanceSettings(bool reload = false);
	void LoadAdvancedSettings();
	void LoadSettings(bool changedOnly);

	OBSPropertiesView *CreateEncoderPropertyView(const char *encoder,
						     const char *path,
						     bool changed = false);

	/* general */
	void LoadLanguageList();
	void LoadThemeList(bool firstLoad);
	void LoadBranchesList();

	/* stream */
	void InitStreamPage();
	bool IsCustomService() const;
	inline bool IsWHIP() const;
	void LoadServices(bool showAll);
	void OnOAuthStreamKeyConnected();
	void OnAuthConnected();
	QString lastService;
	QString protocol;
	QString lastCustomServer;
	int prevLangIndex;
	bool prevBrowserAccel;

	void ServiceChanged(bool resetFields = false);
	QString FindProtocol();
	void UpdateServerList();
	void UpdateKeyLink();
	void UpdateVodTrackSetting();
	void UpdateServiceRecommendations();
	void UpdateMoreInfoLink();
	void UpdateAdvNetworkGroup();

	/* Appearance */
	void InitAppearancePage();

	bool IsCustomServer();

private slots:
	void UpdateMultitrackVideo();
	void RecreateOutputResolutionWidget();
	bool UpdateResFPSLimits();
	void DisplayEnforceWarning(bool checked);
	void on_show_clicked();
	void on_authPwShow_clicked();
	void on_connectAccount_clicked();
	void on_disconnectAccount_clicked();
	void on_useStreamKey_clicked();
	void on_useAuth_toggled();
	void on_server_currentIndexChanged(int index);

	void on_hotkeyFilterReset_clicked();
	void on_hotkeyFilterSearch_textChanged(const QString text);
	void on_hotkeyFilterInput_KeyChanged(obs_key_combination_t combo);

private:
	/* output */
	void LoadSimpleOutputSettings();
	void LoadAdvOutputStreamingSettings();
	void LoadAdvOutputStreamingEncoderProperties();
	void LoadAdvOutputRecordingSettings();
	void LoadAdvOutputRecordingEncoderProperties();
	void LoadAdvOutputFFmpegSettings();
	void LoadAdvOutputAudioSettings();
	void SetAdvOutputFFmpegEnablement(FFmpegCodecType encoderType,
					  bool enabled,
					  bool enableEncode = false);

	/* audio */
	void LoadListValues(QComboBox *widget, obs_property_t *prop, int index);
	void LoadAudioDevices();
	void LoadAudioSources();

	/* video */
	void LoadRendererList();
	void ResetDownscales(uint32_t cx, uint32_t cy,
			     bool ignoreAllSignals = false);
	void LoadDownscaleFilters();
	void LoadResolutionLists();
	void LoadFPSData();

	/* a11y */
	void UpdateA11yColors();
	void SetDefaultColors();
	void ResetDefaultColors();
	QColor GetColor(uint32_t colorVal, QString label);
	uint32_t preset = 0;
	uint32_t selectRed = 0x0000FF;
	uint32_t selectGreen = 0x00FF00;
	uint32_t selectBlue = 0xFF7F00;
	uint32_t mixerGreen = 0x267f26;
	uint32_t mixerYellow = 0x267f7f;
	uint32_t mixerRed = 0x26267f;
	uint32_t mixerGreenActive = 0x4cff4c;
	uint32_t mixerYellowActive = 0x4cffff;
	uint32_t mixerRedActive = 0x4c4cff;

	void SaveGeneralSettings();
	void SaveStream1Settings();
	void SaveOutputSettings();
	void SaveAudioSettings();
	void SaveVideoSettings();
	void SaveHotkeySettings();
	void SaveA11ySettings();
	void SaveAppearanceSettings();
	void SaveAdvancedSettings();
	void SaveSettings();

	void SearchHotkeys(const QString &text,
			   obs_key_combination_t filterCombo);

	void UpdateSimpleOutStreamDelayEstimate();
	void UpdateAdvOutStreamDelayEstimate();

	void FillSimpleRecordingValues();
	void FillAudioMonitoringDevices();

	void RecalcOutputResPixels(const char *resText);

	bool AskIfCanCloseSettings();

	void UpdateYouTubeAppDockSettings();

	QIcon generalIcon;
	QIcon appearanceIcon;
	QIcon streamIcon;
	QIcon outputIcon;
	QIcon audioIcon;
	QIcon videoIcon;
	QIcon hotkeysIcon;
	QIcon accessibilityIcon;
	QIcon advancedIcon;

	QIcon GetGeneralIcon() const;
	QIcon GetAppearanceIcon() const;
	QIcon GetStreamIcon() const;
	QIcon GetOutputIcon() const;
	QIcon GetAudioIcon() const;
	QIcon GetVideoIcon() const;
	QIcon GetHotkeysIcon() const;
	QIcon GetAccessibilityIcon() const;
	QIcon GetAdvancedIcon() const;

	int CurrentFLVTrack();
	int SimpleOutGetSelectedAudioTracks();
	int AdvOutGetSelectedAudioTracks();
	int AdvOutGetStreamingSelectedAudioTracks();

	OBSService GetStream1Service();

	bool ServiceAndVCodecCompatible();
	bool ServiceAndACodecCompatible();
	bool ServiceSupportsCodecCheck();

	inline bool AllowsMultiTrack(const char *protocol);
	void SwapMultiTrack(const char *protocol);

private slots:
	void on_theme_activated(int idx);
	void on_themeVariant_activated(int idx);

	void on_listWidget_itemSelectionChanged();
	void on_buttonBox_clicked(QAbstractButton *button);

	void on_service_currentIndexChanged(int idx);
	void on_customServer_textChanged(const QString &text);
	void on_simpleOutputBrowse_clicked();
	void on_advOutRecPathBrowse_clicked();
	void on_advOutFFPathBrowse_clicked();
	void on_advOutEncoder_currentIndexChanged();
	void on_advOutRecEncoder_currentIndexChanged(int idx);
	void on_advOutFFIgnoreCompat_stateChanged(int state);
	void on_advOutFFFormat_currentIndexChanged(int idx);
	void on_advOutFFAEncoder_currentIndexChanged(int idx);
	void on_advOutFFVEncoder_currentIndexChanged(int idx);
	void on_advOutFFType_currentIndexChanged(int idx);

	void on_colorFormat_currentIndexChanged(int idx);
	void on_colorSpace_currentIndexChanged(int idx);

	void on_filenameFormatting_textEdited(const QString &text);
	void on_outputResolution_editTextChanged(const QString &text);
	void on_baseResolution_editTextChanged(const QString &text);

	void on_disableOSXVSync_clicked();

	void on_choose1_clicked();
	void on_choose2_clicked();
	void on_choose3_clicked();
	void on_choose4_clicked();
	void on_choose5_clicked();
	void on_choose6_clicked();
	void on_choose7_clicked();
	void on_choose8_clicked();
	void on_choose9_clicked();
	void on_colorPreset_currentIndexChanged(int idx);

	void GeneralChanged();

#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
	void HideOBSWindowWarning(Qt::CheckState state);
#else
	void HideOBSWindowWarning(int state);
#endif
	void AudioChanged();
	void AudioChangedRestart();
	void ReloadAudioSources();
	void SurroundWarning(int idx);
	void SpeakerLayoutChanged(int idx);
	void LowLatencyBufferingChanged(bool checked);
	void UpdateAudioWarnings();
	void OutputsChanged();
	void Stream1Changed();
	void VideoChanged();
	void VideoChangedResolution();
	void HotkeysChanged();
	bool ScanDuplicateHotkeys(QFormLayout *layout);
	void ReloadHotkeys(obs_hotkey_id ignoreKey = OBS_INVALID_HOTKEY_ID);
	void A11yChanged();
	void AppearanceChanged();
	void AdvancedChanged();
	void AdvancedChangedRestart();

	void UpdateStreamDelayEstimate();

	void UpdateAutomaticReplayBufferCheckboxes();

	void AdvOutSplitFileChanged();
	void AdvOutRecCheckWarnings();
	void AdvOutRecCheckCodecs();

	void SimpleRecordingQualityChanged();
	void SimpleRecordingEncoderChanged();
	void SimpleRecordingQualityLosslessWarning(int idx);

	void SimpleReplayBufferChanged();
	void AdvReplayBufferChanged();

	void SimpleStreamingEncoderChanged();

	OBSService SpawnTempService();

	void SetGeneralIcon(const QIcon &icon);
	void SetAppearanceIcon(const QIcon &icon);
	void SetStreamIcon(const QIcon &icon);
	void SetOutputIcon(const QIcon &icon);
	void SetAudioIcon(const QIcon &icon);
	void SetVideoIcon(const QIcon &icon);
	void SetHotkeysIcon(const QIcon &icon);
	void SetAccessibilityIcon(const QIcon &icon);
	void SetAdvancedIcon(const QIcon &icon);

	void UseStreamKeyAdvClicked();

	void SimpleStreamAudioEncoderChanged();
	void AdvAudioEncodersChanged();

protected:
	virtual void closeEvent(QCloseEvent *event) override;
	virtual void showEvent(QShowEvent *event) override;
	void reject() override;

public:
	OBSBasicSettings(QWidget *parent);
	~OBSBasicSettings();

	inline const QIcon &GetHotkeyConflictIcon() const
	{
		return hotkeyConflictIcon;
	}
};