OBSBasicSettings.hpp 14 KB

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