window-basic-main.cpp 63 KB

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