transition-stinger.c 21 KB

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