window-basic-settings.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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. void SaveCombo(QComboBox *widget, const char *section,
  136. const char *value);
  137. void SaveComboData(QComboBox *widget, const char *section,
  138. const char *value);
  139. void SaveCheckBox(QAbstractButton *widget, const char *section,
  140. const char *value, bool invert = false);
  141. void SaveEdit(QLineEdit *widget, const char *section,
  142. const char *value);
  143. void SaveSpinBox(QSpinBox *widget, const char *section,
  144. const char *value);
  145. void SaveFormat(QComboBox *combo);
  146. void SaveEncoder(QComboBox *combo, const char *section,
  147. const char *value);
  148. bool ResFPSValid(obs_service_resolution *res_list, size_t res_count,
  149. int max_fps);
  150. void ClosestResFPS(obs_service_resolution *res_list, size_t res_count,
  151. int max_fps, int &new_cx, int &new_cy, int &new_fps);
  152. inline bool Changed() const
  153. {
  154. return generalChanged || outputsChanged || stream1Changed ||
  155. audioChanged || videoChanged || advancedChanged ||
  156. hotkeysChanged;
  157. }
  158. inline void EnableApplyButton(bool en)
  159. {
  160. ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(en);
  161. }
  162. inline void ClearChanged()
  163. {
  164. generalChanged = false;
  165. stream1Changed = false;
  166. outputsChanged = false;
  167. audioChanged = false;
  168. videoChanged = false;
  169. hotkeysChanged = false;
  170. advancedChanged = false;
  171. EnableApplyButton(false);
  172. }
  173. #ifdef _WIN32
  174. bool aeroWasDisabled = false;
  175. QCheckBox *toggleAero = nullptr;
  176. void ToggleDisableAero(bool checked);
  177. #endif
  178. void HookWidget(QWidget *widget, const char *signal, const char *slot);
  179. bool QueryChanges();
  180. void LoadEncoderTypes();
  181. void LoadColorRanges();
  182. void LoadFormats();
  183. void ReloadCodecs(const ff_format_desc *formatDesc);
  184. void LoadGeneralSettings();
  185. void LoadStream1Settings();
  186. void LoadOutputSettings();
  187. void LoadAudioSettings();
  188. void LoadVideoSettings();
  189. void
  190. LoadHotkeySettings(obs_hotkey_id ignoreKey = OBS_INVALID_HOTKEY_ID);
  191. void LoadAdvancedSettings();
  192. void LoadSettings(bool changedOnly);
  193. OBSPropertiesView *CreateEncoderPropertyView(const char *encoder,
  194. const char *path,
  195. bool changed = false);
  196. /* general */
  197. void LoadLanguageList();
  198. void LoadThemeList();
  199. /* stream */
  200. void InitStreamPage();
  201. inline bool IsCustomService() const;
  202. void LoadServices(bool showAll);
  203. void OnOAuthStreamKeyConnected();
  204. void OnAuthConnected();
  205. QString lastService;
  206. int prevLangIndex;
  207. bool prevBrowserAccel;
  208. private slots:
  209. void UpdateServerList();
  210. void UpdateKeyLink();
  211. void UpdateVodTrackSetting();
  212. void UpdateServiceRecommendations();
  213. void RecreateOutputResolutionWidget();
  214. void UpdateResFPSLimits();
  215. void UpdateMoreInfoLink();
  216. void DisplayEnforceWarning(bool checked);
  217. void on_show_clicked();
  218. void on_authPwShow_clicked();
  219. void on_connectAccount_clicked();
  220. void on_disconnectAccount_clicked();
  221. void on_useStreamKey_clicked();
  222. void on_useAuth_toggled();
  223. private:
  224. /* output */
  225. void LoadSimpleOutputSettings();
  226. void LoadAdvOutputStreamingSettings();
  227. void LoadAdvOutputStreamingEncoderProperties();
  228. void LoadAdvOutputRecordingSettings();
  229. void LoadAdvOutputRecordingEncoderProperties();
  230. void LoadAdvOutputFFmpegSettings();
  231. void LoadAdvOutputAudioSettings();
  232. void SetAdvOutputFFmpegEnablement(ff_codec_type encoderType,
  233. bool enabled,
  234. bool enableEncode = false);
  235. /* audio */
  236. void LoadListValues(QComboBox *widget, obs_property_t *prop, int index);
  237. void LoadAudioDevices();
  238. void LoadAudioSources();
  239. /* video */
  240. void LoadRendererList();
  241. void ResetDownscales(uint32_t cx, uint32_t cy,
  242. bool ignoreAllSignals = false);
  243. void LoadDownscaleFilters();
  244. void LoadResolutionLists();
  245. void LoadFPSData();
  246. void SaveGeneralSettings();
  247. void SaveStream1Settings();
  248. void SaveOutputSettings();
  249. void SaveAudioSettings();
  250. void SaveVideoSettings();
  251. void SaveHotkeySettings();
  252. void SaveAdvancedSettings();
  253. void SaveSettings();
  254. void UpdateSimpleOutStreamDelayEstimate();
  255. void UpdateAdvOutStreamDelayEstimate();
  256. void FillSimpleRecordingValues();
  257. void FillSimpleStreamingValues();
  258. void FillAudioMonitoringDevices();
  259. void RecalcOutputResPixels(const char *resText);
  260. bool AskIfCanCloseSettings();
  261. QIcon generalIcon;
  262. QIcon streamIcon;
  263. QIcon outputIcon;
  264. QIcon audioIcon;
  265. QIcon videoIcon;
  266. QIcon hotkeysIcon;
  267. QIcon advancedIcon;
  268. QIcon GetGeneralIcon() const;
  269. QIcon GetStreamIcon() const;
  270. QIcon GetOutputIcon() const;
  271. QIcon GetAudioIcon() const;
  272. QIcon GetVideoIcon() const;
  273. QIcon GetHotkeysIcon() const;
  274. QIcon GetAdvancedIcon() const;
  275. int CurrentFLVTrack();
  276. OBSService GetStream1Service();
  277. private slots:
  278. void on_theme_activated(int idx);
  279. void on_listWidget_itemSelectionChanged();
  280. void on_buttonBox_clicked(QAbstractButton *button);
  281. void on_service_currentIndexChanged(int idx);
  282. void on_simpleOutputBrowse_clicked();
  283. void on_advOutRecPathBrowse_clicked();
  284. void on_advOutFFPathBrowse_clicked();
  285. void on_advOutEncoder_currentIndexChanged(int idx);
  286. void on_advOutRecEncoder_currentIndexChanged(int idx);
  287. void on_advOutFFIgnoreCompat_stateChanged(int state);
  288. void on_advOutFFFormat_currentIndexChanged(int idx);
  289. void on_advOutFFAEncoder_currentIndexChanged(int idx);
  290. void on_advOutFFVEncoder_currentIndexChanged(int idx);
  291. void on_advOutFFType_currentIndexChanged(int idx);
  292. void on_colorFormat_currentIndexChanged(const QString &text);
  293. void on_filenameFormatting_textEdited(const QString &text);
  294. void on_outputResolution_editTextChanged(const QString &text);
  295. void on_baseResolution_editTextChanged(const QString &text);
  296. void on_disableOSXVSync_clicked();
  297. void GeneralChanged();
  298. void AudioChanged();
  299. void AudioChangedRestart();
  300. void ReloadAudioSources();
  301. void SurroundWarning(int idx);
  302. void SpeakerLayoutChanged(int idx);
  303. void OutputsChanged();
  304. void Stream1Changed();
  305. void VideoChanged();
  306. void VideoChangedResolution();
  307. void VideoChangedRestart();
  308. void HotkeysChanged();
  309. void ReloadHotkeys(obs_hotkey_id ignoreKey = OBS_INVALID_HOTKEY_ID);
  310. void AdvancedChanged();
  311. void AdvancedChangedRestart();
  312. void UpdateStreamDelayEstimate();
  313. void UpdateAutomaticReplayBufferCheckboxes();
  314. void AdvOutRecCheckWarnings();
  315. void SimpleRecordingQualityChanged();
  316. void SimpleRecordingEncoderChanged();
  317. void SimpleRecordingQualityLosslessWarning(int idx);
  318. void SimpleReplayBufferChanged();
  319. void AdvReplayBufferChanged();
  320. void SimpleStreamingEncoderChanged();
  321. OBSService SpawnTempService();
  322. void SetGeneralIcon(const QIcon &icon);
  323. void SetStreamIcon(const QIcon &icon);
  324. void SetOutputIcon(const QIcon &icon);
  325. void SetAudioIcon(const QIcon &icon);
  326. void SetVideoIcon(const QIcon &icon);
  327. void SetHotkeysIcon(const QIcon &icon);
  328. void SetAdvancedIcon(const QIcon &icon);
  329. void UseStreamKeyAdvClicked();
  330. protected:
  331. virtual void closeEvent(QCloseEvent *event) override;
  332. void reject() override;
  333. public:
  334. OBSBasicSettings(QWidget *parent);
  335. ~OBSBasicSettings();
  336. };