1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

Adapt GDNative VideoStream to use ResourceFormatLoader

Same logic as used for Webm and Theora support in #19937 and #21084,
fixing issues when exporting projects.
This commit is contained in:
Rémi Verschelde
2018-12-12 15:47:57 +01:00
parent 012dac9aad
commit 72feccf205
5 changed files with 55 additions and 160 deletions

View File

@@ -346,3 +346,42 @@ void VideoStreamGDNative::set_audio_track(int p_track) {
audio_track = p_track;
}
/* --- NOTE ResourceFormatLoaderVideoStreamGDNative starts here. ----- */
RES ResourceFormatLoaderVideoStreamGDNative::load(const String &p_path, const String &p_original_path, Error *r_error) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f) {
if (r_error) {
*r_error = ERR_CANT_OPEN;
}
memdelete(f);
return RES();
}
VideoStreamGDNative *stream = memnew(VideoStreamGDNative);
stream->set_file(p_path);
Ref<VideoStreamGDNative> ogv_stream = Ref<VideoStreamGDNative>(stream);
if (r_error) {
*r_error = OK;
}
return ogv_stream;
}
void ResourceFormatLoaderVideoStreamGDNative::get_recognized_extensions(List<String> *p_extensions) const {
Map<String, int>::Element *el = VideoDecoderServer::get_instance()->get_extensions().front();
while (el) {
p_extensions->push_back(el->key());
el = el->next();
}
}
bool ResourceFormatLoaderVideoStreamGDNative::handles_type(const String &p_type) const {
return ClassDB::is_parent_class(p_type, "VideoStream");
}
String ResourceFormatLoaderVideoStreamGDNative::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
if (VideoDecoderServer::get_instance()->get_extensions().has(el))
return "VideoStreamGDNative";
return "";
}