window-basic-settings.hpp 14 KB

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