소스 검색

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
Andreas Reischuck 9 년 전
부모
커밋
e6f950fde9
3개의 변경된 파일27개의 추가작업 그리고 3개의 파일을 삭제
  1. 4 0
      plugins/vlc-video/vlc-video-plugin.c
  2. 5 0
      plugins/vlc-video/vlc-video-plugin.h
  3. 18 3
      plugins/vlc-video/vlc-video-source.c

+ 4 - 0
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);
 

+ 5 - 0
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_;
 

+ 18 - 3
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);