obs-ffmpeg-source.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /*
  2. * Copyright (c) 2015 John R. Bradley <[email protected]>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <obs-module.h>
  17. #include <util/platform.h>
  18. #include <util/dstr.h>
  19. #include "obs-ffmpeg-compat.h"
  20. #include "obs-ffmpeg-formats.h"
  21. #include <media-playback/media.h>
  22. #define FF_LOG(level, format, ...) \
  23. blog(level, "[Media Source]: " format, ##__VA_ARGS__)
  24. #define FF_LOG_S(source, level, format, ...) \
  25. blog(level, "[Media Source '%s']: " format, \
  26. obs_source_get_name(source), ##__VA_ARGS__)
  27. #define FF_BLOG(level, format, ...) \
  28. FF_LOG_S(s->source, level, format, ##__VA_ARGS__)
  29. struct ffmpeg_source {
  30. mp_media_t media;
  31. bool media_valid;
  32. bool destroy_media;
  33. struct SwsContext *sws_ctx;
  34. int sws_width;
  35. int sws_height;
  36. enum AVPixelFormat sws_format;
  37. uint8_t *sws_data;
  38. int sws_linesize;
  39. enum video_range_type range;
  40. obs_source_t *source;
  41. obs_hotkey_id hotkey;
  42. char *input;
  43. char *input_format;
  44. int buffering_mb;
  45. int speed_percent;
  46. bool is_looping;
  47. bool is_local_file;
  48. bool is_hw_decoding;
  49. bool is_clear_on_media_end;
  50. bool restart_on_activate;
  51. bool close_when_inactive;
  52. bool seekable;
  53. enum obs_media_state state;
  54. obs_hotkey_pair_id play_pause_hotkey;
  55. obs_hotkey_id stop_hotkey;
  56. };
  57. static void set_media_state(void *data, enum obs_media_state state)
  58. {
  59. struct ffmpeg_source *s = data;
  60. s->state = state;
  61. }
  62. static bool is_local_file_modified(obs_properties_t *props,
  63. obs_property_t *prop, obs_data_t *settings)
  64. {
  65. UNUSED_PARAMETER(prop);
  66. bool enabled = obs_data_get_bool(settings, "is_local_file");
  67. obs_property_t *input = obs_properties_get(props, "input");
  68. obs_property_t *input_format =
  69. obs_properties_get(props, "input_format");
  70. obs_property_t *local_file = obs_properties_get(props, "local_file");
  71. obs_property_t *looping = obs_properties_get(props, "looping");
  72. obs_property_t *buffering = obs_properties_get(props, "buffering_mb");
  73. obs_property_t *close =
  74. obs_properties_get(props, "close_when_inactive");
  75. obs_property_t *seekable = obs_properties_get(props, "seekable");
  76. obs_property_t *speed = obs_properties_get(props, "speed_percent");
  77. obs_property_set_visible(input, !enabled);
  78. obs_property_set_visible(input_format, !enabled);
  79. obs_property_set_visible(buffering, !enabled);
  80. obs_property_set_visible(close, enabled);
  81. obs_property_set_visible(local_file, enabled);
  82. obs_property_set_visible(looping, enabled);
  83. obs_property_set_visible(speed, enabled);
  84. obs_property_set_visible(seekable, !enabled);
  85. return true;
  86. }
  87. static void ffmpeg_source_defaults(obs_data_t *settings)
  88. {
  89. obs_data_set_default_bool(settings, "is_local_file", true);
  90. obs_data_set_default_bool(settings, "looping", false);
  91. obs_data_set_default_bool(settings, "clear_on_media_end", true);
  92. obs_data_set_default_bool(settings, "restart_on_activate", true);
  93. obs_data_set_default_int(settings, "buffering_mb", 2);
  94. obs_data_set_default_int(settings, "speed_percent", 100);
  95. }
  96. static const char *media_filter =
  97. " (*.mp4 *.ts *.mov *.flv *.mkv *.avi *.mp3 *.ogg *.aac *.wav *.gif *.webm);;";
  98. static const char *video_filter =
  99. " (*.mp4 *.ts *.mov *.flv *.mkv *.avi *.gif *.webm);;";
  100. static const char *audio_filter = " (*.mp3 *.aac *.ogg *.wav);;";
  101. static obs_properties_t *ffmpeg_source_getproperties(void *data)
  102. {
  103. struct ffmpeg_source *s = data;
  104. struct dstr filter = {0};
  105. struct dstr path = {0};
  106. UNUSED_PARAMETER(data);
  107. obs_properties_t *props = obs_properties_create();
  108. obs_properties_set_flags(props, OBS_PROPERTIES_DEFER_UPDATE);
  109. obs_property_t *prop;
  110. // use this when obs allows non-readonly paths
  111. prop = obs_properties_add_bool(props, "is_local_file",
  112. obs_module_text("LocalFile"));
  113. obs_property_set_modified_callback(prop, is_local_file_modified);
  114. dstr_copy(&filter, obs_module_text("MediaFileFilter.AllMediaFiles"));
  115. dstr_cat(&filter, media_filter);
  116. dstr_cat(&filter, obs_module_text("MediaFileFilter.VideoFiles"));
  117. dstr_cat(&filter, video_filter);
  118. dstr_cat(&filter, obs_module_text("MediaFileFilter.AudioFiles"));
  119. dstr_cat(&filter, audio_filter);
  120. dstr_cat(&filter, obs_module_text("MediaFileFilter.AllFiles"));
  121. dstr_cat(&filter, " (*.*)");
  122. if (s && s->input && *s->input) {
  123. const char *slash;
  124. dstr_copy(&path, s->input);
  125. dstr_replace(&path, "\\", "/");
  126. slash = strrchr(path.array, '/');
  127. if (slash)
  128. dstr_resize(&path, slash - path.array + 1);
  129. }
  130. obs_properties_add_path(props, "local_file",
  131. obs_module_text("LocalFile"), OBS_PATH_FILE,
  132. filter.array, path.array);
  133. dstr_free(&filter);
  134. dstr_free(&path);
  135. prop = obs_properties_add_bool(props, "looping",
  136. obs_module_text("Looping"));
  137. obs_properties_add_bool(props, "restart_on_activate",
  138. obs_module_text("RestartWhenActivated"));
  139. prop = obs_properties_add_int_slider(props, "buffering_mb",
  140. obs_module_text("BufferingMB"), 1,
  141. 16, 1);
  142. obs_property_int_set_suffix(prop, " MB");
  143. obs_properties_add_text(props, "input", obs_module_text("Input"),
  144. OBS_TEXT_DEFAULT);
  145. obs_properties_add_text(props, "input_format",
  146. obs_module_text("InputFormat"),
  147. OBS_TEXT_DEFAULT);
  148. #ifndef __APPLE__
  149. obs_properties_add_bool(props, "hw_decode",
  150. obs_module_text("HardwareDecode"));
  151. #endif
  152. obs_properties_add_bool(props, "clear_on_media_end",
  153. obs_module_text("ClearOnMediaEnd"));
  154. prop = obs_properties_add_bool(
  155. props, "close_when_inactive",
  156. obs_module_text("CloseFileWhenInactive"));
  157. obs_property_set_long_description(
  158. prop, obs_module_text("CloseFileWhenInactive.ToolTip"));
  159. prop = obs_properties_add_int_slider(props, "speed_percent",
  160. obs_module_text("SpeedPercentage"),
  161. 1, 200, 1);
  162. obs_property_int_set_suffix(prop, "%");
  163. prop = obs_properties_add_list(props, "color_range",
  164. obs_module_text("ColorRange"),
  165. OBS_COMBO_TYPE_LIST,
  166. OBS_COMBO_FORMAT_INT);
  167. obs_property_list_add_int(prop, obs_module_text("ColorRange.Auto"),
  168. VIDEO_RANGE_DEFAULT);
  169. obs_property_list_add_int(prop, obs_module_text("ColorRange.Partial"),
  170. VIDEO_RANGE_PARTIAL);
  171. obs_property_list_add_int(prop, obs_module_text("ColorRange.Full"),
  172. VIDEO_RANGE_FULL);
  173. obs_properties_add_bool(props, "seekable", obs_module_text("Seekable"));
  174. return props;
  175. }
  176. static void dump_source_info(struct ffmpeg_source *s, const char *input,
  177. const char *input_format)
  178. {
  179. FF_BLOG(LOG_INFO,
  180. "settings:\n"
  181. "\tinput: %s\n"
  182. "\tinput_format: %s\n"
  183. "\tspeed: %d\n"
  184. "\tis_looping: %s\n"
  185. "\tis_hw_decoding: %s\n"
  186. "\tis_clear_on_media_end: %s\n"
  187. "\trestart_on_activate: %s\n"
  188. "\tclose_when_inactive: %s",
  189. input ? input : "(null)",
  190. input_format ? input_format : "(null)", s->speed_percent,
  191. s->is_looping ? "yes" : "no", s->is_hw_decoding ? "yes" : "no",
  192. s->is_clear_on_media_end ? "yes" : "no",
  193. s->restart_on_activate ? "yes" : "no",
  194. s->close_when_inactive ? "yes" : "no");
  195. }
  196. static void get_frame(void *opaque, struct obs_source_frame *f)
  197. {
  198. struct ffmpeg_source *s = opaque;
  199. obs_source_output_video(s->source, f);
  200. }
  201. static void preload_frame(void *opaque, struct obs_source_frame *f)
  202. {
  203. struct ffmpeg_source *s = opaque;
  204. if (s->close_when_inactive)
  205. return;
  206. if (s->is_clear_on_media_end || s->is_looping)
  207. obs_source_preload_video(s->source, f);
  208. }
  209. static void get_audio(void *opaque, struct obs_source_audio *a)
  210. {
  211. struct ffmpeg_source *s = opaque;
  212. obs_source_output_audio(s->source, a);
  213. }
  214. static void media_stopped(void *opaque)
  215. {
  216. struct ffmpeg_source *s = opaque;
  217. if (s->is_clear_on_media_end) {
  218. obs_source_output_video(s->source, NULL);
  219. }
  220. if (s->close_when_inactive && s->media_valid)
  221. s->destroy_media = true;
  222. set_media_state(s, OBS_MEDIA_STATE_ENDED);
  223. obs_source_media_ended(s->source);
  224. }
  225. static void ffmpeg_source_open(struct ffmpeg_source *s)
  226. {
  227. if (s->input && *s->input) {
  228. struct mp_media_info info = {
  229. .opaque = s,
  230. .v_cb = get_frame,
  231. .v_preload_cb = preload_frame,
  232. .a_cb = get_audio,
  233. .stop_cb = media_stopped,
  234. .path = s->input,
  235. .format = s->input_format,
  236. .buffering = s->buffering_mb * 1024 * 1024,
  237. .speed = s->speed_percent,
  238. .force_range = s->range,
  239. .hardware_decoding = s->is_hw_decoding,
  240. .is_local_file = s->is_local_file || s->seekable};
  241. s->media_valid = mp_media_init(&s->media, &info);
  242. }
  243. }
  244. static void ffmpeg_source_tick(void *data, float seconds)
  245. {
  246. UNUSED_PARAMETER(seconds);
  247. struct ffmpeg_source *s = data;
  248. if (s->destroy_media) {
  249. if (s->media_valid) {
  250. mp_media_free(&s->media);
  251. s->media_valid = false;
  252. }
  253. s->destroy_media = false;
  254. }
  255. }
  256. static void ffmpeg_source_start(struct ffmpeg_source *s)
  257. {
  258. if (!s->media_valid)
  259. ffmpeg_source_open(s);
  260. if (s->media_valid) {
  261. mp_media_play(&s->media, s->is_looping);
  262. if (s->is_local_file)
  263. obs_source_show_preloaded_video(s->source);
  264. set_media_state(s, OBS_MEDIA_STATE_PLAYING);
  265. obs_source_media_started(s->source);
  266. }
  267. }
  268. static void ffmpeg_source_update(void *data, obs_data_t *settings)
  269. {
  270. struct ffmpeg_source *s = data;
  271. bool is_local_file = obs_data_get_bool(settings, "is_local_file");
  272. char *input;
  273. char *input_format;
  274. bfree(s->input);
  275. bfree(s->input_format);
  276. if (is_local_file) {
  277. input = (char *)obs_data_get_string(settings, "local_file");
  278. input_format = NULL;
  279. s->is_looping = obs_data_get_bool(settings, "looping");
  280. s->close_when_inactive =
  281. obs_data_get_bool(settings, "close_when_inactive");
  282. } else {
  283. input = (char *)obs_data_get_string(settings, "input");
  284. input_format =
  285. (char *)obs_data_get_string(settings, "input_format");
  286. s->is_looping = false;
  287. s->close_when_inactive = true;
  288. }
  289. s->input = input ? bstrdup(input) : NULL;
  290. s->input_format = input_format ? bstrdup(input_format) : NULL;
  291. #ifndef __APPLE__
  292. s->is_hw_decoding = obs_data_get_bool(settings, "hw_decode");
  293. #endif
  294. s->is_clear_on_media_end =
  295. obs_data_get_bool(settings, "clear_on_media_end");
  296. s->restart_on_activate =
  297. obs_data_get_bool(settings, "restart_on_activate");
  298. s->range = (enum video_range_type)obs_data_get_int(settings,
  299. "color_range");
  300. s->buffering_mb = (int)obs_data_get_int(settings, "buffering_mb");
  301. s->speed_percent = (int)obs_data_get_int(settings, "speed_percent");
  302. s->is_local_file = is_local_file;
  303. s->seekable = obs_data_get_bool(settings, "seekable");
  304. if (s->speed_percent < 1 || s->speed_percent > 200)
  305. s->speed_percent = 100;
  306. if (s->media_valid) {
  307. mp_media_free(&s->media);
  308. s->media_valid = false;
  309. }
  310. bool active = obs_source_active(s->source);
  311. if (!s->close_when_inactive || active)
  312. ffmpeg_source_open(s);
  313. dump_source_info(s, input, input_format);
  314. if (!s->restart_on_activate || active)
  315. ffmpeg_source_start(s);
  316. }
  317. static const char *ffmpeg_source_getname(void *unused)
  318. {
  319. UNUSED_PARAMETER(unused);
  320. return obs_module_text("FFMpegSource");
  321. }
  322. static void restart_hotkey(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey,
  323. bool pressed)
  324. {
  325. UNUSED_PARAMETER(id);
  326. UNUSED_PARAMETER(hotkey);
  327. if (!pressed)
  328. return;
  329. struct ffmpeg_source *s = data;
  330. if (obs_source_active(s->source))
  331. obs_source_media_restart(s->source);
  332. }
  333. static void restart_proc(void *data, calldata_t *cd)
  334. {
  335. restart_hotkey(data, 0, NULL, true);
  336. UNUSED_PARAMETER(cd);
  337. }
  338. static void get_duration(void *data, calldata_t *cd)
  339. {
  340. struct ffmpeg_source *s = data;
  341. int64_t dur = 0;
  342. if (s->media.fmt)
  343. dur = s->media.fmt->duration;
  344. calldata_set_int(cd, "duration", dur * 1000);
  345. }
  346. static void get_nb_frames(void *data, calldata_t *cd)
  347. {
  348. struct ffmpeg_source *s = data;
  349. int64_t frames = 0;
  350. if (!s->media.fmt) {
  351. calldata_set_int(cd, "num_frames", frames);
  352. return;
  353. }
  354. int video_stream_index = av_find_best_stream(
  355. s->media.fmt, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
  356. if (video_stream_index < 0) {
  357. FF_BLOG(LOG_WARNING, "Getting number of frames failed: No "
  358. "video stream in media file!");
  359. calldata_set_int(cd, "num_frames", frames);
  360. return;
  361. }
  362. AVStream *stream = s->media.fmt->streams[video_stream_index];
  363. if (stream->nb_frames > 0) {
  364. frames = stream->nb_frames;
  365. } else {
  366. FF_BLOG(LOG_DEBUG, "nb_frames not set, estimating using frame "
  367. "rate and duration");
  368. AVRational avg_frame_rate = stream->avg_frame_rate;
  369. frames = (int64_t)ceil((double)s->media.fmt->duration /
  370. (double)AV_TIME_BASE *
  371. (double)avg_frame_rate.num /
  372. (double)avg_frame_rate.den);
  373. }
  374. calldata_set_int(cd, "num_frames", frames);
  375. }
  376. static bool ffmpeg_source_play_hotkey(void *data, obs_hotkey_pair_id id,
  377. obs_hotkey_t *hotkey, bool pressed)
  378. {
  379. UNUSED_PARAMETER(id);
  380. UNUSED_PARAMETER(hotkey);
  381. if (!pressed)
  382. return false;
  383. struct ffmpeg_source *s = data;
  384. if (s->state == OBS_MEDIA_STATE_PLAYING ||
  385. !obs_source_active(s->source))
  386. return false;
  387. obs_source_media_play_pause(s->source, false);
  388. return true;
  389. }
  390. static bool ffmpeg_source_pause_hotkey(void *data, obs_hotkey_pair_id id,
  391. obs_hotkey_t *hotkey, bool pressed)
  392. {
  393. UNUSED_PARAMETER(id);
  394. UNUSED_PARAMETER(hotkey);
  395. if (!pressed)
  396. return false;
  397. struct ffmpeg_source *s = data;
  398. if (s->state != OBS_MEDIA_STATE_PLAYING ||
  399. !obs_source_active(s->source))
  400. return false;
  401. obs_source_media_play_pause(s->source, true);
  402. return true;
  403. }
  404. static void ffmpeg_source_stop_hotkey(void *data, obs_hotkey_id id,
  405. obs_hotkey_t *hotkey, bool pressed)
  406. {
  407. UNUSED_PARAMETER(id);
  408. UNUSED_PARAMETER(hotkey);
  409. if (!pressed)
  410. return;
  411. struct ffmpeg_source *s = data;
  412. if (obs_source_active(s->source))
  413. obs_source_media_stop(s->source);
  414. }
  415. static void *ffmpeg_source_create(obs_data_t *settings, obs_source_t *source)
  416. {
  417. UNUSED_PARAMETER(settings);
  418. struct ffmpeg_source *s = bzalloc(sizeof(struct ffmpeg_source));
  419. s->source = source;
  420. s->hotkey = obs_hotkey_register_source(source, "MediaSource.Restart",
  421. obs_module_text("RestartMedia"),
  422. restart_hotkey, s);
  423. s->play_pause_hotkey = obs_hotkey_pair_register_source(
  424. s->source, "MediaSource.Play", obs_module_text("Play"),
  425. "MediaSource.Pause", obs_module_text("Pause"),
  426. ffmpeg_source_play_hotkey, ffmpeg_source_pause_hotkey, s, s);
  427. s->stop_hotkey = obs_hotkey_register_source(source, "MediaSource.Stop",
  428. obs_module_text("Stop"),
  429. ffmpeg_source_stop_hotkey,
  430. s);
  431. proc_handler_t *ph = obs_source_get_proc_handler(source);
  432. proc_handler_add(ph, "void restart()", restart_proc, s);
  433. proc_handler_add(ph, "void get_duration(out int duration)",
  434. get_duration, s);
  435. proc_handler_add(ph, "void get_nb_frames(out int num_frames)",
  436. get_nb_frames, s);
  437. ffmpeg_source_update(s, settings);
  438. return s;
  439. }
  440. static void ffmpeg_source_destroy(void *data)
  441. {
  442. struct ffmpeg_source *s = data;
  443. if (s->hotkey)
  444. obs_hotkey_unregister(s->hotkey);
  445. if (s->media_valid)
  446. mp_media_free(&s->media);
  447. if (s->sws_ctx != NULL)
  448. sws_freeContext(s->sws_ctx);
  449. bfree(s->sws_data);
  450. bfree(s->input);
  451. bfree(s->input_format);
  452. bfree(s);
  453. }
  454. static void ffmpeg_source_activate(void *data)
  455. {
  456. struct ffmpeg_source *s = data;
  457. if (s->restart_on_activate)
  458. obs_source_media_restart(s->source);
  459. }
  460. static void ffmpeg_source_deactivate(void *data)
  461. {
  462. struct ffmpeg_source *s = data;
  463. if (s->restart_on_activate) {
  464. if (s->media_valid) {
  465. mp_media_stop(&s->media);
  466. if (s->is_clear_on_media_end)
  467. obs_source_output_video(s->source, NULL);
  468. }
  469. }
  470. }
  471. static void ffmpeg_source_play_pause(void *data, bool pause)
  472. {
  473. struct ffmpeg_source *s = data;
  474. mp_media_play_pause(&s->media, pause);
  475. if (pause)
  476. set_media_state(s, OBS_MEDIA_STATE_PAUSED);
  477. else
  478. set_media_state(s, OBS_MEDIA_STATE_PLAYING);
  479. }
  480. static void ffmpeg_source_stop(void *data)
  481. {
  482. struct ffmpeg_source *s = data;
  483. if (s->media_valid) {
  484. mp_media_stop(&s->media);
  485. obs_source_output_video(s->source, NULL);
  486. set_media_state(s, OBS_MEDIA_STATE_STOPPED);
  487. }
  488. }
  489. static void ffmpeg_source_restart(void *data)
  490. {
  491. struct ffmpeg_source *s = data;
  492. if (obs_source_active(s->source))
  493. ffmpeg_source_start(s);
  494. set_media_state(s, OBS_MEDIA_STATE_PLAYING);
  495. }
  496. static int64_t ffmpeg_source_get_duration(void *data)
  497. {
  498. struct ffmpeg_source *s = data;
  499. int64_t dur = 0;
  500. if (s->media.fmt)
  501. dur = s->media.fmt->duration / INT64_C(1000);
  502. return dur;
  503. }
  504. static int64_t ffmpeg_source_get_time(void *data)
  505. {
  506. struct ffmpeg_source *s = data;
  507. return mp_get_current_time(&s->media);
  508. }
  509. static void ffmpeg_source_set_time(void *data, int64_t ms)
  510. {
  511. struct ffmpeg_source *s = data;
  512. mp_media_seek_to(&s->media, ms);
  513. }
  514. static enum obs_media_state ffmpeg_source_get_state(void *data)
  515. {
  516. struct ffmpeg_source *s = data;
  517. return s->state;
  518. }
  519. struct obs_source_info ffmpeg_source = {
  520. .id = "ffmpeg_source",
  521. .type = OBS_SOURCE_TYPE_INPUT,
  522. .output_flags = OBS_SOURCE_ASYNC_VIDEO | OBS_SOURCE_AUDIO |
  523. OBS_SOURCE_DO_NOT_DUPLICATE |
  524. OBS_SOURCE_CONTROLLABLE_MEDIA,
  525. .get_name = ffmpeg_source_getname,
  526. .create = ffmpeg_source_create,
  527. .destroy = ffmpeg_source_destroy,
  528. .get_defaults = ffmpeg_source_defaults,
  529. .get_properties = ffmpeg_source_getproperties,
  530. .activate = ffmpeg_source_activate,
  531. .deactivate = ffmpeg_source_deactivate,
  532. .video_tick = ffmpeg_source_tick,
  533. .update = ffmpeg_source_update,
  534. .icon_type = OBS_ICON_TYPE_MEDIA,
  535. .media_play_pause = ffmpeg_source_play_pause,
  536. .media_restart = ffmpeg_source_restart,
  537. .media_stop = ffmpeg_source_stop,
  538. .media_get_duration = ffmpeg_source_get_duration,
  539. .media_get_time = ffmpeg_source_get_time,
  540. .media_set_time = ffmpeg_source_set_time,
  541. .media_get_state = ffmpeg_source_get_state,
  542. };