window-basic-settings.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh 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 advancedIcon READ GetAdvancedIcon WRITE SetAdvancedIcon
  84. DESIGNABLE true)
  85. private:
  86. OBSBasic *main;
  87. std::unique_ptr<Ui::OBSBasicSettings> ui;
  88. std::shared_ptr<Auth> auth;
  89. bool generalChanged = false;
  90. bool stream1Changed = false;
  91. bool outputsChanged = false;
  92. bool audioChanged = false;
  93. bool videoChanged = false;
  94. bool hotkeysChanged = false;
  95. bool advancedChanged = false;
  96. int pageIndex = 0;
  97. bool loading = true;
  98. bool forceAuthReload = false;
  99. std::string savedTheme;
  100. int sampleRateIndex = 0;
  101. int channelIndex = 0;
  102. int lastSimpleRecQualityIdx = 0;
  103. int lastServiceIdx = -1;
  104. int lastIgnoreRecommended = -1;
  105. int lastChannelSetupIdx = 0;
  106. OBSFFFormatDesc formats;
  107. OBSPropertiesView *streamProperties = nullptr;
  108. OBSPropertiesView *streamEncoderProps = nullptr;
  109. OBSPropertiesView *recordEncoderProps = nullptr;
  110. QPointer<QLabel> advOutRecWarning;
  111. QPointer<QLabel> simpleOutRecWarning;
  112. QString curPreset;
  113. QString curQSVPreset;
  114. QString curNVENCPreset;
  115. QString curAMDPreset;
  116. QString curAdvStreamEncoder;
  117. QString curAdvRecordEncoder;
  118. using AudioSource_t =
  119. std::tuple<OBSWeakSource, QPointer<QCheckBox>,
  120. QPointer<QSpinBox>, QPointer<QCheckBox>,
  121. QPointer<QSpinBox>>;
  122. std::vector<AudioSource_t> audioSources;
  123. std::vector<OBSSignal> audioSourceSignals;
  124. OBSSignal sourceCreated;
  125. OBSSignal channelChanged;
  126. std::vector<std::pair<bool, QPointer<OBSHotkeyWidget>>> hotkeys;
  127. OBSSignal hotkeyRegistered;
  128. OBSSignal hotkeyUnregistered;
  129. uint32_t outputCX = 0;
  130. uint32_t outputCY = 0;
  131. QPointer<QCheckBox> simpleVodTrack;
  132. QPointer<QCheckBox> vodTrackCheckbox;
  133. QPointer<QWidget> vodTrackContainer;
  134. QPointer<QRadioButton> vodTrack[MAX_AUDIO_MIXES];
  135. QIcon hotkeyConflictIcon;
  136. void SaveCombo(QComboBox *widget, const char *section,
  137. const char *value);
  138. void SaveComboData(QComboBox *widget, const char *section,
  139. const char *value);
  140. void SaveCheckBox(QAbstractButton *widget, const char *section,
  141. const char *value, bool invert = false);
  142. void SaveEdit(QLineEdit *widget, const char *section,
  143. const char *value);
  144. void SaveSpinBox(QSpinBox *widget, const char *section,
  145. const char *value);
  146. void SaveFormat(QComboBox *combo);
  147. void SaveEncoder(QComboBox *combo, const char *section,
  148. const char *value);
  149. bool ResFPSValid(obs_service_resolution *res_list, size_t res_count,
  150. int max_fps);
  151. void ClosestResFPS(obs_service_resolution *res_list, size_t res_count,
  152. int max_fps, int &new_cx, int &new_cy, int &new_fps);
  153. inline bool Changed() const
  154. {
  155. return generalChanged || outputsChanged || stream1Changed ||
  156. audioChanged || videoChanged || advancedChanged ||
  157. hotkeysChanged;
  158. }
  159. inline void EnableApplyButton(bool en)
  160. {
  161. ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(en);
  162. }
  163. inline void ClearChanged()
  164. {
  165. generalChanged = false;
  166. stream1Changed = false;
  167. outputsChanged = false;
  168. audioChanged = false;
  169. videoChanged = false;
  170. hotkeysChanged = false;
  171. advancedChanged = false;
  172. EnableApplyButton(false);
  173. }
  174. #ifdef _WIN32
  175. bool aeroWasDisabled = false;
  176. QCheckBox *toggleAero = nullptr;
  177. void ToggleDisableAero(bool checked);
  178. #endif
  179. void HookWidget(QWidget *widget, const char *signal, const char *slot);
  180. bool QueryChanges();
  181. void LoadEncoderTypes();
  182. void LoadColorRanges();
  183. void LoadFormats();
  184. void ReloadCodecs(const ff_format_desc *formatDesc);
  185. void LoadGeneralSettings();
  186. void LoadStream1Settings();
  187. void LoadOutputSettings();
  188. void LoadAudioSettings();
  189. void LoadVideoSettings();
  190. void
  191. LoadHotkeySettings(obs_hotkey_id ignoreKey = OBS_INVALID_HOTKEY_ID);
  192. void LoadAdvancedSettings();
  193. void LoadSettings(bool changedOnly);
  194. OBSPropertiesView *CreateEncoderPropertyView(const char *encoder,
  195. const char *path,
  196. bool changed = false);
  197. /* general */
  198. void LoadLanguageList();
  199. void LoadThemeList();
  200. /* stream */
  201. void InitStreamPage();
  202. inline bool IsCustomService() const;
  203. void LoadServices(bool showAll);
  204. void OnOAuthStreamKeyConnected();
  205. void OnAuthConnected();
  206. QString lastService;
  207. int prevLangIndex;
  208. bool prevBrowserAccel;
  209. private slots:
  210. void UpdateServerList();
  211. void UpdateKeyLink();
  212. void UpdateVodTrackSetting();
  213. void UpdateServiceRecommendations();
  214. void RecreateOutputResolutionWidget();
  215. void UpdateResFPSLimits();
  216. void UpdateMoreInfoLink();
  217. void DisplayEnforceWarning(bool checked);
  218. void on_show_clicked();
  219. void on_authPwShow_clicked();
  220. void on_connectAccount_clicked();
  221. void on_disconnectAccount_clicked();
  222. void on_useStreamKey_clicked();
  223. void on_useAuth_toggled();
  224. void on_hotkeyFilterReset_clicked();
  225. void on_hotkeyFilterSearch_textChanged(const QString text);
  226. void on_hotkeyFilterInput_KeyChanged(obs_key_combination_t combo);
  227. private:
  228. /* output */
  229. void LoadSimpleOutputSettings();
  230. void LoadAdvOutputStreamingSettings();
  231. void LoadAdvOutputStreamingEncoderProperties();
  232. void LoadAdvOutputRecordingSettings();
  233. void LoadAdvOutputRecordingEncoderProperties();
  234. void LoadAdvOutputFFmpegSettings();
  235. void LoadAdvOutputAudioSettings();
  236. void SetAdvOutputFFmpegEnablement(ff_codec_type encoderType,
  237. bool enabled,
  238. bool enableEncode = false);
  239. /* audio */
  240. void LoadListValues(QComboBox *widget, obs_property_t *prop, int index);
  241. void LoadAudioDevices();
  242. void LoadAudioSources();
  243. /* video */
  244. void LoadRendererList();
  245. void ResetDownscales(uint32_t cx, uint32_t cy,
  246. bool ignoreAllSignals = false);
  247. void LoadDownscaleFilters();
  248. void LoadResolutionLists();
  249. void LoadFPSData();
  250. void SaveGeneralSettings();
  251. void SaveStream1Settings();
  252. void SaveOutputSettings();
  253. void SaveAudioSettings();
  254. void SaveVideoSettings();
  255. void SaveHotkeySettings();
  256. void SaveAdvancedSettings();
  257. void SaveSettings();
  258. void SearchHotkeys(const QString &text,
  259. obs_key_combination_t filterCombo);
  260. void UpdateSimpleOutStreamDelayEstimate();
  261. void UpdateAdvOutStreamDelayEstimate();
  262. void FillSimpleRecordingValues();
  263. void FillSimpleStreamingValues();
  264. void FillAudioMonitoringDevices();
  265. void RecalcOutputResPixels(const char *resText);
  266. bool AskIfCanCloseSettings();
  267. QIcon generalIcon;
  268. QIcon streamIcon;
  269. QIcon outputIcon;
  270. QIcon audioIcon;
  271. QIcon videoIcon;
  272. QIcon hotkeysIcon;
  273. QIcon advancedIcon;
  274. QIcon GetGeneralIcon() const;
  275. QIcon GetStreamIcon() const;
  276. QIcon GetOutputIcon() const;
  277. QIcon GetAudioIcon() const;
  278. QIcon GetVideoIcon() const;
  279. QIcon GetHotkeysIcon() const;
  280. QIcon GetAdvancedIcon() const;
  281. int CurrentFLVTrack();
  282. OBSService GetStream1Service();
  283. private slots:
  284. void on_theme_activated(int idx);
  285. void on_listWidget_itemSelectionChanged();
  286. void on_buttonBox_clicked(QAbstractButton *button);
  287. void on_service_currentIndexChanged(int idx);
  288. void on_simpleOutputBrowse_clicked();
  289. void on_advOutRecPathBrowse_clicked();
  290. void on_advOutFFPathBrowse_clicked();
  291. void on_advOutEncoder_currentIndexChanged(int idx);
  292. void on_advOutRecEncoder_currentIndexChanged(int idx);
  293. void on_advOutFFIgnoreCompat_stateChanged(int state);
  294. void on_advOutFFFormat_currentIndexChanged(int idx);
  295. void on_advOutFFAEncoder_currentIndexChanged(int idx);
  296. void on_advOutFFVEncoder_currentIndexChanged(int idx);
  297. void on_advOutFFType_currentIndexChanged(int idx);
  298. void on_colorFormat_currentIndexChanged(const QString &text);
  299. void on_filenameFormatting_textEdited(const QString &text);
  300. void on_outputResolution_editTextChanged(const QString &text);
  301. void on_baseResolution_editTextChanged(const QString &text);
  302. void on_disableOSXVSync_clicked();
  303. void GeneralChanged();
  304. void AudioChanged();
  305. void AudioChangedRestart();
  306. void ReloadAudioSources();
  307. void SurroundWarning(int idx);
  308. void SpeakerLayoutChanged(int idx);
  309. void OutputsChanged();
  310. void Stream1Changed();
  311. void VideoChanged();
  312. void VideoChangedResolution();
  313. void VideoChangedRestart();
  314. void HotkeysChanged();
  315. bool ScanDuplicateHotkeys(QFormLayout *layout);
  316. void ReloadHotkeys(obs_hotkey_id ignoreKey = OBS_INVALID_HOTKEY_ID);
  317. void AdvancedChanged();
  318. void AdvancedChangedRestart();
  319. void UpdateStreamDelayEstimate();
  320. void UpdateAutomaticReplayBufferCheckboxes();
  321. void AdvOutRecCheckWarnings();
  322. void SimpleRecordingQualityChanged();
  323. void SimpleRecordingEncoderChanged();
  324. void SimpleRecordingQualityLosslessWarning(int idx);
  325. void SimpleReplayBufferChanged();
  326. void AdvReplayBufferChanged();
  327. void SimpleStreamingEncoderChanged();
  328. OBSService SpawnTempService();
  329. void SetGeneralIcon(const QIcon &icon);
  330. void SetStreamIcon(const QIcon &icon);
  331. void SetOutputIcon(const QIcon &icon);
  332. void SetAudioIcon(const QIcon &icon);
  333. void SetVideoIcon(const QIcon &icon);
  334. void SetHotkeysIcon(const QIcon &icon);
  335. void SetAdvancedIcon(const QIcon &icon);
  336. void UseStreamKeyAdvClicked();
  337. protected:
  338. virtual void closeEvent(QCloseEvent *event) override;
  339. void reject() override;
  340. public:
  341. OBSBasicSettings(QWidget *parent);
  342. ~OBSBasicSettings();
  343. inline const QIcon &GetHotkeyConflictIcon() const
  344. {
  345. return hotkeyConflictIcon;
  346. }
  347. };