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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286
  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_), cy(cy_), fps_num(fps_num_), fps_den(fps_den_)
  435. {
  436. }
  437. };
  438. static void CalcBaseRes(int &baseCX, int &baseCY)
  439. {
  440. const int maxBaseArea = 1920 * 1200;
  441. const int clipResArea = 1920 * 1080;
  442. /* if base resolution unusually high, recalculate to a more reasonable
  443. * value to start the downscaling at, based upon 1920x1080's area.
  444. *
  445. * for 16:9 resolutions this will always change the starting value to
  446. * 1920x1080 */
  447. if ((baseCX * baseCY) > maxBaseArea) {
  448. long double xyAspect =
  449. (long double)baseCX / (long double)baseCY;
  450. baseCY = (int)sqrt((long double)clipResArea / xyAspect);
  451. baseCX = (int)((long double)baseCY * xyAspect);
  452. }
  453. }
  454. bool AutoConfigTestPage::TestSoftwareEncoding()
  455. {
  456. TestMode testMode;
  457. QMetaObject::invokeMethod(this, "UpdateMessage",
  458. Q_ARG(QString, QStringLiteral("")));
  459. /* -----------------------------------*/
  460. /* create obs objects */
  461. OBSEncoderAutoRelease vencoder = obs_video_encoder_create(
  462. "obs_x264", "test_x264", nullptr, nullptr);
  463. OBSEncoderAutoRelease aencoder = obs_audio_encoder_create(
  464. "ffmpeg_aac", "test_aac", nullptr, 0, nullptr);
  465. OBSOutputAutoRelease output =
  466. obs_output_create("null_output", "null", nullptr, nullptr);
  467. /* -----------------------------------*/
  468. /* configure settings */
  469. OBSDataAutoRelease aencoder_settings = obs_data_create();
  470. OBSDataAutoRelease vencoder_settings = obs_data_create();
  471. obs_data_set_int(aencoder_settings, "bitrate", 32);
  472. if (wiz->type != AutoConfig::Type::Recording) {
  473. obs_data_set_int(vencoder_settings, "keyint_sec", 2);
  474. obs_data_set_int(vencoder_settings, "bitrate",
  475. wiz->idealBitrate);
  476. obs_data_set_string(vencoder_settings, "rate_control", "CBR");
  477. obs_data_set_string(vencoder_settings, "profile", "main");
  478. obs_data_set_string(vencoder_settings, "preset", "veryfast");
  479. } else {
  480. obs_data_set_int(vencoder_settings, "crf", 20);
  481. obs_data_set_string(vencoder_settings, "rate_control", "CRF");
  482. obs_data_set_string(vencoder_settings, "profile", "high");
  483. obs_data_set_string(vencoder_settings, "preset", "veryfast");
  484. }
  485. /* -----------------------------------*/
  486. /* apply settings */
  487. obs_encoder_update(vencoder, vencoder_settings);
  488. obs_encoder_update(aencoder, aencoder_settings);
  489. /* -----------------------------------*/
  490. /* connect encoders/services/outputs */
  491. obs_output_set_video_encoder(output, vencoder);
  492. obs_output_set_audio_encoder(output, aencoder, 0);
  493. /* -----------------------------------*/
  494. /* connect signals */
  495. auto on_stopped = [&]() {
  496. unique_lock<mutex> lock(m);
  497. cv.notify_one();
  498. };
  499. using on_stopped_t = decltype(on_stopped);
  500. auto pre_on_stopped = [](void *data, calldata_t *) {
  501. on_stopped_t &on_stopped =
  502. *reinterpret_cast<on_stopped_t *>(data);
  503. on_stopped();
  504. };
  505. signal_handler *sh = obs_output_get_signal_handler(output);
  506. signal_handler_connect(sh, "deactivate", pre_on_stopped, &on_stopped);
  507. /* -----------------------------------*/
  508. /* calculate starting resolution */
  509. int baseCX = wiz->baseResolutionCX;
  510. int baseCY = wiz->baseResolutionCY;
  511. CalcBaseRes(baseCX, baseCY);
  512. /* -----------------------------------*/
  513. /* calculate starting test rates */
  514. int pcores = os_get_physical_cores();
  515. int lcores = os_get_logical_cores();
  516. int maxDataRate;
  517. if (lcores > 8 || pcores > 4) {
  518. /* superb */
  519. maxDataRate = 1920 * 1200 * 60 + 1000;
  520. } else if (lcores > 4 && pcores == 4) {
  521. /* great */
  522. maxDataRate = 1920 * 1080 * 60 + 1000;
  523. } else if (pcores == 4) {
  524. /* okay */
  525. maxDataRate = 1920 * 1080 * 30 + 1000;
  526. } else {
  527. /* toaster */
  528. maxDataRate = 960 * 540 * 30 + 1000;
  529. }
  530. /* -----------------------------------*/
  531. /* perform tests */
  532. vector<Result> results;
  533. int i = 0;
  534. int count = 1;
  535. auto testRes = [&](int cy, int fps_num, int fps_den, bool force) {
  536. int per = ++i * 100 / count;
  537. QMetaObject::invokeMethod(this, "Progress", Q_ARG(int, per));
  538. if (cy > baseCY)
  539. return true;
  540. /* no need for more than 3 tests max */
  541. if (results.size() >= 3)
  542. return true;
  543. if (!fps_num || !fps_den) {
  544. fps_num = wiz->specificFPSNum;
  545. fps_den = wiz->specificFPSDen;
  546. }
  547. long double fps = ((long double)fps_num / (long double)fps_den);
  548. int cx = int(((long double)baseCX / (long double)baseCY) *
  549. (long double)cy);
  550. if (!force && wiz->type != AutoConfig::Type::Recording) {
  551. int est = EstimateMinBitrate(cx, cy, fps_num, fps_den);
  552. if (est > wiz->idealBitrate)
  553. return true;
  554. }
  555. long double rate = (long double)cx * (long double)cy * fps;
  556. if (!force && rate > maxDataRate)
  557. return true;
  558. testMode.SetVideo(cx, cy, fps_num, fps_den);
  559. obs_encoder_set_video(vencoder, obs_get_video());
  560. obs_encoder_set_audio(aencoder, obs_get_audio());
  561. obs_encoder_update(vencoder, vencoder_settings);
  562. obs_output_set_media(output, obs_get_video(), obs_get_audio());
  563. QString cxStr = QString::number(cx);
  564. QString cyStr = QString::number(cy);
  565. QString fpsStr = (fps_den > 1) ? QString::number(fps, 'f', 2)
  566. : QString::number(fps, 'g', 2);
  567. QMetaObject::invokeMethod(
  568. this, "UpdateMessage",
  569. Q_ARG(QString,
  570. QTStr(TEST_RES_VAL).arg(cxStr, cyStr, fpsStr)));
  571. unique_lock<mutex> ul(m);
  572. if (cancel)
  573. return false;
  574. if (!obs_output_start(output)) {
  575. QMetaObject::invokeMethod(this, "Failure",
  576. Q_ARG(QString,
  577. QTStr(TEST_RES_FAIL)));
  578. return false;
  579. }
  580. cv.wait_for(ul, chrono::seconds(5));
  581. obs_output_stop(output);
  582. cv.wait(ul);
  583. int skipped =
  584. (int)video_output_get_skipped_frames(obs_get_video());
  585. if (force || skipped <= 10)
  586. results.emplace_back(cx, cy, fps_num, fps_den);
  587. return !cancel;
  588. };
  589. if (wiz->specificFPSNum && wiz->specificFPSDen) {
  590. count = 7;
  591. if (!testRes(2160, 0, 0, false))
  592. return false;
  593. if (!testRes(1440, 0, 0, false))
  594. return false;
  595. if (!testRes(1080, 0, 0, false))
  596. return false;
  597. if (!testRes(720, 0, 0, false))
  598. return false;
  599. if (!testRes(480, 0, 0, false))
  600. return false;
  601. if (!testRes(360, 0, 0, false))
  602. return false;
  603. if (!testRes(240, 0, 0, true))
  604. return false;
  605. } else {
  606. count = 14;
  607. if (!testRes(2160, 60, 1, false))
  608. return false;
  609. if (!testRes(2160, 30, 1, false))
  610. return false;
  611. if (!testRes(1440, 60, 1, false))
  612. return false;
  613. if (!testRes(1440, 30, 1, false))
  614. return false;
  615. if (!testRes(1080, 60, 1, false))
  616. return false;
  617. if (!testRes(1080, 30, 1, false))
  618. return false;
  619. if (!testRes(720, 60, 1, false))
  620. return false;
  621. if (!testRes(720, 30, 1, false))
  622. return false;
  623. if (!testRes(480, 60, 1, false))
  624. return false;
  625. if (!testRes(480, 30, 1, false))
  626. return false;
  627. if (!testRes(360, 60, 1, false))
  628. return false;
  629. if (!testRes(360, 30, 1, false))
  630. return false;
  631. if (!testRes(240, 60, 1, false))
  632. return false;
  633. if (!testRes(240, 30, 1, true))
  634. return false;
  635. }
  636. /* -----------------------------------*/
  637. /* find preferred settings */
  638. int minArea = 960 * 540 + 1000;
  639. if (!wiz->specificFPSNum && wiz->preferHighFPS && results.size() > 1) {
  640. Result &result1 = results[0];
  641. Result &result2 = results[1];
  642. if (result1.fps_num == 30 && result2.fps_num == 60) {
  643. int nextArea = result2.cx * result2.cy;
  644. if (nextArea >= minArea)
  645. results.erase(results.begin());
  646. }
  647. }
  648. Result result = results.front();
  649. wiz->idealResolutionCX = result.cx;
  650. wiz->idealResolutionCY = result.cy;
  651. wiz->idealFPSNum = result.fps_num;
  652. wiz->idealFPSDen = result.fps_den;
  653. long double fUpperBitrate = EstimateUpperBitrate(
  654. result.cx, result.cy, result.fps_num, result.fps_den);
  655. int upperBitrate = int(floor(fUpperBitrate / 50.0l) * 50.0l);
  656. if (wiz->streamingEncoder != AutoConfig::Encoder::x264) {
  657. upperBitrate *= 114;
  658. upperBitrate /= 100;
  659. }
  660. if (wiz->idealBitrate > upperBitrate)
  661. wiz->idealBitrate = upperBitrate;
  662. softwareTested = true;
  663. return true;
  664. }
  665. void AutoConfigTestPage::FindIdealHardwareResolution()
  666. {
  667. int baseCX = wiz->baseResolutionCX;
  668. int baseCY = wiz->baseResolutionCY;
  669. CalcBaseRes(baseCX, baseCY);
  670. vector<Result> results;
  671. int pcores = os_get_physical_cores();
  672. int maxDataRate;
  673. if (pcores >= 4) {
  674. maxDataRate = 1920 * 1200 * 60 + 1000;
  675. } else {
  676. maxDataRate = 1280 * 720 * 30 + 1000;
  677. }
  678. auto testRes = [&](int cy, int fps_num, int fps_den, bool force) {
  679. if (cy > baseCY)
  680. return;
  681. if (results.size() >= 3)
  682. return;
  683. if (!fps_num || !fps_den) {
  684. fps_num = wiz->specificFPSNum;
  685. fps_den = wiz->specificFPSDen;
  686. }
  687. long double fps = ((long double)fps_num / (long double)fps_den);
  688. int cx = int(((long double)baseCX / (long double)baseCY) *
  689. (long double)cy);
  690. long double rate = (long double)cx * (long double)cy * fps;
  691. if (!force && rate > maxDataRate)
  692. return;
  693. AutoConfig::Encoder encType = wiz->streamingEncoder;
  694. bool nvenc = encType == AutoConfig::Encoder::NVENC;
  695. int minBitrate = EstimateMinBitrate(cx, cy, fps_num, fps_den);
  696. /* most hardware encoders don't have a good quality to bitrate
  697. * ratio, so increase the minimum bitrate estimate for them.
  698. * NVENC currently is the exception because of the improvements
  699. * its made to its quality in recent generations. */
  700. if (!nvenc)
  701. minBitrate = minBitrate * 114 / 100;
  702. if (wiz->type == AutoConfig::Type::Recording)
  703. force = true;
  704. if (force || wiz->idealBitrate >= minBitrate)
  705. results.emplace_back(cx, cy, fps_num, fps_den);
  706. };
  707. if (wiz->specificFPSNum && wiz->specificFPSDen) {
  708. testRes(2160, 0, 0, false);
  709. testRes(1440, 0, 0, false);
  710. testRes(1080, 0, 0, false);
  711. testRes(720, 0, 0, false);
  712. testRes(480, 0, 0, false);
  713. testRes(360, 0, 0, false);
  714. testRes(240, 0, 0, true);
  715. } else {
  716. testRes(2160, 60, 1, false);
  717. testRes(2160, 30, 1, false);
  718. testRes(1440, 60, 1, false);
  719. testRes(1440, 30, 1, false);
  720. testRes(1080, 60, 1, false);
  721. testRes(1080, 30, 1, false);
  722. testRes(720, 60, 1, false);
  723. testRes(720, 30, 1, false);
  724. testRes(480, 60, 1, false);
  725. testRes(480, 30, 1, false);
  726. testRes(360, 60, 1, false);
  727. testRes(360, 30, 1, false);
  728. testRes(240, 60, 1, false);
  729. testRes(240, 30, 1, true);
  730. }
  731. int minArea = 960 * 540 + 1000;
  732. if (!wiz->specificFPSNum && wiz->preferHighFPS && results.size() > 1) {
  733. Result &result1 = results[0];
  734. Result &result2 = results[1];
  735. if (result1.fps_num == 30 && result2.fps_num == 60) {
  736. int nextArea = result2.cx * result2.cy;
  737. if (nextArea >= minArea)
  738. results.erase(results.begin());
  739. }
  740. }
  741. Result result = results.front();
  742. wiz->idealResolutionCX = result.cx;
  743. wiz->idealResolutionCY = result.cy;
  744. wiz->idealFPSNum = result.fps_num;
  745. wiz->idealFPSDen = result.fps_den;
  746. }
  747. void AutoConfigTestPage::TestStreamEncoderThread()
  748. {
  749. bool preferHardware = wiz->preferHardware;
  750. if (!softwareTested) {
  751. if (!preferHardware || !wiz->hardwareEncodingAvailable) {
  752. if (!TestSoftwareEncoding()) {
  753. return;
  754. }
  755. }
  756. }
  757. if (!softwareTested) {
  758. if (wiz->nvencAvailable)
  759. wiz->streamingEncoder = AutoConfig::Encoder::NVENC;
  760. else if (wiz->qsvAvailable)
  761. wiz->streamingEncoder = AutoConfig::Encoder::QSV;
  762. else if (wiz->appleAvailable)
  763. wiz->streamingEncoder = AutoConfig::Encoder::Apple;
  764. else
  765. wiz->streamingEncoder = AutoConfig::Encoder::AMD;
  766. } else {
  767. wiz->streamingEncoder = AutoConfig::Encoder::x264;
  768. }
  769. if (preferHardware && !softwareTested && wiz->hardwareEncodingAvailable)
  770. FindIdealHardwareResolution();
  771. QMetaObject::invokeMethod(this, "NextStage");
  772. }
  773. void AutoConfigTestPage::TestRecordingEncoderThread()
  774. {
  775. if (!wiz->hardwareEncodingAvailable && !softwareTested) {
  776. if (!TestSoftwareEncoding()) {
  777. return;
  778. }
  779. }
  780. if (wiz->type == AutoConfig::Type::Recording &&
  781. wiz->hardwareEncodingAvailable)
  782. FindIdealHardwareResolution();
  783. wiz->recordingQuality = AutoConfig::Quality::High;
  784. bool recordingOnly = wiz->type == AutoConfig::Type::Recording;
  785. if (wiz->hardwareEncodingAvailable) {
  786. if (wiz->nvencAvailable)
  787. wiz->recordingEncoder = AutoConfig::Encoder::NVENC;
  788. else if (wiz->qsvAvailable)
  789. wiz->recordingEncoder = AutoConfig::Encoder::QSV;
  790. else if (wiz->appleAvailable)
  791. wiz->recordingEncoder = AutoConfig::Encoder::Apple;
  792. else
  793. wiz->recordingEncoder = AutoConfig::Encoder::AMD;
  794. } else {
  795. wiz->recordingEncoder = AutoConfig::Encoder::x264;
  796. }
  797. if (wiz->recordingEncoder != AutoConfig::Encoder::NVENC) {
  798. if (!recordingOnly) {
  799. wiz->recordingEncoder = AutoConfig::Encoder::Stream;
  800. wiz->recordingQuality = AutoConfig::Quality::Stream;
  801. }
  802. }
  803. QMetaObject::invokeMethod(this, "NextStage");
  804. }
  805. #define ENCODER_TEXT(x) "Basic.Settings.Output.Simple.Encoder." x
  806. #define ENCODER_SOFTWARE ENCODER_TEXT("Software")
  807. #define ENCODER_NVENC ENCODER_TEXT("Hardware.NVENC.H264")
  808. #define ENCODER_QSV ENCODER_TEXT("Hardware.QSV.H264")
  809. #define ENCODER_AMD ENCODER_TEXT("Hardware.AMD.H264")
  810. #define ENCODER_APPLE ENCODER_TEXT("Hardware.Apple.H264")
  811. #define QUALITY_SAME "Basic.Settings.Output.Simple.RecordingQuality.Stream"
  812. #define QUALITY_HIGH "Basic.Settings.Output.Simple.RecordingQuality.Small"
  813. void set_closest_res(int &cx, int &cy, struct obs_service_resolution *res_list,
  814. size_t count)
  815. {
  816. int best_pixel_diff = 0x7FFFFFFF;
  817. int start_cx = cx;
  818. int start_cy = cy;
  819. for (size_t i = 0; i < count; i++) {
  820. struct obs_service_resolution &res = res_list[i];
  821. int pixel_cx_diff = abs(start_cx - res.cx);
  822. int pixel_cy_diff = abs(start_cy - res.cy);
  823. int pixel_diff = pixel_cx_diff + pixel_cy_diff;
  824. if (pixel_diff < best_pixel_diff) {
  825. best_pixel_diff = pixel_diff;
  826. cx = res.cx;
  827. cy = res.cy;
  828. }
  829. }
  830. }
  831. void AutoConfigTestPage::FinalizeResults()
  832. {
  833. ui->stackedWidget->setCurrentIndex(1);
  834. setSubTitle(QTStr(SUBTITLE_COMPLETE));
  835. QFormLayout *form = results;
  836. auto encName = [](AutoConfig::Encoder enc) -> QString {
  837. switch (enc) {
  838. case AutoConfig::Encoder::x264:
  839. return QTStr(ENCODER_SOFTWARE);
  840. case AutoConfig::Encoder::NVENC:
  841. return QTStr(ENCODER_NVENC);
  842. case AutoConfig::Encoder::QSV:
  843. return QTStr(ENCODER_QSV);
  844. case AutoConfig::Encoder::AMD:
  845. return QTStr(ENCODER_AMD);
  846. case AutoConfig::Encoder::Apple:
  847. return QTStr(ENCODER_APPLE);
  848. case AutoConfig::Encoder::Stream:
  849. return QTStr(QUALITY_SAME);
  850. }
  851. return QTStr(ENCODER_SOFTWARE);
  852. };
  853. auto newLabel = [this](const char *str) -> QLabel * {
  854. return new QLabel(QTStr(str), this);
  855. };
  856. if (wiz->type == AutoConfig::Type::Streaming) {
  857. const char *serverType = wiz->customServer ? "rtmp_custom"
  858. : "rtmp_common";
  859. OBSServiceAutoRelease service = obs_service_create(
  860. serverType, "temp_service", nullptr, nullptr);
  861. OBSDataAutoRelease service_settings = obs_data_create();
  862. OBSDataAutoRelease vencoder_settings = obs_data_create();
  863. obs_data_set_int(vencoder_settings, "bitrate",
  864. wiz->idealBitrate);
  865. obs_data_set_string(service_settings, "service",
  866. wiz->serviceName.c_str());
  867. obs_service_update(service, service_settings);
  868. obs_service_apply_encoder_settings(service, vencoder_settings,
  869. nullptr);
  870. BPtr<obs_service_resolution> res_list;
  871. size_t res_count;
  872. int maxFPS;
  873. obs_service_get_supported_resolutions(service, &res_list,
  874. &res_count);
  875. obs_service_get_max_fps(service, &maxFPS);
  876. if (res_list) {
  877. set_closest_res(wiz->idealResolutionCX,
  878. wiz->idealResolutionCY, res_list,
  879. res_count);
  880. }
  881. if (maxFPS) {
  882. double idealFPS = (double)wiz->idealFPSNum /
  883. (double)wiz->idealFPSDen;
  884. if (idealFPS > (double)maxFPS) {
  885. wiz->idealFPSNum = maxFPS;
  886. wiz->idealFPSDen = 1;
  887. }
  888. }
  889. wiz->idealBitrate =
  890. (int)obs_data_get_int(vencoder_settings, "bitrate");
  891. if (!wiz->customServer)
  892. form->addRow(
  893. newLabel("Basic.AutoConfig.StreamPage.Service"),
  894. new QLabel(wiz->serviceName.c_str(),
  895. ui->finishPage));
  896. form->addRow(newLabel("Basic.AutoConfig.StreamPage.Server"),
  897. new QLabel(wiz->serverName.c_str(),
  898. ui->finishPage));
  899. form->addRow(newLabel("Basic.Settings.Output.VideoBitrate"),
  900. new QLabel(QString::number(wiz->idealBitrate),
  901. ui->finishPage));
  902. form->addRow(newLabel(TEST_RESULT_SE),
  903. new QLabel(encName(wiz->streamingEncoder),
  904. ui->finishPage));
  905. }
  906. QString baseRes =
  907. QString("%1x%2").arg(QString::number(wiz->baseResolutionCX),
  908. QString::number(wiz->baseResolutionCY));
  909. QString scaleRes =
  910. QString("%1x%2").arg(QString::number(wiz->idealResolutionCX),
  911. QString::number(wiz->idealResolutionCY));
  912. if (wiz->recordingEncoder != AutoConfig::Encoder::Stream ||
  913. wiz->recordingQuality != AutoConfig::Quality::Stream)
  914. form->addRow(newLabel(TEST_RESULT_RE),
  915. new QLabel(encName(wiz->recordingEncoder),
  916. ui->finishPage));
  917. QString recQuality;
  918. switch (wiz->recordingQuality) {
  919. case AutoConfig::Quality::High:
  920. recQuality = QTStr(QUALITY_HIGH);
  921. break;
  922. case AutoConfig::Quality::Stream:
  923. recQuality = QTStr(QUALITY_SAME);
  924. break;
  925. }
  926. form->addRow(newLabel("Basic.Settings.Output.Simple.RecordingQuality"),
  927. new QLabel(recQuality, ui->finishPage));
  928. long double fps =
  929. (long double)wiz->idealFPSNum / (long double)wiz->idealFPSDen;
  930. QString fpsStr = (wiz->idealFPSDen > 1) ? QString::number(fps, 'f', 2)
  931. : QString::number(fps, 'g', 2);
  932. form->addRow(newLabel("Basic.Settings.Video.BaseResolution"),
  933. new QLabel(baseRes, ui->finishPage));
  934. form->addRow(newLabel("Basic.Settings.Video.ScaledResolution"),
  935. new QLabel(scaleRes, ui->finishPage));
  936. form->addRow(newLabel("Basic.Settings.Video.FPS"),
  937. new QLabel(fpsStr, ui->finishPage));
  938. }
  939. #define STARTING_SEPARATOR \
  940. "\n==== Auto-config wizard testing commencing ======\n"
  941. #define STOPPING_SEPARATOR \
  942. "\n==== Auto-config wizard testing stopping ========\n"
  943. void AutoConfigTestPage::NextStage()
  944. {
  945. if (testThread.joinable())
  946. testThread.join();
  947. if (cancel)
  948. return;
  949. ui->subProgressLabel->setText(QString());
  950. /* make it skip to bandwidth stage if only set to config recording */
  951. if (stage == Stage::Starting) {
  952. if (!started) {
  953. blog(LOG_INFO, STARTING_SEPARATOR);
  954. started = true;
  955. }
  956. if (wiz->type != AutoConfig::Type::Streaming) {
  957. stage = Stage::StreamEncoder;
  958. } else if (!wiz->bandwidthTest) {
  959. stage = Stage::BandwidthTest;
  960. }
  961. }
  962. if (stage == Stage::Starting) {
  963. stage = Stage::BandwidthTest;
  964. StartBandwidthStage();
  965. } else if (stage == Stage::BandwidthTest) {
  966. stage = Stage::StreamEncoder;
  967. StartStreamEncoderStage();
  968. } else if (stage == Stage::StreamEncoder) {
  969. stage = Stage::RecordingEncoder;
  970. StartRecordingEncoderStage();
  971. } else {
  972. stage = Stage::Finished;
  973. FinalizeResults();
  974. emit completeChanged();
  975. }
  976. }
  977. void AutoConfigTestPage::UpdateMessage(QString message)
  978. {
  979. ui->subProgressLabel->setText(message);
  980. }
  981. void AutoConfigTestPage::Failure(QString message)
  982. {
  983. ui->errorLabel->setText(message);
  984. ui->stackedWidget->setCurrentIndex(2);
  985. }
  986. void AutoConfigTestPage::Progress(int percentage)
  987. {
  988. ui->progressBar->setValue(percentage);
  989. }
  990. AutoConfigTestPage::AutoConfigTestPage(QWidget *parent)
  991. : QWizardPage(parent), ui(new Ui_AutoConfigTestPage)
  992. {
  993. ui->setupUi(this);
  994. setTitle(QTStr("Basic.AutoConfig.TestPage"));
  995. setSubTitle(QTStr(SUBTITLE_TESTING));
  996. setCommitPage(true);
  997. }
  998. AutoConfigTestPage::~AutoConfigTestPage()
  999. {
  1000. if (testThread.joinable()) {
  1001. {
  1002. unique_lock<mutex> ul(m);
  1003. cancel = true;
  1004. cv.notify_one();
  1005. }
  1006. testThread.join();
  1007. }
  1008. if (started)
  1009. blog(LOG_INFO, STOPPING_SEPARATOR);
  1010. }
  1011. void AutoConfigTestPage::initializePage()
  1012. {
  1013. if (wiz->type == AutoConfig::Type::VirtualCam) {
  1014. wiz->idealResolutionCX = wiz->baseResolutionCX;
  1015. wiz->idealResolutionCY = wiz->baseResolutionCY;
  1016. wiz->idealFPSNum = 30;
  1017. wiz->idealFPSDen = 1;
  1018. stage = Stage::Finished;
  1019. } else {
  1020. stage = Stage::Starting;
  1021. }
  1022. setSubTitle(QTStr(SUBTITLE_TESTING));
  1023. softwareTested = false;
  1024. cancel = false;
  1025. DeleteLayout(results);
  1026. results = new QFormLayout();
  1027. results->setContentsMargins(0, 0, 0, 0);
  1028. ui->finishPageLayout->insertLayout(1, results);
  1029. ui->stackedWidget->setCurrentIndex(0);
  1030. NextStage();
  1031. }
  1032. void AutoConfigTestPage::cleanupPage()
  1033. {
  1034. if (testThread.joinable()) {
  1035. {
  1036. unique_lock<mutex> ul(m);
  1037. cancel = true;
  1038. cv.notify_one();
  1039. }
  1040. testThread.join();
  1041. }
  1042. }
  1043. bool AutoConfigTestPage::isComplete() const
  1044. {
  1045. return stage == Stage::Finished;
  1046. }
  1047. int AutoConfigTestPage::nextId() const
  1048. {
  1049. return -1;
  1050. }