transition-stinger.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. #include <obs-module.h>
  2. #include <util/dstr.h>
  3. #include "util/platform.h"
  4. #define TIMING_TIME 0
  5. #define TIMING_FRAME 1
  6. enum matte_layout {
  7. MATTE_LAYOUT_HORIZONTAL,
  8. MATTE_LAYOUT_VERTICAL,
  9. MATTE_LAYOUT_SEPARATE_FILE,
  10. MATTE_LAYOUT_MASK,
  11. };
  12. enum fade_style { FADE_STYLE_FADE_OUT_FADE_IN, FADE_STYLE_CROSS_FADE };
  13. struct stinger_info {
  14. obs_source_t *source;
  15. obs_source_t *media_source;
  16. obs_source_t *matte_source;
  17. uint64_t duration_ns;
  18. uint64_t duration_frames;
  19. uint64_t transition_point_ns;
  20. uint64_t transition_point_frame;
  21. float transition_point;
  22. float transition_a_mul;
  23. float transition_b_mul;
  24. bool transitioning;
  25. bool transition_point_is_frame;
  26. int monitoring_type;
  27. enum fade_style fade_style;
  28. bool track_matte_enabled;
  29. int matte_layout;
  30. float matte_width_factor;
  31. float matte_height_factor;
  32. bool invert_matte;
  33. bool do_texrender;
  34. bool matte_rendered;
  35. gs_effect_t *matte_effect;
  36. gs_eparam_t *ep_a_tex;
  37. gs_eparam_t *ep_b_tex;
  38. gs_eparam_t *ep_matte_tex;
  39. gs_eparam_t *ep_invert_matte;
  40. gs_texrender_t *matte_tex;
  41. gs_texrender_t *stinger_tex;
  42. float (*mix_a)(void *data, float t);
  43. float (*mix_b)(void *data, float t);
  44. };
  45. static const char *stinger_get_name(void *type_data)
  46. {
  47. UNUSED_PARAMETER(type_data);
  48. return obs_module_text("StingerTransition");
  49. }
  50. static float mix_a_fade_in_out(void *data, float t);
  51. static float mix_b_fade_in_out(void *data, float t);
  52. static float mix_a_cross_fade(void *data, float t);
  53. static float mix_b_cross_fade(void *data, float t);
  54. static void stinger_update(void *data, obs_data_t *settings)
  55. {
  56. struct stinger_info *s = data;
  57. const char *path = obs_data_get_string(settings, "path");
  58. bool hw_decode = obs_data_get_bool(settings, "hw_decode");
  59. obs_data_t *media_settings = obs_data_create();
  60. obs_data_set_string(media_settings, "local_file", path);
  61. obs_data_set_bool(media_settings, "hw_decode", hw_decode);
  62. obs_data_set_bool(media_settings, "looping", false);
  63. obs_source_release(s->media_source);
  64. struct dstr name;
  65. dstr_init_copy(&name, obs_source_get_name(s->source));
  66. dstr_cat(&name, " (Stinger)");
  67. s->media_source = obs_source_create_private("ffmpeg_source", name.array,
  68. media_settings);
  69. dstr_free(&name);
  70. obs_data_release(media_settings);
  71. int64_t point = obs_data_get_int(settings, "transition_point");
  72. s->transition_point_is_frame = obs_data_get_int(settings, "tp_type") ==
  73. TIMING_FRAME;
  74. if (s->transition_point_is_frame)
  75. s->transition_point_frame = (uint64_t)point;
  76. else
  77. s->transition_point_ns = (uint64_t)(point * 1000000LL);
  78. bool track_matte_was_enabled = s->track_matte_enabled;
  79. s->track_matte_enabled =
  80. obs_data_get_bool(settings, "track_matte_enabled");
  81. s->matte_layout = (int)obs_data_get_int(settings, "track_matte_layout");
  82. s->matte_width_factor =
  83. (s->matte_layout == MATTE_LAYOUT_HORIZONTAL ? 2.0f : 1.0f);
  84. s->matte_height_factor =
  85. (s->matte_layout == MATTE_LAYOUT_VERTICAL ? 2.0f : 1.0f);
  86. s->invert_matte = obs_data_get_bool(settings, "invert_matte");
  87. s->do_texrender = s->track_matte_enabled &&
  88. s->matte_layout < MATTE_LAYOUT_SEPARATE_FILE;
  89. if (s->matte_source) {
  90. obs_source_release(s->matte_source);
  91. s->matte_source = NULL;
  92. }
  93. if (s->track_matte_enabled &&
  94. s->matte_layout == MATTE_LAYOUT_SEPARATE_FILE) {
  95. const char *tm_path =
  96. obs_data_get_string(settings, "track_matte_path");
  97. obs_data_t *tm_media_settings = obs_data_create();
  98. obs_data_set_string(tm_media_settings, "local_file", tm_path);
  99. obs_data_set_bool(tm_media_settings, "looping", false);
  100. s->matte_source = obs_source_create_private(
  101. "ffmpeg_source", NULL, tm_media_settings);
  102. obs_data_release(tm_media_settings);
  103. // no need to output sound from the matte video
  104. obs_source_set_muted(s->matte_source, true);
  105. }
  106. s->monitoring_type =
  107. (int)obs_data_get_int(settings, "audio_monitoring");
  108. obs_source_set_monitoring_type(s->media_source, s->monitoring_type);
  109. s->fade_style =
  110. (enum fade_style)obs_data_get_int(settings, "audio_fade_style");
  111. switch (s->fade_style) {
  112. default:
  113. case FADE_STYLE_FADE_OUT_FADE_IN:
  114. s->mix_a = mix_a_fade_in_out;
  115. s->mix_b = mix_b_fade_in_out;
  116. break;
  117. case FADE_STYLE_CROSS_FADE:
  118. s->mix_a = mix_a_cross_fade;
  119. s->mix_b = mix_b_cross_fade;
  120. break;
  121. }
  122. if (s->track_matte_enabled != track_matte_was_enabled) {
  123. obs_enter_graphics();
  124. gs_texrender_destroy(s->matte_tex);
  125. gs_texrender_destroy(s->stinger_tex);
  126. s->matte_tex = NULL;
  127. s->stinger_tex = NULL;
  128. if (s->track_matte_enabled) {
  129. s->matte_tex = gs_texrender_create(GS_RGBA, GS_ZS_NONE);
  130. s->stinger_tex =
  131. gs_texrender_create(GS_RGBA, GS_ZS_NONE);
  132. }
  133. obs_leave_graphics();
  134. }
  135. }
  136. static void *stinger_create(obs_data_t *settings, obs_source_t *source)
  137. {
  138. struct stinger_info *s = bzalloc(sizeof(*s));
  139. s->source = source;
  140. s->mix_a = mix_a_fade_in_out;
  141. s->mix_b = mix_b_fade_in_out;
  142. char *effect_file = obs_module_file("stinger_matte_transition.effect");
  143. char *error_string = NULL;
  144. obs_enter_graphics();
  145. s->matte_effect =
  146. gs_effect_create_from_file(effect_file, &error_string);
  147. obs_leave_graphics();
  148. if (!s->matte_effect) {
  149. blog(LOG_ERROR,
  150. "Could not open stinger_matte_transition.effect: %s",
  151. error_string);
  152. bfree(error_string);
  153. bfree(s);
  154. return NULL;
  155. }
  156. bfree(effect_file);
  157. s->ep_a_tex = gs_effect_get_param_by_name(s->matte_effect, "a_tex");
  158. s->ep_b_tex = gs_effect_get_param_by_name(s->matte_effect, "b_tex");
  159. s->ep_matte_tex =
  160. gs_effect_get_param_by_name(s->matte_effect, "matte_tex");
  161. s->ep_invert_matte =
  162. gs_effect_get_param_by_name(s->matte_effect, "invert_matte");
  163. obs_transition_enable_fixed(s->source, true, 0);
  164. obs_source_update(source, settings);
  165. return s;
  166. }
  167. static void stinger_destroy(void *data)
  168. {
  169. struct stinger_info *s = data;
  170. obs_source_release(s->media_source);
  171. obs_source_release(s->matte_source);
  172. obs_enter_graphics();
  173. gs_texrender_destroy(s->matte_tex);
  174. gs_texrender_destroy(s->stinger_tex);
  175. gs_effect_destroy(s->matte_effect);
  176. obs_leave_graphics();
  177. bfree(s);
  178. }
  179. static void stinger_defaults(obs_data_t *settings)
  180. {
  181. obs_data_set_default_bool(settings, "hw_decode", true);
  182. }
  183. static void stinger_matte_render(void *data, gs_texture_t *a, gs_texture_t *b,
  184. float t, uint32_t cx, uint32_t cy)
  185. {
  186. struct stinger_info *s = data;
  187. struct vec4 background;
  188. vec4_zero(&background);
  189. obs_source_t *matte_source =
  190. (s->matte_layout == MATTE_LAYOUT_SEPARATE_FILE
  191. ? s->matte_source
  192. : s->media_source);
  193. float matte_cx = (float)obs_source_get_width(matte_source) /
  194. s->matte_width_factor;
  195. float matte_cy = (float)obs_source_get_height(matte_source) /
  196. s->matte_height_factor;
  197. float width_offset = (s->matte_layout == MATTE_LAYOUT_HORIZONTAL
  198. ? (-matte_cx)
  199. : 0.0f);
  200. float height_offset =
  201. (s->matte_layout == MATTE_LAYOUT_VERTICAL ? (-matte_cy) : 0.0f);
  202. // Track matte media render
  203. if (matte_cx > 0 && matte_cy > 0) {
  204. float scale_x = (float)cx / matte_cx;
  205. float scale_y = (float)cy / matte_cy;
  206. if (gs_texrender_begin(s->matte_tex, cx, cy)) {
  207. gs_matrix_scale3f(scale_x, scale_y, 1.0f);
  208. gs_matrix_translate3f(width_offset, height_offset,
  209. 0.0f);
  210. gs_clear(GS_CLEAR_COLOR, &background, 0.0f, 0);
  211. gs_ortho(0.0f, (float)cx, 0.0f, (float)cy, -100.0f,
  212. 100.0f);
  213. obs_source_video_render(matte_source);
  214. gs_texrender_end(s->matte_tex);
  215. }
  216. }
  217. const bool previous = gs_framebuffer_srgb_enabled();
  218. gs_enable_framebuffer_srgb(true);
  219. gs_effect_set_texture(s->ep_a_tex, a);
  220. gs_effect_set_texture(s->ep_b_tex, b);
  221. gs_effect_set_texture(s->ep_matte_tex,
  222. gs_texrender_get_texture(s->matte_tex));
  223. gs_effect_set_bool(s->ep_invert_matte, s->invert_matte);
  224. while (gs_effect_loop(s->matte_effect, "StingerMatte"))
  225. gs_draw_sprite(NULL, 0, cx, cy);
  226. gs_enable_framebuffer_srgb(previous);
  227. UNUSED_PARAMETER(t);
  228. }
  229. static void stinger_texrender(struct stinger_info *s, uint32_t source_cx,
  230. uint32_t source_cy, uint32_t media_cx,
  231. uint32_t media_cy)
  232. {
  233. if (gs_texrender_begin(s->stinger_tex, source_cx, source_cy)) {
  234. float cx = (float)media_cx / s->matte_width_factor;
  235. float cy = (float)media_cy / s->matte_height_factor;
  236. gs_ortho(0.0f, cx, 0.0f, cy, -100.0f, 100.0f);
  237. gs_blend_state_push();
  238. gs_enable_blending(false);
  239. obs_source_video_render(s->media_source);
  240. gs_blend_state_pop();
  241. gs_texrender_end(s->stinger_tex);
  242. }
  243. }
  244. static void stinger_video_render(void *data, gs_effect_t *effect)
  245. {
  246. struct stinger_info *s = data;
  247. uint32_t media_cx = obs_source_get_width(s->media_source);
  248. uint32_t media_cy = obs_source_get_height(s->media_source);
  249. if (s->track_matte_enabled) {
  250. bool ready = obs_source_active(s->media_source) && !!media_cx &&
  251. !!media_cy;
  252. if (ready) {
  253. if (!s->matte_rendered)
  254. s->matte_rendered = true;
  255. obs_transition_video_render(s->source,
  256. stinger_matte_render);
  257. } else {
  258. obs_transition_video_render_direct(
  259. s->source, s->matte_rendered
  260. ? OBS_TRANSITION_SOURCE_B
  261. : OBS_TRANSITION_SOURCE_A);
  262. }
  263. if (s->matte_layout == MATTE_LAYOUT_MASK)
  264. return;
  265. } else {
  266. float t = obs_transition_get_time(s->source);
  267. bool use_a = t < s->transition_point;
  268. enum obs_transition_target target =
  269. use_a ? OBS_TRANSITION_SOURCE_A
  270. : OBS_TRANSITION_SOURCE_B;
  271. if (!obs_transition_video_render_direct(s->source, target))
  272. return;
  273. }
  274. /* --------------------- */
  275. uint32_t source_cx = obs_source_get_width(s->source);
  276. uint32_t source_cy = obs_source_get_height(s->source);
  277. float source_cxf = (float)source_cx;
  278. float source_cyf = (float)source_cy;
  279. if (!media_cx || !media_cy)
  280. return;
  281. if (s->do_texrender) {
  282. stinger_texrender(s, source_cx, source_cy, media_cx, media_cy);
  283. gs_effect_t *e = obs_get_base_effect(OBS_EFFECT_DEFAULT);
  284. gs_eparam_t *p = gs_effect_get_param_by_name(e, "image");
  285. gs_texture_t *tex = gs_texrender_get_texture(s->stinger_tex);
  286. gs_effect_set_texture(p, tex);
  287. while (gs_effect_loop(e, "Draw"))
  288. gs_draw_sprite(NULL, 0, source_cx, source_cy);
  289. } else {
  290. gs_matrix_push();
  291. gs_matrix_scale3f(source_cxf / (float)media_cx,
  292. source_cyf / (float)media_cy, 1.0f);
  293. obs_source_video_render(s->media_source);
  294. gs_matrix_pop();
  295. }
  296. UNUSED_PARAMETER(effect);
  297. }
  298. static void stinger_video_tick(void *data, float seconds)
  299. {
  300. struct stinger_info *s = data;
  301. if (s->track_matte_enabled) {
  302. gs_texrender_reset(s->stinger_tex);
  303. gs_texrender_reset(s->matte_tex);
  304. }
  305. UNUSED_PARAMETER(seconds);
  306. }
  307. static inline float calc_fade(float t, float mul)
  308. {
  309. t *= mul;
  310. return t > 1.0f ? 1.0f : t;
  311. }
  312. static float mix_a_fade_in_out(void *data, float t)
  313. {
  314. struct stinger_info *s = data;
  315. return 1.0f - calc_fade(t, s->transition_a_mul);
  316. }
  317. static float mix_b_fade_in_out(void *data, float t)
  318. {
  319. struct stinger_info *s = data;
  320. return 1.0f - calc_fade(1.0f - t, s->transition_b_mul);
  321. }
  322. static float mix_a_cross_fade(void *data, float t)
  323. {
  324. UNUSED_PARAMETER(data);
  325. return 1.0f - t;
  326. }
  327. static float mix_b_cross_fade(void *data, float t)
  328. {
  329. UNUSED_PARAMETER(data);
  330. return t;
  331. }
  332. static bool stinger_audio_render(void *data, uint64_t *ts_out,
  333. struct obs_source_audio_mix *audio,
  334. uint32_t mixers, size_t channels,
  335. size_t sample_rate)
  336. {
  337. struct stinger_info *s = data;
  338. uint64_t ts = 0;
  339. if (!s) {
  340. return false;
  341. }
  342. if (!obs_source_audio_pending(s->media_source)) {
  343. ts = obs_source_get_audio_timestamp(s->media_source);
  344. if (!ts)
  345. return false;
  346. }
  347. bool success = obs_transition_audio_render(s->source, ts_out, audio,
  348. mixers, channels,
  349. sample_rate, s->mix_a,
  350. s->mix_b);
  351. if (!ts)
  352. return success;
  353. if (!*ts_out || ts < *ts_out)
  354. *ts_out = ts;
  355. struct obs_source_audio_mix child_audio;
  356. obs_source_get_audio_mix(s->media_source, &child_audio);
  357. for (size_t mix = 0; mix < MAX_AUDIO_MIXES; mix++) {
  358. if ((mixers & (1 << mix)) == 0)
  359. continue;
  360. for (size_t ch = 0; ch < channels; ch++) {
  361. register float *out = audio->output[mix].data[ch];
  362. register float *in = child_audio.output[mix].data[ch];
  363. register float *end = in + AUDIO_OUTPUT_FRAMES;
  364. while (in < end)
  365. *(out++) += *(in++);
  366. }
  367. }
  368. return true;
  369. }
  370. static void stinger_transition_start(void *data)
  371. {
  372. struct stinger_info *s = data;
  373. if (s->media_source) {
  374. calldata_t cd = {0};
  375. proc_handler_t *ph =
  376. obs_source_get_proc_handler(s->media_source);
  377. proc_handler_t *matte_ph =
  378. s->matte_source
  379. ? obs_source_get_proc_handler(s->matte_source)
  380. : NULL;
  381. if (s->transitioning) {
  382. proc_handler_call(ph, "restart", &cd);
  383. if (matte_ph) {
  384. proc_handler_call(matte_ph, "restart", &cd);
  385. }
  386. return;
  387. }
  388. s->matte_rendered = false;
  389. proc_handler_call(ph, "get_duration", &cd);
  390. proc_handler_call(ph, "get_nb_frames", &cd);
  391. s->duration_ns =
  392. (uint64_t)calldata_int(&cd, "duration") + 250000000ULL;
  393. s->duration_frames = (uint64_t)calldata_int(&cd, "num_frames");
  394. if (s->transition_point_is_frame)
  395. s->transition_point =
  396. (float)((long double)s->transition_point_frame /
  397. (long double)s->duration_frames);
  398. else
  399. s->transition_point =
  400. (float)((long double)s->transition_point_ns /
  401. (long double)s->duration_ns);
  402. if (s->transition_point > 0.999f)
  403. s->transition_point = 0.999f;
  404. else if (s->transition_point < 0.001f)
  405. s->transition_point = 0.001f;
  406. s->transition_a_mul = (1.0f / s->transition_point);
  407. s->transition_b_mul = (1.0f / (1.0f - s->transition_point));
  408. if (s->track_matte_enabled && s->matte_source) {
  409. proc_handler_call(matte_ph, "get_duration", &cd);
  410. uint64_t tm_duration_ns =
  411. (uint64_t)calldata_int(&cd, "duration");
  412. s->duration_ns = ((tm_duration_ns > s->duration_ns)
  413. ? (tm_duration_ns)
  414. : (s->duration_ns));
  415. obs_source_add_active_child(s->source, s->matte_source);
  416. }
  417. obs_transition_enable_fixed(
  418. s->source, true, (uint32_t)(s->duration_ns / 1000000));
  419. calldata_free(&cd);
  420. obs_source_add_active_child(s->source, s->media_source);
  421. }
  422. s->transitioning = true;
  423. }
  424. static void stinger_transition_stop(void *data)
  425. {
  426. struct stinger_info *s = data;
  427. if (s->media_source)
  428. obs_source_remove_active_child(s->source, s->media_source);
  429. if (s->matte_source)
  430. obs_source_remove_active_child(s->source, s->matte_source);
  431. s->transitioning = false;
  432. }
  433. static void stinger_enum_active_sources(void *data,
  434. obs_source_enum_proc_t enum_callback,
  435. void *param)
  436. {
  437. struct stinger_info *s = data;
  438. if (s->media_source && s->transitioning)
  439. enum_callback(s->source, s->media_source, param);
  440. if (s->matte_source && s->transitioning)
  441. enum_callback(s->source, s->matte_source, param);
  442. }
  443. static void stinger_enum_all_sources(void *data,
  444. obs_source_enum_proc_t enum_callback,
  445. void *param)
  446. {
  447. struct stinger_info *s = data;
  448. if (s->media_source)
  449. enum_callback(s->source, s->media_source, param);
  450. if (s->matte_source)
  451. enum_callback(s->source, s->matte_source, param);
  452. }
  453. #define FILE_FILTER " (*.mp4 *.ts *.mov *.wmv *.flv *.mkv *.avi *.gif *.webm);;"
  454. static bool transition_point_type_modified(obs_properties_t *ppts,
  455. obs_property_t *p, obs_data_t *s)
  456. {
  457. int64_t type = obs_data_get_int(s, "tp_type");
  458. obs_property_t *prop_transition_point =
  459. obs_properties_get(ppts, "transition_point");
  460. if (type == TIMING_TIME) {
  461. obs_property_set_description(
  462. prop_transition_point,
  463. obs_module_text("TransitionPoint"));
  464. } else {
  465. obs_property_set_description(
  466. prop_transition_point,
  467. obs_module_text("TransitionPointFrame"));
  468. }
  469. bool uses_ms_prefix = (type == TIMING_TIME);
  470. obs_property_int_set_suffix(p, (uses_ms_prefix ? " ms" : ""));
  471. return true;
  472. }
  473. static bool track_matte_layout_modified(obs_properties_t *ppts,
  474. obs_property_t *p, obs_data_t *s)
  475. {
  476. int matte_layout = (int)obs_data_get_int(s, "track_matte_layout");
  477. obs_property_t *prop_matte_path =
  478. obs_properties_get(ppts, "track_matte_path");
  479. bool uses_separate_file = (matte_layout == MATTE_LAYOUT_SEPARATE_FILE);
  480. obs_property_set_visible(prop_matte_path, uses_separate_file);
  481. UNUSED_PARAMETER(p);
  482. return true;
  483. }
  484. static bool track_matte_enabled_modified(obs_properties_t *ppts,
  485. obs_property_t *p, obs_data_t *s)
  486. {
  487. bool track_matte_enabled = obs_data_get_bool(s, "track_matte_enabled");
  488. obs_property_t *prop_tp_type = obs_properties_get(ppts, "tp_type");
  489. if (track_matte_enabled) {
  490. obs_property_set_description(
  491. prop_tp_type,
  492. obs_module_text("AudioTransitionPointType"));
  493. } else {
  494. obs_property_set_description(
  495. prop_tp_type, obs_module_text("TransitionPointType"));
  496. }
  497. UNUSED_PARAMETER(p);
  498. return true;
  499. }
  500. static obs_properties_t *stinger_properties(void *data)
  501. {
  502. obs_properties_t *ppts = obs_properties_create();
  503. struct dstr filter = {0};
  504. obs_properties_set_flags(ppts, OBS_PROPERTIES_DEFER_UPDATE);
  505. dstr_copy(&filter, obs_module_text("FileFilter.VideoFiles"));
  506. dstr_cat(&filter, FILE_FILTER);
  507. dstr_cat(&filter, obs_module_text("FileFilter.AllFiles"));
  508. dstr_cat(&filter, " (*.*)");
  509. // main stinger settings
  510. obs_properties_add_path(ppts, "path", obs_module_text("VideoFile"),
  511. OBS_PATH_FILE, filter.array, NULL);
  512. obs_property_t *p = obs_properties_add_list(
  513. ppts, "tp_type", obs_module_text("TransitionPointType"),
  514. OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
  515. obs_properties_add_bool(ppts, "hw_decode",
  516. obs_module_text("HardwareDecode"));
  517. obs_property_list_add_int(p, obs_module_text("TransitionPointTypeTime"),
  518. TIMING_TIME);
  519. obs_property_list_add_int(
  520. p, obs_module_text("TransitionPointTypeFrame"), TIMING_FRAME);
  521. obs_property_set_modified_callback(p, transition_point_type_modified);
  522. obs_properties_add_int(ppts, "transition_point",
  523. obs_module_text("TransitionPoint"), 0, 120000,
  524. 1);
  525. // track matte properties
  526. {
  527. obs_properties_t *track_matte_group = obs_properties_create();
  528. p = obs_properties_add_list(track_matte_group,
  529. "track_matte_layout",
  530. obs_module_text("TrackMatteLayout"),
  531. OBS_COMBO_TYPE_LIST,
  532. OBS_COMBO_FORMAT_INT);
  533. obs_property_list_add_int(
  534. p, obs_module_text("TrackMatteLayoutHorizontal"),
  535. MATTE_LAYOUT_HORIZONTAL);
  536. obs_property_list_add_int(
  537. p, obs_module_text("TrackMatteLayoutVertical"),
  538. MATTE_LAYOUT_VERTICAL);
  539. /* TODO: Requires way to synchronize or combine two media files
  540. * together */
  541. #if 0
  542. obs_property_list_add_int(
  543. p, obs_module_text("TrackMatteLayoutSeparateFile"),
  544. MATTE_LAYOUT_SEPARATE_FILE);
  545. #endif
  546. obs_property_list_add_int(
  547. p, obs_module_text("TrackMatteLayoutMask"),
  548. MATTE_LAYOUT_MASK);
  549. obs_property_set_modified_callback(p,
  550. track_matte_layout_modified);
  551. obs_properties_add_path(track_matte_group, "track_matte_path",
  552. obs_module_text("TrackMatteVideoFile"),
  553. OBS_PATH_FILE, filter.array, NULL);
  554. obs_properties_add_bool(track_matte_group, "invert_matte",
  555. obs_module_text("InvertTrackMatte"));
  556. p = obs_properties_add_group(
  557. ppts, "track_matte_enabled",
  558. obs_module_text("TrackMatteEnabled"),
  559. OBS_GROUP_CHECKABLE, track_matte_group);
  560. obs_property_set_modified_callback(
  561. p, track_matte_enabled_modified);
  562. }
  563. dstr_free(&filter);
  564. // audio output settings
  565. obs_property_t *monitor_list = obs_properties_add_list(
  566. ppts, "audio_monitoring", obs_module_text("AudioMonitoring"),
  567. OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
  568. obs_property_list_add_int(monitor_list,
  569. obs_module_text("AudioMonitoring.None"),
  570. OBS_MONITORING_TYPE_NONE);
  571. obs_property_list_add_int(
  572. monitor_list, obs_module_text("AudioMonitoring.MonitorOnly"),
  573. OBS_MONITORING_TYPE_MONITOR_ONLY);
  574. obs_property_list_add_int(monitor_list,
  575. obs_module_text("AudioMonitoring.Both"),
  576. OBS_MONITORING_TYPE_MONITOR_AND_OUTPUT);
  577. // audio fade settings
  578. obs_property_t *audio_fade_style = obs_properties_add_list(
  579. ppts, "audio_fade_style", obs_module_text("AudioFadeStyle"),
  580. OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
  581. obs_property_list_add_int(
  582. audio_fade_style,
  583. obs_module_text("AudioFadeStyle.FadeOutFadeIn"),
  584. FADE_STYLE_FADE_OUT_FADE_IN);
  585. obs_property_list_add_int(audio_fade_style,
  586. obs_module_text("AudioFadeStyle.CrossFade"),
  587. FADE_STYLE_CROSS_FADE);
  588. UNUSED_PARAMETER(data);
  589. return ppts;
  590. }
  591. static void missing_file_callback(void *src, const char *new_path, void *data)
  592. {
  593. struct stinger_info *s = src;
  594. obs_data_t *settings = obs_source_get_settings(s->source);
  595. const char *type = data;
  596. if (strcmp(type, "media_source") == 0) {
  597. obs_data_set_string(settings, "path", new_path);
  598. } else if (strcmp(type, "matte_source") == 0) {
  599. obs_data_set_string(settings, "track_matte_path", new_path);
  600. }
  601. obs_source_update(s->source, settings);
  602. obs_data_release(settings);
  603. }
  604. static obs_missing_files_t *stinger_missing_files(void *data)
  605. {
  606. struct stinger_info *s = data;
  607. obs_data_t *settings = obs_source_get_settings(s->source);
  608. obs_missing_files_t *files = obs_missing_files_create();
  609. const char *path = obs_data_get_string(settings, "path");
  610. if (strcmp(path, "") != 0) {
  611. if (!os_file_exists(path)) {
  612. obs_missing_file_t *file = obs_missing_file_create(
  613. path, missing_file_callback,
  614. OBS_MISSING_FILE_SOURCE, s->source,
  615. (void *)"media_source");
  616. obs_missing_files_add_file(files, file);
  617. }
  618. }
  619. const char *track_matte_path =
  620. obs_data_get_string(settings, "track_matte_path");
  621. if (strcmp(track_matte_path, "") != 0) {
  622. if (!os_file_exists(track_matte_path)) {
  623. obs_missing_file_t *file = obs_missing_file_create(
  624. track_matte_path, missing_file_callback,
  625. OBS_MISSING_FILE_SOURCE, s->source,
  626. (void *)"matte_source");
  627. obs_missing_files_add_file(files, file);
  628. }
  629. }
  630. obs_data_release(settings);
  631. return files;
  632. }
  633. struct obs_source_info stinger_transition = {
  634. .id = "obs_stinger_transition",
  635. .type = OBS_SOURCE_TYPE_TRANSITION,
  636. .get_name = stinger_get_name,
  637. .create = stinger_create,
  638. .destroy = stinger_destroy,
  639. .update = stinger_update,
  640. .get_defaults = stinger_defaults,
  641. .video_render = stinger_video_render,
  642. .video_tick = stinger_video_tick,
  643. .audio_render = stinger_audio_render,
  644. .missing_files = stinger_missing_files,
  645. .get_properties = stinger_properties,
  646. .enum_active_sources = stinger_enum_active_sources,
  647. .enum_all_sources = stinger_enum_all_sources,
  648. .transition_start = stinger_transition_start,
  649. .transition_stop = stinger_transition_stop,
  650. };