window-basic-settings.hpp 9.6 KB

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