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

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