Skip to content

Commit

Permalink
Fix loading and exporting of Theora and WebM video streams
Browse files Browse the repository at this point in the history
Theora and WebM video streams were mistakenly imported with a ResourceImporter,
but those imported ogvstr and webmstr were simply links to the local resource.
While that works fine in the editor, it no longer works when exporting a game
as the "source" ogv and webm files are ommitted and only the ogvstr and webmstr
references were exported.

As discussed with @reduz, it doesn't make sense to import videos, as we only
intend to play them back and not modify them/access their raw data. As such we
use a ResourceFormatLoader instead of an importer, to load the file on the fly.
ogv and webm files linked to this loader are now considered as resources, and
thus exported.

Note: The Theora and WebM loaders lack any kind of validity check beyond the
existence of the target file, but it was already the case with the importer.
Better checks and error reports could be added, but those loaders will eventually
be obsoleted by GDNative plugins anyway.

Fixes godotengine#14954.
  • Loading branch information
akien-mga authored and malcolmhoward committed Jul 31, 2018
1 parent 42b2743 commit eed0e67
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 344 deletions.
15 changes: 0 additions & 15 deletions modules/theora/doc_classes/ResourceImporterTheora.xml

This file was deleted.

16 changes: 10 additions & 6 deletions modules/theora/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,22 @@
/*************************************************************************/

#include "register_types.h"
#include "resource_importer_theora.h"

#include "video_stream_theora.h"

static ResourceFormatLoaderTheora *resource_loader_theora = NULL;

void register_theora_types() {

#ifdef TOOLS_ENABLED
Ref<ResourceImporterTheora> theora_import;
theora_import.instance();
ResourceFormatImporter::get_singleton()->add_importer(theora_import);
#endif
resource_loader_theora = memnew(ResourceFormatLoaderTheora);
ResourceLoader::add_resource_format_loader(resource_loader_theora, true);

ClassDB::register_class<VideoStreamTheora>();
}

void unregister_theora_types() {

if (resource_loader_theora) {
memdelete(resource_loader_theora);
}
}
90 changes: 0 additions & 90 deletions modules/theora/resource_importer_theora.cpp

This file was deleted.

58 changes: 0 additions & 58 deletions modules/theora/resource_importer_theora.h

This file was deleted.

43 changes: 43 additions & 0 deletions modules/theora/video_stream_theora.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,3 +730,46 @@ void VideoStreamTheora::_bind_methods() {

ADD_PROPERTY(PropertyInfo(Variant::STRING, "file", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "set_file", "get_file");
}

////////////

RES ResourceFormatLoaderTheora::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();
}

VideoStreamTheora *stream = memnew(VideoStreamTheora);
stream->set_file(p_path);

Ref<VideoStreamTheora> ogv_stream = Ref<VideoStreamTheora>(stream);

if (r_error) {
*r_error = OK;
}

return ogv_stream;
}

void ResourceFormatLoaderTheora::get_recognized_extensions(List<String> *p_extensions) const {

p_extensions->push_back("ogv");
}

bool ResourceFormatLoaderTheora::handles_type(const String &p_type) const {

return ClassDB::is_parent_class(p_type, "VideoStream");
}

String ResourceFormatLoaderTheora::get_resource_type(const String &p_path) const {

String el = p_path.get_extension().to_lower();
if (el == "ogv")
return "VideoStreamTheora";
return "";
}
10 changes: 9 additions & 1 deletion modules/theora/video_stream_theora.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class VideoStreamPlaybackTheora : public VideoStreamPlayback {
class VideoStreamTheora : public VideoStream {

GDCLASS(VideoStreamTheora, VideoStream);
RES_BASE_EXTENSION("ogvstr");
RES_BASE_EXTENSION("ogv");

String file;
int audio_track;
Expand All @@ -186,4 +186,12 @@ class VideoStreamTheora : public VideoStream {
VideoStreamTheora() { audio_track = 0; }
};

class ResourceFormatLoaderTheora : public ResourceFormatLoader {
public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
};

#endif
15 changes: 0 additions & 15 deletions modules/webm/doc_classes/ResourceImporterWebm.xml

This file was deleted.

16 changes: 10 additions & 6 deletions modules/webm/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,22 @@
/*************************************************************************/

#include "register_types.h"
#include "resource_importer_webm.h"

#include "video_stream_webm.h"

static ResourceFormatLoaderWebm *resource_loader_webm = NULL;

void register_webm_types() {

#ifdef TOOLS_ENABLED
Ref<ResourceImporterWebm> webm_import;
webm_import.instance();
ResourceFormatImporter::get_singleton()->add_importer(webm_import);
#endif
resource_loader_webm = memnew(ResourceFormatLoaderWebm);
ResourceLoader::add_resource_format_loader(resource_loader_webm, true);

ClassDB::register_class<VideoStreamWebm>();
}

void unregister_webm_types() {

if (resource_loader_webm) {
memdelete(resource_loader_webm);
}
}
Loading

0 comments on commit eed0e67

Please sign in to comment.