1
0

obs-source.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457
  1. /******************************************************************************
  2. Copyright (C) 2013-2014 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include <inttypes.h>
  15. #include "media-io/format-conversion.h"
  16. #include "media-io/video-frame.h"
  17. #include "util/platform.h"
  18. #include "callback/calldata.h"
  19. #include "graphics/matrix3.h"
  20. #include "graphics/vec3.h"
  21. #include "obs.h"
  22. #include "obs-internal.h"
  23. static void obs_source_destroy(obs_source_t source);
  24. static inline const struct obs_source_info *find_source(struct darray *list,
  25. const char *id)
  26. {
  27. size_t i;
  28. struct obs_source_info *array = list->array;
  29. for (i = 0; i < list->num; i++) {
  30. struct obs_source_info *info = array+i;
  31. if (strcmp(info->id, id) == 0)
  32. return info;
  33. }
  34. return NULL;
  35. }
  36. static const struct obs_source_info *get_source_info(enum obs_source_type type,
  37. const char *id)
  38. {
  39. struct darray *list = NULL;
  40. switch (type) {
  41. case OBS_SOURCE_TYPE_INPUT:
  42. list = &obs->input_types.da;
  43. break;
  44. case OBS_SOURCE_TYPE_FILTER:
  45. list = &obs->filter_types.da;
  46. break;
  47. case OBS_SOURCE_TYPE_TRANSITION:
  48. list = &obs->transition_types.da;
  49. break;
  50. case OBS_SOURCE_TYPE_SCENE:
  51. default:
  52. blog(LOG_ERROR, "get_source_info: invalid source type");
  53. return NULL;
  54. }
  55. return find_source(list, id);
  56. }
  57. bool obs_source_init_handlers(struct obs_source *source)
  58. {
  59. source->signals = signal_handler_create();
  60. if (!source->signals)
  61. return false;
  62. source->procs = proc_handler_create();
  63. return (source->procs != NULL);
  64. }
  65. const char *obs_source_getdisplayname(enum obs_source_type type,
  66. const char *id, const char *locale)
  67. {
  68. const struct obs_source_info *info = get_source_info(type, id);
  69. return (info != NULL) ? info->getname(locale) : NULL;
  70. }
  71. /* internal initialization */
  72. bool obs_source_init(struct obs_source *source,
  73. const struct obs_source_info *info)
  74. {
  75. source->refs = 1;
  76. source->user_volume = 1.0f;
  77. source->present_volume = 1.0f;
  78. source->sync_offset = 0;
  79. pthread_mutex_init_value(&source->filter_mutex);
  80. pthread_mutex_init_value(&source->video_mutex);
  81. pthread_mutex_init_value(&source->audio_mutex);
  82. memcpy(&source->info, info, sizeof(struct obs_source_info));
  83. if (pthread_mutex_init(&source->filter_mutex, NULL) != 0)
  84. return false;
  85. if (pthread_mutex_init(&source->audio_mutex, NULL) != 0)
  86. return false;
  87. if (pthread_mutex_init(&source->video_mutex, NULL) != 0)
  88. return false;
  89. if (info->output_flags & OBS_SOURCE_AUDIO) {
  90. source->audio_line = audio_output_createline(obs->audio.audio,
  91. source->name);
  92. if (!source->audio_line) {
  93. blog(LOG_ERROR, "Failed to create audio line for "
  94. "source '%s'", source->name);
  95. return false;
  96. }
  97. }
  98. return true;
  99. }
  100. static inline void obs_source_dosignal(struct obs_source *source,
  101. const char *signal_obs, const char *signal_source)
  102. {
  103. struct calldata data;
  104. calldata_init(&data);
  105. calldata_setptr(&data, "source", source);
  106. if (signal_obs)
  107. signal_handler_signal(obs->signals, signal_obs, &data);
  108. if (signal_source)
  109. signal_handler_signal(source->signals, signal_source, &data);
  110. calldata_free(&data);
  111. }
  112. obs_source_t obs_source_create(enum obs_source_type type, const char *id,
  113. const char *name, obs_data_t settings)
  114. {
  115. struct obs_source *source;
  116. const struct obs_source_info *info = get_source_info(type, id);
  117. if (!info) {
  118. blog(LOG_ERROR, "Source '%s' not found", id);
  119. return NULL;
  120. }
  121. source = bzalloc(sizeof(struct obs_source));
  122. if (!obs_source_init_handlers(source))
  123. goto fail;
  124. source->name = bstrdup(name);
  125. source->settings = obs_data_newref(settings);
  126. source->data = info->create(source->settings, source);
  127. if (!source->data)
  128. goto fail;
  129. if (!obs_source_init(source, info))
  130. goto fail;
  131. obs_source_dosignal(source, "source-create", NULL);
  132. return source;
  133. fail:
  134. blog(LOG_ERROR, "obs_source_create failed");
  135. obs_source_destroy(source);
  136. return NULL;
  137. }
  138. void source_frame_init(struct source_frame *frame, enum video_format format,
  139. uint32_t width, uint32_t height)
  140. {
  141. struct video_frame vid_frame;
  142. if (!frame)
  143. return;
  144. video_frame_init(&vid_frame, format, width, height);
  145. frame->format = format;
  146. frame->width = width;
  147. frame->height = height;
  148. for (size_t i = 0; i < MAX_AV_PLANES; i++) {
  149. frame->data[i] = vid_frame.data[i];
  150. frame->linesize[i] = vid_frame.linesize[i];
  151. }
  152. }
  153. static void obs_source_destroy(struct obs_source *source)
  154. {
  155. size_t i;
  156. if (!source)
  157. return;
  158. obs_source_dosignal(source, "source-destroy", "destroy");
  159. if (source->filter_parent)
  160. obs_source_filter_remove(source->filter_parent, source);
  161. for (i = 0; i < source->filters.num; i++)
  162. obs_source_release(source->filters.array[i]);
  163. for (i = 0; i < source->video_frames.num; i++)
  164. source_frame_destroy(source->video_frames.array[i]);
  165. gs_entercontext(obs->video.graphics);
  166. texture_destroy(source->output_texture);
  167. gs_leavecontext();
  168. if (source->data)
  169. source->info.destroy(source->data);
  170. for (i = 0; i < MAX_AV_PLANES; i++)
  171. bfree(source->audio_data.data[i]);
  172. audio_line_destroy(source->audio_line);
  173. audio_resampler_destroy(source->resampler);
  174. proc_handler_destroy(source->procs);
  175. signal_handler_destroy(source->signals);
  176. texrender_destroy(source->filter_texrender);
  177. da_free(source->video_frames);
  178. da_free(source->filters);
  179. pthread_mutex_destroy(&source->filter_mutex);
  180. pthread_mutex_destroy(&source->audio_mutex);
  181. pthread_mutex_destroy(&source->video_mutex);
  182. obs_data_release(source->settings);
  183. bfree(source->name);
  184. bfree(source);
  185. }
  186. void obs_source_addref(obs_source_t source)
  187. {
  188. if (source)
  189. ++source->refs;
  190. }
  191. void obs_source_release(obs_source_t source)
  192. {
  193. if (!source)
  194. return;
  195. if (--source->refs == 0)
  196. obs_source_destroy(source);
  197. }
  198. void obs_source_remove(obs_source_t source)
  199. {
  200. struct obs_core_data *data = &obs->data;
  201. size_t id;
  202. pthread_mutex_lock(&data->sources_mutex);
  203. if (!source || source->removed) {
  204. pthread_mutex_unlock(&data->sources_mutex);
  205. return;
  206. }
  207. source->removed = true;
  208. obs_source_addref(source);
  209. id = da_find(data->sources, &source, 0);
  210. if (id != DARRAY_INVALID) {
  211. da_erase_item(data->sources, &source);
  212. obs_source_release(source);
  213. }
  214. pthread_mutex_unlock(&data->sources_mutex);
  215. obs_source_dosignal(source, "source-remove", "remove");
  216. obs_source_release(source);
  217. }
  218. bool obs_source_removed(obs_source_t source)
  219. {
  220. return source ? source->removed : true;
  221. }
  222. obs_properties_t obs_source_properties(enum obs_source_type type,
  223. const char *id, const char *locale)
  224. {
  225. const struct obs_source_info *info = get_source_info(type, id);
  226. if (info && info->get_properties)
  227. return info->get_properties(locale);
  228. return NULL;
  229. }
  230. uint32_t obs_source_get_output_flags(obs_source_t source)
  231. {
  232. return source ? source->info.output_flags : 0;
  233. }
  234. void obs_source_update(obs_source_t source, obs_data_t settings)
  235. {
  236. if (!source) return;
  237. obs_data_apply(source->settings, settings);
  238. if (source->info.update)
  239. source->info.update(source->data, source->settings);
  240. }
  241. static void activate_source(obs_source_t source)
  242. {
  243. if (source->info.activate)
  244. source->info.activate(source->data);
  245. obs_source_dosignal(source, "source-activate", "activate");
  246. }
  247. static void deactivate_source(obs_source_t source)
  248. {
  249. if (source->info.deactivate)
  250. source->info.deactivate(source->data);
  251. obs_source_dosignal(source, "source-deactivate", "deactivate");
  252. }
  253. static void show_source(obs_source_t source)
  254. {
  255. if (source->info.show)
  256. source->info.show(source->data);
  257. obs_source_dosignal(source, "source-show", "show");
  258. }
  259. static void hide_source(obs_source_t source)
  260. {
  261. if (source->info.hide)
  262. source->info.hide(source->data);
  263. obs_source_dosignal(source, "source-hide", "hide");
  264. }
  265. static void activate_tree(obs_source_t parent, obs_source_t child, void *param)
  266. {
  267. if (++child->activate_refs == 1)
  268. activate_source(child);
  269. UNUSED_PARAMETER(parent);
  270. UNUSED_PARAMETER(param);
  271. }
  272. static void deactivate_tree(obs_source_t parent, obs_source_t child,
  273. void *param)
  274. {
  275. if (--child->activate_refs == 0)
  276. deactivate_source(child);
  277. UNUSED_PARAMETER(parent);
  278. UNUSED_PARAMETER(param);
  279. }
  280. static void show_tree(obs_source_t parent, obs_source_t child, void *param)
  281. {
  282. if (++child->show_refs == 1)
  283. show_source(child);
  284. UNUSED_PARAMETER(parent);
  285. UNUSED_PARAMETER(param);
  286. }
  287. static void hide_tree(obs_source_t parent, obs_source_t child, void *param)
  288. {
  289. if (--child->show_refs == 0)
  290. hide_source(child);
  291. UNUSED_PARAMETER(parent);
  292. UNUSED_PARAMETER(param);
  293. }
  294. void obs_source_activate(obs_source_t source, enum view_type type)
  295. {
  296. if (!source) return;
  297. if (++source->show_refs == 1) {
  298. show_source(source);
  299. obs_source_enum_tree(source, show_tree, NULL);
  300. }
  301. if (type == MAIN_VIEW) {
  302. if (++source->activate_refs == 1) {
  303. activate_source(source);
  304. obs_source_enum_tree(source, activate_tree, NULL);
  305. obs_source_set_present_volume(source, 1.0f);
  306. }
  307. }
  308. }
  309. void obs_source_deactivate(obs_source_t source, enum view_type type)
  310. {
  311. if (!source) return;
  312. if (--source->show_refs == 0) {
  313. hide_source(source);
  314. obs_source_enum_tree(source, hide_tree, NULL);
  315. }
  316. if (type == MAIN_VIEW) {
  317. if (--source->activate_refs == 0) {
  318. deactivate_source(source);
  319. obs_source_enum_tree(source, deactivate_tree, NULL);
  320. obs_source_set_present_volume(source, 0.0f);
  321. }
  322. }
  323. }
  324. void obs_source_video_tick(obs_source_t source, float seconds)
  325. {
  326. if (!source) return;
  327. /* reset the filter render texture information once every frame */
  328. if (source->filter_texrender)
  329. texrender_reset(source->filter_texrender);
  330. if (source->info.video_tick)
  331. source->info.video_tick(source->data, seconds);
  332. }
  333. /* unless the value is 3+ hours worth of frames, this won't overflow */
  334. static inline uint64_t conv_frames_to_time(size_t frames)
  335. {
  336. const struct audio_output_info *info;
  337. info = audio_output_getinfo(obs->audio.audio);
  338. return (uint64_t)frames * 1000000000ULL /
  339. (uint64_t)info->samples_per_sec;
  340. }
  341. /* maximum "direct" timestamp variance in nanoseconds */
  342. #define MAX_TS_VAR 5000000000ULL
  343. /* maximum time that timestamp can jump in nanoseconds */
  344. #define MAX_TIMESTAMP_JUMP 2000000000ULL
  345. /* time threshold in nanoseconds to ensure audio timing is as seamless as
  346. * possible */
  347. #define TS_SMOOTHING_THRESHOLD 70000000ULL
  348. static inline void reset_audio_timing(obs_source_t source, uint64_t timetamp)
  349. {
  350. source->timing_set = true;
  351. source->timing_adjust = os_gettime_ns() - timetamp;
  352. }
  353. static inline void handle_ts_jump(obs_source_t source, uint64_t expected,
  354. uint64_t ts, uint64_t diff)
  355. {
  356. blog(LOG_DEBUG, "Timestamp for source '%s' jumped by '%"PRIu64"', "
  357. "expected value %"PRIu64", input value %"PRIu64,
  358. source->name, diff, expected, ts);
  359. /* if has video, ignore audio data until reset */
  360. if (source->info.output_flags & OBS_SOURCE_ASYNC_VIDEO)
  361. source->audio_reset_ref--;
  362. else
  363. reset_audio_timing(source, ts);
  364. }
  365. static void source_output_audio_line(obs_source_t source,
  366. const struct audio_data *data)
  367. {
  368. struct audio_data in = *data;
  369. uint64_t diff;
  370. if (!source->timing_set) {
  371. reset_audio_timing(source, in.timestamp);
  372. /* detects 'directly' set timestamps as long as they're within
  373. * a certain threshold */
  374. if ((source->timing_adjust + MAX_TS_VAR) < MAX_TS_VAR * 2)
  375. source->timing_adjust = 0;
  376. } else {
  377. bool ts_under = (in.timestamp < source->next_audio_ts_min);
  378. diff = ts_under ?
  379. (source->next_audio_ts_min - in.timestamp) :
  380. (in.timestamp - source->next_audio_ts_min);
  381. /* smooth audio if lower or within threshold */
  382. if (diff > MAX_TIMESTAMP_JUMP)
  383. handle_ts_jump(source, source->next_audio_ts_min,
  384. in.timestamp, diff);
  385. else if (ts_under || diff < TS_SMOOTHING_THRESHOLD)
  386. in.timestamp = source->next_audio_ts_min;
  387. }
  388. source->next_audio_ts_min = in.timestamp +
  389. conv_frames_to_time(in.frames);
  390. if (source->audio_reset_ref != 0)
  391. return;
  392. in.timestamp += source->timing_adjust + source->sync_offset;
  393. in.volume = source->user_volume * source->present_volume *
  394. obs->audio.user_volume * obs->audio.present_volume;
  395. audio_line_output(source->audio_line, &in);
  396. }
  397. static bool set_texture_size(obs_source_t source, struct source_frame *frame)
  398. {
  399. if (source->output_texture) {
  400. uint32_t width = texture_getwidth(source->output_texture);
  401. uint32_t height = texture_getheight(source->output_texture);
  402. if (width == frame->width && height == frame->height)
  403. return true;
  404. }
  405. texture_destroy(source->output_texture);
  406. source->output_texture = gs_create_texture(frame->width, frame->height,
  407. GS_RGBA, 1, NULL, GS_DYNAMIC);
  408. return source->output_texture != NULL;
  409. }
  410. enum convert_type {
  411. CONVERT_NONE,
  412. CONVERT_NV12,
  413. CONVERT_420,
  414. CONVERT_422_U,
  415. CONVERT_422_Y,
  416. };
  417. static inline enum convert_type get_convert_type(enum video_format format)
  418. {
  419. switch (format) {
  420. case VIDEO_FORMAT_I420:
  421. return CONVERT_420;
  422. case VIDEO_FORMAT_NV12:
  423. return CONVERT_NV12;
  424. case VIDEO_FORMAT_YVYU:
  425. case VIDEO_FORMAT_YUY2:
  426. return CONVERT_422_Y;
  427. case VIDEO_FORMAT_UYVY:
  428. return CONVERT_422_U;
  429. case VIDEO_FORMAT_NONE:
  430. case VIDEO_FORMAT_RGBA:
  431. case VIDEO_FORMAT_BGRA:
  432. case VIDEO_FORMAT_BGRX:
  433. return CONVERT_NONE;
  434. }
  435. return CONVERT_NONE;
  436. }
  437. static bool upload_frame(texture_t tex, const struct source_frame *frame)
  438. {
  439. void *ptr;
  440. uint32_t linesize;
  441. enum convert_type type = get_convert_type(frame->format);
  442. if (type == CONVERT_NONE) {
  443. texture_setimage(tex, frame->data[0], frame->linesize[0],
  444. false);
  445. return true;
  446. }
  447. if (!texture_map(tex, &ptr, &linesize))
  448. return false;
  449. if (type == CONVERT_420)
  450. decompress_420((const uint8_t* const*)frame->data,
  451. frame->linesize,
  452. 0, frame->height, ptr, linesize);
  453. else if (type == CONVERT_NV12)
  454. decompress_nv12((const uint8_t* const*)frame->data,
  455. frame->linesize,
  456. 0, frame->height, ptr, linesize);
  457. else if (type == CONVERT_422_Y)
  458. decompress_422(frame->data[0], frame->linesize[0],
  459. 0, frame->height, ptr, linesize, true);
  460. else if (type == CONVERT_422_U)
  461. decompress_422(frame->data[0], frame->linesize[0],
  462. 0, frame->height, ptr, linesize, false);
  463. texture_unmap(tex);
  464. return true;
  465. }
  466. static void obs_source_draw_texture(texture_t tex, struct source_frame *frame)
  467. {
  468. effect_t effect = obs->video.default_effect;
  469. bool yuv = format_is_yuv(frame->format);
  470. const char *type = yuv ? "DrawMatrix" : "Draw";
  471. technique_t tech;
  472. eparam_t param;
  473. if (!upload_frame(tex, frame))
  474. return;
  475. tech = effect_gettechnique(effect, type);
  476. technique_begin(tech);
  477. technique_beginpass(tech, 0);
  478. if (yuv) {
  479. param = effect_getparambyname(effect, "color_matrix");
  480. effect_setval(effect, param, frame->color_matrix,
  481. sizeof(float) * 16);
  482. }
  483. param = effect_getparambyname(effect, "image");
  484. effect_settexture(effect, param, tex);
  485. gs_draw_sprite(tex, frame->flip ? GS_FLIP_V : 0, 0, 0);
  486. technique_endpass(tech);
  487. technique_end(tech);
  488. }
  489. static void obs_source_render_async_video(obs_source_t source)
  490. {
  491. struct source_frame *frame = obs_source_getframe(source);
  492. if (!frame)
  493. return;
  494. if (set_texture_size(source, frame))
  495. obs_source_draw_texture(source->output_texture, frame);
  496. obs_source_releaseframe(source, frame);
  497. }
  498. static inline void obs_source_render_filters(obs_source_t source)
  499. {
  500. source->rendering_filter = true;
  501. obs_source_video_render(source->filters.array[0]);
  502. source->rendering_filter = false;
  503. }
  504. static inline void obs_source_default_render(obs_source_t source,
  505. bool color_matrix)
  506. {
  507. effect_t effect = obs->video.default_effect;
  508. const char *tech_name = color_matrix ? "DrawMatrix" : "Draw";
  509. technique_t tech = effect_gettechnique(effect, tech_name);
  510. size_t passes, i;
  511. passes = technique_begin(tech);
  512. for (i = 0; i < passes; i++) {
  513. technique_beginpass(tech, i);
  514. source->info.video_render(source->data, effect);
  515. technique_endpass(tech);
  516. }
  517. technique_end(tech);
  518. }
  519. static inline void obs_source_main_render(obs_source_t source)
  520. {
  521. uint32_t flags = source->info.output_flags;
  522. bool color_matrix = (flags & OBS_SOURCE_COLOR_MATRIX) != 0;
  523. bool default_effect = !source->filter_parent &&
  524. source->filters.num == 0 &&
  525. (flags & OBS_SOURCE_CUSTOM_DRAW) == 0;
  526. if (default_effect)
  527. obs_source_default_render(source, color_matrix);
  528. else
  529. source->info.video_render(source->data, NULL);
  530. }
  531. void obs_source_video_render(obs_source_t source)
  532. {
  533. if (!source) return;
  534. if (source->info.video_render) {
  535. if (source->filters.num && !source->rendering_filter)
  536. obs_source_render_filters(source);
  537. else
  538. obs_source_main_render(source);
  539. } else if (source->filter_target) {
  540. obs_source_video_render(source->filter_target);
  541. } else {
  542. obs_source_render_async_video(source);
  543. }
  544. }
  545. uint32_t obs_source_getwidth(obs_source_t source)
  546. {
  547. if (source && source->info.getwidth)
  548. return source->info.getwidth(source->data);
  549. return 0;
  550. }
  551. uint32_t obs_source_getheight(obs_source_t source)
  552. {
  553. if (source && source->info.getheight)
  554. return source->info.getheight(source->data);
  555. return 0;
  556. }
  557. obs_source_t obs_filter_getparent(obs_source_t filter)
  558. {
  559. return filter ? filter->filter_parent : NULL;
  560. }
  561. obs_source_t obs_filter_gettarget(obs_source_t filter)
  562. {
  563. return filter ? filter->filter_target : NULL;
  564. }
  565. void obs_source_filter_add(obs_source_t source, obs_source_t filter)
  566. {
  567. if (!source || !filter)
  568. return;
  569. pthread_mutex_lock(&source->filter_mutex);
  570. if (da_find(source->filters, &filter, 0) != DARRAY_INVALID) {
  571. blog(LOG_WARNING, "Tried to add a filter that was already "
  572. "present on the source");
  573. return;
  574. }
  575. if (source->filters.num) {
  576. obs_source_t *back = da_end(source->filters);
  577. (*back)->filter_target = filter;
  578. }
  579. da_push_back(source->filters, &filter);
  580. pthread_mutex_unlock(&source->filter_mutex);
  581. filter->filter_parent = source;
  582. filter->filter_target = source;
  583. }
  584. void obs_source_filter_remove(obs_source_t source, obs_source_t filter)
  585. {
  586. size_t idx;
  587. if (!source || !filter)
  588. return;
  589. pthread_mutex_lock(&source->filter_mutex);
  590. idx = da_find(source->filters, &filter, 0);
  591. if (idx == DARRAY_INVALID)
  592. return;
  593. if (idx > 0) {
  594. obs_source_t prev = source->filters.array[idx-1];
  595. prev->filter_target = filter->filter_target;
  596. }
  597. da_erase(source->filters, idx);
  598. pthread_mutex_unlock(&source->filter_mutex);
  599. filter->filter_parent = NULL;
  600. filter->filter_target = NULL;
  601. }
  602. void obs_source_filter_setorder(obs_source_t source, obs_source_t filter,
  603. enum order_movement movement)
  604. {
  605. size_t idx, i;
  606. if (!source || !filter)
  607. return;
  608. idx = da_find(source->filters, &filter, 0);
  609. if (idx == DARRAY_INVALID)
  610. return;
  611. if (movement == ORDER_MOVE_UP) {
  612. if (idx == source->filters.num-1)
  613. return;
  614. da_move_item(source->filters, idx, idx+1);
  615. } else if (movement == ORDER_MOVE_DOWN) {
  616. if (idx == 0)
  617. return;
  618. da_move_item(source->filters, idx, idx-1);
  619. } else if (movement == ORDER_MOVE_TOP) {
  620. if (idx == source->filters.num-1)
  621. return;
  622. da_move_item(source->filters, idx, source->filters.num-1);
  623. } else if (movement == ORDER_MOVE_BOTTOM) {
  624. if (idx == 0)
  625. return;
  626. da_move_item(source->filters, idx, 0);
  627. }
  628. /* reorder filter targets, not the nicest way of dealing with things */
  629. for (i = 0; i < source->filters.num; i++) {
  630. obs_source_t next_filter = (i == source->filters.num-1) ?
  631. source : source->filters.array[idx+1];
  632. source->filters.array[i]->filter_target = next_filter;
  633. }
  634. }
  635. obs_data_t obs_source_getsettings(obs_source_t source)
  636. {
  637. if (!source) return NULL;
  638. obs_data_addref(source->settings);
  639. return source->settings;
  640. }
  641. static inline struct source_frame *filter_async_video(obs_source_t source,
  642. struct source_frame *in)
  643. {
  644. size_t i;
  645. for (i = source->filters.num; i > 0; i--) {
  646. struct obs_source *filter = source->filters.array[i-1];
  647. if (filter->info.filter_video) {
  648. in = filter->info.filter_video(filter->data, in);
  649. if (!in)
  650. return NULL;
  651. }
  652. }
  653. return in;
  654. }
  655. static inline void copy_frame_data_line(struct source_frame *dst,
  656. const struct source_frame *src, uint32_t plane, uint32_t y)
  657. {
  658. uint32_t pos_src = y * src->linesize[plane];
  659. uint32_t pos_dst = y * dst->linesize[plane];
  660. uint32_t bytes = dst->linesize[plane] < src->linesize[plane] ?
  661. dst->linesize[plane] : src->linesize[plane];
  662. memcpy(dst->data[plane] + pos_dst, src->data[plane] + pos_src, bytes);
  663. }
  664. static inline void copy_frame_data_plane(struct source_frame *dst,
  665. const struct source_frame *src, uint32_t plane, uint32_t lines)
  666. {
  667. if (dst->linesize[plane] != src->linesize[plane])
  668. for (uint32_t y = 0; y < lines; y++)
  669. copy_frame_data_line(dst, src, plane, y);
  670. else
  671. memcpy(dst->data[plane], src->data[plane],
  672. dst->linesize[plane] * lines);
  673. }
  674. static void copy_frame_data(struct source_frame *dst,
  675. const struct source_frame *src)
  676. {
  677. dst->flip = src->flip;
  678. dst->timestamp = src->timestamp;
  679. memcpy(dst->color_matrix, src->color_matrix, sizeof(float) * 16);
  680. switch (dst->format) {
  681. case VIDEO_FORMAT_I420:
  682. copy_frame_data_plane(dst, src, 0, dst->height);
  683. copy_frame_data_plane(dst, src, 1, dst->height/2);
  684. copy_frame_data_plane(dst, src, 2, dst->height/2);
  685. break;
  686. case VIDEO_FORMAT_NV12:
  687. copy_frame_data_plane(dst, src, 0, dst->height);
  688. copy_frame_data_plane(dst, src, 1, dst->height/2);
  689. break;
  690. case VIDEO_FORMAT_YVYU:
  691. case VIDEO_FORMAT_YUY2:
  692. case VIDEO_FORMAT_UYVY:
  693. case VIDEO_FORMAT_NONE:
  694. case VIDEO_FORMAT_RGBA:
  695. case VIDEO_FORMAT_BGRA:
  696. case VIDEO_FORMAT_BGRX:
  697. copy_frame_data_plane(dst, src, 0, dst->height);
  698. }
  699. }
  700. static inline struct source_frame *cache_video(const struct source_frame *frame)
  701. {
  702. /* TODO: use an actual cache */
  703. struct source_frame *new_frame = source_frame_create(frame->format,
  704. frame->width, frame->height);
  705. copy_frame_data(new_frame, frame);
  706. return new_frame;
  707. }
  708. void obs_source_output_video(obs_source_t source,
  709. const struct source_frame *frame)
  710. {
  711. if (!source || !frame)
  712. return;
  713. struct source_frame *output = cache_video(frame);
  714. pthread_mutex_lock(&source->filter_mutex);
  715. output = filter_async_video(source, output);
  716. pthread_mutex_unlock(&source->filter_mutex);
  717. if (output) {
  718. pthread_mutex_lock(&source->video_mutex);
  719. da_push_back(source->video_frames, &output);
  720. pthread_mutex_unlock(&source->video_mutex);
  721. }
  722. }
  723. static inline struct filtered_audio *filter_async_audio(obs_source_t source,
  724. struct filtered_audio *in)
  725. {
  726. size_t i;
  727. for (i = source->filters.num; i > 0; i--) {
  728. struct obs_source *filter = source->filters.array[i-1];
  729. if (filter->info.filter_audio) {
  730. in = filter->info.filter_audio(filter->data, in);
  731. if (!in)
  732. return NULL;
  733. }
  734. }
  735. return in;
  736. }
  737. static inline void reset_resampler(obs_source_t source,
  738. const struct source_audio *audio)
  739. {
  740. const struct audio_output_info *obs_info;
  741. struct resample_info output_info;
  742. obs_info = audio_output_getinfo(obs->audio.audio);
  743. output_info.format = obs_info->format;
  744. output_info.samples_per_sec = obs_info->samples_per_sec;
  745. output_info.speakers = obs_info->speakers;
  746. source->sample_info.format = audio->format;
  747. source->sample_info.samples_per_sec = audio->samples_per_sec;
  748. source->sample_info.speakers = audio->speakers;
  749. if (source->sample_info.samples_per_sec == obs_info->samples_per_sec &&
  750. source->sample_info.format == obs_info->format &&
  751. source->sample_info.speakers == obs_info->speakers) {
  752. source->audio_failed = false;
  753. return;
  754. }
  755. audio_resampler_destroy(source->resampler);
  756. source->resampler = audio_resampler_create(&output_info,
  757. &source->sample_info);
  758. source->audio_failed = source->resampler == NULL;
  759. if (source->resampler == NULL)
  760. blog(LOG_ERROR, "creation of resampler failed");
  761. }
  762. static inline void copy_audio_data(obs_source_t source,
  763. const uint8_t *const data[], uint32_t frames, uint64_t ts)
  764. {
  765. size_t planes = audio_output_planes(obs->audio.audio);
  766. size_t blocksize = audio_output_blocksize(obs->audio.audio);
  767. size_t size = (size_t)frames * blocksize;
  768. bool resize = source->audio_storage_size < size;
  769. source->audio_data.frames = frames;
  770. source->audio_data.timestamp = ts;
  771. for (size_t i = 0; i < planes; i++) {
  772. /* ensure audio storage capacity */
  773. if (resize) {
  774. bfree(source->audio_data.data[i]);
  775. source->audio_data.data[i] = bmalloc(size);
  776. }
  777. memcpy(source->audio_data.data[i], data[i], size);
  778. }
  779. if (resize)
  780. source->audio_storage_size = size;
  781. }
  782. /* resamples/remixes new audio to the designated main audio output format */
  783. static void process_audio(obs_source_t source, const struct source_audio *audio)
  784. {
  785. if (source->sample_info.samples_per_sec != audio->samples_per_sec ||
  786. source->sample_info.format != audio->format ||
  787. source->sample_info.speakers != audio->speakers)
  788. reset_resampler(source, audio);
  789. if (source->audio_failed)
  790. return;
  791. if (source->resampler) {
  792. uint8_t *output[MAX_AV_PLANES];
  793. uint32_t frames;
  794. uint64_t offset;
  795. memset(output, 0, sizeof(output));
  796. audio_resampler_resample(source->resampler,
  797. output, &frames, &offset,
  798. audio->data, audio->frames);
  799. copy_audio_data(source, (const uint8_t *const *)output, frames,
  800. audio->timestamp - offset);
  801. } else {
  802. copy_audio_data(source, audio->data, audio->frames,
  803. audio->timestamp);
  804. }
  805. }
  806. void obs_source_output_audio(obs_source_t source,
  807. const struct source_audio *audio)
  808. {
  809. uint32_t flags;
  810. struct filtered_audio *output;
  811. if (!source || !audio)
  812. return;
  813. flags = source->info.output_flags;
  814. process_audio(source, audio);
  815. pthread_mutex_lock(&source->filter_mutex);
  816. output = filter_async_audio(source, &source->audio_data);
  817. if (output) {
  818. bool async = (flags & OBS_SOURCE_ASYNC_VIDEO) != 0;
  819. pthread_mutex_lock(&source->audio_mutex);
  820. /* wait for video to start before outputting any audio so we
  821. * have a base for sync */
  822. if (source->timing_set || !async) {
  823. struct audio_data data;
  824. for (int i = 0; i < MAX_AV_PLANES; i++)
  825. data.data[i] = output->data[i];
  826. data.frames = output->frames;
  827. data.timestamp = output->timestamp;
  828. source_output_audio_line(source, &data);
  829. }
  830. pthread_mutex_unlock(&source->audio_mutex);
  831. }
  832. pthread_mutex_unlock(&source->filter_mutex);
  833. }
  834. static inline bool frame_out_of_bounds(obs_source_t source, uint64_t ts)
  835. {
  836. return ((ts - source->last_frame_ts) > MAX_TIMESTAMP_JUMP);
  837. }
  838. static inline struct source_frame *get_closest_frame(obs_source_t source,
  839. uint64_t sys_time, int *audio_time_refs)
  840. {
  841. struct source_frame *next_frame = source->video_frames.array[0];
  842. struct source_frame *frame = NULL;
  843. uint64_t sys_offset = sys_time - source->last_sys_timestamp;
  844. uint64_t frame_time = next_frame->timestamp;
  845. uint64_t frame_offset = 0;
  846. /* account for timestamp invalidation */
  847. if (frame_out_of_bounds(source, frame_time)) {
  848. source->last_frame_ts = next_frame->timestamp;
  849. (*audio_time_refs)++;
  850. } else {
  851. frame_offset = frame_time - source->last_frame_ts;
  852. source->last_frame_ts += sys_offset;
  853. }
  854. while (frame_offset <= sys_offset) {
  855. source_frame_destroy(frame);
  856. frame = next_frame;
  857. da_erase(source->video_frames, 0);
  858. if (!source->video_frames.num)
  859. break;
  860. next_frame = source->video_frames.array[0];
  861. /* more timestamp checking and compensating */
  862. if ((next_frame->timestamp - frame_time) > MAX_TIMESTAMP_JUMP) {
  863. source->last_frame_ts =
  864. next_frame->timestamp - frame_offset;
  865. (*audio_time_refs)++;
  866. }
  867. frame_time = next_frame->timestamp;
  868. frame_offset = frame_time - source->last_frame_ts;
  869. }
  870. return frame;
  871. }
  872. /*
  873. * Ensures that cached frames are displayed on time. If multiple frames
  874. * were cached between renders, then releases the unnecessary frames and uses
  875. * the frame with the closest timing to ensure sync. Also ensures that timing
  876. * with audio is synchronized.
  877. */
  878. struct source_frame *obs_source_getframe(obs_source_t source)
  879. {
  880. struct source_frame *frame = NULL;
  881. int audio_time_refs = 0;
  882. uint64_t sys_time;
  883. if (!source)
  884. return NULL;
  885. pthread_mutex_lock(&source->video_mutex);
  886. if (!source->video_frames.num)
  887. goto unlock;
  888. sys_time = os_gettime_ns();
  889. if (!source->last_frame_ts) {
  890. frame = source->video_frames.array[0];
  891. da_erase(source->video_frames, 0);
  892. source->last_frame_ts = frame->timestamp;
  893. } else {
  894. frame = get_closest_frame(source, sys_time, &audio_time_refs);
  895. }
  896. /* reset timing to current system time */
  897. if (frame) {
  898. source->audio_reset_ref += audio_time_refs;
  899. source->timing_adjust = sys_time - frame->timestamp;
  900. source->timing_set = true;
  901. }
  902. source->last_sys_timestamp = sys_time;
  903. unlock:
  904. pthread_mutex_unlock(&source->video_mutex);
  905. if (frame)
  906. obs_source_addref(source);
  907. return frame;
  908. }
  909. void obs_source_releaseframe(obs_source_t source, struct source_frame *frame)
  910. {
  911. if (source && frame) {
  912. source_frame_destroy(frame);
  913. obs_source_release(source);
  914. }
  915. }
  916. const char *obs_source_getname(obs_source_t source)
  917. {
  918. return source ? source->name : NULL;
  919. }
  920. void obs_source_setname(obs_source_t source, const char *name)
  921. {
  922. if (!source) return;
  923. bfree(source->name);
  924. source->name = bstrdup(name);
  925. }
  926. void obs_source_gettype(obs_source_t source, enum obs_source_type *type,
  927. const char **id)
  928. {
  929. if (!source) return;
  930. if (type) *type = source->info.type;
  931. if (id) *id = source->info.id;
  932. }
  933. static inline void render_filter_bypass(obs_source_t target, effect_t effect,
  934. bool use_matrix)
  935. {
  936. const char *tech_name = use_matrix ? "DrawMatrix" : "Draw";
  937. technique_t tech = effect_gettechnique(effect, tech_name);
  938. size_t passes, i;
  939. passes = technique_begin(tech);
  940. for (i = 0; i < passes; i++) {
  941. technique_beginpass(tech, i);
  942. obs_source_video_render(target);
  943. technique_endpass(tech);
  944. }
  945. technique_end(tech);
  946. }
  947. static inline void render_filter_tex(texture_t tex, effect_t effect,
  948. uint32_t width, uint32_t height, bool use_matrix)
  949. {
  950. const char *tech_name = use_matrix ? "DrawMatrix" : "Draw";
  951. technique_t tech = effect_gettechnique(effect, tech_name);
  952. eparam_t image = effect_getparambyname(effect, "image");
  953. size_t passes, i;
  954. effect_settexture(effect, image, tex);
  955. passes = technique_begin(tech);
  956. for (i = 0; i < passes; i++) {
  957. technique_beginpass(tech, i);
  958. gs_draw_sprite(tex, width, height, 0);
  959. technique_endpass(tech);
  960. }
  961. technique_end(tech);
  962. }
  963. void obs_source_process_filter(obs_source_t filter, effect_t effect,
  964. uint32_t width, uint32_t height, enum gs_color_format format,
  965. enum allow_direct_render allow_direct)
  966. {
  967. obs_source_t target, parent;
  968. uint32_t target_flags, parent_flags;
  969. int cx, cy;
  970. bool use_matrix, expects_def, can_directly;
  971. if (!filter) return;
  972. target = obs_filter_gettarget(filter);
  973. parent = obs_filter_getparent(filter);
  974. target_flags = target->info.output_flags;
  975. parent_flags = parent->info.output_flags;
  976. cx = obs_source_getwidth(target);
  977. cy = obs_source_getheight(target);
  978. use_matrix = !!(target_flags & OBS_SOURCE_COLOR_MATRIX);
  979. expects_def = !(parent_flags & OBS_SOURCE_CUSTOM_DRAW);
  980. can_directly = allow_direct == ALLOW_DIRECT_RENDERING;
  981. /* if the parent does not use any custom effects, and this is the last
  982. * filter in the chain for the parent, then render the parent directly
  983. * using the filter effect instead of rendering to texture to reduce
  984. * the total number of passes */
  985. if (can_directly && expects_def && target == parent) {
  986. render_filter_bypass(target, effect, use_matrix);
  987. return;
  988. }
  989. if (!filter->filter_texrender)
  990. filter->filter_texrender = texrender_create(format,
  991. GS_ZS_NONE);
  992. if (texrender_begin(filter->filter_texrender, cx, cy)) {
  993. gs_ortho(0.0f, (float)cx, 0.0f, (float)cy, -100.0f, 100.0f);
  994. if (expects_def && parent == target)
  995. obs_source_default_render(parent, use_matrix);
  996. else
  997. obs_source_video_render(target);
  998. texrender_end(filter->filter_texrender);
  999. }
  1000. /* --------------------------- */
  1001. render_filter_tex(texrender_gettexture(filter->filter_texrender),
  1002. effect, width, height, use_matrix);
  1003. }
  1004. signal_handler_t obs_source_signalhandler(obs_source_t source)
  1005. {
  1006. return source ? source->signals : NULL;
  1007. }
  1008. proc_handler_t obs_source_prochandler(obs_source_t source)
  1009. {
  1010. return source ? source->procs : NULL;
  1011. }
  1012. void obs_source_setvolume(obs_source_t source, float volume)
  1013. {
  1014. if (source) {
  1015. struct calldata data = {0};
  1016. calldata_setptr(&data, "source", source);
  1017. calldata_setfloat(&data, "volume", volume);
  1018. signal_handler_signal(source->signals, "volume", &data);
  1019. signal_handler_signal(obs->signals, "source-volume", &data);
  1020. volume = calldata_float(&data, "volume");
  1021. calldata_free(&data);
  1022. source->user_volume = volume;
  1023. }
  1024. }
  1025. static void set_tree_preset_vol(obs_source_t parent, obs_source_t child,
  1026. void *param)
  1027. {
  1028. float *vol = param;
  1029. child->present_volume = *vol;
  1030. UNUSED_PARAMETER(parent);
  1031. }
  1032. void obs_source_set_present_volume(obs_source_t source, float volume)
  1033. {
  1034. if (source) {
  1035. source->present_volume = volume;
  1036. /* don't set the presentation volume of the tree if a
  1037. * transition source, let the transition handle presentation
  1038. * volume for the child sources itself. */
  1039. if (source->info.type != OBS_SOURCE_TYPE_TRANSITION)
  1040. obs_source_enum_tree(source, set_tree_preset_vol,
  1041. &volume);
  1042. }
  1043. }
  1044. float obs_source_getvolume(obs_source_t source)
  1045. {
  1046. return source ? source->user_volume : 0.0f;
  1047. }
  1048. float obs_source_get_present_volume(obs_source_t source)
  1049. {
  1050. return source ? source->present_volume : 0.0f;
  1051. }
  1052. void obs_source_set_sync_offset(obs_source_t source, int64_t offset)
  1053. {
  1054. if (source)
  1055. source->sync_offset = offset;
  1056. }
  1057. int64_t obs_source_get_sync_offset(obs_source_t source)
  1058. {
  1059. return source ? source->sync_offset : 0;
  1060. }
  1061. struct source_enum_data {
  1062. obs_source_enum_proc_t enum_callback;
  1063. void *param;
  1064. };
  1065. static void enum_source_tree_callback(obs_source_t parent, obs_source_t child,
  1066. void *param)
  1067. {
  1068. struct source_enum_data *data = param;
  1069. if (child->info.enum_sources && !child->enum_refs) {
  1070. child->enum_refs++;
  1071. child->info.enum_sources(child->data,
  1072. enum_source_tree_callback, data);
  1073. child->enum_refs--;
  1074. }
  1075. data->enum_callback(parent, child, data->param);
  1076. }
  1077. void obs_source_enum_sources(obs_source_t source,
  1078. obs_source_enum_proc_t enum_callback,
  1079. void *param)
  1080. {
  1081. if (!source || !source->info.enum_sources || source->enum_refs)
  1082. return;
  1083. obs_source_addref(source);
  1084. source->enum_refs++;
  1085. source->info.enum_sources(source->data, enum_callback, param);
  1086. source->enum_refs--;
  1087. obs_source_release(source);
  1088. }
  1089. void obs_source_enum_tree(obs_source_t source,
  1090. obs_source_enum_proc_t enum_callback,
  1091. void *param)
  1092. {
  1093. struct source_enum_data data = {enum_callback, param};
  1094. if (!source || !source->info.enum_sources || source->enum_refs)
  1095. return;
  1096. obs_source_addref(source);
  1097. source->enum_refs++;
  1098. source->info.enum_sources(source->data, enum_source_tree_callback,
  1099. &data);
  1100. source->enum_refs--;
  1101. obs_source_release(source);
  1102. }
  1103. void obs_source_add_child(obs_source_t parent, obs_source_t child)
  1104. {
  1105. if (!parent || !child) return;
  1106. for (int i = 0; i < parent->show_refs; i++) {
  1107. enum view_type type;
  1108. type = (i < parent->activate_refs) ? MAIN_VIEW : AUX_VIEW;
  1109. obs_source_activate(child, type);
  1110. }
  1111. }
  1112. void obs_source_remove_child(obs_source_t parent, obs_source_t child)
  1113. {
  1114. if (!parent || !child) return;
  1115. for (int i = 0; i < parent->show_refs; i++) {
  1116. enum view_type type;
  1117. type = (i < parent->activate_refs) ? MAIN_VIEW : AUX_VIEW;
  1118. obs_source_deactivate(child, type);
  1119. }
  1120. }
  1121. static void reset_transition_vol(obs_source_t parent, obs_source_t child,
  1122. void *param)
  1123. {
  1124. child->transition_volume = 0.0f;
  1125. UNUSED_PARAMETER(parent);
  1126. UNUSED_PARAMETER(param);
  1127. }
  1128. static void add_transition_vol(obs_source_t parent, obs_source_t child,
  1129. void *param)
  1130. {
  1131. float *vol = param;
  1132. child->transition_volume += *vol;
  1133. UNUSED_PARAMETER(parent);
  1134. }
  1135. static void apply_transition_vol(obs_source_t parent, obs_source_t child,
  1136. void *param)
  1137. {
  1138. child->present_volume = child->transition_volume;
  1139. UNUSED_PARAMETER(parent);
  1140. UNUSED_PARAMETER(param);
  1141. }
  1142. void obs_transition_begin_frame(obs_source_t transition)
  1143. {
  1144. if (!transition) return;
  1145. obs_source_enum_tree(transition, reset_transition_vol, NULL);
  1146. }
  1147. void obs_source_set_transition_vol(obs_source_t source, float vol)
  1148. {
  1149. if (!source) return;
  1150. add_transition_vol(NULL, source, &vol);
  1151. obs_source_enum_tree(source, add_transition_vol, &vol);
  1152. }
  1153. void obs_transition_end_frame(obs_source_t transition)
  1154. {
  1155. if (!transition) return;
  1156. obs_source_enum_tree(transition, apply_transition_vol, NULL);
  1157. }