window-basic-settings.hpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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 QComboBox;
  27. class QCheckBox;
  28. class QLabel;
  29. class OBSPropertiesView;
  30. class OBSHotkeyWidget;
  31. #include "ui_OBSBasicSettings.h"
  32. #define VOLUME_METER_DECAY_FAST 23.53
  33. #define VOLUME_METER_DECAY_MEDIUM 11.76
  34. #define VOLUME_METER_DECAY_SLOW 8.57
  35. class SilentUpdateCheckBox : public QCheckBox {
  36. Q_OBJECT
  37. public slots:
  38. void setCheckedSilently(bool checked)
  39. {
  40. bool blocked = blockSignals(true);
  41. setChecked(checked);
  42. blockSignals(blocked);
  43. }
  44. };
  45. class SilentUpdateSpinBox : public QSpinBox {
  46. Q_OBJECT
  47. public slots:
  48. void setValueSilently(int val)
  49. {
  50. bool blocked = blockSignals(true);
  51. setValue(val);
  52. blockSignals(blocked);
  53. }
  54. };
  55. class OBSFFDeleter {
  56. public:
  57. void operator()(const ff_format_desc *format)
  58. {
  59. ff_format_desc_free(format);
  60. }
  61. void operator()(const ff_codec_desc *codec)
  62. {
  63. ff_codec_desc_free(codec);
  64. }
  65. };
  66. using OBSFFCodecDesc = std::unique_ptr<const ff_codec_desc, OBSFFDeleter>;
  67. using OBSFFFormatDesc = std::unique_ptr<const ff_format_desc, OBSFFDeleter>;
  68. class OBSBasicSettings : public QDialog {
  69. Q_OBJECT
  70. Q_PROPERTY(QIcon generalIcon WRITE SetGeneralIcon NOTIFY SetGeneralIcon)
  71. Q_PROPERTY(QIcon streamIcon WRITE SetStreamIcon NOTIFY SetStreamIcon)
  72. Q_PROPERTY(QIcon outputIcon WRITE SetOutputIcon NOTIFY SetOutputIcon)
  73. Q_PROPERTY(QIcon audioIcon WRITE SetAudioIcon NOTIFY SetAudioIcon)
  74. Q_PROPERTY(QIcon videoIcon WRITE SetVideoIcon NOTIFY SetVideoIcon)
  75. Q_PROPERTY(QIcon hotkeysIcon WRITE SetHotkeysIcon NOTIFY SetHotkeysIcon)
  76. Q_PROPERTY(
  77. QIcon advancedIcon WRITE SetAdvancedIcon NOTIFY SetAdvancedIcon)
  78. private:
  79. OBSBasic *main;
  80. std::unique_ptr<Ui::OBSBasicSettings> ui;
  81. std::shared_ptr<Auth> auth;
  82. bool generalChanged = false;
  83. bool stream1Changed = false;
  84. bool outputsChanged = false;
  85. bool audioChanged = false;
  86. bool videoChanged = false;
  87. bool hotkeysChanged = false;
  88. bool advancedChanged = false;
  89. int pageIndex = 0;
  90. bool loading = true;
  91. std::string savedTheme;
  92. int lastSimpleRecQualityIdx = 0;
  93. int lastChannelSetupIdx = 0;
  94. OBSFFFormatDesc formats;
  95. OBSPropertiesView *streamProperties = nullptr;
  96. OBSPropertiesView *streamEncoderProps = nullptr;
  97. OBSPropertiesView *recordEncoderProps = nullptr;
  98. QPointer<QLabel> advOutRecWarning;
  99. QPointer<QLabel> simpleOutRecWarning;
  100. QString curPreset;
  101. QString curQSVPreset;
  102. QString curNVENCPreset;
  103. QString curAMDPreset;
  104. QString curAdvStreamEncoder;
  105. QString curAdvRecordEncoder;
  106. using AudioSource_t =
  107. std::tuple<OBSWeakSource, QPointer<QCheckBox>,
  108. QPointer<QSpinBox>, QPointer<QCheckBox>,
  109. QPointer<QSpinBox>>;
  110. std::vector<AudioSource_t> audioSources;
  111. std::vector<OBSSignal> audioSourceSignals;
  112. OBSSignal sourceCreated;
  113. OBSSignal channelChanged;
  114. std::vector<std::pair<bool, QPointer<OBSHotkeyWidget>>> hotkeys;
  115. OBSSignal hotkeyRegistered;
  116. OBSSignal hotkeyUnregistered;
  117. uint32_t outputCX = 0;
  118. uint32_t outputCY = 0;
  119. void SaveCombo(QComboBox *widget, const char *section,
  120. const char *value);
  121. void SaveComboData(QComboBox *widget, const char *section,
  122. const char *value);
  123. void SaveCheckBox(QAbstractButton *widget, const char *section,
  124. const char *value, bool invert = false);
  125. void SaveEdit(QLineEdit *widget, const char *section,
  126. const char *value);
  127. void SaveSpinBox(QSpinBox *widget, const char *section,
  128. const char *value);
  129. void SaveFormat(QComboBox *combo);
  130. void SaveEncoder(QComboBox *combo, const char *section,
  131. const char *value);
  132. inline bool Changed() const
  133. {
  134. return generalChanged || outputsChanged || stream1Changed ||
  135. audioChanged || videoChanged || advancedChanged ||
  136. hotkeysChanged;
  137. }
  138. inline void EnableApplyButton(bool en)
  139. {
  140. ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(en);
  141. }
  142. inline void ClearChanged()
  143. {
  144. generalChanged = false;
  145. stream1Changed = false;
  146. outputsChanged = false;
  147. audioChanged = false;
  148. videoChanged = false;
  149. hotkeysChanged = false;
  150. advancedChanged = false;
  151. EnableApplyButton(false);
  152. }
  153. #ifdef _WIN32
  154. bool aeroWasDisabled = false;
  155. QCheckBox *toggleAero = nullptr;
  156. void ToggleDisableAero(bool checked);
  157. #endif
  158. void HookWidget(QWidget *widget, const char *signal, const char *slot);
  159. bool QueryChanges();
  160. void LoadEncoderTypes();
  161. void LoadColorRanges();
  162. void LoadFormats();
  163. void ReloadCodecs(const ff_format_desc *formatDesc);
  164. void LoadGeneralSettings();
  165. void LoadStream1Settings();
  166. void LoadOutputSettings();
  167. void LoadAudioSettings();
  168. void LoadVideoSettings();
  169. void
  170. LoadHotkeySettings(obs_hotkey_id ignoreKey = OBS_INVALID_HOTKEY_ID);
  171. void LoadAdvancedSettings();
  172. void LoadSettings(bool changedOnly);
  173. OBSPropertiesView *CreateEncoderPropertyView(const char *encoder,
  174. const char *path,
  175. bool changed = false);
  176. /* general */
  177. void LoadLanguageList();
  178. void LoadThemeList();
  179. /* stream */
  180. void InitStreamPage();
  181. inline bool IsCustomService() const;
  182. void LoadServices(bool showAll);
  183. void OnOAuthStreamKeyConnected();
  184. void OnAuthConnected();
  185. QString lastService;
  186. private slots:
  187. void UpdateServerList();
  188. void UpdateKeyLink();
  189. void on_show_clicked();
  190. void on_authPwShow_clicked();
  191. void on_connectAccount_clicked();
  192. void on_disconnectAccount_clicked();
  193. void on_useStreamKey_clicked();
  194. void on_useAuth_toggled();
  195. private:
  196. /* output */
  197. void LoadSimpleOutputSettings();
  198. void LoadAdvOutputStreamingSettings();
  199. void LoadAdvOutputStreamingEncoderProperties();
  200. void LoadAdvOutputRecordingSettings();
  201. void LoadAdvOutputRecordingEncoderProperties();
  202. void LoadAdvOutputFFmpegSettings();
  203. void LoadAdvOutputAudioSettings();
  204. void SetAdvOutputFFmpegEnablement(ff_codec_type encoderType,
  205. bool enabled,
  206. bool enableEncode = false);
  207. /* audio */
  208. void LoadListValues(QComboBox *widget, obs_property_t *prop, int index);
  209. void LoadAudioDevices();
  210. void LoadAudioSources();
  211. /* video */
  212. void LoadRendererList();
  213. void ResetDownscales(uint32_t cx, uint32_t cy);
  214. void LoadDownscaleFilters();
  215. void LoadResolutionLists();
  216. void LoadFPSData();
  217. void SaveGeneralSettings();
  218. void SaveStream1Settings();
  219. void SaveOutputSettings();
  220. void SaveAudioSettings();
  221. void SaveVideoSettings();
  222. void SaveHotkeySettings();
  223. void SaveAdvancedSettings();
  224. void SaveSettings();
  225. void UpdateSimpleOutStreamDelayEstimate();
  226. void UpdateAdvOutStreamDelayEstimate();
  227. void FillSimpleRecordingValues();
  228. void FillSimpleStreamingValues();
  229. void FillAudioMonitoringDevices();
  230. void RecalcOutputResPixels(const char *resText);
  231. private slots:
  232. void on_theme_activated(int idx);
  233. void on_listWidget_itemSelectionChanged();
  234. void on_buttonBox_clicked(QAbstractButton *button);
  235. void on_service_currentIndexChanged(int idx);
  236. void on_simpleOutputBrowse_clicked();
  237. void on_advOutRecPathBrowse_clicked();
  238. void on_advOutFFPathBrowse_clicked();
  239. void on_advOutEncoder_currentIndexChanged(int idx);
  240. void on_advOutRecEncoder_currentIndexChanged(int idx);
  241. void on_advOutFFIgnoreCompat_stateChanged(int state);
  242. void on_advOutFFFormat_currentIndexChanged(int idx);
  243. void on_advOutFFAEncoder_currentIndexChanged(int idx);
  244. void on_advOutFFVEncoder_currentIndexChanged(int idx);
  245. void on_advOutFFType_currentIndexChanged(int idx);
  246. void on_colorFormat_currentIndexChanged(const QString &text);
  247. void on_filenameFormatting_textEdited(const QString &text);
  248. void on_outputResolution_editTextChanged(const QString &text);
  249. void on_baseResolution_editTextChanged(const QString &text);
  250. void on_disableOSXVSync_clicked();
  251. void GeneralChanged();
  252. void AudioChanged();
  253. void AudioChangedRestart();
  254. void ReloadAudioSources();
  255. void SurroundWarning(int idx);
  256. void SpeakerLayoutChanged(int idx);
  257. void OutputsChanged();
  258. void Stream1Changed();
  259. void VideoChanged();
  260. void VideoChangedResolution();
  261. void VideoChangedRestart();
  262. void HotkeysChanged();
  263. void ReloadHotkeys(obs_hotkey_id ignoreKey = OBS_INVALID_HOTKEY_ID);
  264. void AdvancedChanged();
  265. void AdvancedChangedRestart();
  266. void UpdateStreamDelayEstimate();
  267. void UpdateAutomaticReplayBufferCheckboxes();
  268. void AdvOutRecCheckWarnings();
  269. void SimpleRecordingQualityChanged();
  270. void SimpleRecordingEncoderChanged();
  271. void SimpleRecordingQualityLosslessWarning(int idx);
  272. void SimpleReplayBufferChanged();
  273. void AdvReplayBufferChanged();
  274. void SimpleStreamingEncoderChanged();
  275. OBSService SpawnTempService();
  276. void SetGeneralIcon(const QIcon &icon);
  277. void SetStreamIcon(const QIcon &icon);
  278. void SetOutputIcon(const QIcon &icon);
  279. void SetAudioIcon(const QIcon &icon);
  280. void SetVideoIcon(const QIcon &icon);
  281. void SetHotkeysIcon(const QIcon &icon);
  282. void SetAdvancedIcon(const QIcon &icon);
  283. protected:
  284. virtual void closeEvent(QCloseEvent *event);
  285. public:
  286. OBSBasicSettings(QWidget *parent);
  287. ~OBSBasicSettings();
  288. };