window-basic-settings.hpp 8.8 KB

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