window-basic-main.cpp 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558
  1. /******************************************************************************
  2. Copyright (C) 2013-2014 by Hugh Bailey <[email protected]>
  3. Zachary Lund <[email protected]>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ******************************************************************************/
  15. #include <time.h>
  16. #include <obs.hpp>
  17. #include <QMessageBox>
  18. #include <QShowEvent>
  19. #include <QDesktopServices>
  20. #include <QFileDialog>
  21. #include <QNetworkRequest>
  22. #include <QNetworkReply>
  23. #include <util/dstr.h>
  24. #include <util/util.hpp>
  25. #include <util/platform.h>
  26. #include <graphics/math-defs.h>
  27. #include "obs-app.hpp"
  28. #include "platform.hpp"
  29. #include "window-basic-settings.hpp"
  30. #include "window-namedialog.hpp"
  31. #include "window-basic-source-select.hpp"
  32. #include "window-basic-main.hpp"
  33. #include "window-basic-properties.hpp"
  34. #include "window-log-reply.hpp"
  35. #include "window-remux.hpp"
  36. #include "qt-wrappers.hpp"
  37. #include "display-helpers.hpp"
  38. #include "volume-control.hpp"
  39. #include "ui_OBSBasic.h"
  40. #include <fstream>
  41. #include <sstream>
  42. #include <QScreen>
  43. #include <QWindow>
  44. #define PREVIEW_EDGE_SIZE 10
  45. using namespace std;
  46. Q_DECLARE_METATYPE(OBSScene);
  47. Q_DECLARE_METATYPE(OBSSceneItem);
  48. Q_DECLARE_METATYPE(OBSSource);
  49. Q_DECLARE_METATYPE(obs_order_movement);
  50. static void AddExtraModulePaths()
  51. {
  52. BPtr<char> base_module_dir =
  53. os_get_config_path("obs-studio/plugins/%module%");
  54. if (!base_module_dir)
  55. return;
  56. string path = (char*)base_module_dir;
  57. obs_add_module_path((path + "/bin").c_str(), (path + "/data").c_str());
  58. }
  59. static QList<QKeySequence> DeleteKeys;
  60. OBSBasic::OBSBasic(QWidget *parent)
  61. : OBSMainWindow (parent),
  62. ui (new Ui::OBSBasic)
  63. {
  64. ui->setupUi(this);
  65. connect(windowHandle(), &QWindow::screenChanged, [this]() {
  66. struct obs_video_info ovi;
  67. if (obs_get_video_info(&ovi))
  68. ResizePreview(ovi.base_width, ovi.base_height);
  69. });
  70. stringstream name;
  71. name << "OBS " << App()->GetVersionString();
  72. blog(LOG_INFO, "%s", name.str().c_str());
  73. setWindowTitle(QT_UTF8(name.str().c_str()));
  74. connect(ui->scenes->itemDelegate(),
  75. SIGNAL(closeEditor(QWidget*,
  76. QAbstractItemDelegate::EndEditHint)),
  77. this,
  78. SLOT(SceneNameEdited(QWidget*,
  79. QAbstractItemDelegate::EndEditHint)));
  80. connect(ui->sources->itemDelegate(),
  81. SIGNAL(closeEditor(QWidget*,
  82. QAbstractItemDelegate::EndEditHint)),
  83. this,
  84. SLOT(SceneItemNameEdited(QWidget*,
  85. QAbstractItemDelegate::EndEditHint)));
  86. cpuUsageInfo = os_cpu_usage_info_start();
  87. cpuUsageTimer = new QTimer(this);
  88. connect(cpuUsageTimer, SIGNAL(timeout()),
  89. ui->statusbar, SLOT(UpdateCPUUsage()));
  90. cpuUsageTimer->start(3000);
  91. DeleteKeys =
  92. #ifdef __APPLE__
  93. QList<QKeySequence>{{Qt::Key_Backspace}} <<
  94. #endif
  95. QKeySequence::keyBindings(QKeySequence::Delete);
  96. #ifdef __APPLE__
  97. ui->actionRemoveSource->setShortcuts(DeleteKeys);
  98. ui->actionRemoveScene->setShortcuts(DeleteKeys);
  99. ui->action_Settings->setMenuRole(QAction::PreferencesRole);
  100. ui->actionE_xit->setMenuRole(QAction::QuitRole);
  101. #endif
  102. }
  103. static void SaveAudioDevice(const char *name, int channel, obs_data_t *parent)
  104. {
  105. obs_source_t *source = obs_get_output_source(channel);
  106. if (!source)
  107. return;
  108. obs_data_t *data = obs_save_source(source);
  109. obs_data_set_obj(parent, name, data);
  110. obs_data_release(data);
  111. obs_source_release(source);
  112. }
  113. static obs_data_t *GenerateSaveData()
  114. {
  115. obs_data_t *saveData = obs_data_create();
  116. obs_data_array_t *sourcesArray = obs_save_sources();
  117. obs_source_t *currentScene = obs_get_output_source(0);
  118. const char *sceneName = obs_source_get_name(currentScene);
  119. SaveAudioDevice(DESKTOP_AUDIO_1, 1, saveData);
  120. SaveAudioDevice(DESKTOP_AUDIO_2, 2, saveData);
  121. SaveAudioDevice(AUX_AUDIO_1, 3, saveData);
  122. SaveAudioDevice(AUX_AUDIO_2, 4, saveData);
  123. SaveAudioDevice(AUX_AUDIO_3, 5, saveData);
  124. obs_data_set_string(saveData, "current_scene", sceneName);
  125. obs_data_set_array(saveData, "sources", sourcesArray);
  126. obs_data_array_release(sourcesArray);
  127. obs_source_release(currentScene);
  128. return saveData;
  129. }
  130. void OBSBasic::ClearVolumeControls()
  131. {
  132. VolControl *control;
  133. for (size_t i = 0; i < volumes.size(); i++) {
  134. control = volumes[i];
  135. delete control;
  136. }
  137. volumes.clear();
  138. }
  139. void OBSBasic::Save(const char *file)
  140. {
  141. obs_data_t *saveData = GenerateSaveData();
  142. const char *jsonData = obs_data_get_json(saveData);
  143. /* TODO maybe a message box here? */
  144. if (!os_quick_write_utf8_file(file, jsonData, strlen(jsonData), false))
  145. blog(LOG_ERROR, "Could not save scene data to %s", file);
  146. obs_data_release(saveData);
  147. }
  148. static void LoadAudioDevice(const char *name, int channel, obs_data_t *parent)
  149. {
  150. obs_data_t *data = obs_data_get_obj(parent, name);
  151. if (!data)
  152. return;
  153. obs_source_t *source = obs_load_source(data);
  154. if (source) {
  155. obs_set_output_source(channel, source);
  156. obs_source_release(source);
  157. }
  158. obs_data_release(data);
  159. }
  160. void OBSBasic::CreateDefaultScene()
  161. {
  162. obs_scene_t *scene = obs_scene_create(Str("Basic.Scene"));
  163. obs_source_t *source = obs_scene_get_source(scene);
  164. obs_add_source(source);
  165. #ifdef __APPLE__
  166. source = obs_source_create(OBS_SOURCE_TYPE_INPUT, "display_capture",
  167. Str("Basic.DisplayCapture"), NULL);
  168. if (source) {
  169. obs_scene_add(scene, source);
  170. obs_add_source(source);
  171. obs_source_release(source);
  172. }
  173. #endif
  174. obs_set_output_source(0, obs_scene_get_source(scene));
  175. obs_scene_release(scene);
  176. }
  177. void OBSBasic::Load(const char *file)
  178. {
  179. if (!file) {
  180. blog(LOG_ERROR, "Could not find file %s", file);
  181. return;
  182. }
  183. BPtr<char> jsonData = os_quick_read_utf8_file(file);
  184. if (!jsonData) {
  185. CreateDefaultScene();
  186. return;
  187. }
  188. obs_data_t *data = obs_data_create_from_json(jsonData);
  189. obs_data_array_t *sources = obs_data_get_array(data, "sources");
  190. const char *sceneName = obs_data_get_string(data,
  191. "current_scene");
  192. obs_source_t *curScene;
  193. LoadAudioDevice(DESKTOP_AUDIO_1, 1, data);
  194. LoadAudioDevice(DESKTOP_AUDIO_2, 2, data);
  195. LoadAudioDevice(AUX_AUDIO_1, 3, data);
  196. LoadAudioDevice(AUX_AUDIO_2, 4, data);
  197. LoadAudioDevice(AUX_AUDIO_3, 5, data);
  198. obs_load_sources(sources);
  199. curScene = obs_get_source_by_name(sceneName);
  200. obs_set_output_source(0, curScene);
  201. obs_source_release(curScene);
  202. obs_data_array_release(sources);
  203. obs_data_release(data);
  204. }
  205. static inline bool HasAudioDevices(const char *source_id)
  206. {
  207. const char *output_id = source_id;
  208. obs_properties_t *props = obs_get_source_properties(
  209. OBS_SOURCE_TYPE_INPUT, output_id);
  210. size_t count = 0;
  211. if (!props)
  212. return false;
  213. obs_property_t *devices = obs_properties_get(props, "device_id");
  214. if (devices)
  215. count = obs_property_list_item_count(devices);
  216. obs_properties_destroy(props);
  217. return count != 0;
  218. }
  219. static void OBSStartStreaming(void *data, calldata_t *params)
  220. {
  221. UNUSED_PARAMETER(params);
  222. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  223. "StreamingStart");
  224. }
  225. static void OBSStopStreaming(void *data, calldata_t *params)
  226. {
  227. int code = (int)calldata_int(params, "code");
  228. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  229. "StreamingStop", Q_ARG(int, code));
  230. }
  231. static void OBSStartRecording(void *data, calldata_t *params)
  232. {
  233. UNUSED_PARAMETER(params);
  234. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  235. "RecordingStart");
  236. }
  237. static void OBSStopRecording(void *data, calldata_t *params)
  238. {
  239. UNUSED_PARAMETER(params);
  240. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  241. "RecordingStop");
  242. }
  243. #define SERVICE_PATH "obs-studio/basic/service.json"
  244. void OBSBasic::SaveService()
  245. {
  246. if (!service)
  247. return;
  248. BPtr<char> serviceJsonPath(os_get_config_path(SERVICE_PATH));
  249. if (!serviceJsonPath)
  250. return;
  251. obs_data_t *data = obs_data_create();
  252. obs_data_t *settings = obs_service_get_settings(service);
  253. obs_data_set_string(data, "type", obs_service_gettype(service));
  254. obs_data_set_obj(data, "settings", settings);
  255. const char *json = obs_data_get_json(data);
  256. os_quick_write_utf8_file(serviceJsonPath, json, strlen(json), false);
  257. obs_data_release(settings);
  258. obs_data_release(data);
  259. }
  260. bool OBSBasic::LoadService()
  261. {
  262. const char *type;
  263. BPtr<char> serviceJsonPath(os_get_config_path(SERVICE_PATH));
  264. if (!serviceJsonPath)
  265. return false;
  266. BPtr<char> jsonText = os_quick_read_utf8_file(serviceJsonPath);
  267. if (!jsonText)
  268. return false;
  269. obs_data_t *data = obs_data_create_from_json(jsonText);
  270. obs_data_set_default_string(data, "type", "rtmp_common");
  271. type = obs_data_get_string(data, "type");
  272. obs_data_t *settings = obs_data_get_obj(data, "settings");
  273. service = obs_service_create(type, "default_service", settings);
  274. obs_data_release(settings);
  275. obs_data_release(data);
  276. return !!service;
  277. }
  278. bool OBSBasic::InitOutputs()
  279. {
  280. fileOutput = obs_output_create("flv_output", "default_file_output",
  281. nullptr);
  282. if (!fileOutput)
  283. return false;
  284. streamOutput = obs_output_create("rtmp_output", "default_stream",
  285. nullptr);
  286. if (!streamOutput)
  287. return false;
  288. signal_handler_connect(obs_output_get_signal_handler(streamOutput),
  289. "start", OBSStartStreaming, this);
  290. signal_handler_connect(obs_output_get_signal_handler(streamOutput),
  291. "stop", OBSStopStreaming, this);
  292. signal_handler_connect(obs_output_get_signal_handler(fileOutput),
  293. "start", OBSStartRecording, this);
  294. signal_handler_connect(obs_output_get_signal_handler(fileOutput),
  295. "stop", OBSStopRecording, this);
  296. return true;
  297. }
  298. bool OBSBasic::InitEncoders()
  299. {
  300. x264 = obs_video_encoder_create("obs_x264", "default_h264", nullptr);
  301. if (!x264)
  302. return false;
  303. aac = obs_audio_encoder_create("libfdk_aac", "default_aac", nullptr);
  304. if (!aac)
  305. aac = obs_audio_encoder_create("ffmpeg_aac", "default_aac",
  306. nullptr);
  307. if (!aac)
  308. return false;
  309. return true;
  310. }
  311. bool OBSBasic::InitService()
  312. {
  313. if (LoadService())
  314. return true;
  315. service = obs_service_create("rtmp_common", "default_service", nullptr);
  316. if (!service)
  317. return false;
  318. return true;
  319. }
  320. bool OBSBasic::InitBasicConfigDefaults()
  321. {
  322. bool hasDesktopAudio = HasAudioDevices(App()->OutputAudioSource());
  323. bool hasInputAudio = HasAudioDevices(App()->InputAudioSource());
  324. config_set_default_int(basicConfig, "Window", "PosX", -1);
  325. config_set_default_int(basicConfig, "Window", "PosY", -1);
  326. config_set_default_int(basicConfig, "Window", "SizeX", -1);
  327. config_set_default_int(basicConfig, "Window", "SizeY", -1);
  328. vector<MonitorInfo> monitors;
  329. GetMonitors(monitors);
  330. if (!monitors.size()) {
  331. OBSErrorBox(NULL, "There appears to be no monitors. Er, this "
  332. "technically shouldn't be possible.");
  333. return false;
  334. }
  335. uint32_t cx = monitors[0].cx;
  336. uint32_t cy = monitors[0].cy;
  337. /* TODO: temporary */
  338. config_set_default_string(basicConfig, "SimpleOutput", "FilePath",
  339. GetDefaultVideoSavePath().c_str());
  340. config_set_default_uint (basicConfig, "SimpleOutput", "VBitrate",
  341. 2500);
  342. config_set_default_uint (basicConfig, "SimpleOutput", "ABitrate", 128);
  343. config_set_default_bool (basicConfig, "SimpleOutput", "Reconnect",
  344. true);
  345. config_set_default_uint (basicConfig, "SimpleOutput", "RetryDelay", 2);
  346. config_set_default_uint (basicConfig, "SimpleOutput", "MaxRetries",
  347. 20);
  348. config_set_default_bool (basicConfig, "SimpleOutput", "UseAdvanced",
  349. false);
  350. config_set_default_bool (basicConfig, "SimpleOutput", "UseCBR", true);
  351. config_set_default_string(basicConfig, "SimpleOutput", "Preset",
  352. "veryfast");
  353. config_set_default_uint (basicConfig, "Video", "BaseCX", cx);
  354. config_set_default_uint (basicConfig, "Video", "BaseCY", cy);
  355. cx = cx * 10 / 15;
  356. cy = cy * 10 / 15;
  357. config_set_default_uint (basicConfig, "Video", "OutputCX", cx);
  358. config_set_default_uint (basicConfig, "Video", "OutputCY", cy);
  359. config_set_default_uint (basicConfig, "Video", "FPSType", 0);
  360. config_set_default_string(basicConfig, "Video", "FPSCommon", "30");
  361. config_set_default_uint (basicConfig, "Video", "FPSInt", 30);
  362. config_set_default_uint (basicConfig, "Video", "FPSNum", 30);
  363. config_set_default_uint (basicConfig, "Video", "FPSDen", 1);
  364. config_set_default_uint (basicConfig, "Audio", "SampleRate", 44100);
  365. config_set_default_string(basicConfig, "Audio", "ChannelSetup",
  366. "Stereo");
  367. config_set_default_uint (basicConfig, "Audio", "BufferingTime", 1000);
  368. config_set_default_string(basicConfig, "Audio", "DesktopDevice1",
  369. hasDesktopAudio ? "default" : "disabled");
  370. config_set_default_string(basicConfig, "Audio", "DesktopDevice2",
  371. "disabled");
  372. config_set_default_string(basicConfig, "Audio", "AuxDevice1",
  373. hasInputAudio ? "default" : "disabled");
  374. config_set_default_string(basicConfig, "Audio", "AuxDevice2",
  375. "disabled");
  376. config_set_default_string(basicConfig, "Audio", "AuxDevice3",
  377. "disabled");
  378. return true;
  379. }
  380. bool OBSBasic::InitBasicConfig()
  381. {
  382. BPtr<char> configPath(os_get_config_path("obs-studio/basic/basic.ini"));
  383. int code = basicConfig.Open(configPath, CONFIG_OPEN_ALWAYS);
  384. if (code != CONFIG_SUCCESS) {
  385. OBSErrorBox(NULL, "Failed to open basic.ini: %d", code);
  386. return false;
  387. }
  388. return InitBasicConfigDefaults();
  389. }
  390. void OBSBasic::InitOBSCallbacks()
  391. {
  392. signal_handler_connect(obs_get_signal_handler(), "source_add",
  393. OBSBasic::SourceAdded, this);
  394. signal_handler_connect(obs_get_signal_handler(), "source_remove",
  395. OBSBasic::SourceRemoved, this);
  396. signal_handler_connect(obs_get_signal_handler(), "channel_change",
  397. OBSBasic::ChannelChanged, this);
  398. signal_handler_connect(obs_get_signal_handler(), "source_activate",
  399. OBSBasic::SourceActivated, this);
  400. signal_handler_connect(obs_get_signal_handler(), "source_deactivate",
  401. OBSBasic::SourceDeactivated, this);
  402. signal_handler_connect(obs_get_signal_handler(), "source_rename",
  403. OBSBasic::SourceRenamed, this);
  404. }
  405. void OBSBasic::InitPrimitives()
  406. {
  407. obs_enter_graphics();
  408. gs_render_start(true);
  409. gs_vertex2f(0.0f, 0.0f);
  410. gs_vertex2f(0.0f, 1.0f);
  411. gs_vertex2f(1.0f, 1.0f);
  412. gs_vertex2f(1.0f, 0.0f);
  413. gs_vertex2f(0.0f, 0.0f);
  414. box = gs_render_save();
  415. gs_render_start(true);
  416. for (int i = 0; i <= 360; i += (360/20)) {
  417. float pos = RAD(float(i));
  418. gs_vertex2f(cosf(pos), sinf(pos));
  419. }
  420. circle = gs_render_save();
  421. obs_leave_graphics();
  422. }
  423. void OBSBasic::OBSInit()
  424. {
  425. BPtr<char> savePath(os_get_config_path("obs-studio/basic/scenes.json"));
  426. /* make sure it's fully displayed before doing any initialization */
  427. show();
  428. App()->processEvents();
  429. if (!obs_startup(App()->GetLocale()))
  430. throw "Failed to initialize libobs";
  431. if (!InitBasicConfig())
  432. throw "Failed to load basic.ini";
  433. if (!ResetAudio())
  434. throw "Failed to initialize audio";
  435. int ret = ResetVideo();
  436. switch (ret) {
  437. case OBS_VIDEO_MODULE_NOT_FOUND:
  438. throw "Failed to initialize video: Graphics module not found";
  439. case OBS_VIDEO_NOT_SUPPORTED:
  440. throw "Failed to initialize video: Required graphics API "
  441. "functionality not found on these drivers or "
  442. "unavailable on this equipment";
  443. case OBS_VIDEO_INVALID_PARAM:
  444. throw "Failed to initialize video: Invalid parameters";
  445. default:
  446. if (ret != OBS_VIDEO_SUCCESS)
  447. throw "Failed to initialize video: Unspecified error";
  448. }
  449. InitOBSCallbacks();
  450. AddExtraModulePaths();
  451. obs_load_all_modules();
  452. if (!InitOutputs())
  453. throw "Failed to initialize outputs";
  454. if (!InitEncoders())
  455. throw "Failed to initialize encoders";
  456. if (!InitService())
  457. throw "Failed to initialize service";
  458. InitPrimitives();
  459. Load(savePath);
  460. ResetAudioDevices();
  461. TimedCheckForUpdates();
  462. loaded = true;
  463. }
  464. OBSBasic::~OBSBasic()
  465. {
  466. BPtr<char> savePath(os_get_config_path("obs-studio/basic/scenes.json"));
  467. SaveService();
  468. Save(savePath);
  469. /* XXX: any obs data must be released before calling obs_shutdown.
  470. * currently, we can't automate this with C++ RAII because of the
  471. * delicate nature of obs_shutdown needing to be freed before the UI
  472. * can be freed, and we have no control over the destruction order of
  473. * the Qt UI stuff, so we have to manually clear any references to
  474. * libobs. */
  475. delete cpuUsageTimer;
  476. os_cpu_usage_info_destroy(cpuUsageInfo);
  477. if (interaction)
  478. delete interaction;
  479. if (properties)
  480. delete properties;
  481. if (transformWindow)
  482. delete transformWindow;
  483. ClearVolumeControls();
  484. ui->sources->clear();
  485. ui->scenes->clear();
  486. obs_enter_graphics();
  487. gs_vertexbuffer_destroy(box);
  488. gs_vertexbuffer_destroy(circle);
  489. obs_leave_graphics();
  490. obs_shutdown();
  491. config_set_int(App()->GlobalConfig(), "General", "LastVersion",
  492. LIBOBS_API_VER);
  493. config_save(App()->GlobalConfig());
  494. }
  495. OBSScene OBSBasic::GetCurrentScene()
  496. {
  497. QListWidgetItem *item = ui->scenes->currentItem();
  498. return item ? item->data(Qt::UserRole).value<OBSScene>() : nullptr;
  499. }
  500. OBSSceneItem OBSBasic::GetSceneItem(QListWidgetItem *item)
  501. {
  502. return item ? item->data(Qt::UserRole).value<OBSSceneItem>() : nullptr;
  503. }
  504. OBSSceneItem OBSBasic::GetCurrentSceneItem()
  505. {
  506. return GetSceneItem(ui->sources->currentItem());
  507. }
  508. void OBSBasic::UpdateSources(OBSScene scene)
  509. {
  510. ui->sources->clear();
  511. obs_scene_enum_items(scene,
  512. [] (obs_scene_t *scene, obs_sceneitem_t *item, void *p)
  513. {
  514. OBSBasic *window = static_cast<OBSBasic*>(p);
  515. window->InsertSceneItem(item);
  516. UNUSED_PARAMETER(scene);
  517. return true;
  518. }, this);
  519. }
  520. void OBSBasic::InsertSceneItem(obs_sceneitem_t *item)
  521. {
  522. obs_source_t *source = obs_sceneitem_get_source(item);
  523. const char *name = obs_source_get_name(source);
  524. QListWidgetItem *listItem = new QListWidgetItem(QT_UTF8(name));
  525. listItem->setData(Qt::UserRole,
  526. QVariant::fromValue(OBSSceneItem(item)));
  527. ui->sources->insertItem(0, listItem);
  528. ui->sources->setCurrentRow(0);
  529. /* if the source was just created, open properties dialog */
  530. if (sourceSceneRefs[source] == 0 && loaded)
  531. CreatePropertiesWindow(source);
  532. }
  533. void OBSBasic::CreateInteractionWindow(obs_source_t *source)
  534. {
  535. if (interaction)
  536. interaction->close();
  537. interaction = new OBSBasicInteraction(this, source);
  538. interaction->Init();
  539. interaction->setAttribute(Qt::WA_DeleteOnClose, true);
  540. }
  541. void OBSBasic::CreatePropertiesWindow(obs_source_t *source)
  542. {
  543. if (properties)
  544. properties->close();
  545. properties = new OBSBasicProperties(this, source);
  546. properties->Init();
  547. properties->setAttribute(Qt::WA_DeleteOnClose, true);
  548. }
  549. /* Qt callbacks for invokeMethod */
  550. void OBSBasic::AddScene(OBSSource source)
  551. {
  552. const char *name = obs_source_get_name(source);
  553. obs_scene_t *scene = obs_scene_from_source(source);
  554. QListWidgetItem *item = new QListWidgetItem(QT_UTF8(name));
  555. item->setData(Qt::UserRole, QVariant::fromValue(OBSScene(scene)));
  556. ui->scenes->addItem(item);
  557. signal_handler_t *handler = obs_source_get_signal_handler(source);
  558. signal_handler_connect(handler, "item_add",
  559. OBSBasic::SceneItemAdded, this);
  560. signal_handler_connect(handler, "item_remove",
  561. OBSBasic::SceneItemRemoved, this);
  562. signal_handler_connect(handler, "item_select",
  563. OBSBasic::SceneItemSelected, this);
  564. signal_handler_connect(handler, "item_deselect",
  565. OBSBasic::SceneItemDeselected, this);
  566. signal_handler_connect(handler, "item_move_up",
  567. OBSBasic::SceneItemMoveUp, this);
  568. signal_handler_connect(handler, "item_move_down",
  569. OBSBasic::SceneItemMoveDown, this);
  570. signal_handler_connect(handler, "item_move_top",
  571. OBSBasic::SceneItemMoveTop, this);
  572. signal_handler_connect(handler, "item_move_bottom",
  573. OBSBasic::SceneItemMoveBottom, this);
  574. }
  575. void OBSBasic::RemoveScene(OBSSource source)
  576. {
  577. const char *name = obs_source_get_name(source);
  578. QListWidgetItem *sel = ui->scenes->currentItem();
  579. QList<QListWidgetItem*> items = ui->scenes->findItems(QT_UTF8(name),
  580. Qt::MatchExactly);
  581. if (sel != nullptr) {
  582. if (items.contains(sel))
  583. ui->sources->clear();
  584. delete sel;
  585. }
  586. }
  587. void OBSBasic::AddSceneItem(OBSSceneItem item)
  588. {
  589. obs_scene_t *scene = obs_sceneitem_get_scene(item);
  590. obs_source_t *source = obs_sceneitem_get_source(item);
  591. if (GetCurrentScene() == scene)
  592. InsertSceneItem(item);
  593. sourceSceneRefs[source] = sourceSceneRefs[source] + 1;
  594. }
  595. void OBSBasic::RemoveSceneItem(OBSSceneItem item)
  596. {
  597. obs_scene_t *scene = obs_sceneitem_get_scene(item);
  598. if (GetCurrentScene() == scene) {
  599. for (int i = 0; i < ui->sources->count(); i++) {
  600. QListWidgetItem *listItem = ui->sources->item(i);
  601. QVariant userData = listItem->data(Qt::UserRole);
  602. if (userData.value<OBSSceneItem>() == item) {
  603. delete listItem;
  604. break;
  605. }
  606. }
  607. }
  608. obs_source_t *source = obs_sceneitem_get_source(item);
  609. int scenes = sourceSceneRefs[source] - 1;
  610. sourceSceneRefs[source] = scenes;
  611. if (scenes == 0) {
  612. obs_source_remove(source);
  613. sourceSceneRefs.erase(source);
  614. }
  615. }
  616. void OBSBasic::UpdateSceneSelection(OBSSource source)
  617. {
  618. if (source) {
  619. obs_scene_t *scene = obs_scene_from_source(source);
  620. const char *name = obs_source_get_name(source);
  621. if (!scene)
  622. return;
  623. QList<QListWidgetItem*> items =
  624. ui->scenes->findItems(QT_UTF8(name), Qt::MatchExactly);
  625. if (items.count()) {
  626. sceneChanging = true;
  627. ui->scenes->setCurrentItem(items.first());
  628. sceneChanging = false;
  629. UpdateSources(scene);
  630. }
  631. }
  632. }
  633. static void RenameListValues(QListWidget *listWidget, const QString &newName,
  634. const QString &prevName)
  635. {
  636. QList<QListWidgetItem*> items =
  637. listWidget->findItems(prevName, Qt::MatchExactly);
  638. for (int i = 0; i < items.count(); i++)
  639. items[i]->setText(newName);
  640. }
  641. void OBSBasic::RenameSources(QString newName, QString prevName)
  642. {
  643. RenameListValues(ui->scenes, newName, prevName);
  644. RenameListValues(ui->sources, newName, prevName);
  645. for (size_t i = 0; i < volumes.size(); i++) {
  646. if (volumes[i]->GetName().compare(prevName) == 0)
  647. volumes[i]->SetName(newName);
  648. }
  649. }
  650. void OBSBasic::SelectSceneItem(OBSScene scene, OBSSceneItem item, bool select)
  651. {
  652. if (!select || scene != GetCurrentScene())
  653. return;
  654. for (int i = 0; i < ui->sources->count(); i++) {
  655. QListWidgetItem *witem = ui->sources->item(i);
  656. QVariant data = witem->data(Qt::UserRole);
  657. if (!data.canConvert<OBSSceneItem>())
  658. continue;
  659. if (item != data.value<OBSSceneItem>())
  660. continue;
  661. ui->sources->setCurrentItem(witem);
  662. break;
  663. }
  664. }
  665. void OBSBasic::MoveSceneItem(OBSSceneItem item, obs_order_movement movement)
  666. {
  667. OBSScene scene = obs_sceneitem_get_scene(item);
  668. if (scene != GetCurrentScene())
  669. return;
  670. int curRow = ui->sources->currentRow();
  671. if (curRow == -1)
  672. return;
  673. QListWidgetItem *listItem = ui->sources->takeItem(curRow);
  674. switch (movement) {
  675. case OBS_ORDER_MOVE_UP:
  676. if (curRow > 0)
  677. curRow--;
  678. break;
  679. case OBS_ORDER_MOVE_DOWN:
  680. if (curRow < ui->sources->count())
  681. curRow++;
  682. break;
  683. case OBS_ORDER_MOVE_TOP:
  684. curRow = 0;
  685. break;
  686. case OBS_ORDER_MOVE_BOTTOM:
  687. curRow = ui->sources->count();
  688. break;
  689. }
  690. ui->sources->insertItem(curRow, listItem);
  691. ui->sources->setCurrentRow(curRow);
  692. }
  693. void OBSBasic::ActivateAudioSource(OBSSource source)
  694. {
  695. VolControl *vol = new VolControl(source);
  696. volumes.push_back(vol);
  697. ui->volumeWidgets->layout()->addWidget(vol);
  698. }
  699. void OBSBasic::DeactivateAudioSource(OBSSource source)
  700. {
  701. for (size_t i = 0; i < volumes.size(); i++) {
  702. if (volumes[i]->GetSource() == source) {
  703. delete volumes[i];
  704. volumes.erase(volumes.begin() + i);
  705. break;
  706. }
  707. }
  708. }
  709. bool OBSBasic::QueryRemoveSource(obs_source_t *source)
  710. {
  711. const char *name = obs_source_get_name(source);
  712. QString text = QTStr("ConfirmRemove.Text");
  713. text.replace("$1", QT_UTF8(name));
  714. QMessageBox remove_source;
  715. remove_source.setText(text);
  716. QAbstractButton *Yes = remove_source.addButton(QTStr("Yes"),
  717. QMessageBox::YesRole);
  718. remove_source.addButton(QTStr("No"), QMessageBox::NoRole);
  719. remove_source.setIcon(QMessageBox::Question);
  720. remove_source.setWindowTitle(QTStr("ConfirmRemove.Title"));
  721. remove_source.exec();
  722. return Yes == remove_source.clickedButton();
  723. }
  724. #define UPDATE_CHECK_INTERVAL (60*60*24*4) /* 4 days */
  725. #ifdef UPDATE_SPARKLE
  726. void init_sparkle_updater(bool update_to_undeployed);
  727. void trigger_sparkle_update();
  728. #endif
  729. void OBSBasic::TimedCheckForUpdates()
  730. {
  731. #ifdef UPDATE_SPARKLE
  732. init_sparkle_updater(config_get_bool(App()->GlobalConfig(), "General",
  733. "UpdateToUndeployed"));
  734. #else
  735. long long lastUpdate = config_get_int(App()->GlobalConfig(), "General",
  736. "LastUpdateCheck");
  737. uint32_t lastVersion = config_get_int(App()->GlobalConfig(), "General",
  738. "LastVersion");
  739. if (lastVersion < LIBOBS_API_VER) {
  740. lastUpdate = 0;
  741. config_set_int(App()->GlobalConfig(), "General",
  742. "LastUpdateCheck", 0);
  743. }
  744. long long t = (long long)time(nullptr);
  745. long long secs = t - lastUpdate;
  746. if (secs > UPDATE_CHECK_INTERVAL)
  747. CheckForUpdates();
  748. #endif
  749. }
  750. void OBSBasic::CheckForUpdates()
  751. {
  752. #ifdef UPDATE_SPARKLE
  753. trigger_sparkle_update();
  754. #else
  755. ui->actionCheckForUpdates->setEnabled(false);
  756. string versionString("obs-basic ");
  757. versionString += App()->GetVersionString();
  758. QNetworkRequest request;
  759. request.setUrl(QUrl("https://obsproject.com/obs2_update/basic.json"));
  760. request.setRawHeader("User-Agent", versionString.c_str());
  761. updateReply = networkManager.get(request);
  762. connect(updateReply, SIGNAL(finished()),
  763. this, SLOT(updateFileFinished()));
  764. connect(updateReply, SIGNAL(readyRead()),
  765. this, SLOT(updateFileRead()));
  766. #endif
  767. }
  768. void OBSBasic::updateFileRead()
  769. {
  770. updateReturnData.push_back(updateReply->readAll());
  771. }
  772. #ifdef __APPLE__
  773. #define VERSION_ENTRY "mac"
  774. #elif _WIN32
  775. #define VERSION_ENTRY "windows"
  776. #else
  777. #define VERSION_ENTRY "other"
  778. #endif
  779. void OBSBasic::updateFileFinished()
  780. {
  781. ui->actionCheckForUpdates->setEnabled(true);
  782. if (updateReply->error()) {
  783. blog(LOG_WARNING, "Update check failed: %s",
  784. QT_TO_UTF8(updateReply->errorString()));
  785. return;
  786. }
  787. const char *jsonReply = updateReturnData.constData();
  788. if (!jsonReply || !*jsonReply)
  789. return;
  790. obs_data_t *returnData = obs_data_create_from_json(jsonReply);
  791. obs_data_t *versionData = obs_data_get_obj(returnData, VERSION_ENTRY);
  792. const char *description = obs_data_get_string(returnData,
  793. "description");
  794. const char *download = obs_data_get_string(versionData, "download");
  795. if (returnData && versionData && description && download) {
  796. long major = obs_data_get_int(versionData, "major");
  797. long minor = obs_data_get_int(versionData, "minor");
  798. long patch = obs_data_get_int(versionData, "patch");
  799. long version = MAKE_SEMANTIC_VERSION(major, minor, patch);
  800. blog(LOG_INFO, "Update check: latest version is: %ld.%ld.%ld",
  801. major, minor, patch);
  802. if (version > LIBOBS_API_VER) {
  803. QString str = QTStr("UpdateAvailable.Text");
  804. QMessageBox messageBox(this);
  805. str = str.arg(QString::number(major),
  806. QString::number(minor),
  807. QString::number(patch),
  808. download);
  809. messageBox.setWindowTitle(QTStr("UpdateAvailable"));
  810. messageBox.setTextFormat(Qt::RichText);
  811. messageBox.setText(str);
  812. messageBox.setInformativeText(QT_UTF8(description));
  813. messageBox.exec();
  814. long long t = (long long)time(nullptr);
  815. config_set_int(App()->GlobalConfig(), "General",
  816. "LastUpdateCheck", t);
  817. config_save(App()->GlobalConfig());
  818. }
  819. } else {
  820. blog(LOG_WARNING, "Bad JSON file received from server");
  821. }
  822. obs_data_release(versionData);
  823. obs_data_release(returnData);
  824. updateReturnData.clear();
  825. }
  826. void OBSBasic::RemoveSelectedScene()
  827. {
  828. OBSScene scene = GetCurrentScene();
  829. if (scene) {
  830. obs_source_t *source = obs_scene_get_source(scene);
  831. if (QueryRemoveSource(source))
  832. obs_source_remove(source);
  833. }
  834. }
  835. void OBSBasic::RemoveSelectedSceneItem()
  836. {
  837. OBSSceneItem item = GetCurrentSceneItem();
  838. if (item) {
  839. obs_source_t *source = obs_sceneitem_get_source(item);
  840. if (QueryRemoveSource(source))
  841. obs_sceneitem_remove(item);
  842. }
  843. }
  844. /* OBS Callbacks */
  845. void OBSBasic::SceneItemAdded(void *data, calldata_t *params)
  846. {
  847. OBSBasic *window = static_cast<OBSBasic*>(data);
  848. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  849. QMetaObject::invokeMethod(window, "AddSceneItem",
  850. Q_ARG(OBSSceneItem, OBSSceneItem(item)));
  851. }
  852. void OBSBasic::SceneItemRemoved(void *data, calldata_t *params)
  853. {
  854. OBSBasic *window = static_cast<OBSBasic*>(data);
  855. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  856. QMetaObject::invokeMethod(window, "RemoveSceneItem",
  857. Q_ARG(OBSSceneItem, OBSSceneItem(item)));
  858. }
  859. void OBSBasic::SceneItemSelected(void *data, calldata_t *params)
  860. {
  861. OBSBasic *window = static_cast<OBSBasic*>(data);
  862. obs_scene_t *scene = (obs_scene_t*)calldata_ptr(params, "scene");
  863. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  864. QMetaObject::invokeMethod(window, "SelectSceneItem",
  865. Q_ARG(OBSScene, scene), Q_ARG(OBSSceneItem, item),
  866. Q_ARG(bool, true));
  867. }
  868. void OBSBasic::SceneItemDeselected(void *data, calldata_t *params)
  869. {
  870. OBSBasic *window = static_cast<OBSBasic*>(data);
  871. obs_scene_t *scene = (obs_scene_t*)calldata_ptr(params, "scene");
  872. obs_sceneitem_t *item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  873. QMetaObject::invokeMethod(window, "SelectSceneItem",
  874. Q_ARG(OBSScene, scene), Q_ARG(OBSSceneItem, item),
  875. Q_ARG(bool, false));
  876. }
  877. void OBSBasic::SourceAdded(void *data, calldata_t *params)
  878. {
  879. OBSBasic *window = static_cast<OBSBasic*>(data);
  880. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  881. if (obs_scene_from_source(source) != NULL)
  882. QMetaObject::invokeMethod(window,
  883. "AddScene",
  884. Q_ARG(OBSSource, OBSSource(source)));
  885. }
  886. void OBSBasic::SourceRemoved(void *data, calldata_t *params)
  887. {
  888. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  889. if (obs_scene_from_source(source) != NULL)
  890. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  891. "RemoveScene",
  892. Q_ARG(OBSSource, OBSSource(source)));
  893. }
  894. void OBSBasic::SourceActivated(void *data, calldata_t *params)
  895. {
  896. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  897. uint32_t flags = obs_source_get_output_flags(source);
  898. if (flags & OBS_SOURCE_AUDIO)
  899. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  900. "ActivateAudioSource",
  901. Q_ARG(OBSSource, OBSSource(source)));
  902. }
  903. void OBSBasic::SourceDeactivated(void *data, calldata_t *params)
  904. {
  905. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  906. uint32_t flags = obs_source_get_output_flags(source);
  907. if (flags & OBS_SOURCE_AUDIO)
  908. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  909. "DeactivateAudioSource",
  910. Q_ARG(OBSSource, OBSSource(source)));
  911. }
  912. void OBSBasic::SourceRenamed(void *data, calldata_t *params)
  913. {
  914. const char *newName = calldata_string(params, "new_name");
  915. const char *prevName = calldata_string(params, "prev_name");
  916. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  917. "RenameSources",
  918. Q_ARG(QString, QT_UTF8(newName)),
  919. Q_ARG(QString, QT_UTF8(prevName)));
  920. }
  921. void OBSBasic::ChannelChanged(void *data, calldata_t *params)
  922. {
  923. obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
  924. uint32_t channel = (uint32_t)calldata_int(params, "channel");
  925. if (channel == 0)
  926. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  927. "UpdateSceneSelection",
  928. Q_ARG(OBSSource, OBSSource(source)));
  929. }
  930. void OBSBasic::DrawBackdrop(float cx, float cy)
  931. {
  932. if (!box)
  933. return;
  934. gs_effect_t *solid = obs_get_solid_effect();
  935. gs_eparam_t *color = gs_effect_get_param_by_name(solid, "color");
  936. gs_technique_t *tech = gs_effect_get_technique(solid, "Solid");
  937. vec4 colorVal;
  938. vec4_set(&colorVal, 0.0f, 0.0f, 0.0f, 1.0f);
  939. gs_effect_set_vec4(color, &colorVal);
  940. gs_technique_begin(tech);
  941. gs_technique_begin_pass(tech, 0);
  942. gs_matrix_push();
  943. gs_matrix_identity();
  944. gs_matrix_scale3f(float(cx), float(cy), 1.0f);
  945. gs_load_vertexbuffer(box);
  946. gs_draw(GS_TRISTRIP, 0, 0);
  947. gs_matrix_pop();
  948. gs_technique_end_pass(tech);
  949. gs_technique_end(tech);
  950. gs_load_vertexbuffer(nullptr);
  951. }
  952. void OBSBasic::RenderMain(void *data, uint32_t cx, uint32_t cy)
  953. {
  954. OBSBasic *window = static_cast<OBSBasic*>(data);
  955. obs_video_info ovi;
  956. obs_get_video_info(&ovi);
  957. window->previewCX = int(window->previewScale * float(ovi.base_width));
  958. window->previewCY = int(window->previewScale * float(ovi.base_height));
  959. gs_viewport_push();
  960. gs_projection_push();
  961. /* --------------------------------------- */
  962. gs_ortho(0.0f, float(ovi.base_width), 0.0f, float(ovi.base_height),
  963. -100.0f, 100.0f);
  964. gs_set_viewport(window->previewX, window->previewY,
  965. window->previewCX, window->previewCY);
  966. window->DrawBackdrop(float(ovi.base_width), float(ovi.base_height));
  967. obs_render_main_view();
  968. gs_load_vertexbuffer(nullptr);
  969. /* --------------------------------------- */
  970. QSize previewSize = GetPixelSize(window->ui->preview);
  971. float right = float(previewSize.width()) - window->previewX;
  972. float bottom = float(previewSize.height()) - window->previewY;
  973. gs_ortho(-window->previewX, right,
  974. -window->previewY, bottom,
  975. -100.0f, 100.0f);
  976. gs_reset_viewport();
  977. window->ui->preview->DrawSceneEditing();
  978. /* --------------------------------------- */
  979. gs_projection_pop();
  980. gs_viewport_pop();
  981. UNUSED_PARAMETER(cx);
  982. UNUSED_PARAMETER(cy);
  983. }
  984. void OBSBasic::SceneItemMoveUp(void *data, calldata_t *params)
  985. {
  986. OBSSceneItem item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  987. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  988. "MoveSceneItem",
  989. Q_ARG(OBSSceneItem, OBSSceneItem(item)),
  990. Q_ARG(obs_order_movement, OBS_ORDER_MOVE_UP));
  991. }
  992. void OBSBasic::SceneItemMoveDown(void *data, calldata_t *params)
  993. {
  994. OBSSceneItem item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  995. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  996. "MoveSceneItem",
  997. Q_ARG(OBSSceneItem, OBSSceneItem(item)),
  998. Q_ARG(obs_order_movement, OBS_ORDER_MOVE_DOWN));
  999. }
  1000. void OBSBasic::SceneItemMoveTop(void *data, calldata_t *params)
  1001. {
  1002. OBSSceneItem item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  1003. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  1004. "MoveSceneItem",
  1005. Q_ARG(OBSSceneItem, OBSSceneItem(item)),
  1006. Q_ARG(obs_order_movement, OBS_ORDER_MOVE_TOP));
  1007. }
  1008. void OBSBasic::SceneItemMoveBottom(void *data, calldata_t *params)
  1009. {
  1010. OBSSceneItem item = (obs_sceneitem_t*)calldata_ptr(params, "item");
  1011. QMetaObject::invokeMethod(static_cast<OBSBasic*>(data),
  1012. "MoveSceneItem",
  1013. Q_ARG(OBSSceneItem, OBSSceneItem(item)),
  1014. Q_ARG(obs_order_movement, OBS_ORDER_MOVE_BOTTOM));
  1015. }
  1016. /* Main class functions */
  1017. obs_service_t *OBSBasic::GetService()
  1018. {
  1019. if (!service)
  1020. service = obs_service_create("rtmp_common", NULL, NULL);
  1021. return service;
  1022. }
  1023. void OBSBasic::SetService(obs_service_t *newService)
  1024. {
  1025. if (newService) {
  1026. if (service)
  1027. obs_service_destroy(service);
  1028. service = newService;
  1029. }
  1030. }
  1031. #ifdef _WIN32
  1032. #define IS_WIN32 1
  1033. #else
  1034. #define IS_WIN32 0
  1035. #endif
  1036. static inline int AttemptToResetVideo(struct obs_video_info *ovi)
  1037. {
  1038. int ret = obs_reset_video(ovi);
  1039. if (ret == OBS_VIDEO_INVALID_PARAM) {
  1040. struct obs_video_info new_params = *ovi;
  1041. if (new_params.window_width == 0)
  1042. new_params.window_width = 512;
  1043. if (new_params.window_height == 0)
  1044. new_params.window_height = 512;
  1045. new_params.output_width = new_params.window_width;
  1046. new_params.output_height = new_params.window_height;
  1047. new_params.base_width = new_params.window_width;
  1048. new_params.base_height = new_params.window_height;
  1049. ret = obs_reset_video(&new_params);
  1050. }
  1051. return ret;
  1052. }
  1053. int OBSBasic::ResetVideo()
  1054. {
  1055. struct obs_video_info ovi;
  1056. int ret;
  1057. GetConfigFPS(ovi.fps_num, ovi.fps_den);
  1058. ovi.graphics_module = App()->GetRenderModule();
  1059. ovi.base_width = (uint32_t)config_get_uint(basicConfig,
  1060. "Video", "BaseCX");
  1061. ovi.base_height = (uint32_t)config_get_uint(basicConfig,
  1062. "Video", "BaseCY");
  1063. ovi.output_width = (uint32_t)config_get_uint(basicConfig,
  1064. "Video", "OutputCX");
  1065. ovi.output_height = (uint32_t)config_get_uint(basicConfig,
  1066. "Video", "OutputCY");
  1067. ovi.output_format = VIDEO_FORMAT_NV12;
  1068. ovi.adapter = 0;
  1069. ovi.gpu_conversion = true;
  1070. QTToGSWindow(ui->preview->winId(), ovi.window);
  1071. //required to make opengl display stuff on osx(?)
  1072. ResizePreview(ovi.base_width, ovi.base_height);
  1073. QSize size = GetPixelSize(ui->preview);
  1074. ovi.window_width = size.width();
  1075. ovi.window_height = size.height();
  1076. ret = AttemptToResetVideo(&ovi);
  1077. if (IS_WIN32 && ret != OBS_VIDEO_SUCCESS) {
  1078. /* Try OpenGL if DirectX fails on windows */
  1079. if (astrcmpi(ovi.graphics_module, "libobs-opengl") != 0) {
  1080. blog(LOG_WARNING, "Failed to initialize obs video (%d) "
  1081. "with graphics_module='%s', retrying "
  1082. "with graphics_module='%s'",
  1083. ret, ovi.graphics_module,
  1084. "libobs-opengl");
  1085. ovi.graphics_module = "libobs-opengl";
  1086. ret = AttemptToResetVideo(&ovi);
  1087. }
  1088. }
  1089. if (ret == OBS_VIDEO_SUCCESS)
  1090. obs_add_draw_callback(OBSBasic::RenderMain, this);
  1091. return ret;
  1092. }
  1093. bool OBSBasic::ResetAudio()
  1094. {
  1095. struct audio_output_info ai;
  1096. ai.name = "Main Audio Track";
  1097. ai.format = AUDIO_FORMAT_FLOAT;
  1098. ai.samples_per_sec = config_get_uint(basicConfig, "Audio",
  1099. "SampleRate");
  1100. const char *channelSetupStr = config_get_string(basicConfig,
  1101. "Audio", "ChannelSetup");
  1102. if (strcmp(channelSetupStr, "Mono") == 0)
  1103. ai.speakers = SPEAKERS_MONO;
  1104. else
  1105. ai.speakers = SPEAKERS_STEREO;
  1106. ai.buffer_ms = config_get_uint(basicConfig, "Audio", "BufferingTime");
  1107. return obs_reset_audio(&ai);
  1108. }
  1109. void OBSBasic::ResetAudioDevice(const char *sourceId, const char *deviceName,
  1110. const char *deviceDesc, int channel)
  1111. {
  1112. const char *deviceId = config_get_string(basicConfig, "Audio",
  1113. deviceName);
  1114. obs_source_t *source;
  1115. obs_data_t *settings;
  1116. bool same = false;
  1117. source = obs_get_output_source(channel);
  1118. if (source) {
  1119. settings = obs_source_get_settings(source);
  1120. const char *curId = obs_data_get_string(settings, "device_id");
  1121. same = (strcmp(curId, deviceId) == 0);
  1122. obs_data_release(settings);
  1123. obs_source_release(source);
  1124. }
  1125. if (!same)
  1126. obs_set_output_source(channel, nullptr);
  1127. if (!same && strcmp(deviceId, "disabled") != 0) {
  1128. obs_data_t *settings = obs_data_create();
  1129. obs_data_set_string(settings, "device_id", deviceId);
  1130. source = obs_source_create(OBS_SOURCE_TYPE_INPUT,
  1131. sourceId, deviceDesc, settings);
  1132. obs_data_release(settings);
  1133. obs_set_output_source(channel, source);
  1134. obs_source_release(source);
  1135. }
  1136. }
  1137. void OBSBasic::ResetAudioDevices()
  1138. {
  1139. ResetAudioDevice(App()->OutputAudioSource(), "DesktopDevice1",
  1140. Str("Basic.DesktopDevice1"), 1);
  1141. ResetAudioDevice(App()->OutputAudioSource(), "DesktopDevice2",
  1142. Str("Basic.DesktopDevice2"), 2);
  1143. ResetAudioDevice(App()->InputAudioSource(), "AuxDevice1",
  1144. Str("Basic.AuxDevice1"), 3);
  1145. ResetAudioDevice(App()->InputAudioSource(), "AuxDevice2",
  1146. Str("Basic.AuxDevice2"), 4);
  1147. ResetAudioDevice(App()->InputAudioSource(), "AuxDevice3",
  1148. Str("Basic.AuxDevice3"), 5);
  1149. }
  1150. void OBSBasic::ResizePreview(uint32_t cx, uint32_t cy)
  1151. {
  1152. QSize targetSize;
  1153. /* resize preview panel to fix to the top section of the window */
  1154. targetSize = GetPixelSize(ui->preview);
  1155. GetScaleAndCenterPos(int(cx), int(cy),
  1156. targetSize.width() - PREVIEW_EDGE_SIZE * 2,
  1157. targetSize.height() - PREVIEW_EDGE_SIZE * 2,
  1158. previewX, previewY, previewScale);
  1159. previewX += float(PREVIEW_EDGE_SIZE);
  1160. previewY += float(PREVIEW_EDGE_SIZE);
  1161. if (isVisible()) {
  1162. if (resizeTimer)
  1163. killTimer(resizeTimer);
  1164. resizeTimer = startTimer(100);
  1165. }
  1166. }
  1167. void OBSBasic::closeEvent(QCloseEvent *event)
  1168. {
  1169. QWidget::closeEvent(event);
  1170. if (!event->isAccepted())
  1171. return;
  1172. // remove draw callback in case our drawable surfaces go away before
  1173. // the destructor gets called
  1174. obs_remove_draw_callback(OBSBasic::RenderMain, this);
  1175. }
  1176. void OBSBasic::changeEvent(QEvent *event)
  1177. {
  1178. /* TODO */
  1179. UNUSED_PARAMETER(event);
  1180. }
  1181. void OBSBasic::resizeEvent(QResizeEvent *event)
  1182. {
  1183. struct obs_video_info ovi;
  1184. if (obs_get_video_info(&ovi))
  1185. ResizePreview(ovi.base_width, ovi.base_height);
  1186. UNUSED_PARAMETER(event);
  1187. }
  1188. void OBSBasic::timerEvent(QTimerEvent *event)
  1189. {
  1190. if (event->timerId() == resizeTimer) {
  1191. killTimer(resizeTimer);
  1192. resizeTimer = 0;
  1193. QSize size = GetPixelSize(ui->preview);
  1194. obs_resize(size.width(), size.height());
  1195. }
  1196. }
  1197. void OBSBasic::on_action_New_triggered()
  1198. {
  1199. /* TODO */
  1200. }
  1201. void OBSBasic::on_action_Open_triggered()
  1202. {
  1203. /* TODO */
  1204. }
  1205. void OBSBasic::on_action_Save_triggered()
  1206. {
  1207. /* TODO */
  1208. }
  1209. void OBSBasic::on_actionShow_Recordings_triggered()
  1210. {
  1211. const char *path = config_get_string(basicConfig,
  1212. "SimpleOutput", "FilePath");
  1213. QDesktopServices::openUrl(QUrl::fromLocalFile(path));
  1214. }
  1215. void OBSBasic::on_actionRemux_triggered()
  1216. {
  1217. const char *path = config_get_string(basicConfig,
  1218. "SimpleOutput", "FilePath");
  1219. OBSRemux remux(path, this);
  1220. remux.exec();
  1221. }
  1222. void OBSBasic::on_action_Settings_triggered()
  1223. {
  1224. OBSBasicSettings settings(this);
  1225. settings.exec();
  1226. }
  1227. void OBSBasic::on_scenes_currentItemChanged(QListWidgetItem *current,
  1228. QListWidgetItem *prev)
  1229. {
  1230. obs_source_t *source = NULL;
  1231. if (sceneChanging)
  1232. return;
  1233. if (current) {
  1234. obs_scene_t *scene;
  1235. scene = current->data(Qt::UserRole).value<OBSScene>();
  1236. source = obs_scene_get_source(scene);
  1237. }
  1238. /* TODO: allow transitions */
  1239. obs_set_output_source(0, source);
  1240. UNUSED_PARAMETER(prev);
  1241. }
  1242. void OBSBasic::EditSceneName()
  1243. {
  1244. QListWidgetItem *item = ui->scenes->currentItem();
  1245. Qt::ItemFlags flags = item->flags();
  1246. item->setFlags(flags | Qt::ItemIsEditable);
  1247. ui->scenes->editItem(item);
  1248. item->setFlags(flags);
  1249. }
  1250. void OBSBasic::on_scenes_customContextMenuRequested(const QPoint &pos)
  1251. {
  1252. QListWidgetItem *item = ui->scenes->itemAt(pos);
  1253. QMenu popup;
  1254. popup.addAction(QTStr("Add"),
  1255. this, SLOT(on_actionAddScene_triggered()));
  1256. if (item) {
  1257. popup.addSeparator();
  1258. popup.addAction(QTStr("Rename"),
  1259. this, SLOT(EditSceneName()));
  1260. popup.addAction(QTStr("Remove"),
  1261. this, SLOT(RemoveSelectedScene()),
  1262. DeleteKeys.front());
  1263. }
  1264. popup.exec(QCursor::pos());
  1265. }
  1266. void OBSBasic::on_actionAddScene_triggered()
  1267. {
  1268. string name;
  1269. QString format{QTStr("Basic.Main.DefaultSceneName.Text")};
  1270. int i = 1;
  1271. QString placeHolderText = format.arg(i);
  1272. obs_source_t *source = nullptr;
  1273. while ((source = obs_get_source_by_name(QT_TO_UTF8(placeHolderText)))) {
  1274. obs_source_release(source);
  1275. placeHolderText = format.arg(++i);
  1276. }
  1277. bool accepted = NameDialog::AskForName(this,
  1278. QTStr("Basic.Main.AddSceneDlg.Title"),
  1279. QTStr("Basic.Main.AddSceneDlg.Text"),
  1280. name,
  1281. placeHolderText);
  1282. if (accepted) {
  1283. if (name.empty()) {
  1284. QMessageBox::information(this,
  1285. QTStr("NoNameEntered.Title"),
  1286. QTStr("NoNameEntered.Text"));
  1287. on_actionAddScene_triggered();
  1288. return;
  1289. }
  1290. obs_source_t *source = obs_get_source_by_name(name.c_str());
  1291. if (source) {
  1292. QMessageBox::information(this,
  1293. QTStr("NameExists.Title"),
  1294. QTStr("NameExists.Text"));
  1295. obs_source_release(source);
  1296. on_actionAddScene_triggered();
  1297. return;
  1298. }
  1299. obs_scene_t *scene = obs_scene_create(name.c_str());
  1300. source = obs_scene_get_source(scene);
  1301. obs_add_source(source);
  1302. obs_scene_release(scene);
  1303. obs_set_output_source(0, source);
  1304. }
  1305. }
  1306. void OBSBasic::on_actionRemoveScene_triggered()
  1307. {
  1308. OBSScene scene = GetCurrentScene();
  1309. obs_source_t *source = obs_scene_get_source(scene);
  1310. if (source && QueryRemoveSource(source))
  1311. obs_source_remove(source);
  1312. }
  1313. void OBSBasic::on_actionSceneProperties_triggered()
  1314. {
  1315. /* TODO */
  1316. }
  1317. void OBSBasic::on_actionSceneUp_triggered()
  1318. {
  1319. /* TODO */
  1320. }
  1321. void OBSBasic::on_actionSceneDown_triggered()
  1322. {
  1323. /* TODO */
  1324. }
  1325. void OBSBasic::on_sources_currentItemChanged(QListWidgetItem *current,
  1326. QListWidgetItem *prev)
  1327. {
  1328. auto select_one = [] (obs_scene_t *scene, obs_sceneitem_t *item,
  1329. void *param)
  1330. {
  1331. obs_sceneitem_t *selectedItem =
  1332. *reinterpret_cast<OBSSceneItem*>(param);
  1333. obs_sceneitem_select(item, (selectedItem == item));
  1334. UNUSED_PARAMETER(scene);
  1335. return true;
  1336. };
  1337. if (!current)
  1338. return;
  1339. OBSSceneItem item = current->data(Qt::UserRole).value<OBSSceneItem>();
  1340. obs_source_t *source = obs_sceneitem_get_source(item);
  1341. if ((obs_source_get_output_flags(source) & OBS_SOURCE_VIDEO) == 0)
  1342. return;
  1343. obs_scene_enum_items(GetCurrentScene(), select_one, &item);
  1344. UNUSED_PARAMETER(prev);
  1345. }
  1346. void OBSBasic::EditSceneItemName()
  1347. {
  1348. QListWidgetItem *item = ui->sources->currentItem();
  1349. Qt::ItemFlags flags = item->flags();
  1350. item->setFlags(flags | Qt::ItemIsEditable);
  1351. ui->sources->editItem(item);
  1352. item->setFlags(flags);
  1353. }
  1354. void OBSBasic::on_sources_customContextMenuRequested(const QPoint &pos)
  1355. {
  1356. QListWidgetItem *item = ui->sources->itemAt(pos);
  1357. QMenu popup;
  1358. QPointer<QMenu> addSourceMenu = CreateAddSourcePopupMenu();
  1359. if (addSourceMenu)
  1360. popup.addMenu(addSourceMenu);
  1361. if (item) {
  1362. if (addSourceMenu)
  1363. popup.addSeparator();
  1364. OBSSceneItem sceneItem = GetSceneItem(item);
  1365. obs_source_t *source = obs_sceneitem_get_source(sceneItem);
  1366. QAction *action;
  1367. popup.addAction(QTStr("Rename"), this,
  1368. SLOT(EditSceneItemName()));
  1369. popup.addAction(QTStr("Remove"), this,
  1370. SLOT(on_actionRemoveSource_triggered()),
  1371. DeleteKeys.front());
  1372. popup.addSeparator();
  1373. popup.addMenu(ui->orderMenu);
  1374. popup.addMenu(ui->transformMenu);
  1375. popup.addSeparator();
  1376. action = popup.addAction(QTStr("Interact"), this,
  1377. SLOT(on_actionInteract_triggered()));
  1378. action->setEnabled(obs_source_get_output_flags(source) &
  1379. OBS_SOURCE_INTERACTION);
  1380. popup.addAction(QTStr("Properties"), this,
  1381. SLOT(on_actionSourceProperties_triggered()));
  1382. }
  1383. popup.exec(QCursor::pos());
  1384. }
  1385. void OBSBasic::on_sources_itemDoubleClicked(QListWidgetItem *witem)
  1386. {
  1387. if (!witem)
  1388. return;
  1389. OBSSceneItem item = GetSceneItem(witem);
  1390. OBSSource source = obs_sceneitem_get_source(item);
  1391. if (source)
  1392. CreatePropertiesWindow(source);
  1393. }
  1394. void OBSBasic::AddSource(const char *id)
  1395. {
  1396. if (id && *id) {
  1397. OBSBasicSourceSelect sourceSelect(this, id);
  1398. sourceSelect.exec();
  1399. }
  1400. }
  1401. QMenu *OBSBasic::CreateAddSourcePopupMenu()
  1402. {
  1403. const char *type;
  1404. bool foundValues = false;
  1405. size_t idx = 0;
  1406. QMenu *popup = new QMenu(QTStr("Add"));
  1407. while (obs_enum_input_types(idx++, &type)) {
  1408. const char *name = obs_source_get_display_name(
  1409. OBS_SOURCE_TYPE_INPUT, type);
  1410. if (strcmp(type, "scene") == 0)
  1411. continue;
  1412. QAction *popupItem = new QAction(QT_UTF8(name), this);
  1413. popupItem->setData(QT_UTF8(type));
  1414. connect(popupItem, SIGNAL(triggered(bool)),
  1415. this, SLOT(AddSourceFromAction()));
  1416. popup->addAction(popupItem);
  1417. foundValues = true;
  1418. }
  1419. if (!foundValues) {
  1420. delete popup;
  1421. popup = nullptr;
  1422. }
  1423. return popup;
  1424. }
  1425. void OBSBasic::AddSourceFromAction()
  1426. {
  1427. QAction *action = qobject_cast<QAction*>(sender());
  1428. if (!action)
  1429. return;
  1430. AddSource(QT_TO_UTF8(action->data().toString()));
  1431. }
  1432. void OBSBasic::AddSourcePopupMenu(const QPoint &pos)
  1433. {
  1434. if (!GetCurrentScene()) {
  1435. // Tell the user he needs a scene first (help beginners).
  1436. QMessageBox::information(this,
  1437. QTStr("Basic.Main.AddSourceHelp.Title"),
  1438. QTStr("Basic.Main.AddSourceHelp.Text"));
  1439. return;
  1440. }
  1441. QPointer<QMenu> popup = CreateAddSourcePopupMenu();
  1442. if (popup)
  1443. popup->exec(pos);
  1444. }
  1445. void OBSBasic::on_actionAddSource_triggered()
  1446. {
  1447. AddSourcePopupMenu(QCursor::pos());
  1448. }
  1449. void OBSBasic::on_actionRemoveSource_triggered()
  1450. {
  1451. OBSSceneItem item = GetCurrentSceneItem();
  1452. obs_source_t *source = obs_sceneitem_get_source(item);
  1453. if (source && QueryRemoveSource(source))
  1454. obs_sceneitem_remove(item);
  1455. }
  1456. void OBSBasic::on_actionInteract_triggered()
  1457. {
  1458. OBSSceneItem item = GetCurrentSceneItem();
  1459. OBSSource source = obs_sceneitem_get_source(item);
  1460. if (source)
  1461. CreateInteractionWindow(source);
  1462. }
  1463. void OBSBasic::on_actionSourceProperties_triggered()
  1464. {
  1465. OBSSceneItem item = GetCurrentSceneItem();
  1466. OBSSource source = obs_sceneitem_get_source(item);
  1467. if (source)
  1468. CreatePropertiesWindow(source);
  1469. }
  1470. void OBSBasic::on_actionSourceUp_triggered()
  1471. {
  1472. OBSSceneItem item = GetCurrentSceneItem();
  1473. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_UP);
  1474. }
  1475. void OBSBasic::on_actionSourceDown_triggered()
  1476. {
  1477. OBSSceneItem item = GetCurrentSceneItem();
  1478. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_DOWN);
  1479. }
  1480. void OBSBasic::on_actionMoveUp_triggered()
  1481. {
  1482. OBSSceneItem item = GetCurrentSceneItem();
  1483. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_UP);
  1484. }
  1485. void OBSBasic::on_actionMoveDown_triggered()
  1486. {
  1487. OBSSceneItem item = GetCurrentSceneItem();
  1488. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_DOWN);
  1489. }
  1490. void OBSBasic::on_actionMoveToTop_triggered()
  1491. {
  1492. OBSSceneItem item = GetCurrentSceneItem();
  1493. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_TOP);
  1494. }
  1495. void OBSBasic::on_actionMoveToBottom_triggered()
  1496. {
  1497. OBSSceneItem item = GetCurrentSceneItem();
  1498. obs_sceneitem_set_order(item, OBS_ORDER_MOVE_BOTTOM);
  1499. }
  1500. static BPtr<char> ReadLogFile(const char *log)
  1501. {
  1502. BPtr<char> logDir(os_get_config_path("obs-studio/logs"));
  1503. string path = (char*)logDir;
  1504. path += "/";
  1505. path += log;
  1506. BPtr<char> file = os_quick_read_utf8_file(path.c_str());
  1507. if (!file)
  1508. blog(LOG_WARNING, "Failed to read log file %s", path.c_str());
  1509. return file;
  1510. }
  1511. void OBSBasic::UploadLog(const char *file)
  1512. {
  1513. BPtr<char> fileString{ReadLogFile(file)};
  1514. if (!fileString)
  1515. return;
  1516. if (!*fileString)
  1517. return;
  1518. ui->menuLogFiles->setEnabled(false);
  1519. auto data_deleter = [](obs_data_t *d) { obs_data_release(d); };
  1520. using data_t = unique_ptr<struct obs_data, decltype(data_deleter)>;
  1521. data_t content{obs_data_create(), data_deleter};
  1522. data_t files{obs_data_create(), data_deleter};
  1523. data_t request{obs_data_create(), data_deleter};
  1524. obs_data_set_string(content.get(), "content", fileString);
  1525. obs_data_set_obj(files.get(), file, content.get());
  1526. stringstream ss;
  1527. ss << "OBS " << App()->GetVersionString()
  1528. << " log file uploaded at " << CurrentDateTimeString();
  1529. obs_data_set_string(request.get(), "description", ss.str().c_str());
  1530. obs_data_set_bool(request.get(), "public", false);
  1531. obs_data_set_obj(request.get(), "files", files.get());
  1532. const char *json = obs_data_get_json(request.get());
  1533. if (!json) {
  1534. blog(LOG_ERROR, "Failed to get JSON data for log upload");
  1535. return;
  1536. }
  1537. logUploadPostData.setData(json, (int)strlen(json));
  1538. QUrl url("https://api.github.com/gists");
  1539. logUploadReply = networkManager.post(QNetworkRequest(url),
  1540. &logUploadPostData);
  1541. connect(logUploadReply, SIGNAL(finished()),
  1542. this, SLOT(logUploadFinished()));
  1543. connect(logUploadReply, SIGNAL(readyRead()),
  1544. this, SLOT(logUploadRead()));
  1545. }
  1546. void OBSBasic::on_actionShowLogs_triggered()
  1547. {
  1548. BPtr<char> logDir(os_get_config_path("obs-studio/logs"));
  1549. QUrl url = QUrl::fromLocalFile(QT_UTF8(logDir));
  1550. QDesktopServices::openUrl(url);
  1551. }
  1552. void OBSBasic::on_actionUploadCurrentLog_triggered()
  1553. {
  1554. UploadLog(App()->GetCurrentLog());
  1555. }
  1556. void OBSBasic::on_actionUploadLastLog_triggered()
  1557. {
  1558. UploadLog(App()->GetLastLog());
  1559. }
  1560. void OBSBasic::on_actionCheckForUpdates_triggered()
  1561. {
  1562. CheckForUpdates();
  1563. }
  1564. void OBSBasic::logUploadRead()
  1565. {
  1566. logUploadReturnData.push_back(logUploadReply->readAll());
  1567. }
  1568. void OBSBasic::logUploadFinished()
  1569. {
  1570. ui->menuLogFiles->setEnabled(true);
  1571. if (logUploadReply->error()) {
  1572. QMessageBox::information(this,
  1573. QTStr("LogReturnDialog.ErrorUploadingLog"),
  1574. logUploadReply->errorString());
  1575. return;
  1576. }
  1577. const char *jsonReply = logUploadReturnData.constData();
  1578. if (!jsonReply || !*jsonReply)
  1579. return;
  1580. obs_data_t *returnData = obs_data_create_from_json(jsonReply);
  1581. QString logURL = obs_data_get_string(returnData, "html_url");
  1582. obs_data_release(returnData);
  1583. OBSLogReply logDialog(this, logURL);
  1584. logDialog.exec();
  1585. logUploadReturnData.clear();
  1586. }
  1587. static void RenameListItem(OBSBasic *parent, QListWidget *listWidget,
  1588. obs_source_t *source, const string &name)
  1589. {
  1590. const char *prevName = obs_source_get_name(source);
  1591. if (name == prevName)
  1592. return;
  1593. obs_source_t *foundSource = obs_get_source_by_name(name.c_str());
  1594. QListWidgetItem *listItem = listWidget->currentItem();
  1595. if (foundSource || name.empty()) {
  1596. listItem->setText(QT_UTF8(prevName));
  1597. if (foundSource) {
  1598. QMessageBox::information(parent,
  1599. QTStr("NameExists.Title"),
  1600. QTStr("NameExists.Text"));
  1601. } else if (name.empty()) {
  1602. QMessageBox::information(parent,
  1603. QTStr("NoNameEntered.Title"),
  1604. QTStr("NoNameEntered.Text"));
  1605. }
  1606. obs_source_release(foundSource);
  1607. } else {
  1608. listItem->setText(QT_UTF8(name.c_str()));
  1609. obs_source_set_name(source, name.c_str());
  1610. }
  1611. }
  1612. void OBSBasic::SceneNameEdited(QWidget *editor,
  1613. QAbstractItemDelegate::EndEditHint endHint)
  1614. {
  1615. OBSScene scene = GetCurrentScene();
  1616. QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
  1617. string text = QT_TO_UTF8(edit->text().trimmed());
  1618. if (!scene)
  1619. return;
  1620. obs_source_t *source = obs_scene_get_source(scene);
  1621. RenameListItem(this, ui->scenes, source, text);
  1622. UNUSED_PARAMETER(endHint);
  1623. }
  1624. void OBSBasic::SceneItemNameEdited(QWidget *editor,
  1625. QAbstractItemDelegate::EndEditHint endHint)
  1626. {
  1627. OBSSceneItem item = GetCurrentSceneItem();
  1628. QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
  1629. string text = QT_TO_UTF8(edit->text().trimmed());
  1630. if (!item)
  1631. return;
  1632. obs_source_t *source = obs_sceneitem_get_source(item);
  1633. RenameListItem(this, ui->sources, source, text);
  1634. UNUSED_PARAMETER(endHint);
  1635. }
  1636. void OBSBasic::StreamingStart()
  1637. {
  1638. ui->streamButton->setText(QTStr("Basic.Main.StopStreaming"));
  1639. ui->streamButton->setEnabled(true);
  1640. ui->statusbar->StreamStarted(streamOutput);
  1641. }
  1642. void OBSBasic::StreamingStop(int code)
  1643. {
  1644. const char *errorMessage;
  1645. switch (code) {
  1646. case OBS_OUTPUT_BAD_PATH:
  1647. errorMessage = Str("Output.ConnectFail.BadPath");
  1648. break;
  1649. case OBS_OUTPUT_CONNECT_FAILED:
  1650. errorMessage = Str("Output.ConnectFail.ConnectFailed");
  1651. break;
  1652. case OBS_OUTPUT_INVALID_STREAM:
  1653. errorMessage = Str("Output.ConnectFail.InvalidStream");
  1654. break;
  1655. default:
  1656. case OBS_OUTPUT_ERROR:
  1657. errorMessage = Str("Output.ConnectFail.Error");
  1658. break;
  1659. case OBS_OUTPUT_DISCONNECTED:
  1660. /* doesn't happen if output is set to reconnect. note that
  1661. * reconnects are handled in the output, not in the UI */
  1662. errorMessage = Str("Output.ConnectFail.Disconnected");
  1663. }
  1664. activeRefs--;
  1665. ui->statusbar->StreamStopped();
  1666. ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
  1667. ui->streamButton->setEnabled(true);
  1668. if (code != OBS_OUTPUT_SUCCESS)
  1669. QMessageBox::information(this,
  1670. QTStr("Output.ConnectFail.Title"),
  1671. QT_UTF8(errorMessage));
  1672. }
  1673. void OBSBasic::RecordingStart()
  1674. {
  1675. ui->statusbar->RecordingStarted(fileOutput);
  1676. }
  1677. void OBSBasic::RecordingStop()
  1678. {
  1679. ui->statusbar->RecordingStopped();
  1680. activeRefs--;
  1681. ui->recordButton->setText(QTStr("Basic.Main.StartRecording"));
  1682. }
  1683. void OBSBasic::SetupEncoders()
  1684. {
  1685. if (activeRefs == 0) {
  1686. obs_data_t *x264Settings = obs_data_create();
  1687. obs_data_t *aacSettings = obs_data_create();
  1688. int videoBitrate = config_get_uint(basicConfig, "SimpleOutput",
  1689. "VBitrate");
  1690. int audioBitrate = config_get_uint(basicConfig, "SimpleOutput",
  1691. "ABitrate");
  1692. bool advanced = config_get_bool(basicConfig, "SimpleOutput",
  1693. "UseAdvanced");
  1694. bool useCBR = config_get_bool(basicConfig, "SimpleOutput",
  1695. "UseCBR");
  1696. const char *preset = config_get_string(basicConfig,
  1697. "SimpleOutput", "Preset");
  1698. const char *custom = config_get_string(basicConfig,
  1699. "SimpleOutput", "x264Settings");
  1700. obs_data_set_int(x264Settings, "bitrate", videoBitrate);
  1701. obs_data_set_int(x264Settings, "buffer_size", videoBitrate);
  1702. if (advanced) {
  1703. obs_data_set_string(x264Settings, "preset", preset);
  1704. obs_data_set_string(x264Settings, "x264opts", custom);
  1705. obs_data_set_bool(x264Settings, "cbr", useCBR);
  1706. } else {
  1707. obs_data_set_bool(x264Settings, "cbr", true);
  1708. }
  1709. obs_data_set_int(aacSettings, "bitrate", audioBitrate);
  1710. obs_encoder_update(x264, x264Settings);
  1711. obs_encoder_update(aac, aacSettings);
  1712. obs_data_release(x264Settings);
  1713. obs_data_release(aacSettings);
  1714. obs_encoder_set_video(x264, obs_get_video());
  1715. obs_encoder_set_audio(aac, obs_get_audio());
  1716. }
  1717. }
  1718. void OBSBasic::on_streamButton_clicked()
  1719. {
  1720. if (obs_output_active(streamOutput)) {
  1721. obs_output_stop(streamOutput);
  1722. } else {
  1723. SaveService();
  1724. SetupEncoders();
  1725. obs_output_set_video_encoder(streamOutput, x264);
  1726. obs_output_set_audio_encoder(streamOutput, aac);
  1727. obs_output_set_service(streamOutput, service);
  1728. bool reconnect = config_get_bool(basicConfig, "SimpleOutput",
  1729. "Reconnect");
  1730. int retryDelay = config_get_uint(basicConfig, "SimpleOutput",
  1731. "RetryDelay");
  1732. int maxRetries = config_get_uint(basicConfig, "SimpleOutput",
  1733. "MaxRetries");
  1734. if (!reconnect)
  1735. maxRetries = 0;
  1736. obs_output_set_reconnect_settings(streamOutput, maxRetries,
  1737. retryDelay);
  1738. if (obs_output_start(streamOutput)) {
  1739. activeRefs++;
  1740. ui->streamButton->setEnabled(false);
  1741. ui->streamButton->setText(
  1742. QTStr("Basic.Main.Connecting"));
  1743. }
  1744. }
  1745. }
  1746. void OBSBasic::on_recordButton_clicked()
  1747. {
  1748. if (obs_output_active(fileOutput)) {
  1749. obs_output_stop(fileOutput);
  1750. } else {
  1751. const char *path = config_get_string(basicConfig,
  1752. "SimpleOutput", "FilePath");
  1753. os_dir_t *dir = path ? os_opendir(path) : nullptr;
  1754. if (!dir) {
  1755. QMessageBox::information(this,
  1756. QTStr("Output.BadPath.Title"),
  1757. QTStr("Output.BadPath.Text"));
  1758. return;
  1759. }
  1760. os_closedir(dir);
  1761. string strPath;
  1762. strPath += path;
  1763. char lastChar = strPath.back();
  1764. if (lastChar != '/' && lastChar != '\\')
  1765. strPath += "/";
  1766. strPath += GenerateTimeDateFilename("flv");
  1767. SetupEncoders();
  1768. obs_output_set_video_encoder(fileOutput, x264);
  1769. obs_output_set_audio_encoder(fileOutput, aac);
  1770. obs_data_t *settings = obs_data_create();
  1771. obs_data_set_string(settings, "path", strPath.c_str());
  1772. obs_output_update(fileOutput, settings);
  1773. obs_data_release(settings);
  1774. if (obs_output_start(fileOutput)) {
  1775. activeRefs++;
  1776. ui->recordButton->setText(
  1777. QTStr("Basic.Main.StopRecording"));
  1778. }
  1779. }
  1780. }
  1781. void OBSBasic::on_settingsButton_clicked()
  1782. {
  1783. OBSBasicSettings settings(this);
  1784. settings.exec();
  1785. }
  1786. void OBSBasic::GetFPSCommon(uint32_t &num, uint32_t &den) const
  1787. {
  1788. const char *val = config_get_string(basicConfig, "Video", "FPSCommon");
  1789. if (strcmp(val, "10") == 0) {
  1790. num = 10;
  1791. den = 1;
  1792. } else if (strcmp(val, "20") == 0) {
  1793. num = 20;
  1794. den = 1;
  1795. } else if (strcmp(val, "25") == 0) {
  1796. num = 25;
  1797. den = 1;
  1798. } else if (strcmp(val, "29.97") == 0) {
  1799. num = 30000;
  1800. den = 1001;
  1801. } else if (strcmp(val, "48") == 0) {
  1802. num = 48;
  1803. den = 1;
  1804. } else if (strcmp(val, "59.94") == 0) {
  1805. num = 60000;
  1806. den = 1001;
  1807. } else if (strcmp(val, "60") == 0) {
  1808. num = 60;
  1809. den = 1;
  1810. } else {
  1811. num = 30;
  1812. den = 1;
  1813. }
  1814. }
  1815. void OBSBasic::GetFPSInteger(uint32_t &num, uint32_t &den) const
  1816. {
  1817. num = (uint32_t)config_get_uint(basicConfig, "Video", "FPSInt");
  1818. den = 1;
  1819. }
  1820. void OBSBasic::GetFPSFraction(uint32_t &num, uint32_t &den) const
  1821. {
  1822. num = (uint32_t)config_get_uint(basicConfig, "Video", "FPSNum");
  1823. den = (uint32_t)config_get_uint(basicConfig, "Video", "FPSDen");
  1824. }
  1825. void OBSBasic::GetFPSNanoseconds(uint32_t &num, uint32_t &den) const
  1826. {
  1827. num = 1000000000;
  1828. den = (uint32_t)config_get_uint(basicConfig, "Video", "FPSNS");
  1829. }
  1830. void OBSBasic::GetConfigFPS(uint32_t &num, uint32_t &den) const
  1831. {
  1832. uint32_t type = config_get_uint(basicConfig, "Video", "FPSType");
  1833. if (type == 1) //"Integer"
  1834. GetFPSInteger(num, den);
  1835. else if (type == 2) //"Fraction"
  1836. GetFPSFraction(num, den);
  1837. else if (false) //"Nanoseconds", currently not implemented
  1838. GetFPSNanoseconds(num, den);
  1839. else
  1840. GetFPSCommon(num, den);
  1841. }
  1842. config_t *OBSBasic::Config() const
  1843. {
  1844. return basicConfig;
  1845. }
  1846. void OBSBasic::on_actionEditTransform_triggered()
  1847. {
  1848. if (transformWindow)
  1849. transformWindow->close();
  1850. transformWindow = new OBSBasicTransform(this);
  1851. transformWindow->show();
  1852. transformWindow->setAttribute(Qt::WA_DeleteOnClose, true);
  1853. }
  1854. void OBSBasic::on_actionResetTransform_triggered()
  1855. {
  1856. auto func = [] (obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  1857. {
  1858. if (!obs_sceneitem_selected(item))
  1859. return true;
  1860. obs_transform_info info;
  1861. vec2_set(&info.pos, 0.0f, 0.0f);
  1862. vec2_set(&info.scale, 1.0f, 1.0f);
  1863. info.rot = 0.0f;
  1864. info.alignment = OBS_ALIGN_TOP | OBS_ALIGN_LEFT;
  1865. info.bounds_type = OBS_BOUNDS_NONE;
  1866. info.bounds_alignment = OBS_ALIGN_CENTER;
  1867. vec2_set(&info.bounds, 0.0f, 0.0f);
  1868. obs_sceneitem_set_info(item, &info);
  1869. UNUSED_PARAMETER(scene);
  1870. UNUSED_PARAMETER(param);
  1871. return true;
  1872. };
  1873. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  1874. }
  1875. static void GetItemBox(obs_sceneitem_t *item, vec3 &tl, vec3 &br)
  1876. {
  1877. matrix4 boxTransform;
  1878. obs_sceneitem_get_box_transform(item, &boxTransform);
  1879. vec3_set(&tl, M_INFINITE, M_INFINITE, 0.0f);
  1880. vec3_set(&br, -M_INFINITE, -M_INFINITE, 0.0f);
  1881. auto GetMinPos = [&] (float x, float y)
  1882. {
  1883. vec3 pos;
  1884. vec3_set(&pos, x, y, 0.0f);
  1885. vec3_transform(&pos, &pos, &boxTransform);
  1886. vec3_min(&tl, &tl, &pos);
  1887. vec3_max(&br, &br, &pos);
  1888. };
  1889. GetMinPos(0.0f, 0.0f);
  1890. GetMinPos(1.0f, 0.0f);
  1891. GetMinPos(0.0f, 1.0f);
  1892. GetMinPos(1.0f, 1.0f);
  1893. }
  1894. static vec3 GetItemTL(obs_sceneitem_t *item)
  1895. {
  1896. vec3 tl, br;
  1897. GetItemBox(item, tl, br);
  1898. return tl;
  1899. }
  1900. static void SetItemTL(obs_sceneitem_t *item, const vec3 &tl)
  1901. {
  1902. vec3 newTL;
  1903. vec2 pos;
  1904. obs_sceneitem_get_pos(item, &pos);
  1905. newTL = GetItemTL(item);
  1906. pos.x += tl.x - newTL.x;
  1907. pos.y += tl.y - newTL.y;
  1908. obs_sceneitem_set_pos(item, &pos);
  1909. }
  1910. static bool RotateSelectedSources(obs_scene_t *scene, obs_sceneitem_t *item,
  1911. void *param)
  1912. {
  1913. if (!obs_sceneitem_selected(item))
  1914. return true;
  1915. float rot = *reinterpret_cast<float*>(param);
  1916. vec3 tl = GetItemTL(item);
  1917. rot += obs_sceneitem_get_rot(item);
  1918. if (rot >= 360.0f) rot -= 360.0f;
  1919. else if (rot <= -360.0f) rot += 360.0f;
  1920. obs_sceneitem_set_rot(item, rot);
  1921. SetItemTL(item, tl);
  1922. UNUSED_PARAMETER(scene);
  1923. UNUSED_PARAMETER(param);
  1924. return true;
  1925. };
  1926. void OBSBasic::on_actionRotate90CW_triggered()
  1927. {
  1928. float f90CW = 90.0f;
  1929. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f90CW);
  1930. }
  1931. void OBSBasic::on_actionRotate90CCW_triggered()
  1932. {
  1933. float f90CCW = -90.0f;
  1934. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f90CCW);
  1935. }
  1936. void OBSBasic::on_actionRotate180_triggered()
  1937. {
  1938. float f180 = 180.0f;
  1939. obs_scene_enum_items(GetCurrentScene(), RotateSelectedSources, &f180);
  1940. }
  1941. static bool MultiplySelectedItemScale(obs_scene_t *scene, obs_sceneitem_t *item,
  1942. void *param)
  1943. {
  1944. vec2 &mul = *reinterpret_cast<vec2*>(param);
  1945. if (!obs_sceneitem_selected(item))
  1946. return true;
  1947. vec3 tl = GetItemTL(item);
  1948. vec2 scale;
  1949. obs_sceneitem_get_scale(item, &scale);
  1950. vec2_mul(&scale, &scale, &mul);
  1951. obs_sceneitem_set_scale(item, &scale);
  1952. SetItemTL(item, tl);
  1953. UNUSED_PARAMETER(scene);
  1954. return true;
  1955. }
  1956. void OBSBasic::on_actionFlipHorizontal_triggered()
  1957. {
  1958. vec2 scale;
  1959. vec2_set(&scale, -1.0f, 1.0f);
  1960. obs_scene_enum_items(GetCurrentScene(), MultiplySelectedItemScale,
  1961. &scale);
  1962. }
  1963. void OBSBasic::on_actionFlipVertical_triggered()
  1964. {
  1965. vec2 scale;
  1966. vec2_set(&scale, 1.0f, -1.0f);
  1967. obs_scene_enum_items(GetCurrentScene(), MultiplySelectedItemScale,
  1968. &scale);
  1969. }
  1970. static bool CenterAlignSelectedItems(obs_scene_t *scene, obs_sceneitem_t *item,
  1971. void *param)
  1972. {
  1973. obs_bounds_type boundsType = *reinterpret_cast<obs_bounds_type*>(param);
  1974. if (!obs_sceneitem_selected(item))
  1975. return true;
  1976. obs_video_info ovi;
  1977. obs_get_video_info(&ovi);
  1978. obs_transform_info itemInfo;
  1979. vec2_set(&itemInfo.pos, 0.0f, 0.0f);
  1980. vec2_set(&itemInfo.scale, 1.0f, 1.0f);
  1981. itemInfo.alignment = OBS_ALIGN_LEFT | OBS_ALIGN_TOP;
  1982. itemInfo.rot = 0.0f;
  1983. vec2_set(&itemInfo.bounds,
  1984. float(ovi.base_width), float(ovi.base_height));
  1985. itemInfo.bounds_type = boundsType;
  1986. itemInfo.bounds_alignment = OBS_ALIGN_CENTER;
  1987. obs_sceneitem_set_info(item, &itemInfo);
  1988. UNUSED_PARAMETER(scene);
  1989. return true;
  1990. }
  1991. void OBSBasic::on_actionFitToScreen_triggered()
  1992. {
  1993. obs_bounds_type boundsType = OBS_BOUNDS_SCALE_INNER;
  1994. obs_scene_enum_items(GetCurrentScene(), CenterAlignSelectedItems,
  1995. &boundsType);
  1996. }
  1997. void OBSBasic::on_actionStretchToScreen_triggered()
  1998. {
  1999. obs_bounds_type boundsType = OBS_BOUNDS_STRETCH;
  2000. obs_scene_enum_items(GetCurrentScene(), CenterAlignSelectedItems,
  2001. &boundsType);
  2002. }
  2003. void OBSBasic::on_actionCenterToScreen_triggered()
  2004. {
  2005. auto func = [] (obs_scene_t *scene, obs_sceneitem_t *item, void *param)
  2006. {
  2007. vec3 tl, br, itemCenter, screenCenter, offset;
  2008. obs_video_info ovi;
  2009. if (!obs_sceneitem_selected(item))
  2010. return true;
  2011. obs_get_video_info(&ovi);
  2012. vec3_set(&screenCenter, float(ovi.base_width),
  2013. float(ovi.base_height), 0.0f);
  2014. vec3_mulf(&screenCenter, &screenCenter, 0.5f);
  2015. GetItemBox(item, tl, br);
  2016. vec3_sub(&itemCenter, &br, &tl);
  2017. vec3_mulf(&itemCenter, &itemCenter, 0.5f);
  2018. vec3_add(&itemCenter, &itemCenter, &tl);
  2019. vec3_sub(&offset, &screenCenter, &itemCenter);
  2020. vec3_add(&tl, &tl, &offset);
  2021. SetItemTL(item, tl);
  2022. UNUSED_PARAMETER(scene);
  2023. UNUSED_PARAMETER(param);
  2024. return true;
  2025. };
  2026. obs_scene_enum_items(GetCurrentScene(), func, nullptr);
  2027. }