window-basic-settings.hpp 14 KB

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