window-basic-settings.hpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain Bailey <[email protected]>
  3. Philippe Groarke <[email protected]>
  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 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ******************************************************************************/
  15. #pragma once
  16. #include <util/util.hpp>
  17. #include <QDialog>
  18. #include <QPointer>
  19. #include <memory>
  20. #include <string>
  21. #include <obs.hpp>
  22. #include "auth-base.hpp"
  23. #include "ffmpeg-utils.hpp"
  24. #include "obs-app-theming.hpp"
  25. class OBSBasic;
  26. class QAbstractButton;
  27. class QRadioButton;
  28. class QComboBox;
  29. class QCheckBox;
  30. class QLabel;
  31. class QButtonGroup;
  32. class OBSPropertiesView;
  33. class OBSHotkeyWidget;
  34. #include "ui_OBSBasicSettings.h"
  35. #define VOLUME_METER_DECAY_FAST 23.53
  36. #define VOLUME_METER_DECAY_MEDIUM 11.76
  37. #define VOLUME_METER_DECAY_SLOW 8.57
  38. class SilentUpdateCheckBox : public QCheckBox {
  39. Q_OBJECT
  40. public slots:
  41. void setCheckedSilently(bool checked)
  42. {
  43. bool blocked = blockSignals(true);
  44. setChecked(checked);
  45. blockSignals(blocked);
  46. }
  47. };
  48. class SilentUpdateSpinBox : public QSpinBox {
  49. Q_OBJECT
  50. public slots:
  51. void setValueSilently(int val)
  52. {
  53. bool blocked = blockSignals(true);
  54. setValue(val);
  55. blockSignals(blocked);
  56. }
  57. };
  58. std::string DeserializeConfigText(const char *value);
  59. class OBSBasicSettings : public QDialog {
  60. Q_OBJECT
  61. Q_PROPERTY(QIcon generalIcon READ GetGeneralIcon WRITE SetGeneralIcon
  62. DESIGNABLE true)
  63. Q_PROPERTY(QIcon appearanceIcon READ GetAppearanceIcon WRITE
  64. SetAppearanceIcon DESIGNABLE true)
  65. Q_PROPERTY(QIcon streamIcon READ GetStreamIcon WRITE SetStreamIcon
  66. DESIGNABLE true)
  67. Q_PROPERTY(QIcon outputIcon READ GetOutputIcon WRITE SetOutputIcon
  68. DESIGNABLE true)
  69. Q_PROPERTY(QIcon audioIcon READ GetAudioIcon WRITE SetAudioIcon
  70. DESIGNABLE true)
  71. Q_PROPERTY(QIcon videoIcon READ GetVideoIcon WRITE SetVideoIcon
  72. DESIGNABLE true)
  73. Q_PROPERTY(QIcon hotkeysIcon READ GetHotkeysIcon WRITE SetHotkeysIcon
  74. DESIGNABLE true)
  75. Q_PROPERTY(QIcon accessibilityIcon READ GetAccessibilityIcon WRITE
  76. SetAccessibilityIcon DESIGNABLE true)
  77. Q_PROPERTY(QIcon advancedIcon READ GetAdvancedIcon WRITE SetAdvancedIcon
  78. DESIGNABLE true)
  79. enum Pages {
  80. GENERAL,
  81. APPEARANCE,
  82. STREAM,
  83. OUTPUT,
  84. AUDIO,
  85. VIDEO,
  86. HOTKEYS,
  87. ACCESSIBILITY,
  88. ADVANCED,
  89. NUM_PAGES
  90. };
  91. private:
  92. OBSBasic *main;
  93. std::unique_ptr<Ui::OBSBasicSettings> ui;
  94. std::shared_ptr<Auth> auth;
  95. bool generalChanged = false;
  96. bool stream1Changed = false;
  97. bool outputsChanged = false;
  98. bool audioChanged = false;
  99. bool videoChanged = false;
  100. bool hotkeysChanged = false;
  101. bool a11yChanged = false;
  102. bool appearanceChanged = false;
  103. bool advancedChanged = false;
  104. int pageIndex = 0;
  105. bool loading = true;
  106. bool forceAuthReload = false;
  107. bool forceUpdateCheck = false;
  108. int sampleRateIndex = 0;
  109. int channelIndex = 0;
  110. bool llBufferingEnabled = false;
  111. bool hotkeysLoaded = false;
  112. int lastSimpleRecQualityIdx = 0;
  113. int lastServiceIdx = -1;
  114. int lastIgnoreRecommended = -1;
  115. int lastChannelSetupIdx = 0;
  116. static constexpr uint32_t ENCODER_HIDE_FLAGS =
  117. (OBS_ENCODER_CAP_DEPRECATED | OBS_ENCODER_CAP_INTERNAL);
  118. OBSTheme *savedTheme = nullptr;
  119. std::vector<FFmpegFormat> formats;
  120. OBSPropertiesView *streamProperties = nullptr;
  121. OBSPropertiesView *streamEncoderProps = nullptr;
  122. OBSPropertiesView *recordEncoderProps = nullptr;
  123. QPointer<QLabel> advOutRecWarning;
  124. QPointer<QLabel> simpleOutRecWarning;
  125. QString curPreset;
  126. QString curQSVPreset;
  127. QString curNVENCPreset;
  128. QString curAMDPreset;
  129. QString curAMDAV1Preset;
  130. QString curAdvStreamEncoder;
  131. QString curAdvRecordEncoder;
  132. using AudioSource_t =
  133. std::tuple<OBSWeakSource, QPointer<QCheckBox>,
  134. QPointer<QSpinBox>, QPointer<QCheckBox>,
  135. QPointer<QSpinBox>>;
  136. std::vector<AudioSource_t> audioSources;
  137. std::vector<OBSSignal> audioSourceSignals;
  138. OBSSignal sourceCreated;
  139. OBSSignal channelChanged;
  140. std::vector<std::pair<bool, QPointer<OBSHotkeyWidget>>> hotkeys;
  141. OBSSignal hotkeyRegistered;
  142. OBSSignal hotkeyUnregistered;
  143. uint32_t outputCX = 0;
  144. uint32_t outputCY = 0;
  145. QPointer<QCheckBox> simpleVodTrack;
  146. QPointer<QCheckBox> vodTrackCheckbox;
  147. QPointer<QWidget> vodTrackContainer;
  148. QPointer<QRadioButton> vodTrack[MAX_AUDIO_MIXES];
  149. QIcon hotkeyConflictIcon;
  150. void SaveCombo(QComboBox *widget, const char *section,
  151. const char *value);
  152. void SaveComboData(QComboBox *widget, const char *section,
  153. const char *value);
  154. void SaveCheckBox(QAbstractButton *widget, const char *section,
  155. const char *value, bool invert = false);
  156. void SaveGroupBox(QGroupBox *widget, const char *section,
  157. const char *value);
  158. void SaveEdit(QLineEdit *widget, const char *section,
  159. const char *value);
  160. void SaveSpinBox(QSpinBox *widget, const char *section,
  161. const char *value);
  162. void SaveFormat(QComboBox *combo);
  163. void SaveEncoder(QComboBox *combo, const char *section,
  164. const char *value);
  165. bool ResFPSValid(obs_service_resolution *res_list, size_t res_count,
  166. int max_fps);
  167. void ClosestResFPS(obs_service_resolution *res_list, size_t res_count,
  168. int max_fps, int &new_cx, int &new_cy, int &new_fps);
  169. inline bool Changed() const
  170. {
  171. return generalChanged || appearanceChanged || outputsChanged ||
  172. stream1Changed || audioChanged || videoChanged ||
  173. advancedChanged || hotkeysChanged || a11yChanged;
  174. }
  175. inline void EnableApplyButton(bool en)
  176. {
  177. ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(en);
  178. }
  179. inline void ClearChanged()
  180. {
  181. generalChanged = false;
  182. stream1Changed = false;
  183. outputsChanged = false;
  184. audioChanged = false;
  185. videoChanged = false;
  186. hotkeysChanged = false;
  187. a11yChanged = false;
  188. advancedChanged = false;
  189. appearanceChanged = false;
  190. EnableApplyButton(false);
  191. }
  192. template<typename Widget, typename WidgetParent, typename... SignalArgs,
  193. typename... SlotArgs>
  194. void HookWidget(Widget *widget,
  195. void (WidgetParent::*signal)(SignalArgs...),
  196. void (OBSBasicSettings::*slot)(SlotArgs...))
  197. {
  198. QObject::connect(widget, signal, this, slot);
  199. widget->setProperty("changed", QVariant(false));
  200. }
  201. bool QueryChanges();
  202. bool QueryAllowedToClose();
  203. void ResetEncoders(bool streamOnly = false);
  204. void LoadColorRanges();
  205. void LoadColorSpaces();
  206. void LoadColorFormats();
  207. void LoadFormats();
  208. void ReloadCodecs(const FFmpegFormat &format);
  209. void UpdateColorFormatSpaceWarning();
  210. void LoadGeneralSettings();
  211. void LoadStream1Settings();
  212. void LoadOutputSettings();
  213. void LoadAudioSettings();
  214. void LoadVideoSettings();
  215. void
  216. LoadHotkeySettings(obs_hotkey_id ignoreKey = OBS_INVALID_HOTKEY_ID);
  217. void LoadA11ySettings(bool presetChange = false);
  218. void LoadAppearanceSettings(bool reload = false);
  219. void LoadAdvancedSettings();
  220. void LoadSettings(bool changedOnly);
  221. OBSPropertiesView *CreateEncoderPropertyView(const char *encoder,
  222. const char *path,
  223. bool changed = false);
  224. /* general */
  225. void LoadLanguageList();
  226. void LoadThemeList(bool firstLoad);
  227. void LoadBranchesList();
  228. /* stream */
  229. void InitStreamPage();
  230. inline bool IsCustomService() const;
  231. inline bool IsWHIP() const;
  232. void LoadServices(bool showAll);
  233. void OnOAuthStreamKeyConnected();
  234. void OnAuthConnected();
  235. QString lastService;
  236. QString protocol;
  237. QString lastCustomServer;
  238. int prevLangIndex;
  239. bool prevBrowserAccel;
  240. void ServiceChanged(bool resetFields = false);
  241. QString FindProtocol();
  242. void UpdateServerList();
  243. void UpdateKeyLink();
  244. void UpdateVodTrackSetting();
  245. void UpdateServiceRecommendations();
  246. void UpdateMoreInfoLink();
  247. void UpdateAdvNetworkGroup();
  248. /* Appearance */
  249. void InitAppearancePage();
  250. bool IsCustomServer();
  251. private slots:
  252. void RecreateOutputResolutionWidget();
  253. bool UpdateResFPSLimits();
  254. void DisplayEnforceWarning(bool checked);
  255. void on_show_clicked();
  256. void on_authPwShow_clicked();
  257. void on_connectAccount_clicked();
  258. void on_disconnectAccount_clicked();
  259. void on_useStreamKey_clicked();
  260. void on_useAuth_toggled();
  261. void on_server_currentIndexChanged(int index);
  262. void on_hotkeyFilterReset_clicked();
  263. void on_hotkeyFilterSearch_textChanged(const QString text);
  264. void on_hotkeyFilterInput_KeyChanged(obs_key_combination_t combo);
  265. private:
  266. /* output */
  267. void LoadSimpleOutputSettings();
  268. void LoadAdvOutputStreamingSettings();
  269. void LoadAdvOutputStreamingEncoderProperties();
  270. void LoadAdvOutputRecordingSettings();
  271. void LoadAdvOutputRecordingEncoderProperties();
  272. void LoadAdvOutputFFmpegSettings();
  273. void LoadAdvOutputAudioSettings();
  274. void SetAdvOutputFFmpegEnablement(FFmpegCodecType encoderType,
  275. bool enabled,
  276. bool enableEncode = false);
  277. /* audio */
  278. void LoadListValues(QComboBox *widget, obs_property_t *prop, int index);
  279. void LoadAudioDevices();
  280. void LoadAudioSources();
  281. /* video */
  282. void LoadRendererList();
  283. void ResetDownscales(uint32_t cx, uint32_t cy,
  284. bool ignoreAllSignals = false);
  285. void LoadDownscaleFilters();
  286. void LoadResolutionLists();
  287. void LoadFPSData();
  288. /* a11y */
  289. void UpdateA11yColors();
  290. void SetDefaultColors();
  291. void ResetDefaultColors();
  292. QColor GetColor(uint32_t colorVal, QString label);
  293. uint32_t preset = 0;
  294. uint32_t selectRed = 0x0000FF;
  295. uint32_t selectGreen = 0x00FF00;
  296. uint32_t selectBlue = 0xFF7F00;
  297. uint32_t mixerGreen = 0x267f26;
  298. uint32_t mixerYellow = 0x267f7f;
  299. uint32_t mixerRed = 0x26267f;
  300. uint32_t mixerGreenActive = 0x4cff4c;
  301. uint32_t mixerYellowActive = 0x4cffff;
  302. uint32_t mixerRedActive = 0x4c4cff;
  303. void SaveGeneralSettings();
  304. void SaveStream1Settings();
  305. void SaveOutputSettings();
  306. void SaveAudioSettings();
  307. void SaveVideoSettings();
  308. void SaveHotkeySettings();
  309. void SaveA11ySettings();
  310. void SaveAppearanceSettings();
  311. void SaveAdvancedSettings();
  312. void SaveSettings();
  313. void SearchHotkeys(const QString &text,
  314. obs_key_combination_t filterCombo);
  315. void UpdateSimpleOutStreamDelayEstimate();
  316. void UpdateAdvOutStreamDelayEstimate();
  317. void FillSimpleRecordingValues();
  318. void FillAudioMonitoringDevices();
  319. void RecalcOutputResPixels(const char *resText);
  320. bool AskIfCanCloseSettings();
  321. void UpdateYouTubeAppDockSettings();
  322. QIcon generalIcon;
  323. QIcon appearanceIcon;
  324. QIcon streamIcon;
  325. QIcon outputIcon;
  326. QIcon audioIcon;
  327. QIcon videoIcon;
  328. QIcon hotkeysIcon;
  329. QIcon accessibilityIcon;
  330. QIcon advancedIcon;
  331. QIcon GetGeneralIcon() const;
  332. QIcon GetAppearanceIcon() const;
  333. QIcon GetStreamIcon() const;
  334. QIcon GetOutputIcon() const;
  335. QIcon GetAudioIcon() const;
  336. QIcon GetVideoIcon() const;
  337. QIcon GetHotkeysIcon() const;
  338. QIcon GetAccessibilityIcon() const;
  339. QIcon GetAdvancedIcon() const;
  340. int CurrentFLVTrack();
  341. int SimpleOutGetSelectedAudioTracks();
  342. int AdvOutGetSelectedAudioTracks();
  343. int AdvOutGetStreamingSelectedAudioTracks();
  344. OBSService GetStream1Service();
  345. bool ServiceAndVCodecCompatible();
  346. bool ServiceAndACodecCompatible();
  347. bool ServiceSupportsCodecCheck();
  348. inline bool AllowsMultiTrack(const char *protocol);
  349. void SwapMultiTrack(const char *protocol);
  350. private slots:
  351. void on_theme_activated(int idx);
  352. void on_themeVariant_activated(int idx);
  353. void on_listWidget_itemSelectionChanged();
  354. void on_buttonBox_clicked(QAbstractButton *button);
  355. void on_service_currentIndexChanged(int idx);
  356. void on_customServer_textChanged(const QString &text);
  357. void on_simpleOutputBrowse_clicked();
  358. void on_advOutRecPathBrowse_clicked();
  359. void on_advOutFFPathBrowse_clicked();
  360. void on_advOutEncoder_currentIndexChanged();
  361. void on_advOutRecEncoder_currentIndexChanged(int idx);
  362. void on_advOutFFIgnoreCompat_stateChanged(int state);
  363. void on_advOutFFFormat_currentIndexChanged(int idx);
  364. void on_advOutFFAEncoder_currentIndexChanged(int idx);
  365. void on_advOutFFVEncoder_currentIndexChanged(int idx);
  366. void on_advOutFFType_currentIndexChanged(int idx);
  367. void on_colorFormat_currentIndexChanged(int idx);
  368. void on_colorSpace_currentIndexChanged(int idx);
  369. void on_filenameFormatting_textEdited(const QString &text);
  370. void on_outputResolution_editTextChanged(const QString &text);
  371. void on_baseResolution_editTextChanged(const QString &text);
  372. void on_disableOSXVSync_clicked();
  373. void on_choose1_clicked();
  374. void on_choose2_clicked();
  375. void on_choose3_clicked();
  376. void on_choose4_clicked();
  377. void on_choose5_clicked();
  378. void on_choose6_clicked();
  379. void on_choose7_clicked();
  380. void on_choose8_clicked();
  381. void on_choose9_clicked();
  382. void on_colorPreset_currentIndexChanged(int idx);
  383. void GeneralChanged();
  384. #if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
  385. void HideOBSWindowWarning(Qt::CheckState state);
  386. #else
  387. void HideOBSWindowWarning(int state);
  388. #endif
  389. void AudioChanged();
  390. void AudioChangedRestart();
  391. void ReloadAudioSources();
  392. void SurroundWarning(int idx);
  393. void SpeakerLayoutChanged(int idx);
  394. void LowLatencyBufferingChanged(bool checked);
  395. void UpdateAudioWarnings();
  396. void OutputsChanged();
  397. void Stream1Changed();
  398. void VideoChanged();
  399. void VideoChangedResolution();
  400. void HotkeysChanged();
  401. bool ScanDuplicateHotkeys(QFormLayout *layout);
  402. void ReloadHotkeys(obs_hotkey_id ignoreKey = OBS_INVALID_HOTKEY_ID);
  403. void A11yChanged();
  404. void AppearanceChanged();
  405. void AdvancedChanged();
  406. void AdvancedChangedRestart();
  407. void UpdateStreamDelayEstimate();
  408. void UpdateAutomaticReplayBufferCheckboxes();
  409. void AdvOutSplitFileChanged();
  410. void AdvOutRecCheckWarnings();
  411. void AdvOutRecCheckCodecs();
  412. void SimpleRecordingQualityChanged();
  413. void SimpleRecordingEncoderChanged();
  414. void SimpleRecordingQualityLosslessWarning(int idx);
  415. void SimpleReplayBufferChanged();
  416. void AdvReplayBufferChanged();
  417. void SimpleStreamingEncoderChanged();
  418. OBSService SpawnTempService();
  419. void SetGeneralIcon(const QIcon &icon);
  420. void SetAppearanceIcon(const QIcon &icon);
  421. void SetStreamIcon(const QIcon &icon);
  422. void SetOutputIcon(const QIcon &icon);
  423. void SetAudioIcon(const QIcon &icon);
  424. void SetVideoIcon(const QIcon &icon);
  425. void SetHotkeysIcon(const QIcon &icon);
  426. void SetAccessibilityIcon(const QIcon &icon);
  427. void SetAdvancedIcon(const QIcon &icon);
  428. void UseStreamKeyAdvClicked();
  429. void SimpleStreamAudioEncoderChanged();
  430. void AdvAudioEncodersChanged();
  431. protected:
  432. virtual void closeEvent(QCloseEvent *event) override;
  433. virtual void showEvent(QShowEvent *event) override;
  434. void reject() override;
  435. public:
  436. OBSBasicSettings(QWidget *parent);
  437. ~OBSBasicSettings();
  438. inline const QIcon &GetHotkeyConflictIcon() const
  439. {
  440. return hotkeyConflictIcon;
  441. }
  442. };