window-basic-auto-config-test.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290
  1. #include <chrono>
  2. #include <QFormLayout>
  3. #include <obs.hpp>
  4. #include <util/platform.h>
  5. #include <util/util_uint64.h>
  6. #include <graphics/vec4.h>
  7. #include <graphics/graphics.h>
  8. #include <graphics/math-extra.h>
  9. #include "window-basic-auto-config.hpp"
  10. #include "window-basic-main.hpp"
  11. #include "qt-wrappers.hpp"
  12. #include "obs-app.hpp"
  13. #include "ui_AutoConfigTestPage.h"
  14. #define wiz reinterpret_cast<AutoConfig *>(wizard())
  15. using namespace std;
  16. /* ------------------------------------------------------------------------- */
  17. class TestMode {
  18. obs_video_info ovi;
  19. OBSSource source[6];
  20. static void render_rand(void *, uint32_t cx, uint32_t cy)
  21. {
  22. gs_effect_t *solid = obs_get_base_effect(OBS_EFFECT_SOLID);
  23. gs_eparam_t *randomvals[3] = {
  24. gs_effect_get_param_by_name(solid, "randomvals1"),
  25. gs_effect_get_param_by_name(solid, "randomvals2"),
  26. gs_effect_get_param_by_name(solid, "randomvals3")};
  27. struct vec4 r;
  28. for (int i = 0; i < 3; i++) {
  29. vec4_set(&r, rand_float(true) * 100.0f,
  30. rand_float(true) * 100.0f,
  31. rand_float(true) * 50000.0f + 10000.0f, 0.0f);
  32. gs_effect_set_vec4(randomvals[i], &r);
  33. }
  34. while (gs_effect_loop(solid, "Random"))
  35. gs_draw_sprite(nullptr, 0, cx, cy);
  36. }
  37. public:
  38. inline TestMode()
  39. {
  40. obs_get_video_info(&ovi);
  41. obs_add_main_render_callback(render_rand, this);
  42. for (uint32_t i = 0; i < 6; i++) {
  43. source[i] = obs_get_output_source(i);
  44. obs_source_release(source[i]);
  45. obs_set_output_source(i, nullptr);
  46. }
  47. }
  48. inline ~TestMode()
  49. {
  50. for (uint32_t i = 0; i < 6; i++)
  51. obs_set_output_source(i, source[i]);
  52. obs_remove_main_render_callback(render_rand, this);
  53. obs_reset_video(&ovi);
  54. }
  55. inline void SetVideo(int cx, int cy, int fps_num, int fps_den)
  56. {
  57. obs_video_info newOVI = ovi;
  58. newOVI.output_width = (uint32_t)cx;
  59. newOVI.output_height = (uint32_t)cy;
  60. newOVI.fps_num = (uint32_t)fps_num;
  61. newOVI.fps_den = (uint32_t)fps_den;
  62. obs_reset_video(&newOVI);
  63. }
  64. };
  65. /* ------------------------------------------------------------------------- */
  66. #define TEST_STR(x) "Basic.AutoConfig.TestPage." x
  67. #define SUBTITLE_TESTING TEST_STR("SubTitle.Testing")
  68. #define SUBTITLE_COMPLETE TEST_STR("SubTitle.Complete")
  69. #define TEST_BW TEST_STR("TestingBandwidth")
  70. #define TEST_BW_NO_OUTPUT TEST_STR("TestingBandwidth.NoOutput")
  71. #define TEST_BW_CONNECTING TEST_STR("TestingBandwidth.Connecting")
  72. #define TEST_BW_CONNECT_FAIL TEST_STR("TestingBandwidth.ConnectFailed")
  73. #define TEST_BW_SERVER TEST_STR("TestingBandwidth.Server")
  74. #define TEST_RES_VAL TEST_STR("TestingRes.Resolution")
  75. #define TEST_RES_FAIL TEST_STR("TestingRes.Fail")
  76. #define TEST_SE TEST_STR("TestingStreamEncoder")
  77. #define TEST_RE TEST_STR("TestingRecordingEncoder")
  78. #define TEST_RESULT_SE TEST_STR("Result.StreamingEncoder")
  79. #define TEST_RESULT_RE TEST_STR("Result.RecordingEncoder")
  80. void AutoConfigTestPage::StartBandwidthStage()
  81. {
  82. ui->progressLabel->setText(QTStr(TEST_BW));
  83. testThread = std::thread([this]() { TestBandwidthThread(); });
  84. }
  85. void AutoConfigTestPage::StartStreamEncoderStage()
  86. {
  87. ui->progressLabel->setText(QTStr(TEST_SE));
  88. testThread = std::thread([this]() { TestStreamEncoderThread(); });
  89. }
  90. void AutoConfigTestPage::StartRecordingEncoderStage()
  91. {
  92. ui->progressLabel->setText(QTStr(TEST_RE));
  93. testThread = std::thread([this]() { TestRecordingEncoderThread(); });
  94. }
  95. void AutoConfigTestPage::GetServers(std::vector<ServerInfo> &servers)
  96. {
  97. OBSDataAutoRelease settings = obs_data_create();
  98. obs_data_set_string(settings, "service", wiz->serviceName.c_str());
  99. obs_properties_t *ppts = obs_get_service_properties("rtmp_common");
  100. obs_property_t *p = obs_properties_get(ppts, "service");
  101. obs_property_modified(p, settings);
  102. p = obs_properties_get(ppts, "server");
  103. size_t count = obs_property_list_item_count(p);
  104. servers.reserve(count);
  105. for (size_t i = 0; i < count; i++) {
  106. const char *name = obs_property_list_item_name(p, i);
  107. const char *server = obs_property_list_item_string(p, i);
  108. if (wiz->CanTestServer(name)) {
  109. ServerInfo info(name, server);
  110. servers.push_back(info);
  111. }
  112. }
  113. obs_properties_destroy(ppts);
  114. }
  115. static inline void string_depad_key(string &key)
  116. {
  117. while (!key.empty()) {
  118. char ch = key.back();
  119. if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r')
  120. key.pop_back();
  121. else
  122. break;
  123. }
  124. }
  125. const char *FindAudioEncoderFromCodec(const char *type);
  126. static inline bool can_use_output(const char *prot, const char *output,
  127. const char *prot_test1,
  128. const char *prot_test2 = nullptr)
  129. {
  130. return (strcmp(prot, prot_test1) == 0 ||
  131. (prot_test2 && strcmp(prot, prot_test2) == 0)) &&
  132. (obs_get_output_flags(output) & OBS_OUTPUT_SERVICE) != 0;
  133. }
  134. static bool return_first_id(void *data, const char *id)
  135. {
  136. const char **output = (const char **)data;
  137. *output = id;
  138. return false;
  139. }
  140. void AutoConfigTestPage::TestBandwidthThread()
  141. {
  142. bool connected = false;
  143. bool stopped = false;
  144. TestMode testMode;
  145. testMode.SetVideo(128, 128, 60, 1);
  146. QMetaObject::invokeMethod(this, "Progress", Q_ARG(int, 0));
  147. /*
  148. * create encoders
  149. * create output
  150. * test for 10 seconds
  151. */
  152. QMetaObject::invokeMethod(this, "UpdateMessage",
  153. Q_ARG(QString, QStringLiteral("")));
  154. /* -----------------------------------*/
  155. /* create obs objects */
  156. const char *serverType = wiz->customServer ? "rtmp_custom"
  157. : "rtmp_common";
  158. OBSEncoderAutoRelease vencoder = obs_video_encoder_create(
  159. "obs_x264", "test_x264", nullptr, nullptr);
  160. OBSEncoderAutoRelease aencoder = obs_audio_encoder_create(
  161. "ffmpeg_aac", "test_aac", nullptr, 0, nullptr);
  162. OBSServiceAutoRelease service = obs_service_create(
  163. serverType, "test_service", nullptr, nullptr);
  164. /* -----------------------------------*/
  165. /* configure settings */
  166. // service: "service", "server", "key"
  167. // vencoder: "bitrate", "rate_control",
  168. // obs_service_apply_encoder_settings
  169. // aencoder: "bitrate"
  170. // output: "bind_ip" via main config -> "Output", "BindIP"
  171. // obs_output_set_service
  172. OBSDataAutoRelease service_settings = obs_data_create();
  173. OBSDataAutoRelease vencoder_settings = obs_data_create();
  174. OBSDataAutoRelease aencoder_settings = obs_data_create();
  175. OBSDataAutoRelease output_settings = obs_data_create();
  176. std::string key = wiz->key;
  177. if (wiz->service == AutoConfig::Service::Twitch) {
  178. string_depad_key(key);
  179. key += "?bandwidthtest";
  180. } else if (wiz->serviceName == "Restream.io" ||
  181. wiz->serviceName == "Restream.io - RTMP") {
  182. string_depad_key(key);
  183. key += "?test=true";
  184. } else if (wiz->serviceName == "Restream.io - FTL") {
  185. string_depad_key(key);
  186. key += "?test";
  187. }
  188. obs_data_set_string(service_settings, "service",
  189. wiz->serviceName.c_str());
  190. obs_data_set_string(service_settings, "key", key.c_str());
  191. obs_data_set_int(vencoder_settings, "bitrate", wiz->startingBitrate);
  192. obs_data_set_string(vencoder_settings, "rate_control", "CBR");
  193. obs_data_set_string(vencoder_settings, "preset", "veryfast");
  194. obs_data_set_int(vencoder_settings, "keyint_sec", 2);
  195. obs_data_set_int(aencoder_settings, "bitrate", 32);
  196. OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
  197. const char *bind_ip =
  198. config_get_string(main->Config(), "Output", "BindIP");
  199. obs_data_set_string(output_settings, "bind_ip", bind_ip);
  200. /* -----------------------------------*/
  201. /* determine which servers to test */
  202. std::vector<ServerInfo> servers;
  203. if (wiz->customServer)
  204. servers.emplace_back(wiz->server.c_str(), wiz->server.c_str());
  205. else
  206. GetServers(servers);
  207. /* just use the first server if it only has one alternate server,
  208. * or if using Restream or Nimo TV due to their "auto" servers */
  209. if (servers.size() < 3 ||
  210. wiz->serviceName.substr(0, 11) == "Restream.io" ||
  211. wiz->serviceName == "Nimo TV") {
  212. servers.resize(1);
  213. } else if (wiz->service == AutoConfig::Service::Twitch &&
  214. wiz->twitchAuto) {
  215. /* if using Twitch and "Auto" is available, test 3 closest
  216. * server */
  217. servers.erase(servers.begin() + 1);
  218. servers.resize(3);
  219. } else if (wiz->service == AutoConfig::Service::YouTube) {
  220. /* Only test first set of primary + backup servers */
  221. servers.resize(2);
  222. }
  223. /* -----------------------------------*/
  224. /* apply service settings */
  225. obs_service_update(service, service_settings);
  226. obs_service_apply_encoder_settings(service, vencoder_settings,
  227. aencoder_settings);
  228. /* -----------------------------------*/
  229. /* create output */
  230. /* Check if the service has a preferred output type */
  231. const char *output_type =
  232. obs_service_get_preferred_output_type(service);
  233. if (!output_type ||
  234. (obs_get_output_flags(output_type) & OBS_OUTPUT_SERVICE) == 0) {
  235. /* Otherwise, prefer first-party output types */
  236. const char *protocol = obs_service_get_protocol(service);
  237. if (can_use_output(protocol, "rtmp_output", "RTMP", "RTMPS")) {
  238. output_type = "rtmp_output";
  239. } else if (can_use_output(protocol, "ffmpeg_hls_muxer",
  240. "HLS")) {
  241. output_type = "ffmpeg_hls_muxer";
  242. } else if (can_use_output(protocol, "ffmpeg_mpegts_muxer",
  243. "SRT", "RIST")) {
  244. output_type = "ffmpeg_mpegts_muxer";
  245. }
  246. /* If third-party protocol, use the first enumerated type */
  247. if (!output_type)
  248. obs_enum_output_types_with_protocol(
  249. protocol, &output_type, return_first_id);
  250. /* If none, fail */
  251. if (!output_type) {
  252. QMetaObject::invokeMethod(
  253. this, "Failure",
  254. Q_ARG(QString, QTStr(TEST_BW_NO_OUTPUT)));
  255. return;
  256. }
  257. }
  258. OBSOutputAutoRelease output =
  259. obs_output_create(output_type, "test_stream", nullptr, nullptr);
  260. obs_output_update(output, output_settings);
  261. const char *audio_codec = obs_output_get_supported_audio_codecs(output);
  262. if (strcmp(audio_codec, "aac") != 0) {
  263. const char *id = FindAudioEncoderFromCodec(audio_codec);
  264. aencoder = obs_audio_encoder_create(id, "test_audio", nullptr,
  265. 0, nullptr);
  266. }
  267. /* -----------------------------------*/
  268. /* connect encoders/services/outputs */
  269. obs_encoder_update(vencoder, vencoder_settings);
  270. obs_encoder_update(aencoder, aencoder_settings);
  271. obs_encoder_set_video(vencoder, obs_get_video());
  272. obs_encoder_set_audio(aencoder, obs_get_audio());
  273. obs_output_set_video_encoder(output, vencoder);
  274. obs_output_set_audio_encoder(output, aencoder, 0);
  275. obs_output_set_reconnect_settings(output, 0, 0);
  276. obs_output_set_service(output, service);
  277. /* -----------------------------------*/
  278. /* connect signals */
  279. auto on_started = [&]() {
  280. unique_lock<mutex> lock(m);
  281. connected = true;
  282. stopped = false;
  283. cv.notify_one();
  284. };
  285. auto on_stopped = [&]() {
  286. unique_lock<mutex> lock(m);
  287. connected = false;
  288. stopped = true;
  289. cv.notify_one();
  290. };
  291. using on_started_t = decltype(on_started);
  292. using on_stopped_t = decltype(on_stopped);
  293. auto pre_on_started = [](void *data, calldata_t *) {
  294. on_started_t &on_started =
  295. *reinterpret_cast<on_started_t *>(data);
  296. on_started();
  297. };
  298. auto pre_on_stopped = [](void *data, calldata_t *) {
  299. on_stopped_t &on_stopped =
  300. *reinterpret_cast<on_stopped_t *>(data);
  301. on_stopped();
  302. };
  303. signal_handler *sh = obs_output_get_signal_handler(output);
  304. signal_handler_connect(sh, "start", pre_on_started, &on_started);
  305. signal_handler_connect(sh, "stop", pre_on_stopped, &on_stopped);
  306. /* -----------------------------------*/
  307. /* test servers */
  308. bool success = false;
  309. for (size_t i = 0; i < servers.size(); i++) {
  310. auto &server = servers[i];
  311. connected = false;
  312. stopped = false;
  313. int per = int((i + 1) * 100 / servers.size());
  314. QMetaObject::invokeMethod(this, "Progress", Q_ARG(int, per));
  315. QMetaObject::invokeMethod(
  316. this, "UpdateMessage",
  317. Q_ARG(QString, QTStr(TEST_BW_CONNECTING)
  318. .arg(server.name.c_str())));
  319. obs_data_set_string(service_settings, "server",
  320. server.address.c_str());
  321. obs_service_update(service, service_settings);
  322. if (!obs_output_start(output))
  323. continue;
  324. unique_lock<mutex> ul(m);
  325. if (cancel) {
  326. ul.unlock();
  327. obs_output_force_stop(output);
  328. return;
  329. }
  330. if (!stopped && !connected)
  331. cv.wait(ul);
  332. if (cancel) {
  333. ul.unlock();
  334. obs_output_force_stop(output);
  335. return;
  336. }
  337. if (!connected)
  338. continue;
  339. QMetaObject::invokeMethod(
  340. this, "UpdateMessage",
  341. Q_ARG(QString,
  342. QTStr(TEST_BW_SERVER).arg(server.name.c_str())));
  343. /* ignore first 2.5 seconds due to possible buffering skewing
  344. * the result */
  345. cv.wait_for(ul, chrono::milliseconds(2500));
  346. if (stopped)
  347. continue;
  348. if (cancel) {
  349. ul.unlock();
  350. obs_output_force_stop(output);
  351. return;
  352. }
  353. /* continue test */
  354. int start_bytes = (int)obs_output_get_total_bytes(output);
  355. uint64_t t_start = os_gettime_ns();
  356. cv.wait_for(ul, chrono::seconds(10));
  357. if (stopped)
  358. continue;
  359. if (cancel) {
  360. ul.unlock();
  361. obs_output_force_stop(output);
  362. return;
  363. }
  364. obs_output_stop(output);
  365. cv.wait(ul);
  366. uint64_t total_time = os_gettime_ns() - t_start;
  367. if (total_time == 0)
  368. total_time = 1;
  369. int total_bytes =
  370. (int)obs_output_get_total_bytes(output) - start_bytes;
  371. uint64_t bitrate = util_mul_div64(
  372. total_bytes, 8ULL * 1000000000ULL / 1000ULL,
  373. total_time);
  374. if (obs_output_get_frames_dropped(output) ||
  375. (int)bitrate < (wiz->startingBitrate * 75 / 100)) {
  376. server.bitrate = (int)bitrate * 70 / 100;
  377. } else {
  378. server.bitrate = wiz->startingBitrate;
  379. }
  380. server.ms = obs_output_get_connect_time_ms(output);
  381. success = true;
  382. }
  383. if (!success) {
  384. QMetaObject::invokeMethod(this, "Failure",
  385. Q_ARG(QString,
  386. QTStr(TEST_BW_CONNECT_FAIL)));
  387. return;
  388. }
  389. int bestBitrate = 0;
  390. int bestMS = 0x7FFFFFFF;
  391. string bestServer;
  392. string bestServerName;
  393. for (auto &server : servers) {
  394. bool close = abs(server.bitrate - bestBitrate) < 400;
  395. if ((!close && server.bitrate > bestBitrate) ||
  396. (close && server.ms < bestMS)) {
  397. bestServer = server.address;
  398. bestServerName = server.name;
  399. bestBitrate = server.bitrate;
  400. bestMS = server.ms;
  401. }
  402. }
  403. wiz->server = std::move(bestServer);
  404. wiz->serverName = std::move(bestServerName);
  405. wiz->idealBitrate = bestBitrate;
  406. QMetaObject::invokeMethod(this, "NextStage");
  407. }
  408. /* this is used to estimate the lower bitrate limit for a given
  409. * resolution/fps. yes, it is a totally arbitrary equation that gets
  410. * the closest to the expected values */
  411. static long double EstimateBitrateVal(int cx, int cy, int fps_num, int fps_den)
  412. {
  413. long fps = (long double)fps_num / (long double)fps_den;
  414. long double areaVal = pow((long double)(cx * cy), 0.85l);
  415. return areaVal * sqrt(pow(fps, 1.1l));
  416. }
  417. static long double EstimateMinBitrate(int cx, int cy, int fps_num, int fps_den)
  418. {
  419. long double val = EstimateBitrateVal(1920, 1080, 60, 1) / 5800.0l;
  420. return EstimateBitrateVal(cx, cy, fps_num, fps_den) / val;
  421. }
  422. static long double EstimateUpperBitrate(int cx, int cy, int fps_num,
  423. int fps_den)
  424. {
  425. long double val = EstimateBitrateVal(1280, 720, 30, 1) / 3000.0l;
  426. return EstimateBitrateVal(cx, cy, fps_num, fps_den) / val;
  427. }
  428. struct Result {
  429. int cx;
  430. int cy;
  431. int fps_num;
  432. int fps_den;
  433. inline Result(int cx_, int cy_, int fps_num_, int fps_den_)
  434. : cx(cx_),
  435. cy(cy_),
  436. fps_num(fps_num_),
  437. fps_den(fps_den_)
  438. {
  439. }
  440. };
  441. static void CalcBaseRes(int &baseCX, int &baseCY)
  442. {
  443. const int maxBaseArea = 1920 * 1200;
  444. const int clipResArea = 1920 * 1080;
  445. /* if base resolution unusually high, recalculate to a more reasonable
  446. * value to start the downscaling at, based upon 1920x1080's area.
  447. *
  448. * for 16:9 resolutions this will always change the starting value to
  449. * 1920x1080 */
  450. if ((baseCX * baseCY) > maxBaseArea) {
  451. long double xyAspect =
  452. (long double)baseCX / (long double)baseCY;
  453. baseCY = (int)sqrt((long double)clipResArea / xyAspect);
  454. baseCX = (int)((long double)baseCY * xyAspect);
  455. }
  456. }
  457. bool AutoConfigTestPage::TestSoftwareEncoding()
  458. {
  459. TestMode testMode;
  460. QMetaObject::invokeMethod(this, "UpdateMessage",
  461. Q_ARG(QString, QStringLiteral("")));
  462. /* -----------------------------------*/
  463. /* create obs objects */
  464. OBSEncoderAutoRelease vencoder = obs_video_encoder_create(
  465. "obs_x264", "test_x264", nullptr, nullptr);
  466. OBSEncoderAutoRelease aencoder = obs_audio_encoder_create(
  467. "ffmpeg_aac", "test_aac", nullptr, 0, nullptr);
  468. OBSOutputAutoRelease output =
  469. obs_output_create("null_output", "null", nullptr, nullptr);
  470. /* -----------------------------------*/
  471. /* configure settings */
  472. OBSDataAutoRelease aencoder_settings = obs_data_create();
  473. OBSDataAutoRelease vencoder_settings = obs_data_create();
  474. obs_data_set_int(aencoder_settings, "bitrate", 32);
  475. if (wiz->type != AutoConfig::Type::Recording) {
  476. obs_data_set_int(vencoder_settings, "keyint_sec", 2);
  477. obs_data_set_int(vencoder_settings, "bitrate",
  478. wiz->idealBitrate);
  479. obs_data_set_string(vencoder_settings, "rate_control", "CBR");
  480. obs_data_set_string(vencoder_settings, "profile", "main");
  481. obs_data_set_string(vencoder_settings, "preset", "veryfast");
  482. } else {
  483. obs_data_set_int(vencoder_settings, "crf", 20);
  484. obs_data_set_string(vencoder_settings, "rate_control", "CRF");
  485. obs_data_set_string(vencoder_settings, "profile", "high");
  486. obs_data_set_string(vencoder_settings, "preset", "veryfast");
  487. }
  488. /* -----------------------------------*/
  489. /* apply settings */
  490. obs_encoder_update(vencoder, vencoder_settings);
  491. obs_encoder_update(aencoder, aencoder_settings);
  492. /* -----------------------------------*/
  493. /* connect encoders/services/outputs */
  494. obs_output_set_video_encoder(output, vencoder);
  495. obs_output_set_audio_encoder(output, aencoder, 0);
  496. /* -----------------------------------*/
  497. /* connect signals */
  498. auto on_stopped = [&]() {
  499. unique_lock<mutex> lock(m);
  500. cv.notify_one();
  501. };
  502. using on_stopped_t = decltype(on_stopped);
  503. auto pre_on_stopped = [](void *data, calldata_t *) {
  504. on_stopped_t &on_stopped =
  505. *reinterpret_cast<on_stopped_t *>(data);
  506. on_stopped();
  507. };
  508. signal_handler *sh = obs_output_get_signal_handler(output);
  509. signal_handler_connect(sh, "deactivate", pre_on_stopped, &on_stopped);
  510. /* -----------------------------------*/
  511. /* calculate starting resolution */
  512. int baseCX = wiz->baseResolutionCX;
  513. int baseCY = wiz->baseResolutionCY;
  514. CalcBaseRes(baseCX, baseCY);
  515. /* -----------------------------------*/
  516. /* calculate starting test rates */
  517. int pcores = os_get_physical_cores();
  518. int lcores = os_get_logical_cores();
  519. int maxDataRate;
  520. if (lcores > 8 || pcores > 4) {
  521. /* superb */
  522. maxDataRate = 1920 * 1200 * 60 + 1000;
  523. } else if (lcores > 4 && pcores == 4) {
  524. /* great */
  525. maxDataRate = 1920 * 1080 * 60 + 1000;
  526. } else if (pcores == 4) {
  527. /* okay */
  528. maxDataRate = 1920 * 1080 * 30 + 1000;
  529. } else {
  530. /* toaster */
  531. maxDataRate = 960 * 540 * 30 + 1000;
  532. }
  533. /* -----------------------------------*/
  534. /* perform tests */
  535. vector<Result> results;
  536. int i = 0;
  537. int count = 1;
  538. auto testRes = [&](int cy, int fps_num, int fps_den, bool force) {
  539. int per = ++i * 100 / count;
  540. QMetaObject::invokeMethod(this, "Progress", Q_ARG(int, per));
  541. if (cy > baseCY)
  542. return true;
  543. /* no need for more than 3 tests max */
  544. if (results.size() >= 3)
  545. return true;
  546. if (!fps_num || !fps_den) {
  547. fps_num = wiz->specificFPSNum;
  548. fps_den = wiz->specificFPSDen;
  549. }
  550. long double fps = ((long double)fps_num / (long double)fps_den);
  551. int cx = int(((long double)baseCX / (long double)baseCY) *
  552. (long double)cy);
  553. if (!force && wiz->type != AutoConfig::Type::Recording) {
  554. int est = EstimateMinBitrate(cx, cy, fps_num, fps_den);
  555. if (est > wiz->idealBitrate)
  556. return true;
  557. }
  558. long double rate = (long double)cx * (long double)cy * fps;
  559. if (!force && rate > maxDataRate)
  560. return true;
  561. testMode.SetVideo(cx, cy, fps_num, fps_den);
  562. obs_encoder_set_video(vencoder, obs_get_video());
  563. obs_encoder_set_audio(aencoder, obs_get_audio());
  564. obs_encoder_update(vencoder, vencoder_settings);
  565. obs_output_set_media(output, obs_get_video(), obs_get_audio());
  566. QString cxStr = QString::number(cx);
  567. QString cyStr = QString::number(cy);
  568. QString fpsStr = (fps_den > 1) ? QString::number(fps, 'f', 2)
  569. : QString::number(fps, 'g', 2);
  570. QMetaObject::invokeMethod(
  571. this, "UpdateMessage",
  572. Q_ARG(QString,
  573. QTStr(TEST_RES_VAL).arg(cxStr, cyStr, fpsStr)));
  574. unique_lock<mutex> ul(m);
  575. if (cancel)
  576. return false;
  577. if (!obs_output_start(output)) {
  578. QMetaObject::invokeMethod(this, "Failure",
  579. Q_ARG(QString,
  580. QTStr(TEST_RES_FAIL)));
  581. return false;
  582. }
  583. cv.wait_for(ul, chrono::seconds(5));
  584. obs_output_stop(output);
  585. cv.wait(ul);
  586. int skipped =
  587. (int)video_output_get_skipped_frames(obs_get_video());
  588. if (force || skipped <= 10)
  589. results.emplace_back(cx, cy, fps_num, fps_den);
  590. return !cancel;
  591. };
  592. if (wiz->specificFPSNum && wiz->specificFPSDen) {
  593. count = 7;
  594. if (!testRes(2160, 0, 0, false))
  595. return false;
  596. if (!testRes(1440, 0, 0, false))
  597. return false;
  598. if (!testRes(1080, 0, 0, false))
  599. return false;
  600. if (!testRes(720, 0, 0, false))
  601. return false;
  602. if (!testRes(480, 0, 0, false))
  603. return false;
  604. if (!testRes(360, 0, 0, false))
  605. return false;
  606. if (!testRes(240, 0, 0, true))
  607. return false;
  608. } else {
  609. count = 14;
  610. if (!testRes(2160, 60, 1, false))
  611. return false;
  612. if (!testRes(2160, 30, 1, false))
  613. return false;
  614. if (!testRes(1440, 60, 1, false))
  615. return false;
  616. if (!testRes(1440, 30, 1, false))
  617. return false;
  618. if (!testRes(1080, 60, 1, false))
  619. return false;
  620. if (!testRes(1080, 30, 1, false))
  621. return false;
  622. if (!testRes(720, 60, 1, false))
  623. return false;
  624. if (!testRes(720, 30, 1, false))
  625. return false;
  626. if (!testRes(480, 60, 1, false))
  627. return false;
  628. if (!testRes(480, 30, 1, false))
  629. return false;
  630. if (!testRes(360, 60, 1, false))
  631. return false;
  632. if (!testRes(360, 30, 1, false))
  633. return false;
  634. if (!testRes(240, 60, 1, false))
  635. return false;
  636. if (!testRes(240, 30, 1, true))
  637. return false;
  638. }
  639. /* -----------------------------------*/
  640. /* find preferred settings */
  641. int minArea = 960 * 540 + 1000;
  642. if (!wiz->specificFPSNum && wiz->preferHighFPS && results.size() > 1) {
  643. Result &result1 = results[0];
  644. Result &result2 = results[1];
  645. if (result1.fps_num == 30 && result2.fps_num == 60) {
  646. int nextArea = result2.cx * result2.cy;
  647. if (nextArea >= minArea)
  648. results.erase(results.begin());
  649. }
  650. }
  651. Result result = results.front();
  652. wiz->idealResolutionCX = result.cx;
  653. wiz->idealResolutionCY = result.cy;
  654. wiz->idealFPSNum = result.fps_num;
  655. wiz->idealFPSDen = result.fps_den;
  656. long double fUpperBitrate = EstimateUpperBitrate(
  657. result.cx, result.cy, result.fps_num, result.fps_den);
  658. int upperBitrate = int(floor(fUpperBitrate / 50.0l) * 50.0l);
  659. if (wiz->streamingEncoder != AutoConfig::Encoder::x264) {
  660. upperBitrate *= 114;
  661. upperBitrate /= 100;
  662. }
  663. if (wiz->idealBitrate > upperBitrate)
  664. wiz->idealBitrate = upperBitrate;
  665. softwareTested = true;
  666. return true;
  667. }
  668. void AutoConfigTestPage::FindIdealHardwareResolution()
  669. {
  670. int baseCX = wiz->baseResolutionCX;
  671. int baseCY = wiz->baseResolutionCY;
  672. CalcBaseRes(baseCX, baseCY);
  673. vector<Result> results;
  674. int pcores = os_get_physical_cores();
  675. int maxDataRate;
  676. if (pcores >= 4) {
  677. maxDataRate = 1920 * 1200 * 60 + 1000;
  678. } else {
  679. maxDataRate = 1280 * 720 * 30 + 1000;
  680. }
  681. auto testRes = [&](int cy, int fps_num, int fps_den, bool force) {
  682. if (cy > baseCY)
  683. return;
  684. if (results.size() >= 3)
  685. return;
  686. if (!fps_num || !fps_den) {
  687. fps_num = wiz->specificFPSNum;
  688. fps_den = wiz->specificFPSDen;
  689. }
  690. long double fps = ((long double)fps_num / (long double)fps_den);
  691. int cx = int(((long double)baseCX / (long double)baseCY) *
  692. (long double)cy);
  693. long double rate = (long double)cx * (long double)cy * fps;
  694. if (!force && rate > maxDataRate)
  695. return;
  696. AutoConfig::Encoder encType = wiz->streamingEncoder;
  697. bool nvenc = encType == AutoConfig::Encoder::NVENC;
  698. int minBitrate = EstimateMinBitrate(cx, cy, fps_num, fps_den);
  699. /* most hardware encoders don't have a good quality to bitrate
  700. * ratio, so increase the minimum bitrate estimate for them.
  701. * NVENC currently is the exception because of the improvements
  702. * its made to its quality in recent generations. */
  703. if (!nvenc)
  704. minBitrate = minBitrate * 114 / 100;
  705. if (wiz->type == AutoConfig::Type::Recording)
  706. force = true;
  707. if (force || wiz->idealBitrate >= minBitrate)
  708. results.emplace_back(cx, cy, fps_num, fps_den);
  709. };
  710. if (wiz->specificFPSNum && wiz->specificFPSDen) {
  711. testRes(2160, 0, 0, false);
  712. testRes(1440, 0, 0, false);
  713. testRes(1080, 0, 0, false);
  714. testRes(720, 0, 0, false);
  715. testRes(480, 0, 0, false);
  716. testRes(360, 0, 0, false);
  717. testRes(240, 0, 0, true);
  718. } else {
  719. testRes(2160, 60, 1, false);
  720. testRes(2160, 30, 1, false);
  721. testRes(1440, 60, 1, false);
  722. testRes(1440, 30, 1, false);
  723. testRes(1080, 60, 1, false);
  724. testRes(1080, 30, 1, false);
  725. testRes(720, 60, 1, false);
  726. testRes(720, 30, 1, false);
  727. testRes(480, 60, 1, false);
  728. testRes(480, 30, 1, false);
  729. testRes(360, 60, 1, false);
  730. testRes(360, 30, 1, false);
  731. testRes(240, 60, 1, false);
  732. testRes(240, 30, 1, true);
  733. }
  734. int minArea = 960 * 540 + 1000;
  735. if (!wiz->specificFPSNum && wiz->preferHighFPS && results.size() > 1) {
  736. Result &result1 = results[0];
  737. Result &result2 = results[1];
  738. if (result1.fps_num == 30 && result2.fps_num == 60) {
  739. int nextArea = result2.cx * result2.cy;
  740. if (nextArea >= minArea)
  741. results.erase(results.begin());
  742. }
  743. }
  744. Result result = results.front();
  745. wiz->idealResolutionCX = result.cx;
  746. wiz->idealResolutionCY = result.cy;
  747. wiz->idealFPSNum = result.fps_num;
  748. wiz->idealFPSDen = result.fps_den;
  749. }
  750. void AutoConfigTestPage::TestStreamEncoderThread()
  751. {
  752. bool preferHardware = wiz->preferHardware;
  753. if (!softwareTested) {
  754. if (!preferHardware || !wiz->hardwareEncodingAvailable) {
  755. if (!TestSoftwareEncoding()) {
  756. return;
  757. }
  758. }
  759. }
  760. if (!softwareTested) {
  761. if (wiz->nvencAvailable)
  762. wiz->streamingEncoder = AutoConfig::Encoder::NVENC;
  763. else if (wiz->qsvAvailable)
  764. wiz->streamingEncoder = AutoConfig::Encoder::QSV;
  765. else if (wiz->appleAvailable)
  766. wiz->streamingEncoder = AutoConfig::Encoder::Apple;
  767. else
  768. wiz->streamingEncoder = AutoConfig::Encoder::AMD;
  769. } else {
  770. wiz->streamingEncoder = AutoConfig::Encoder::x264;
  771. }
  772. if (preferHardware && !softwareTested && wiz->hardwareEncodingAvailable)
  773. FindIdealHardwareResolution();
  774. QMetaObject::invokeMethod(this, "NextStage");
  775. }
  776. void AutoConfigTestPage::TestRecordingEncoderThread()
  777. {
  778. if (!wiz->hardwareEncodingAvailable && !softwareTested) {
  779. if (!TestSoftwareEncoding()) {
  780. return;
  781. }
  782. }
  783. if (wiz->type == AutoConfig::Type::Recording &&
  784. wiz->hardwareEncodingAvailable)
  785. FindIdealHardwareResolution();
  786. wiz->recordingQuality = AutoConfig::Quality::High;
  787. bool recordingOnly = wiz->type == AutoConfig::Type::Recording;
  788. if (wiz->hardwareEncodingAvailable) {
  789. if (wiz->nvencAvailable)
  790. wiz->recordingEncoder = AutoConfig::Encoder::NVENC;
  791. else if (wiz->qsvAvailable)
  792. wiz->recordingEncoder = AutoConfig::Encoder::QSV;
  793. else if (wiz->appleAvailable)
  794. wiz->recordingEncoder = AutoConfig::Encoder::Apple;
  795. else
  796. wiz->recordingEncoder = AutoConfig::Encoder::AMD;
  797. } else {
  798. wiz->recordingEncoder = AutoConfig::Encoder::x264;
  799. }
  800. if (wiz->recordingEncoder != AutoConfig::Encoder::NVENC) {
  801. if (!recordingOnly) {
  802. wiz->recordingEncoder = AutoConfig::Encoder::Stream;
  803. wiz->recordingQuality = AutoConfig::Quality::Stream;
  804. }
  805. }
  806. QMetaObject::invokeMethod(this, "NextStage");
  807. }
  808. #define ENCODER_TEXT(x) "Basic.Settings.Output.Simple.Encoder." x
  809. #define ENCODER_SOFTWARE ENCODER_TEXT("Software")
  810. #define ENCODER_NVENC ENCODER_TEXT("Hardware.NVENC.H264")
  811. #define ENCODER_QSV ENCODER_TEXT("Hardware.QSV.H264")
  812. #define ENCODER_AMD ENCODER_TEXT("Hardware.AMD.H264")
  813. #define ENCODER_APPLE ENCODER_TEXT("Hardware.Apple.H264")
  814. #define QUALITY_SAME "Basic.Settings.Output.Simple.RecordingQuality.Stream"
  815. #define QUALITY_HIGH "Basic.Settings.Output.Simple.RecordingQuality.Small"
  816. void set_closest_res(int &cx, int &cy, struct obs_service_resolution *res_list,
  817. size_t count)
  818. {
  819. int best_pixel_diff = 0x7FFFFFFF;
  820. int start_cx = cx;
  821. int start_cy = cy;
  822. for (size_t i = 0; i < count; i++) {
  823. struct obs_service_resolution &res = res_list[i];
  824. int pixel_cx_diff = abs(start_cx - res.cx);
  825. int pixel_cy_diff = abs(start_cy - res.cy);
  826. int pixel_diff = pixel_cx_diff + pixel_cy_diff;
  827. if (pixel_diff < best_pixel_diff) {
  828. best_pixel_diff = pixel_diff;
  829. cx = res.cx;
  830. cy = res.cy;
  831. }
  832. }
  833. }
  834. void AutoConfigTestPage::FinalizeResults()
  835. {
  836. ui->stackedWidget->setCurrentIndex(1);
  837. setSubTitle(QTStr(SUBTITLE_COMPLETE));
  838. QFormLayout *form = results;
  839. auto encName = [](AutoConfig::Encoder enc) -> QString {
  840. switch (enc) {
  841. case AutoConfig::Encoder::x264:
  842. return QTStr(ENCODER_SOFTWARE);
  843. case AutoConfig::Encoder::NVENC:
  844. return QTStr(ENCODER_NVENC);
  845. case AutoConfig::Encoder::QSV:
  846. return QTStr(ENCODER_QSV);
  847. case AutoConfig::Encoder::AMD:
  848. return QTStr(ENCODER_AMD);
  849. case AutoConfig::Encoder::Apple:
  850. return QTStr(ENCODER_APPLE);
  851. case AutoConfig::Encoder::Stream:
  852. return QTStr(QUALITY_SAME);
  853. }
  854. return QTStr(ENCODER_SOFTWARE);
  855. };
  856. auto newLabel = [this](const char *str) -> QLabel * {
  857. return new QLabel(QTStr(str), this);
  858. };
  859. if (wiz->type == AutoConfig::Type::Streaming) {
  860. const char *serverType = wiz->customServer ? "rtmp_custom"
  861. : "rtmp_common";
  862. OBSServiceAutoRelease service = obs_service_create(
  863. serverType, "temp_service", nullptr, nullptr);
  864. OBSDataAutoRelease service_settings = obs_data_create();
  865. OBSDataAutoRelease vencoder_settings = obs_data_create();
  866. obs_data_set_int(vencoder_settings, "bitrate",
  867. wiz->idealBitrate);
  868. obs_data_set_string(service_settings, "service",
  869. wiz->serviceName.c_str());
  870. obs_service_update(service, service_settings);
  871. obs_service_apply_encoder_settings(service, vencoder_settings,
  872. nullptr);
  873. BPtr<obs_service_resolution> res_list;
  874. size_t res_count;
  875. int maxFPS;
  876. obs_service_get_supported_resolutions(service, &res_list,
  877. &res_count);
  878. obs_service_get_max_fps(service, &maxFPS);
  879. if (res_list) {
  880. set_closest_res(wiz->idealResolutionCX,
  881. wiz->idealResolutionCY, res_list,
  882. res_count);
  883. }
  884. if (maxFPS) {
  885. double idealFPS = (double)wiz->idealFPSNum /
  886. (double)wiz->idealFPSDen;
  887. if (idealFPS > (double)maxFPS) {
  888. wiz->idealFPSNum = maxFPS;
  889. wiz->idealFPSDen = 1;
  890. }
  891. }
  892. wiz->idealBitrate =
  893. (int)obs_data_get_int(vencoder_settings, "bitrate");
  894. if (!wiz->customServer)
  895. form->addRow(
  896. newLabel("Basic.AutoConfig.StreamPage.Service"),
  897. new QLabel(wiz->serviceName.c_str(),
  898. ui->finishPage));
  899. form->addRow(newLabel("Basic.AutoConfig.StreamPage.Server"),
  900. new QLabel(wiz->serverName.c_str(),
  901. ui->finishPage));
  902. form->addRow(newLabel("Basic.Settings.Output.VideoBitrate"),
  903. new QLabel(QString::number(wiz->idealBitrate),
  904. ui->finishPage));
  905. form->addRow(newLabel(TEST_RESULT_SE),
  906. new QLabel(encName(wiz->streamingEncoder),
  907. ui->finishPage));
  908. }
  909. QString baseRes =
  910. QString("%1x%2").arg(QString::number(wiz->baseResolutionCX),
  911. QString::number(wiz->baseResolutionCY));
  912. QString scaleRes =
  913. QString("%1x%2").arg(QString::number(wiz->idealResolutionCX),
  914. QString::number(wiz->idealResolutionCY));
  915. if (wiz->recordingEncoder != AutoConfig::Encoder::Stream ||
  916. wiz->recordingQuality != AutoConfig::Quality::Stream)
  917. form->addRow(newLabel(TEST_RESULT_RE),
  918. new QLabel(encName(wiz->recordingEncoder),
  919. ui->finishPage));
  920. QString recQuality;
  921. switch (wiz->recordingQuality) {
  922. case AutoConfig::Quality::High:
  923. recQuality = QTStr(QUALITY_HIGH);
  924. break;
  925. case AutoConfig::Quality::Stream:
  926. recQuality = QTStr(QUALITY_SAME);
  927. break;
  928. }
  929. form->addRow(newLabel("Basic.Settings.Output.Simple.RecordingQuality"),
  930. new QLabel(recQuality, ui->finishPage));
  931. long double fps =
  932. (long double)wiz->idealFPSNum / (long double)wiz->idealFPSDen;
  933. QString fpsStr = (wiz->idealFPSDen > 1) ? QString::number(fps, 'f', 2)
  934. : QString::number(fps, 'g', 2);
  935. form->addRow(newLabel("Basic.Settings.Video.BaseResolution"),
  936. new QLabel(baseRes, ui->finishPage));
  937. form->addRow(newLabel("Basic.Settings.Video.ScaledResolution"),
  938. new QLabel(scaleRes, ui->finishPage));
  939. form->addRow(newLabel("Basic.Settings.Video.FPS"),
  940. new QLabel(fpsStr, ui->finishPage));
  941. }
  942. #define STARTING_SEPARATOR \
  943. "\n==== Auto-config wizard testing commencing ======\n"
  944. #define STOPPING_SEPARATOR \
  945. "\n==== Auto-config wizard testing stopping ========\n"
  946. void AutoConfigTestPage::NextStage()
  947. {
  948. if (testThread.joinable())
  949. testThread.join();
  950. if (cancel)
  951. return;
  952. ui->subProgressLabel->setText(QString());
  953. /* make it skip to bandwidth stage if only set to config recording */
  954. if (stage == Stage::Starting) {
  955. if (!started) {
  956. blog(LOG_INFO, STARTING_SEPARATOR);
  957. started = true;
  958. }
  959. if (wiz->type != AutoConfig::Type::Streaming) {
  960. stage = Stage::StreamEncoder;
  961. } else if (!wiz->bandwidthTest) {
  962. stage = Stage::BandwidthTest;
  963. }
  964. }
  965. if (stage == Stage::Starting) {
  966. stage = Stage::BandwidthTest;
  967. StartBandwidthStage();
  968. } else if (stage == Stage::BandwidthTest) {
  969. stage = Stage::StreamEncoder;
  970. StartStreamEncoderStage();
  971. } else if (stage == Stage::StreamEncoder) {
  972. stage = Stage::RecordingEncoder;
  973. StartRecordingEncoderStage();
  974. } else {
  975. stage = Stage::Finished;
  976. FinalizeResults();
  977. emit completeChanged();
  978. }
  979. }
  980. void AutoConfigTestPage::UpdateMessage(QString message)
  981. {
  982. ui->subProgressLabel->setText(message);
  983. }
  984. void AutoConfigTestPage::Failure(QString message)
  985. {
  986. ui->errorLabel->setText(message);
  987. ui->stackedWidget->setCurrentIndex(2);
  988. }
  989. void AutoConfigTestPage::Progress(int percentage)
  990. {
  991. ui->progressBar->setValue(percentage);
  992. }
  993. AutoConfigTestPage::AutoConfigTestPage(QWidget *parent)
  994. : QWizardPage(parent),
  995. ui(new Ui_AutoConfigTestPage)
  996. {
  997. ui->setupUi(this);
  998. setTitle(QTStr("Basic.AutoConfig.TestPage"));
  999. setSubTitle(QTStr(SUBTITLE_TESTING));
  1000. setCommitPage(true);
  1001. }
  1002. AutoConfigTestPage::~AutoConfigTestPage()
  1003. {
  1004. if (testThread.joinable()) {
  1005. {
  1006. unique_lock<mutex> ul(m);
  1007. cancel = true;
  1008. cv.notify_one();
  1009. }
  1010. testThread.join();
  1011. }
  1012. if (started)
  1013. blog(LOG_INFO, STOPPING_SEPARATOR);
  1014. }
  1015. void AutoConfigTestPage::initializePage()
  1016. {
  1017. if (wiz->type == AutoConfig::Type::VirtualCam) {
  1018. wiz->idealResolutionCX = wiz->baseResolutionCX;
  1019. wiz->idealResolutionCY = wiz->baseResolutionCY;
  1020. wiz->idealFPSNum = 30;
  1021. wiz->idealFPSDen = 1;
  1022. stage = Stage::Finished;
  1023. } else {
  1024. stage = Stage::Starting;
  1025. }
  1026. setSubTitle(QTStr(SUBTITLE_TESTING));
  1027. softwareTested = false;
  1028. cancel = false;
  1029. DeleteLayout(results);
  1030. results = new QFormLayout();
  1031. results->setContentsMargins(0, 0, 0, 0);
  1032. ui->finishPageLayout->insertLayout(1, results);
  1033. ui->stackedWidget->setCurrentIndex(0);
  1034. NextStage();
  1035. }
  1036. void AutoConfigTestPage::cleanupPage()
  1037. {
  1038. if (testThread.joinable()) {
  1039. {
  1040. unique_lock<mutex> ul(m);
  1041. cancel = true;
  1042. cv.notify_one();
  1043. }
  1044. testThread.join();
  1045. }
  1046. }
  1047. bool AutoConfigTestPage::isComplete() const
  1048. {
  1049. return stage == Stage::Finished;
  1050. }
  1051. int AutoConfigTestPage::nextId() const
  1052. {
  1053. return -1;
  1054. }