window-basic-settings.hpp 15 KB

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