window-basic-settings.hpp 10 KB

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