window-basic-settings.hpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  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 SaveText(QPlainTextEdit *widget, const char *section,
  163. const char *value);
  164. void SaveFormat(QComboBox *combo);
  165. void SaveEncoder(QComboBox *combo, const char *section,
  166. const char *value);
  167. bool ResFPSValid(obs_service_resolution *res_list, size_t res_count,
  168. int max_fps);
  169. void ClosestResFPS(obs_service_resolution *res_list, size_t res_count,
  170. int max_fps, int &new_cx, int &new_cy, int &new_fps);
  171. inline bool Changed() const
  172. {
  173. return generalChanged || appearanceChanged || outputsChanged ||
  174. stream1Changed || audioChanged || videoChanged ||
  175. advancedChanged || hotkeysChanged || a11yChanged;
  176. }
  177. inline void EnableApplyButton(bool en)
  178. {
  179. ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(en);
  180. }
  181. inline void ClearChanged()
  182. {
  183. generalChanged = false;
  184. stream1Changed = false;
  185. outputsChanged = false;
  186. audioChanged = false;
  187. videoChanged = false;
  188. hotkeysChanged = false;
  189. a11yChanged = false;
  190. advancedChanged = false;
  191. appearanceChanged = false;
  192. EnableApplyButton(false);
  193. }
  194. template<typename Widget, typename WidgetParent, typename... SignalArgs,
  195. typename... SlotArgs>
  196. void HookWidget(Widget *widget,
  197. void (WidgetParent::*signal)(SignalArgs...),
  198. void (OBSBasicSettings::*slot)(SlotArgs...))
  199. {
  200. QObject::connect(widget, signal, this, slot);
  201. widget->setProperty("changed", QVariant(false));
  202. }
  203. bool QueryChanges();
  204. bool QueryAllowedToClose();
  205. void ResetEncoders(bool streamOnly = false);
  206. void LoadColorRanges();
  207. void LoadColorSpaces();
  208. void LoadColorFormats();
  209. void LoadFormats();
  210. void ReloadCodecs(const FFmpegFormat &format);
  211. void UpdateColorFormatSpaceWarning();
  212. void LoadGeneralSettings();
  213. void LoadStream1Settings();
  214. void LoadOutputSettings();
  215. void LoadAudioSettings();
  216. void LoadVideoSettings();
  217. void
  218. LoadHotkeySettings(obs_hotkey_id ignoreKey = OBS_INVALID_HOTKEY_ID);
  219. void LoadA11ySettings(bool presetChange = false);
  220. void LoadAppearanceSettings(bool reload = false);
  221. void LoadAdvancedSettings();
  222. void LoadSettings(bool changedOnly);
  223. OBSPropertiesView *CreateEncoderPropertyView(const char *encoder,
  224. const char *path,
  225. bool changed = false);
  226. /* general */
  227. void LoadLanguageList();
  228. void LoadThemeList(bool firstLoad);
  229. void LoadBranchesList();
  230. /* stream */
  231. void InitStreamPage();
  232. bool IsCustomService() const;
  233. inline bool IsWHIP() const;
  234. void LoadServices(bool showAll);
  235. void OnOAuthStreamKeyConnected();
  236. void OnAuthConnected();
  237. QString lastService;
  238. QString protocol;
  239. QString lastCustomServer;
  240. int prevLangIndex;
  241. bool prevBrowserAccel;
  242. void ServiceChanged(bool resetFields = false);
  243. QString FindProtocol();
  244. void UpdateServerList();
  245. void UpdateKeyLink();
  246. void UpdateVodTrackSetting();
  247. void UpdateServiceRecommendations();
  248. void UpdateMoreInfoLink();
  249. void UpdateAdvNetworkGroup();
  250. /* Appearance */
  251. void InitAppearancePage();
  252. bool IsCustomServer();
  253. private slots:
  254. void UpdateMultitrackVideo();
  255. void RecreateOutputResolutionWidget();
  256. bool UpdateResFPSLimits();
  257. void DisplayEnforceWarning(bool checked);
  258. void on_show_clicked();
  259. void on_authPwShow_clicked();
  260. void on_connectAccount_clicked();
  261. void on_disconnectAccount_clicked();
  262. void on_useStreamKey_clicked();
  263. void on_useAuth_toggled();
  264. void on_server_currentIndexChanged(int index);
  265. void on_hotkeyFilterReset_clicked();
  266. void on_hotkeyFilterSearch_textChanged(const QString text);
  267. void on_hotkeyFilterInput_KeyChanged(obs_key_combination_t combo);
  268. private:
  269. /* output */
  270. void LoadSimpleOutputSettings();
  271. void LoadAdvOutputStreamingSettings();
  272. void LoadAdvOutputStreamingEncoderProperties();
  273. void LoadAdvOutputRecordingSettings();
  274. void LoadAdvOutputRecordingEncoderProperties();
  275. void LoadAdvOutputFFmpegSettings();
  276. void LoadAdvOutputAudioSettings();
  277. void SetAdvOutputFFmpegEnablement(FFmpegCodecType encoderType,
  278. bool enabled,
  279. bool enableEncode = false);
  280. /* audio */
  281. void LoadListValues(QComboBox *widget, obs_property_t *prop, int index);
  282. void LoadAudioDevices();
  283. void LoadAudioSources();
  284. /* video */
  285. void LoadRendererList();
  286. void ResetDownscales(uint32_t cx, uint32_t cy,
  287. bool ignoreAllSignals = false);
  288. void LoadDownscaleFilters();
  289. void LoadResolutionLists();
  290. void LoadFPSData();
  291. /* a11y */
  292. void UpdateA11yColors();
  293. void SetDefaultColors();
  294. void ResetDefaultColors();
  295. QColor GetColor(uint32_t colorVal, QString label);
  296. uint32_t preset = 0;
  297. uint32_t selectRed = 0x0000FF;
  298. uint32_t selectGreen = 0x00FF00;
  299. uint32_t selectBlue = 0xFF7F00;
  300. uint32_t mixerGreen = 0x267f26;
  301. uint32_t mixerYellow = 0x267f7f;
  302. uint32_t mixerRed = 0x26267f;
  303. uint32_t mixerGreenActive = 0x4cff4c;
  304. uint32_t mixerYellowActive = 0x4cffff;
  305. uint32_t mixerRedActive = 0x4c4cff;
  306. void SaveGeneralSettings();
  307. void SaveStream1Settings();
  308. void SaveOutputSettings();
  309. void SaveAudioSettings();
  310. void SaveVideoSettings();
  311. void SaveHotkeySettings();
  312. void SaveA11ySettings();
  313. void SaveAppearanceSettings();
  314. void SaveAdvancedSettings();
  315. void SaveSettings();
  316. void SearchHotkeys(const QString &text,
  317. obs_key_combination_t filterCombo);
  318. void UpdateSimpleOutStreamDelayEstimate();
  319. void UpdateAdvOutStreamDelayEstimate();
  320. void FillSimpleRecordingValues();
  321. void FillAudioMonitoringDevices();
  322. void RecalcOutputResPixels(const char *resText);
  323. bool AskIfCanCloseSettings();
  324. void UpdateYouTubeAppDockSettings();
  325. QIcon generalIcon;
  326. QIcon appearanceIcon;
  327. QIcon streamIcon;
  328. QIcon outputIcon;
  329. QIcon audioIcon;
  330. QIcon videoIcon;
  331. QIcon hotkeysIcon;
  332. QIcon accessibilityIcon;
  333. QIcon advancedIcon;
  334. QIcon GetGeneralIcon() const;
  335. QIcon GetAppearanceIcon() const;
  336. QIcon GetStreamIcon() const;
  337. QIcon GetOutputIcon() const;
  338. QIcon GetAudioIcon() const;
  339. QIcon GetVideoIcon() const;
  340. QIcon GetHotkeysIcon() const;
  341. QIcon GetAccessibilityIcon() const;
  342. QIcon GetAdvancedIcon() const;
  343. int CurrentFLVTrack();
  344. int SimpleOutGetSelectedAudioTracks();
  345. int AdvOutGetSelectedAudioTracks();
  346. int AdvOutGetStreamingSelectedAudioTracks();
  347. OBSService GetStream1Service();
  348. bool ServiceAndVCodecCompatible();
  349. bool ServiceAndACodecCompatible();
  350. bool ServiceSupportsCodecCheck();
  351. inline bool AllowsMultiTrack(const char *protocol);
  352. void SwapMultiTrack(const char *protocol);
  353. private slots:
  354. void on_theme_activated(int idx);
  355. void on_themeVariant_activated(int idx);
  356. void on_listWidget_itemSelectionChanged();
  357. void on_buttonBox_clicked(QAbstractButton *button);
  358. void on_service_currentIndexChanged(int idx);
  359. void on_customServer_textChanged(const QString &text);
  360. void on_simpleOutputBrowse_clicked();
  361. void on_advOutRecPathBrowse_clicked();
  362. void on_advOutFFPathBrowse_clicked();
  363. void on_advOutEncoder_currentIndexChanged();
  364. void on_advOutRecEncoder_currentIndexChanged(int idx);
  365. void on_advOutFFIgnoreCompat_stateChanged(int state);
  366. void on_advOutFFFormat_currentIndexChanged(int idx);
  367. void on_advOutFFAEncoder_currentIndexChanged(int idx);
  368. void on_advOutFFVEncoder_currentIndexChanged(int idx);
  369. void on_advOutFFType_currentIndexChanged(int idx);
  370. void on_colorFormat_currentIndexChanged(int idx);
  371. void on_colorSpace_currentIndexChanged(int idx);
  372. void on_filenameFormatting_textEdited(const QString &text);
  373. void on_outputResolution_editTextChanged(const QString &text);
  374. void on_baseResolution_editTextChanged(const QString &text);
  375. void on_disableOSXVSync_clicked();
  376. void on_choose1_clicked();
  377. void on_choose2_clicked();
  378. void on_choose3_clicked();
  379. void on_choose4_clicked();
  380. void on_choose5_clicked();
  381. void on_choose6_clicked();
  382. void on_choose7_clicked();
  383. void on_choose8_clicked();
  384. void on_choose9_clicked();
  385. void on_colorPreset_currentIndexChanged(int idx);
  386. void GeneralChanged();
  387. #if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
  388. void HideOBSWindowWarning(Qt::CheckState state);
  389. #else
  390. void HideOBSWindowWarning(int state);
  391. #endif
  392. void AudioChanged();
  393. void AudioChangedRestart();
  394. void ReloadAudioSources();
  395. void SurroundWarning(int idx);
  396. void SpeakerLayoutChanged(int idx);
  397. void LowLatencyBufferingChanged(bool checked);
  398. void UpdateAudioWarnings();
  399. void OutputsChanged();
  400. void Stream1Changed();
  401. void VideoChanged();
  402. void VideoChangedResolution();
  403. void HotkeysChanged();
  404. bool ScanDuplicateHotkeys(QFormLayout *layout);
  405. void ReloadHotkeys(obs_hotkey_id ignoreKey = OBS_INVALID_HOTKEY_ID);
  406. void A11yChanged();
  407. void AppearanceChanged();
  408. void AdvancedChanged();
  409. void AdvancedChangedRestart();
  410. void UpdateStreamDelayEstimate();
  411. void UpdateAutomaticReplayBufferCheckboxes();
  412. void AdvOutSplitFileChanged();
  413. void AdvOutRecCheckWarnings();
  414. void AdvOutRecCheckCodecs();
  415. void SimpleRecordingQualityChanged();
  416. void SimpleRecordingEncoderChanged();
  417. void SimpleRecordingQualityLosslessWarning(int idx);
  418. void SimpleReplayBufferChanged();
  419. void AdvReplayBufferChanged();
  420. void SimpleStreamingEncoderChanged();
  421. OBSService SpawnTempService();
  422. void SetGeneralIcon(const QIcon &icon);
  423. void SetAppearanceIcon(const QIcon &icon);
  424. void SetStreamIcon(const QIcon &icon);
  425. void SetOutputIcon(const QIcon &icon);
  426. void SetAudioIcon(const QIcon &icon);
  427. void SetVideoIcon(const QIcon &icon);
  428. void SetHotkeysIcon(const QIcon &icon);
  429. void SetAccessibilityIcon(const QIcon &icon);
  430. void SetAdvancedIcon(const QIcon &icon);
  431. void UseStreamKeyAdvClicked();
  432. void SimpleStreamAudioEncoderChanged();
  433. void AdvAudioEncodersChanged();
  434. protected:
  435. virtual void closeEvent(QCloseEvent *event) override;
  436. virtual void showEvent(QShowEvent *event) override;
  437. void reject() override;
  438. public:
  439. OBSBasicSettings(QWidget *parent);
  440. ~OBSBasicSettings();
  441. inline const QIcon &GetHotkeyConflictIcon() const
  442. {
  443. return hotkeyConflictIcon;
  444. }
  445. };