window-basic-settings.hpp 14 KB

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