From e6f950fde924f41c2f9ee746427f8cf3b259c4bd Mon Sep 17 00:00:00 2001 From: Andreas Reischuck Date: Wed, 10 Aug 2016 00:52:22 +0200 Subject: [PATCH] vlc-video: Fix URLs not working on windows libvlc_media_new_path implies a file. To get media based upon URLs, use libvlc_media_new_location. Additionally, if using a URL, it's best to give it some playback caching/buffering, at least 100 milliseconds. Closes jp9000/obs-studio#590 --- plugins/vlc-video/vlc-video-plugin.c | 4 ++++ plugins/vlc-video/vlc-video-plugin.h | 5 +++++ plugins/vlc-video/vlc-video-source.c | 21 ++++++++++++++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/plugins/vlc-video/vlc-video-plugin.c b/plugins/vlc-video/vlc-video-plugin.c index 0cbe7aa54..49c4e4843 100644 --- a/plugins/vlc-video/vlc-video-plugin.c +++ b/plugins/vlc-video/vlc-video-plugin.c @@ -16,6 +16,8 @@ LIBVLC_EVENT_ATTACH libvlc_event_attach_; /* libvlc media */ LIBVLC_MEDIA_NEW_PATH libvlc_media_new_path_; +LIBVLC_MEDIA_NEW_LOCATION libvlc_media_new_location_; +LIBVLC_MEDIA_ADD_OPTION libvlc_media_add_option_; LIBVLC_MEDIA_RELEASE libvlc_media_release_; LIBVLC_MEDIA_RELEASE libvlc_media_retain_; @@ -76,6 +78,8 @@ static bool load_vlc_funcs(void) /* libvlc media */ LOAD_VLC_FUNC(libvlc_media_new_path); + LOAD_VLC_FUNC(libvlc_media_new_location); + LOAD_VLC_FUNC(libvlc_media_add_option); LOAD_VLC_FUNC(libvlc_media_release); LOAD_VLC_FUNC(libvlc_media_retain); diff --git a/plugins/vlc-video/vlc-video-plugin.h b/plugins/vlc-video/vlc-video-plugin.h index 9eefb39ec..53cb2551e 100644 --- a/plugins/vlc-video/vlc-video-plugin.h +++ b/plugins/vlc-video/vlc-video-plugin.h @@ -29,6 +29,9 @@ typedef int (*LIBVLC_EVENT_ATTACH)(libvlc_event_manager_t *p_event_manager, /* libvlc media */ typedef libvlc_media_t *(*LIBVLC_MEDIA_NEW_PATH)( libvlc_instance_t *p_instance, const char *path); +typedef libvlc_media_t *(*LIBVLC_MEDIA_NEW_LOCATION)( + libvlc_instance_t *p_instance, const char *location); +typedef void (*LIBVLC_MEDIA_ADD_OPTION)(libvlc_media_t *p_md, const char *options); typedef void (*LIBVLC_MEDIA_RETAIN)(libvlc_media_t *p_md); typedef void (*LIBVLC_MEDIA_RELEASE)(libvlc_media_t *p_md); @@ -119,6 +122,8 @@ extern LIBVLC_EVENT_ATTACH libvlc_event_attach_; /* libvlc media */ extern LIBVLC_MEDIA_NEW_PATH libvlc_media_new_path_; +extern LIBVLC_MEDIA_NEW_LOCATION libvlc_media_new_location_; +extern LIBVLC_MEDIA_ADD_OPTION libvlc_media_add_option_; extern LIBVLC_MEDIA_RELEASE libvlc_media_release_; extern LIBVLC_MEDIA_RETAIN libvlc_media_retain_; diff --git a/plugins/vlc-video/vlc-video-source.c b/plugins/vlc-video/vlc-video-source.c index 824d57cc5..5c4079bbe 100644 --- a/plugins/vlc-video/vlc-video-source.c +++ b/plugins/vlc-video/vlc-video-source.c @@ -76,7 +76,9 @@ static libvlc_media_t *get_media(struct darray *array, const char *path) static inline libvlc_media_t *create_media_from_file(const char *file) { - return libvlc_media_new_path_(libvlc, file); + return (file && strstr(file, "://") != NULL) + ? libvlc_media_new_location_(libvlc, file) + : libvlc_media_new_path_(libvlc, file); } static void free_files(struct darray *array) @@ -299,11 +301,18 @@ static unsigned vlcs_video_format(void **p_data, char *chroma, unsigned *width, enum video_format new_format; enum video_range_type range; bool new_range; + unsigned new_width = 0; + unsigned new_height = 0; size_t i = 0; new_format = convert_vlc_video_format(chroma, &new_range); - libvlc_video_get_size_(c->media_player, 0, width, height); + libvlc_video_get_size_(c->media_player, 0, &new_width, &new_height); + + if (new_width && new_height) { + *width = new_width; + *height = new_height; + } /* don't allocate a new frame if format/width/height hasn't changed */ if (c->frame.format != new_format || @@ -382,12 +391,14 @@ static void add_file(struct vlc_source *c, struct darray *array, struct media_file_data data; struct dstr new_path = {0}; libvlc_media_t *new_media; + bool is_url = path && strstr(path, "://") != NULL; new_files.da = *array; dstr_copy(&new_path, path); #ifdef _WIN32 - dstr_replace(&new_path, "/", "\\"); + if (!is_url) + dstr_replace(&new_path, "/", "\\"); #endif path = new_path.array; @@ -399,6 +410,10 @@ static void add_file(struct vlc_source *c, struct darray *array, new_media = create_media_from_file(path); if (new_media) { + if (is_url) + libvlc_media_add_option_(new_media, + ":network-caching=100"); + data.path = new_path.array; data.media = new_media; da_push_back(new_files, &data);