OBSBasicSettings.hpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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. bool IsCustomServer();
  183. private slots:
  184. void UpdateMultitrackVideo();
  185. void RecreateOutputResolutionWidget();
  186. bool UpdateResFPSLimits();
  187. void DisplayEnforceWarning(bool checked);
  188. void on_show_clicked();
  189. void on_authPwShow_clicked();
  190. void on_connectAccount_clicked();
  191. void on_disconnectAccount_clicked();
  192. void on_useStreamKey_clicked();
  193. void on_useAuth_toggled();
  194. void on_server_currentIndexChanged(int index);
  195. void on_hotkeyFilterReset_clicked();
  196. void on_hotkeyFilterSearch_textChanged(const QString text);
  197. void on_hotkeyFilterInput_KeyChanged(obs_key_combination_t combo);
  198. private:
  199. /* output */
  200. void LoadSimpleOutputSettings();
  201. void LoadAdvOutputStreamingSettings();
  202. void LoadAdvOutputStreamingEncoderProperties();
  203. void LoadAdvOutputRecordingSettings();
  204. void LoadAdvOutputRecordingEncoderProperties();
  205. void LoadAdvOutputFFmpegSettings();
  206. void LoadAdvOutputAudioSettings();
  207. void SetAdvOutputFFmpegEnablement(FFmpegCodecType encoderType, bool enabled, bool enableEncode = false);
  208. /* audio */
  209. void LoadListValues(QComboBox *widget, obs_property_t *prop, int index);
  210. void LoadAudioDevices();
  211. void LoadAudioSources();
  212. /* video */
  213. void LoadRendererList();
  214. void ResetDownscales(uint32_t cx, uint32_t cy, bool ignoreAllSignals = false);
  215. void LoadDownscaleFilters();
  216. void LoadResolutionLists();
  217. void LoadFPSData();
  218. /* a11y */
  219. void UpdateA11yColors();
  220. void SetDefaultColors();
  221. void ResetDefaultColors();
  222. QColor GetColor(uint32_t colorVal, QString label);
  223. uint32_t preset = 0;
  224. uint32_t selectRed = 0x0000FF;
  225. uint32_t selectGreen = 0x00FF00;
  226. uint32_t selectBlue = 0xFF7F00;
  227. uint32_t mixerGreen = 0x267f26;
  228. uint32_t mixerYellow = 0x267f7f;
  229. uint32_t mixerRed = 0x26267f;
  230. uint32_t mixerGreenActive = 0x4cff4c;
  231. uint32_t mixerYellowActive = 0x4cffff;
  232. uint32_t mixerRedActive = 0x4c4cff;
  233. void SaveGeneralSettings();
  234. void SaveStream1Settings();
  235. void SaveOutputSettings();
  236. void SaveAudioSettings();
  237. void SaveVideoSettings();
  238. void SaveHotkeySettings();
  239. void SaveA11ySettings();
  240. void SaveAppearanceSettings();
  241. void SaveAdvancedSettings();
  242. void SaveSettings();
  243. void SearchHotkeys(const QString &text, obs_key_combination_t filterCombo);
  244. void UpdateSimpleOutStreamDelayEstimate();
  245. void UpdateAdvOutStreamDelayEstimate();
  246. void FillSimpleRecordingValues();
  247. void FillAudioMonitoringDevices();
  248. void RecalcOutputResPixels(const char *resText);
  249. bool AskIfCanCloseSettings();
  250. void UpdateYouTubeAppDockSettings();
  251. QIcon generalIcon;
  252. QIcon appearanceIcon;
  253. QIcon streamIcon;
  254. QIcon outputIcon;
  255. QIcon audioIcon;
  256. QIcon videoIcon;
  257. QIcon hotkeysIcon;
  258. QIcon accessibilityIcon;
  259. QIcon advancedIcon;
  260. QIcon GetGeneralIcon() const;
  261. QIcon GetAppearanceIcon() const;
  262. QIcon GetStreamIcon() const;
  263. QIcon GetOutputIcon() const;
  264. QIcon GetAudioIcon() const;
  265. QIcon GetVideoIcon() const;
  266. QIcon GetHotkeysIcon() const;
  267. QIcon GetAccessibilityIcon() const;
  268. QIcon GetAdvancedIcon() const;
  269. int CurrentFLVTrack();
  270. int SimpleOutGetSelectedAudioTracks();
  271. int AdvOutGetSelectedAudioTracks();
  272. int AdvOutGetStreamingSelectedAudioTracks();
  273. OBSService GetStream1Service();
  274. bool ServiceAndVCodecCompatible();
  275. bool ServiceAndACodecCompatible();
  276. bool ServiceSupportsCodecCheck();
  277. inline bool AllowsMultiTrack(const char *protocol);
  278. void SwapMultiTrack(const char *protocol);
  279. private slots:
  280. void on_theme_activated(int idx);
  281. void on_themeVariant_activated(int idx);
  282. void on_listWidget_itemSelectionChanged();
  283. void on_buttonBox_clicked(QAbstractButton *button);
  284. void on_service_currentIndexChanged(int idx);
  285. void on_customServer_textChanged(const QString &text);
  286. void on_simpleOutputBrowse_clicked();
  287. void on_advOutRecPathBrowse_clicked();
  288. void on_advOutFFPathBrowse_clicked();
  289. void on_advOutEncoder_currentIndexChanged();
  290. void on_advOutRecEncoder_currentIndexChanged(int idx);
  291. void on_advOutFFIgnoreCompat_stateChanged(int state);
  292. void on_advOutFFFormat_currentIndexChanged(int idx);
  293. void on_advOutFFAEncoder_currentIndexChanged(int idx);
  294. void on_advOutFFVEncoder_currentIndexChanged(int idx);
  295. void on_advOutFFType_currentIndexChanged(int idx);
  296. void on_colorFormat_currentIndexChanged(int idx);
  297. void on_colorSpace_currentIndexChanged(int idx);
  298. void on_filenameFormatting_textEdited(const QString &text);
  299. void on_outputResolution_editTextChanged(const QString &text);
  300. void on_baseResolution_editTextChanged(const QString &text);
  301. void on_disableOSXVSync_clicked();
  302. void on_choose1_clicked();
  303. void on_choose2_clicked();
  304. void on_choose3_clicked();
  305. void on_choose4_clicked();
  306. void on_choose5_clicked();
  307. void on_choose6_clicked();
  308. void on_choose7_clicked();
  309. void on_choose8_clicked();
  310. void on_choose9_clicked();
  311. void on_colorPreset_currentIndexChanged(int idx);
  312. void GeneralChanged();
  313. #if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
  314. void HideOBSWindowWarning(Qt::CheckState state);
  315. #else
  316. void HideOBSWindowWarning(int state);
  317. #endif
  318. void AudioChanged();
  319. void AudioChangedRestart();
  320. void ReloadAudioSources();
  321. void SurroundWarning(int idx);
  322. void SpeakerLayoutChanged(int idx);
  323. void LowLatencyBufferingChanged(bool checked);
  324. void UpdateAudioWarnings();
  325. void OutputsChanged();
  326. void Stream1Changed();
  327. void VideoChanged();
  328. void VideoChangedResolution();
  329. void HotkeysChanged();
  330. bool ScanDuplicateHotkeys(QFormLayout *layout);
  331. void ReloadHotkeys(obs_hotkey_id ignoreKey = OBS_INVALID_HOTKEY_ID);
  332. void A11yChanged();
  333. void AppearanceChanged();
  334. void AdvancedChanged();
  335. void AdvancedChangedRestart();
  336. void UpdateStreamDelayEstimate();
  337. void UpdateAutomaticReplayBufferCheckboxes();
  338. void AdvOutSplitFileChanged();
  339. void AdvOutRecCheckWarnings();
  340. void AdvOutRecCheckCodecs();
  341. void SimpleRecordingQualityChanged();
  342. void SimpleRecordingEncoderChanged();
  343. void SimpleRecordingQualityLosslessWarning(int idx);
  344. void SimpleReplayBufferChanged();
  345. void AdvReplayBufferChanged();
  346. void SimpleStreamingEncoderChanged();
  347. OBSService SpawnTempService();
  348. void SetGeneralIcon(const QIcon &icon);
  349. void SetAppearanceIcon(const QIcon &icon);
  350. void SetStreamIcon(const QIcon &icon);
  351. void SetOutputIcon(const QIcon &icon);
  352. void SetAudioIcon(const QIcon &icon);
  353. void SetVideoIcon(const QIcon &icon);
  354. void SetHotkeysIcon(const QIcon &icon);
  355. void SetAccessibilityIcon(const QIcon &icon);
  356. void SetAdvancedIcon(const QIcon &icon);
  357. void UseStreamKeyAdvClicked();
  358. void SimpleStreamAudioEncoderChanged();
  359. void AdvAudioEncodersChanged();
  360. protected:
  361. virtual void closeEvent(QCloseEvent *event) override;
  362. virtual void showEvent(QShowEvent *event) override;
  363. void reject() override;
  364. public:
  365. OBSBasicSettings(QWidget *parent);
  366. ~OBSBasicSettings();
  367. inline const QIcon &GetHotkeyConflictIcon() const { return hotkeyConflictIcon; }
  368. };