window-basic-auto-config.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #pragma once
  2. #include <QWizard>
  3. #include <QPointer>
  4. #include <QFormLayout>
  5. #include <QWizardPage>
  6. #include <condition_variable>
  7. #include <utility>
  8. #include <thread>
  9. #include <vector>
  10. #include <string>
  11. #include <mutex>
  12. class Ui_AutoConfigStartPage;
  13. class Ui_AutoConfigVideoPage;
  14. class Ui_AutoConfigStreamPage;
  15. class Ui_AutoConfigTestPage;
  16. class AutoConfig : public QWizard {
  17. Q_OBJECT
  18. friend class AutoConfigStartPage;
  19. friend class AutoConfigVideoPage;
  20. friend class AutoConfigStreamPage;
  21. friend class AutoConfigTestPage;
  22. enum class Type {
  23. Invalid,
  24. Streaming,
  25. Recording
  26. };
  27. enum class Service {
  28. Twitch,
  29. Hitbox,
  30. Other
  31. };
  32. enum class Encoder {
  33. x264,
  34. NVENC,
  35. QSV,
  36. AMD,
  37. Stream
  38. };
  39. enum class Quality {
  40. Stream,
  41. High
  42. };
  43. enum class FPSType : int {
  44. PreferHighFPS,
  45. PreferHighRes,
  46. UseCurrent,
  47. fps30,
  48. fps60
  49. };
  50. static inline const char *GetEncoderId(Encoder enc);
  51. Service service = Service::Other;
  52. Quality recordingQuality = Quality::Stream;
  53. Encoder recordingEncoder = Encoder::Stream;
  54. Encoder streamingEncoder = Encoder::x264;
  55. Type type = Type::Streaming;
  56. FPSType fpsType = FPSType::PreferHighFPS;
  57. int idealBitrate = 2500;
  58. int baseResolutionCX = 1920;
  59. int baseResolutionCY = 1080;
  60. int idealResolutionCX = 1280;
  61. int idealResolutionCY = 720;
  62. int idealFPSNum = 60;
  63. int idealFPSDen = 1;
  64. std::string serviceName;
  65. std::string serverName;
  66. std::string server;
  67. std::string key;
  68. bool hardwareEncodingAvailable = false;
  69. bool nvencAvailable = false;
  70. bool qsvAvailable = false;
  71. bool vceAvailable = false;
  72. int startingBitrate = 2500;
  73. bool customServer = false;
  74. bool bandwidthTest = false;
  75. bool testRegions = true;
  76. bool regionUS = true;
  77. bool regionEU = true;
  78. bool regionAsia = true;
  79. bool regionOther = true;
  80. bool preferHighFPS = false;
  81. bool preferHardware = false;
  82. int specificFPSNum = 0;
  83. int specificFPSDen = 0;
  84. void TestHardwareEncoding();
  85. bool CanTestServer(const char *server);
  86. virtual void done(int result) override;
  87. void SaveStreamSettings();
  88. void SaveSettings();
  89. public:
  90. AutoConfig(QWidget *parent);
  91. ~AutoConfig();
  92. enum Page {
  93. StartPage,
  94. VideoPage,
  95. StreamPage,
  96. TestPage
  97. };
  98. };
  99. class AutoConfigStartPage : public QWizardPage {
  100. Q_OBJECT
  101. friend class AutoConfig;
  102. Ui_AutoConfigStartPage *ui;
  103. public:
  104. AutoConfigStartPage(QWidget *parent = nullptr);
  105. ~AutoConfigStartPage();
  106. virtual int nextId() const override;
  107. public slots:
  108. void on_prioritizeStreaming_clicked();
  109. void on_prioritizeRecording_clicked();
  110. };
  111. class AutoConfigVideoPage : public QWizardPage {
  112. Q_OBJECT
  113. friend class AutoConfig;
  114. Ui_AutoConfigVideoPage *ui;
  115. public:
  116. AutoConfigVideoPage(QWidget *parent = nullptr);
  117. ~AutoConfigVideoPage();
  118. virtual int nextId() const override;
  119. virtual bool validatePage() override;
  120. };
  121. class AutoConfigStreamPage : public QWizardPage {
  122. Q_OBJECT
  123. friend class AutoConfig;
  124. Ui_AutoConfigStreamPage *ui;
  125. QString lastService;
  126. bool ready = false;
  127. void LoadServices(bool showAll);
  128. public:
  129. AutoConfigStreamPage(QWidget *parent = nullptr);
  130. ~AutoConfigStreamPage();
  131. virtual bool isComplete() const override;
  132. virtual int nextId() const override;
  133. virtual bool validatePage() override;
  134. public slots:
  135. void on_show_clicked();
  136. void ServiceChanged();
  137. void UpdateKeyLink();
  138. void UpdateServerList();
  139. void UpdateCompleted();
  140. };
  141. class AutoConfigTestPage : public QWizardPage {
  142. Q_OBJECT
  143. friend class AutoConfig;
  144. QPointer<QFormLayout> results;
  145. Ui_AutoConfigTestPage *ui;
  146. std::thread testThread;
  147. std::condition_variable cv;
  148. std::mutex m;
  149. bool cancel = false;
  150. bool started = false;
  151. enum class Stage {
  152. Starting,
  153. BandwidthTest,
  154. StreamEncoder,
  155. RecordingEncoder,
  156. Finished
  157. };
  158. Stage stage = Stage::Starting;
  159. bool softwareTested = false;
  160. void StartBandwidthStage();
  161. void StartStreamEncoderStage();
  162. void StartRecordingEncoderStage();
  163. void FindIdealHardwareResolution();
  164. bool TestSoftwareEncoding();
  165. void TestBandwidthThread();
  166. void TestStreamEncoderThread();
  167. void TestRecordingEncoderThread();
  168. void FinalizeResults();
  169. struct ServerInfo {
  170. std::string name;
  171. std::string address;
  172. int bitrate = 0;
  173. int ms = -1;
  174. inline ServerInfo() {}
  175. inline ServerInfo(const char *name_, const char *address_)
  176. : name(name_), address(address_)
  177. {
  178. }
  179. };
  180. void GetServers(std::vector<ServerInfo> &servers);
  181. public:
  182. AutoConfigTestPage(QWidget *parent = nullptr);
  183. ~AutoConfigTestPage();
  184. virtual void initializePage() override;
  185. virtual void cleanupPage() override;
  186. virtual bool isComplete() const override;
  187. virtual int nextId() const override;
  188. public slots:
  189. void NextStage();
  190. void UpdateMessage(QString message);
  191. void Failure(QString message);
  192. void Progress(int percentage);
  193. };