window-basic-settings.hpp 14 KB

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