vlc-video-source.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  1. #include "vlc-video-plugin.h"
  2. #include <media-io/video-frame.h>
  3. #include <util/threading.h>
  4. #include <util/platform.h>
  5. #include <util/dstr.h>
  6. #define do_log(level, format, ...) \
  7. blog(level, "[vlc_source: '%s'] " format, \
  8. obs_source_get_name(ss->source), ##__VA_ARGS__)
  9. #define warn(format, ...) do_log(LOG_WARNING, format, ##__VA_ARGS__)
  10. /* clang-format off */
  11. #define S_PLAYLIST "playlist"
  12. #define S_LOOP "loop"
  13. #define S_SHUFFLE "shuffle"
  14. #define S_BEHAVIOR "playback_behavior"
  15. #define S_BEHAVIOR_STOP_RESTART "stop_restart"
  16. #define S_BEHAVIOR_PAUSE_UNPAUSE "pause_unpause"
  17. #define S_BEHAVIOR_ALWAYS_PLAY "always_play"
  18. #define S_NETWORK_CACHING "network_caching"
  19. #define S_TRACK "track"
  20. #define S_SUBTITLE_ENABLE "subtitle_enable"
  21. #define S_SUBTITLE_TRACK "subtitle"
  22. #define T_(text) obs_module_text(text)
  23. #define T_PLAYLIST T_("Playlist")
  24. #define T_LOOP T_("LoopPlaylist")
  25. #define T_SHUFFLE T_("shuffle")
  26. #define T_BEHAVIOR T_("PlaybackBehavior")
  27. #define T_BEHAVIOR_STOP_RESTART T_("PlaybackBehavior.StopRestart")
  28. #define T_BEHAVIOR_PAUSE_UNPAUSE T_("PlaybackBehavior.PauseUnpause")
  29. #define T_BEHAVIOR_ALWAYS_PLAY T_("PlaybackBehavior.AlwaysPlay")
  30. #define T_NETWORK_CACHING T_("NetworkCaching")
  31. #define T_TRACK T_("AudioTrack")
  32. #define T_SUBTITLE_ENABLE T_("SubtitleEnable")
  33. #define T_SUBTITLE_TRACK T_("SubtitleTrack")
  34. /* clang-format on */
  35. /* ------------------------------------------------------------------------- */
  36. struct media_file_data {
  37. char *path;
  38. libvlc_media_t *media;
  39. };
  40. enum behavior {
  41. BEHAVIOR_STOP_RESTART,
  42. BEHAVIOR_PAUSE_UNPAUSE,
  43. BEHAVIOR_ALWAYS_PLAY,
  44. };
  45. struct vlc_source {
  46. obs_source_t *source;
  47. libvlc_media_player_t *media_player;
  48. libvlc_media_list_player_t *media_list_player;
  49. struct obs_source_frame frame;
  50. struct obs_source_audio audio;
  51. size_t audio_capacity;
  52. pthread_mutex_t mutex;
  53. DARRAY(struct media_file_data) files;
  54. enum behavior behavior;
  55. bool loop;
  56. bool shuffle;
  57. obs_hotkey_id play_pause_hotkey;
  58. obs_hotkey_id restart_hotkey;
  59. obs_hotkey_id stop_hotkey;
  60. obs_hotkey_id playlist_next_hotkey;
  61. obs_hotkey_id playlist_prev_hotkey;
  62. };
  63. static libvlc_media_t *get_media(struct darray *array, const char *path)
  64. {
  65. DARRAY(struct media_file_data) files;
  66. libvlc_media_t *media = NULL;
  67. files.da = *array;
  68. for (size_t i = 0; i < files.num; i++) {
  69. const char *cur_path = files.array[i].path;
  70. if (strcmp(path, cur_path) == 0) {
  71. media = files.array[i].media;
  72. libvlc_media_retain_(media);
  73. break;
  74. }
  75. }
  76. return media;
  77. }
  78. static inline libvlc_media_t *create_media_from_file(const char *file)
  79. {
  80. return (file && strstr(file, "://") != NULL)
  81. ? libvlc_media_new_location_(libvlc, file)
  82. : libvlc_media_new_path_(libvlc, file);
  83. }
  84. static void free_files(struct darray *array)
  85. {
  86. DARRAY(struct media_file_data) files;
  87. files.da = *array;
  88. for (size_t i = 0; i < files.num; i++) {
  89. bfree(files.array[i].path);
  90. libvlc_media_release_(files.array[i].media);
  91. }
  92. da_free(files);
  93. }
  94. #define MAKEFORMAT(ch0, ch1, ch2, ch3) \
  95. ((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \
  96. ((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24))
  97. static inline bool chroma_is(const char *chroma, const char *val)
  98. {
  99. return *(uint32_t *)chroma == *(uint32_t *)val;
  100. }
  101. static enum video_format convert_vlc_video_format(char *chroma, bool *full)
  102. {
  103. *full = false;
  104. #define CHROMA_TEST(val, ret) \
  105. if (chroma_is(chroma, val)) \
  106. return ret
  107. #define CHROMA_CONV(val, new_val, ret) \
  108. do { \
  109. if (chroma_is(chroma, val)) { \
  110. *(uint32_t *)chroma = (uint32_t)new_val; \
  111. return ret; \
  112. } \
  113. } while (false)
  114. #define CHROMA_CONV_FULL(val, new_val, ret) \
  115. do { \
  116. *full = true; \
  117. CHROMA_CONV(val, new_val, ret); \
  118. } while (false)
  119. CHROMA_TEST("RGBA", VIDEO_FORMAT_RGBA);
  120. CHROMA_TEST("BGRA", VIDEO_FORMAT_BGRA);
  121. /* 4:2:0 formats */
  122. CHROMA_TEST("NV12", VIDEO_FORMAT_NV12);
  123. CHROMA_TEST("I420", VIDEO_FORMAT_I420);
  124. CHROMA_TEST("IYUV", VIDEO_FORMAT_I420);
  125. CHROMA_CONV("NV21", MAKEFORMAT('N', 'V', '1', '2'), VIDEO_FORMAT_NV12);
  126. CHROMA_CONV("I422", MAKEFORMAT('N', 'V', '1', '2'), VIDEO_FORMAT_NV12);
  127. CHROMA_CONV("Y42B", MAKEFORMAT('N', 'V', '1', '2'), VIDEO_FORMAT_NV12);
  128. CHROMA_CONV("YV12", MAKEFORMAT('N', 'V', '1', '2'), VIDEO_FORMAT_NV12);
  129. CHROMA_CONV("yv12", MAKEFORMAT('N', 'V', '1', '2'), VIDEO_FORMAT_NV12);
  130. CHROMA_CONV_FULL("J420", MAKEFORMAT('J', '4', '2', '0'),
  131. VIDEO_FORMAT_I420);
  132. /* 4:2:2 formats */
  133. CHROMA_TEST("UYVY", VIDEO_FORMAT_UYVY);
  134. CHROMA_TEST("UYNV", VIDEO_FORMAT_UYVY);
  135. CHROMA_TEST("UYNY", VIDEO_FORMAT_UYVY);
  136. CHROMA_TEST("Y422", VIDEO_FORMAT_UYVY);
  137. CHROMA_TEST("HDYC", VIDEO_FORMAT_UYVY);
  138. CHROMA_TEST("AVUI", VIDEO_FORMAT_UYVY);
  139. CHROMA_TEST("uyv1", VIDEO_FORMAT_UYVY);
  140. CHROMA_TEST("2vuy", VIDEO_FORMAT_UYVY);
  141. CHROMA_TEST("2Vuy", VIDEO_FORMAT_UYVY);
  142. CHROMA_TEST("2Vu1", VIDEO_FORMAT_UYVY);
  143. CHROMA_TEST("YUY2", VIDEO_FORMAT_YUY2);
  144. CHROMA_TEST("YUYV", VIDEO_FORMAT_YUY2);
  145. CHROMA_TEST("YUNV", VIDEO_FORMAT_YUY2);
  146. CHROMA_TEST("V422", VIDEO_FORMAT_YUY2);
  147. CHROMA_TEST("YVYU", VIDEO_FORMAT_YVYU);
  148. CHROMA_CONV("v210", MAKEFORMAT('U', 'Y', 'V', 'Y'), VIDEO_FORMAT_UYVY);
  149. CHROMA_CONV("cyuv", MAKEFORMAT('U', 'Y', 'V', 'Y'), VIDEO_FORMAT_UYVY);
  150. CHROMA_CONV("CYUV", MAKEFORMAT('U', 'Y', 'V', 'Y'), VIDEO_FORMAT_UYVY);
  151. CHROMA_CONV("VYUY", MAKEFORMAT('U', 'Y', 'V', 'Y'), VIDEO_FORMAT_UYVY);
  152. CHROMA_CONV("NV16", MAKEFORMAT('U', 'Y', 'V', 'Y'), VIDEO_FORMAT_UYVY);
  153. CHROMA_CONV("NV61", MAKEFORMAT('U', 'Y', 'V', 'Y'), VIDEO_FORMAT_UYVY);
  154. CHROMA_CONV("I410", MAKEFORMAT('U', 'Y', 'V', 'Y'), VIDEO_FORMAT_UYVY);
  155. CHROMA_CONV("I422", MAKEFORMAT('U', 'Y', 'V', 'Y'), VIDEO_FORMAT_UYVY);
  156. CHROMA_CONV("Y42B", MAKEFORMAT('U', 'Y', 'V', 'Y'), VIDEO_FORMAT_UYVY);
  157. CHROMA_CONV("J422", MAKEFORMAT('U', 'Y', 'V', 'Y'), VIDEO_FORMAT_UYVY);
  158. /* 4:4:4 formats */
  159. CHROMA_TEST("I444", VIDEO_FORMAT_I444);
  160. CHROMA_CONV_FULL("J444", MAKEFORMAT('R', 'G', 'B', 'A'),
  161. VIDEO_FORMAT_RGBA);
  162. CHROMA_CONV("YUVA", MAKEFORMAT('R', 'G', 'B', 'A'), VIDEO_FORMAT_RGBA);
  163. /* 4:4:0 formats */
  164. CHROMA_CONV("I440", MAKEFORMAT('I', '4', '4', '4'), VIDEO_FORMAT_I444);
  165. CHROMA_CONV("J440", MAKEFORMAT('I', '4', '4', '4'), VIDEO_FORMAT_I444);
  166. /* 4:1:0 formats */
  167. CHROMA_CONV("YVU9", MAKEFORMAT('N', 'V', '1', '2'), VIDEO_FORMAT_UYVY);
  168. CHROMA_CONV("I410", MAKEFORMAT('N', 'V', '1', '2'), VIDEO_FORMAT_UYVY);
  169. /* 4:1:1 formats */
  170. CHROMA_CONV("I411", MAKEFORMAT('N', 'V', '1', '2'), VIDEO_FORMAT_UYVY);
  171. CHROMA_CONV("Y41B", MAKEFORMAT('N', 'V', '1', '2'), VIDEO_FORMAT_UYVY);
  172. /* greyscale formats */
  173. CHROMA_TEST("GREY", VIDEO_FORMAT_Y800);
  174. CHROMA_TEST("Y800", VIDEO_FORMAT_Y800);
  175. CHROMA_TEST("Y8 ", VIDEO_FORMAT_Y800);
  176. #undef CHROMA_CONV_FULL
  177. #undef CHROMA_CONV
  178. #undef CHROMA_TEST
  179. *(uint32_t *)chroma = (uint32_t)MAKEFORMAT('B', 'G', 'R', 'A');
  180. return VIDEO_FORMAT_BGRA;
  181. }
  182. static inline unsigned get_format_lines(enum video_format format,
  183. unsigned height, size_t plane)
  184. {
  185. switch (format) {
  186. case VIDEO_FORMAT_I420:
  187. case VIDEO_FORMAT_NV12:
  188. return (plane == 0) ? height : height / 2;
  189. case VIDEO_FORMAT_YVYU:
  190. case VIDEO_FORMAT_YUY2:
  191. case VIDEO_FORMAT_UYVY:
  192. case VIDEO_FORMAT_I444:
  193. case VIDEO_FORMAT_RGBA:
  194. case VIDEO_FORMAT_BGRA:
  195. case VIDEO_FORMAT_BGRX:
  196. case VIDEO_FORMAT_Y800:
  197. return height;
  198. case VIDEO_FORMAT_NONE:
  199. default:
  200. break;
  201. }
  202. return 0;
  203. }
  204. static enum audio_format convert_vlc_audio_format(char *format)
  205. {
  206. #define AUDIO_TEST(val, ret) \
  207. if (chroma_is(format, val)) \
  208. return ret
  209. #define AUDIO_CONV(val, new_val, ret) \
  210. do { \
  211. if (chroma_is(format, val)) { \
  212. *(uint32_t *)format = (uint32_t)new_val; \
  213. return ret; \
  214. } \
  215. } while (false)
  216. AUDIO_TEST("S16N", AUDIO_FORMAT_16BIT);
  217. AUDIO_TEST("S32N", AUDIO_FORMAT_32BIT);
  218. AUDIO_TEST("FL32", AUDIO_FORMAT_FLOAT);
  219. AUDIO_CONV("U16N", MAKEFORMAT('S', '1', '6', 'N'), AUDIO_FORMAT_16BIT);
  220. AUDIO_CONV("U32N", MAKEFORMAT('S', '3', '2', 'N'), AUDIO_FORMAT_32BIT);
  221. AUDIO_CONV("S24N", MAKEFORMAT('S', '3', '2', 'N'), AUDIO_FORMAT_32BIT);
  222. AUDIO_CONV("U24N", MAKEFORMAT('S', '3', '2', 'N'), AUDIO_FORMAT_32BIT);
  223. AUDIO_CONV("FL64", MAKEFORMAT('F', 'L', '3', '2'), AUDIO_FORMAT_FLOAT);
  224. AUDIO_CONV("S16I", MAKEFORMAT('S', '1', '6', 'N'), AUDIO_FORMAT_16BIT);
  225. AUDIO_CONV("U16I", MAKEFORMAT('S', '1', '6', 'N'), AUDIO_FORMAT_16BIT);
  226. AUDIO_CONV("S24I", MAKEFORMAT('S', '3', '2', 'N'), AUDIO_FORMAT_32BIT);
  227. AUDIO_CONV("U24I", MAKEFORMAT('S', '3', '2', 'N'), AUDIO_FORMAT_32BIT);
  228. AUDIO_CONV("S32I", MAKEFORMAT('S', '3', '2', 'N'), AUDIO_FORMAT_32BIT);
  229. AUDIO_CONV("U32I", MAKEFORMAT('S', '3', '2', 'N'), AUDIO_FORMAT_32BIT);
  230. #undef AUDIO_CONV
  231. #undef AUDIO_TEST
  232. *(uint32_t *)format = (uint32_t)MAKEFORMAT('F', 'L', '3', '2');
  233. return AUDIO_FORMAT_FLOAT;
  234. }
  235. /* ------------------------------------------------------------------------- */
  236. static void vlcs_get_metadata(void *data, calldata_t *cd)
  237. {
  238. struct vlc_source *vlcs = data;
  239. const char *data_id = calldata_string(cd, "tag_id");
  240. if (!vlcs || !data_id)
  241. return;
  242. libvlc_media_t *media =
  243. libvlc_media_player_get_media_(vlcs->media_player);
  244. if (!media)
  245. return;
  246. #define VLC_META(media, cd, did, tid, tag) \
  247. else if (strcmp(did, tid) == 0) \
  248. { \
  249. calldata_set_string(cd, "tag_data", \
  250. libvlc_media_get_meta_(media, tag)); \
  251. }
  252. if (strcmp(data_id, "title") == 0)
  253. calldata_set_string(cd, "tag_data",
  254. libvlc_media_get_meta_(media,
  255. libvlc_meta_Title));
  256. VLC_META(media, cd, data_id, "artist", libvlc_meta_Artist)
  257. VLC_META(media, cd, data_id, "genre", libvlc_meta_Genre)
  258. VLC_META(media, cd, data_id, "copyright", libvlc_meta_Copyright)
  259. VLC_META(media, cd, data_id, "album", libvlc_meta_Album)
  260. VLC_META(media, cd, data_id, "track_number", libvlc_meta_TrackNumber)
  261. VLC_META(media, cd, data_id, "description", libvlc_meta_Description)
  262. VLC_META(media, cd, data_id, "rating", libvlc_meta_Rating)
  263. VLC_META(media, cd, data_id, "date", libvlc_meta_Date)
  264. VLC_META(media, cd, data_id, "setting", libvlc_meta_Setting)
  265. VLC_META(media, cd, data_id, "url", libvlc_meta_URL)
  266. VLC_META(media, cd, data_id, "language", libvlc_meta_Language)
  267. VLC_META(media, cd, data_id, "now_playing", libvlc_meta_NowPlaying)
  268. VLC_META(media, cd, data_id, "publisher", libvlc_meta_Publisher)
  269. VLC_META(media, cd, data_id, "encoded_by", libvlc_meta_EncodedBy)
  270. VLC_META(media, cd, data_id, "artwork_url", libvlc_meta_ArtworkURL)
  271. VLC_META(media, cd, data_id, "track_id", libvlc_meta_TrackID)
  272. VLC_META(media, cd, data_id, "track_total", libvlc_meta_TrackTotal)
  273. VLC_META(media, cd, data_id, "director", libvlc_meta_Director)
  274. VLC_META(media, cd, data_id, "season", libvlc_meta_Season)
  275. VLC_META(media, cd, data_id, "episode", libvlc_meta_Episode)
  276. VLC_META(media, cd, data_id, "show_name", libvlc_meta_ShowName)
  277. VLC_META(media, cd, data_id, "actors", libvlc_meta_Actors)
  278. VLC_META(media, cd, data_id, "album_artist", libvlc_meta_AlbumArtist)
  279. VLC_META(media, cd, data_id, "disc_number", libvlc_meta_DiscNumber)
  280. VLC_META(media, cd, data_id, "disc_total", libvlc_meta_DiscTotal)
  281. libvlc_media_release_(media);
  282. #undef VLC_META
  283. }
  284. /* ------------------------------------------------------------------------- */
  285. static const char *vlcs_get_name(void *unused)
  286. {
  287. UNUSED_PARAMETER(unused);
  288. return obs_module_text("VLCSource");
  289. }
  290. static void vlcs_destroy(void *data)
  291. {
  292. struct vlc_source *c = data;
  293. if (c->media_list_player) {
  294. libvlc_media_list_player_stop_(c->media_list_player);
  295. libvlc_media_list_player_release_(c->media_list_player);
  296. }
  297. if (c->media_player) {
  298. libvlc_media_player_release_(c->media_player);
  299. }
  300. bfree((void *)c->audio.data[0]);
  301. obs_source_frame_free(&c->frame);
  302. free_files(&c->files.da);
  303. pthread_mutex_destroy(&c->mutex);
  304. bfree(c);
  305. }
  306. static void *vlcs_video_lock(void *data, void **planes)
  307. {
  308. struct vlc_source *c = data;
  309. for (size_t i = 0; i < MAX_AV_PLANES && c->frame.data[i] != NULL; i++)
  310. planes[i] = c->frame.data[i];
  311. return NULL;
  312. }
  313. static void vlcs_video_display(void *data, void *picture)
  314. {
  315. struct vlc_source *c = data;
  316. c->frame.timestamp = (uint64_t)libvlc_clock_() * 1000ULL - time_start;
  317. obs_source_output_video(c->source, &c->frame);
  318. UNUSED_PARAMETER(picture);
  319. }
  320. static unsigned vlcs_video_format(void **p_data, char *chroma, unsigned *width,
  321. unsigned *height, unsigned *pitches,
  322. unsigned *lines)
  323. {
  324. struct vlc_source *c = *p_data;
  325. enum video_format new_format;
  326. enum video_range_type range;
  327. bool new_range;
  328. unsigned new_width = 0;
  329. unsigned new_height = 0;
  330. size_t i = 0;
  331. new_format = convert_vlc_video_format(chroma, &new_range);
  332. /* This is used because VLC will by default try to use a different
  333. * scaling than what the file uses (probably for optimization reasons).
  334. * For example, if the file is 1920x1080, it will try to render it by
  335. * 1920x1088, which isn't what we want. Calling libvlc_video_get_size
  336. * gets the actual video file's size, and thus fixes the problem.
  337. * However this doesn't work with URLs, so if it returns a 0 value, it
  338. * shouldn't be used. */
  339. libvlc_video_get_size_(c->media_player, 0, &new_width, &new_height);
  340. if (new_width && new_height) {
  341. *width = new_width;
  342. *height = new_height;
  343. }
  344. /* don't allocate a new frame if format/width/height hasn't changed */
  345. if (c->frame.format != new_format || c->frame.width != *width ||
  346. c->frame.height != *height) {
  347. obs_source_frame_free(&c->frame);
  348. obs_source_frame_init(&c->frame, new_format, *width, *height);
  349. c->frame.format = new_format;
  350. c->frame.full_range = new_range;
  351. range = c->frame.full_range ? VIDEO_RANGE_FULL
  352. : VIDEO_RANGE_PARTIAL;
  353. video_format_get_parameters(VIDEO_CS_DEFAULT, range,
  354. c->frame.color_matrix,
  355. c->frame.color_range_min,
  356. c->frame.color_range_max);
  357. }
  358. while (c->frame.data[i]) {
  359. pitches[i] = (unsigned)c->frame.linesize[i];
  360. lines[i] = get_format_lines(c->frame.format, *height, i);
  361. i++;
  362. }
  363. return 1;
  364. }
  365. static void vlcs_audio_play(void *data, const void *samples, unsigned count,
  366. int64_t pts)
  367. {
  368. struct vlc_source *c = data;
  369. size_t size = get_audio_size(c->audio.format, c->audio.speakers, count);
  370. if (c->audio_capacity < count) {
  371. c->audio.data[0] = brealloc((void *)c->audio.data[0], size);
  372. c->audio_capacity = count;
  373. }
  374. memcpy((void *)c->audio.data[0], samples, size);
  375. c->audio.timestamp = (uint64_t)pts * 1000ULL - time_start;
  376. c->audio.frames = count;
  377. obs_source_output_audio(c->source, &c->audio);
  378. }
  379. static int vlcs_audio_setup(void **p_data, char *format, unsigned *rate,
  380. unsigned *channels)
  381. {
  382. struct vlc_source *c = *p_data;
  383. enum audio_format new_audio_format;
  384. new_audio_format = convert_vlc_audio_format(format);
  385. if (*channels > 8)
  386. *channels = 8;
  387. /* don't free audio data if the data is the same format */
  388. if (c->audio.format == new_audio_format &&
  389. c->audio.samples_per_sec == *rate &&
  390. c->audio.speakers == (enum speaker_layout) * channels)
  391. return 0;
  392. c->audio_capacity = 0;
  393. bfree((void *)c->audio.data[0]);
  394. memset(&c->audio, 0, sizeof(c->audio));
  395. c->audio.speakers = (enum speaker_layout) * channels;
  396. c->audio.samples_per_sec = *rate;
  397. c->audio.format = new_audio_format;
  398. return 0;
  399. }
  400. static void add_file(struct vlc_source *c, struct darray *array,
  401. const char *path, int network_caching, int track_index,
  402. int subtitle_index, bool subtitle_enable)
  403. {
  404. DARRAY(struct media_file_data) new_files;
  405. struct media_file_data data;
  406. struct dstr new_path = {0};
  407. libvlc_media_t *new_media;
  408. bool is_url = path && strstr(path, "://") != NULL;
  409. new_files.da = *array;
  410. dstr_copy(&new_path, path);
  411. #ifdef _WIN32
  412. if (!is_url)
  413. dstr_replace(&new_path, "/", "\\");
  414. #endif
  415. path = new_path.array;
  416. new_media = get_media(&c->files.da, path);
  417. if (!new_media)
  418. new_media = get_media(&new_files.da, path);
  419. if (!new_media)
  420. new_media = create_media_from_file(path);
  421. if (new_media) {
  422. if (is_url) {
  423. struct dstr network_caching_option = {0};
  424. dstr_catf(&network_caching_option,
  425. ":network-caching=%d", network_caching);
  426. libvlc_media_add_option_(new_media,
  427. network_caching_option.array);
  428. dstr_free(&network_caching_option);
  429. }
  430. struct dstr track_option = {0};
  431. dstr_catf(&track_option, ":audio-track=%d", track_index - 1);
  432. libvlc_media_add_option_(new_media, track_option.array);
  433. dstr_free(&track_option);
  434. struct dstr sub_option = {0};
  435. if (subtitle_enable) {
  436. dstr_catf(&sub_option, ":sub-track=%d",
  437. subtitle_index - 1);
  438. }
  439. libvlc_media_add_option_(new_media, sub_option.array);
  440. dstr_free(&sub_option);
  441. data.path = new_path.array;
  442. data.media = new_media;
  443. da_push_back(new_files, &data);
  444. } else {
  445. dstr_free(&new_path);
  446. }
  447. *array = new_files.da;
  448. }
  449. static bool valid_extension(const char *ext)
  450. {
  451. struct dstr test = {0};
  452. bool valid = false;
  453. const char *b;
  454. const char *e;
  455. if (!ext || !*ext)
  456. return false;
  457. b = EXTENSIONS_MEDIA + 1;
  458. e = strchr(b, ';');
  459. for (;;) {
  460. if (e)
  461. dstr_ncopy(&test, b, e - b);
  462. else
  463. dstr_copy(&test, b);
  464. if (dstr_cmpi(&test, ext) == 0) {
  465. valid = true;
  466. break;
  467. }
  468. if (!e)
  469. break;
  470. b = e + 2;
  471. e = strchr(b, ';');
  472. }
  473. dstr_free(&test);
  474. return valid;
  475. }
  476. static void vlcs_update(void *data, obs_data_t *settings)
  477. {
  478. DARRAY(struct media_file_data) new_files;
  479. DARRAY(struct media_file_data) old_files;
  480. libvlc_media_list_t *media_list;
  481. struct vlc_source *c = data;
  482. obs_data_array_t *array;
  483. const char *behavior;
  484. size_t count;
  485. int network_caching;
  486. int track_index;
  487. int subtitle_index;
  488. bool subtitle_enable;
  489. da_init(new_files);
  490. da_init(old_files);
  491. array = obs_data_get_array(settings, S_PLAYLIST);
  492. count = obs_data_array_count(array);
  493. c->loop = obs_data_get_bool(settings, S_LOOP);
  494. behavior = obs_data_get_string(settings, S_BEHAVIOR);
  495. network_caching = (int)obs_data_get_int(settings, S_NETWORK_CACHING);
  496. track_index = (int)obs_data_get_int(settings, S_TRACK);
  497. subtitle_index = (int)obs_data_get_int(settings, S_SUBTITLE_TRACK);
  498. subtitle_enable = obs_data_get_bool(settings, S_SUBTITLE_ENABLE);
  499. if (astrcmpi(behavior, S_BEHAVIOR_PAUSE_UNPAUSE) == 0) {
  500. c->behavior = BEHAVIOR_PAUSE_UNPAUSE;
  501. } else if (astrcmpi(behavior, S_BEHAVIOR_ALWAYS_PLAY) == 0) {
  502. c->behavior = BEHAVIOR_ALWAYS_PLAY;
  503. } else { /* S_BEHAVIOR_STOP_RESTART */
  504. c->behavior = BEHAVIOR_STOP_RESTART;
  505. }
  506. /* ------------------------------------- */
  507. /* create new list of sources */
  508. for (size_t i = 0; i < count; i++) {
  509. obs_data_t *item = obs_data_array_item(array, i);
  510. const char *path = obs_data_get_string(item, "value");
  511. os_dir_t *dir = os_opendir(path);
  512. if (dir) {
  513. struct dstr dir_path = {0};
  514. struct os_dirent *ent;
  515. for (;;) {
  516. const char *ext;
  517. ent = os_readdir(dir);
  518. if (!ent)
  519. break;
  520. if (ent->directory)
  521. continue;
  522. ext = os_get_path_extension(ent->d_name);
  523. if (!valid_extension(ext))
  524. continue;
  525. dstr_copy(&dir_path, path);
  526. dstr_cat_ch(&dir_path, '/');
  527. dstr_cat(&dir_path, ent->d_name);
  528. add_file(c, &new_files.da, dir_path.array,
  529. network_caching, track_index,
  530. subtitle_index, subtitle_enable);
  531. }
  532. dstr_free(&dir_path);
  533. os_closedir(dir);
  534. } else {
  535. add_file(c, &new_files.da, path, network_caching,
  536. track_index, subtitle_index, subtitle_enable);
  537. }
  538. obs_data_release(item);
  539. }
  540. /* ------------------------------------- */
  541. /* update settings data */
  542. libvlc_media_list_player_stop_(c->media_list_player);
  543. pthread_mutex_lock(&c->mutex);
  544. old_files.da = c->files.da;
  545. c->files.da = new_files.da;
  546. pthread_mutex_unlock(&c->mutex);
  547. /* ------------------------------------- */
  548. /* shuffle playlist */
  549. c->shuffle = obs_data_get_bool(settings, S_SHUFFLE);
  550. if (c->files.num > 1 && c->shuffle) {
  551. DARRAY(struct media_file_data) new_files;
  552. DARRAY(size_t) idxs;
  553. da_init(new_files);
  554. da_init(idxs);
  555. da_resize(idxs, c->files.num);
  556. da_reserve(new_files, c->files.num);
  557. for (size_t i = 0; i < c->files.num; i++) {
  558. idxs.array[i] = i;
  559. }
  560. for (size_t i = idxs.num; i > 0; i--) {
  561. size_t val = rand() % i;
  562. size_t idx = idxs.array[val];
  563. da_push_back(new_files, &c->files.array[idx]);
  564. da_erase(idxs, val);
  565. }
  566. da_free(c->files);
  567. da_free(idxs);
  568. c->files.da = new_files.da;
  569. }
  570. /* ------------------------------------- */
  571. /* clean up and restart playback */
  572. free_files(&old_files.da);
  573. media_list = libvlc_media_list_new_(libvlc);
  574. libvlc_media_list_lock_(media_list);
  575. for (size_t i = 0; i < c->files.num; i++)
  576. libvlc_media_list_add_media_(media_list,
  577. c->files.array[i].media);
  578. libvlc_media_list_unlock_(media_list);
  579. libvlc_media_list_player_set_media_list_(c->media_list_player,
  580. media_list);
  581. libvlc_media_list_release_(media_list);
  582. libvlc_media_list_player_set_playback_mode_(
  583. c->media_list_player, c->loop ? libvlc_playback_mode_loop
  584. : libvlc_playback_mode_default);
  585. if (c->files.num && (c->behavior == BEHAVIOR_ALWAYS_PLAY ||
  586. obs_source_active(c->source)))
  587. libvlc_media_list_player_play_(c->media_list_player);
  588. else
  589. obs_source_output_video(c->source, NULL);
  590. obs_data_array_release(array);
  591. }
  592. static void vlcs_started(const struct libvlc_event_t *event, void *data)
  593. {
  594. struct vlc_source *c = data;
  595. obs_source_media_started(c->source);
  596. UNUSED_PARAMETER(event);
  597. }
  598. static void vlcs_stopped(const struct libvlc_event_t *event, void *data)
  599. {
  600. struct vlc_source *c = data;
  601. if (!c->loop) {
  602. obs_source_output_video(c->source, NULL);
  603. }
  604. obs_source_media_ended(c->source);
  605. UNUSED_PARAMETER(event);
  606. }
  607. static enum obs_media_state vlcs_get_state(void *data)
  608. {
  609. struct vlc_source *c = data;
  610. libvlc_state_t state = libvlc_media_player_get_state_(c->media_player);
  611. switch (state) {
  612. case libvlc_NothingSpecial:
  613. return OBS_MEDIA_STATE_NONE;
  614. case libvlc_Opening:
  615. return OBS_MEDIA_STATE_OPENING;
  616. case libvlc_Buffering:
  617. return OBS_MEDIA_STATE_BUFFERING;
  618. case libvlc_Playing:
  619. return OBS_MEDIA_STATE_PLAYING;
  620. case libvlc_Paused:
  621. return OBS_MEDIA_STATE_PAUSED;
  622. case libvlc_Stopped:
  623. return OBS_MEDIA_STATE_STOPPED;
  624. case libvlc_Ended:
  625. return OBS_MEDIA_STATE_ENDED;
  626. case libvlc_Error:
  627. return OBS_MEDIA_STATE_ERROR;
  628. }
  629. return 0;
  630. }
  631. static void vlcs_play_pause(void *data, bool pause)
  632. {
  633. struct vlc_source *c = data;
  634. if (pause)
  635. libvlc_media_list_player_pause_(c->media_list_player);
  636. else
  637. libvlc_media_list_player_play_(c->media_list_player);
  638. }
  639. static void vlcs_restart(void *data)
  640. {
  641. struct vlc_source *c = data;
  642. libvlc_media_list_player_stop_(c->media_list_player);
  643. libvlc_media_list_player_play_(c->media_list_player);
  644. }
  645. static void vlcs_stop(void *data)
  646. {
  647. struct vlc_source *c = data;
  648. libvlc_media_list_player_stop_(c->media_list_player);
  649. obs_source_output_video(c->source, NULL);
  650. }
  651. static void vlcs_playlist_next(void *data)
  652. {
  653. struct vlc_source *c = data;
  654. libvlc_media_list_player_next_(c->media_list_player);
  655. }
  656. static void vlcs_playlist_prev(void *data)
  657. {
  658. struct vlc_source *c = data;
  659. libvlc_media_list_player_previous_(c->media_list_player);
  660. }
  661. static int64_t vlcs_get_duration(void *data)
  662. {
  663. struct vlc_source *c = data;
  664. return (int64_t)libvlc_media_player_get_length_(c->media_player);
  665. }
  666. static int64_t vlcs_get_time(void *data)
  667. {
  668. struct vlc_source *c = data;
  669. return (int64_t)libvlc_media_player_get_time_(c->media_player);
  670. }
  671. static void vlcs_set_time(void *data, int64_t ms)
  672. {
  673. struct vlc_source *c = data;
  674. libvlc_media_player_set_time_(c->media_player, (libvlc_time_t)ms);
  675. }
  676. static void vlcs_play_pause_hotkey(void *data, obs_hotkey_id id,
  677. obs_hotkey_t *hotkey, bool pressed)
  678. {
  679. UNUSED_PARAMETER(id);
  680. UNUSED_PARAMETER(hotkey);
  681. struct vlc_source *c = data;
  682. enum obs_media_state state = obs_source_media_get_state(c->source);
  683. if (pressed && obs_source_showing(c->source)) {
  684. if (state == OBS_MEDIA_STATE_PLAYING)
  685. obs_source_media_play_pause(c->source, true);
  686. else if (state == OBS_MEDIA_STATE_PAUSED)
  687. obs_source_media_play_pause(c->source, false);
  688. }
  689. }
  690. static void vlcs_restart_hotkey(void *data, obs_hotkey_id id,
  691. obs_hotkey_t *hotkey, bool pressed)
  692. {
  693. UNUSED_PARAMETER(id);
  694. UNUSED_PARAMETER(hotkey);
  695. struct vlc_source *c = data;
  696. if (pressed && obs_source_showing(c->source))
  697. obs_source_media_restart(c->source);
  698. }
  699. static void vlcs_stop_hotkey(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey,
  700. bool pressed)
  701. {
  702. UNUSED_PARAMETER(id);
  703. UNUSED_PARAMETER(hotkey);
  704. struct vlc_source *c = data;
  705. if (pressed && obs_source_showing(c->source))
  706. obs_source_media_stop(c->source);
  707. }
  708. static void vlcs_playlist_next_hotkey(void *data, obs_hotkey_id id,
  709. obs_hotkey_t *hotkey, bool pressed)
  710. {
  711. UNUSED_PARAMETER(id);
  712. UNUSED_PARAMETER(hotkey);
  713. struct vlc_source *c = data;
  714. if (pressed && obs_source_showing(c->source))
  715. obs_source_media_next(c->source);
  716. }
  717. static void vlcs_playlist_prev_hotkey(void *data, obs_hotkey_id id,
  718. obs_hotkey_t *hotkey, bool pressed)
  719. {
  720. UNUSED_PARAMETER(id);
  721. UNUSED_PARAMETER(hotkey);
  722. struct vlc_source *c = data;
  723. if (pressed && obs_source_showing(c->source))
  724. obs_source_media_previous(c->source);
  725. }
  726. static void *vlcs_create(obs_data_t *settings, obs_source_t *source)
  727. {
  728. struct vlc_source *c = bzalloc(sizeof(*c));
  729. c->source = source;
  730. c->play_pause_hotkey = obs_hotkey_register_source(
  731. source, "VLCSource.PlayPause", obs_module_text("PlayPause"),
  732. vlcs_play_pause_hotkey, c);
  733. c->restart_hotkey = obs_hotkey_register_source(
  734. source, "VLCSource.Restart", obs_module_text("Restart"),
  735. vlcs_restart_hotkey, c);
  736. c->stop_hotkey = obs_hotkey_register_source(source, "VLCSource.Stop",
  737. obs_module_text("Stop"),
  738. vlcs_stop_hotkey, c);
  739. c->playlist_next_hotkey = obs_hotkey_register_source(
  740. source, "VLCSource.PlaylistNext",
  741. obs_module_text("PlaylistNext"), vlcs_playlist_next_hotkey, c);
  742. c->playlist_prev_hotkey = obs_hotkey_register_source(
  743. source, "VLCSource.PlaylistPrev",
  744. obs_module_text("PlaylistPrev"), vlcs_playlist_prev_hotkey, c);
  745. pthread_mutex_init_value(&c->mutex);
  746. if (pthread_mutex_init(&c->mutex, NULL) != 0)
  747. goto error;
  748. if (!load_libvlc())
  749. goto error;
  750. c->media_list_player = libvlc_media_list_player_new_(libvlc);
  751. if (!c->media_list_player)
  752. goto error;
  753. c->media_player = libvlc_media_player_new_(libvlc);
  754. if (!c->media_player)
  755. goto error;
  756. libvlc_media_list_player_set_media_player_(c->media_list_player,
  757. c->media_player);
  758. libvlc_video_set_callbacks_(c->media_player, vlcs_video_lock, NULL,
  759. vlcs_video_display, c);
  760. libvlc_video_set_format_callbacks_(c->media_player, vlcs_video_format,
  761. NULL);
  762. libvlc_audio_set_callbacks_(c->media_player, vlcs_audio_play, NULL,
  763. NULL, NULL, NULL, c);
  764. libvlc_audio_set_format_callbacks_(c->media_player, vlcs_audio_setup,
  765. NULL);
  766. libvlc_event_manager_t *event_manager;
  767. event_manager = libvlc_media_player_event_manager_(c->media_player);
  768. libvlc_event_attach_(event_manager, libvlc_MediaPlayerEndReached,
  769. vlcs_stopped, c);
  770. libvlc_event_attach_(event_manager, libvlc_MediaPlayerOpening,
  771. vlcs_started, c);
  772. proc_handler_t *ph = obs_source_get_proc_handler(source);
  773. proc_handler_add(
  774. ph, "void get_metadata(in string tag_id out string tag_data)",
  775. vlcs_get_metadata, c);
  776. obs_source_update(source, NULL);
  777. UNUSED_PARAMETER(settings);
  778. return c;
  779. error:
  780. vlcs_destroy(c);
  781. return NULL;
  782. }
  783. static void vlcs_activate(void *data)
  784. {
  785. struct vlc_source *c = data;
  786. if (c->behavior == BEHAVIOR_STOP_RESTART) {
  787. libvlc_media_list_player_play_(c->media_list_player);
  788. } else if (c->behavior == BEHAVIOR_PAUSE_UNPAUSE) {
  789. libvlc_media_list_player_play_(c->media_list_player);
  790. }
  791. }
  792. static void vlcs_deactivate(void *data)
  793. {
  794. struct vlc_source *c = data;
  795. if (c->behavior == BEHAVIOR_STOP_RESTART) {
  796. libvlc_media_list_player_stop_(c->media_list_player);
  797. obs_source_output_video(c->source, NULL);
  798. } else if (c->behavior == BEHAVIOR_PAUSE_UNPAUSE) {
  799. libvlc_media_list_player_pause_(c->media_list_player);
  800. }
  801. }
  802. static void vlcs_defaults(obs_data_t *settings)
  803. {
  804. obs_data_set_default_bool(settings, S_LOOP, true);
  805. obs_data_set_default_bool(settings, S_SHUFFLE, false);
  806. obs_data_set_default_string(settings, S_BEHAVIOR,
  807. S_BEHAVIOR_STOP_RESTART);
  808. obs_data_set_default_int(settings, S_NETWORK_CACHING, 400);
  809. obs_data_set_default_int(settings, S_TRACK, 1);
  810. obs_data_set_default_bool(settings, S_SUBTITLE_ENABLE, false);
  811. obs_data_set_default_int(settings, S_SUBTITLE_TRACK, 1);
  812. }
  813. static obs_properties_t *vlcs_properties(void *data)
  814. {
  815. obs_properties_t *ppts = obs_properties_create();
  816. struct vlc_source *c = data;
  817. struct dstr filter = {0};
  818. struct dstr exts = {0};
  819. struct dstr path = {0};
  820. obs_property_t *p;
  821. obs_properties_set_flags(ppts, OBS_PROPERTIES_DEFER_UPDATE);
  822. obs_properties_add_bool(ppts, S_LOOP, T_LOOP);
  823. obs_properties_add_bool(ppts, S_SHUFFLE, T_SHUFFLE);
  824. if (c) {
  825. pthread_mutex_lock(&c->mutex);
  826. if (c->files.num) {
  827. struct media_file_data *last = da_end(c->files);
  828. const char *slash;
  829. dstr_copy(&path, last->path);
  830. dstr_replace(&path, "\\", "/");
  831. slash = strrchr(path.array, '/');
  832. if (slash)
  833. dstr_resize(&path, slash - path.array + 1);
  834. }
  835. pthread_mutex_unlock(&c->mutex);
  836. }
  837. p = obs_properties_add_list(ppts, S_BEHAVIOR, T_BEHAVIOR,
  838. OBS_COMBO_TYPE_LIST,
  839. OBS_COMBO_FORMAT_STRING);
  840. obs_property_list_add_string(p, T_BEHAVIOR_STOP_RESTART,
  841. S_BEHAVIOR_STOP_RESTART);
  842. obs_property_list_add_string(p, T_BEHAVIOR_PAUSE_UNPAUSE,
  843. S_BEHAVIOR_PAUSE_UNPAUSE);
  844. obs_property_list_add_string(p, T_BEHAVIOR_ALWAYS_PLAY,
  845. S_BEHAVIOR_ALWAYS_PLAY);
  846. dstr_cat(&filter, "Media Files (");
  847. dstr_copy(&exts, EXTENSIONS_MEDIA);
  848. dstr_replace(&exts, ";", " ");
  849. dstr_cat_dstr(&filter, &exts);
  850. dstr_cat(&filter, ");;Video Files (");
  851. dstr_copy(&exts, EXTENSIONS_VIDEO);
  852. dstr_replace(&exts, ";", " ");
  853. dstr_cat_dstr(&filter, &exts);
  854. dstr_cat(&filter, ");;Audio Files (");
  855. dstr_copy(&exts, EXTENSIONS_AUDIO);
  856. dstr_replace(&exts, ";", " ");
  857. dstr_cat_dstr(&filter, &exts);
  858. dstr_cat(&filter, ");;Playlist Files (");
  859. dstr_copy(&exts, EXTENSIONS_PLAYLIST);
  860. dstr_replace(&exts, ";", " ");
  861. dstr_cat_dstr(&filter, &exts);
  862. dstr_cat(&filter, ")");
  863. obs_properties_add_editable_list(ppts, S_PLAYLIST, T_PLAYLIST,
  864. OBS_EDITABLE_LIST_TYPE_FILES_AND_URLS,
  865. filter.array, path.array);
  866. dstr_free(&path);
  867. dstr_free(&filter);
  868. dstr_free(&exts);
  869. obs_properties_add_int(ppts, S_NETWORK_CACHING, T_NETWORK_CACHING, 100,
  870. 60000, 10);
  871. obs_properties_add_int(ppts, S_TRACK, T_TRACK, 1, 10, 1);
  872. obs_properties_add_bool(ppts, S_SUBTITLE_ENABLE, T_SUBTITLE_ENABLE);
  873. obs_properties_add_int(ppts, S_SUBTITLE_TRACK, T_SUBTITLE_TRACK, 1, 10,
  874. 1);
  875. return ppts;
  876. }
  877. static void missing_file_callback(void *src, const char *new_path, void *data)
  878. {
  879. struct vlc_source *s = src;
  880. const char *orig_path = data;
  881. obs_source_t *source = s->source;
  882. obs_data_t *settings = obs_source_get_settings(source);
  883. obs_data_array_t *files = obs_data_get_array(settings, S_PLAYLIST);
  884. size_t l = obs_data_array_count(files);
  885. for (size_t i = 0; i < l; i++) {
  886. obs_data_t *file = obs_data_array_item(files, i);
  887. const char *path = obs_data_get_string(file, "value");
  888. if (strcmp(path, orig_path) == 0) {
  889. obs_data_set_string(file, "value", new_path);
  890. obs_data_release(file);
  891. break;
  892. }
  893. obs_data_release(file);
  894. }
  895. obs_source_update(source, settings);
  896. obs_data_array_release(files);
  897. obs_data_release(settings);
  898. }
  899. static obs_missing_files_t *vlcs_missingfiles(void *data)
  900. {
  901. struct vlc_source *s = data;
  902. obs_missing_files_t *missing_files = obs_missing_files_create();
  903. obs_source_t *source = s->source;
  904. obs_data_t *settings = obs_source_get_settings(source);
  905. obs_data_array_t *files = obs_data_get_array(settings, S_PLAYLIST);
  906. size_t l = obs_data_array_count(files);
  907. for (size_t i = 0; i < l; i++) {
  908. obs_data_t *item = obs_data_array_item(files, i);
  909. const char *path = obs_data_get_string(item, "value");
  910. if (strcmp(path, "") != 0) {
  911. if (!os_file_exists(path) &&
  912. strstr(path, "://") == NULL) {
  913. obs_missing_file_t *file =
  914. obs_missing_file_create(
  915. path, missing_file_callback,
  916. OBS_MISSING_FILE_SOURCE, source,
  917. (void *)path);
  918. obs_missing_files_add_file(missing_files, file);
  919. }
  920. }
  921. obs_data_release(item);
  922. }
  923. obs_data_array_release(files);
  924. obs_data_release(settings);
  925. return missing_files;
  926. }
  927. struct obs_source_info vlc_source_info = {
  928. .id = "vlc_source",
  929. .type = OBS_SOURCE_TYPE_INPUT,
  930. .output_flags = OBS_SOURCE_ASYNC_VIDEO | OBS_SOURCE_AUDIO |
  931. OBS_SOURCE_DO_NOT_DUPLICATE |
  932. OBS_SOURCE_CONTROLLABLE_MEDIA,
  933. .get_name = vlcs_get_name,
  934. .create = vlcs_create,
  935. .destroy = vlcs_destroy,
  936. .update = vlcs_update,
  937. .get_defaults = vlcs_defaults,
  938. .get_properties = vlcs_properties,
  939. .activate = vlcs_activate,
  940. .deactivate = vlcs_deactivate,
  941. .missing_files = vlcs_missingfiles,
  942. .icon_type = OBS_ICON_TYPE_MEDIA,
  943. .media_play_pause = vlcs_play_pause,
  944. .media_restart = vlcs_restart,
  945. .media_stop = vlcs_stop,
  946. .media_next = vlcs_playlist_next,
  947. .media_previous = vlcs_playlist_prev,
  948. .media_get_duration = vlcs_get_duration,
  949. .media_get_time = vlcs_get_time,
  950. .media_set_time = vlcs_set_time,
  951. .media_get_state = vlcs_get_state,
  952. };