Skip to content

Commit 1acb720

Browse files
starryalleyfire
authored andcommitted
Add WMF video playing (audio control isn't implemented)
Thanks to the DisplaySweet team https://github.com/DisplaySweet. Implement WMF video resource loading and playback functionality Audio does not work yet. Co-Authored-by: Mark Kuo <starryalley@gmail.com>
1 parent e0603ae commit 1acb720

11 files changed

+1487
-0
lines changed

modules/wmf/SCsub

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python
2+
from misc.utility.scons_hints import *
3+
4+
Import("env")
5+
6+
if env.msvc:
7+
env.Append(
8+
LINKFLAGS=["mfplat.lib", "mf.lib", "wmcodecdspuuid.lib", "mfuuid.lib", "mfreadwrite.lib", "strmiids.lib"]
9+
)
10+
else:
11+
env.Append(LIBS=["mfplat", "mf", "wmcodecdspuuid", "mfuuid", "mfreadwrite", "strmiids"])
12+
13+
Import("env_modules")
14+
15+
env_wmf = env_modules.Clone()
16+
17+
env_wmf.add_source_files(env.modules_sources, "*.cpp")
18+
Export("env")

modules/wmf/config.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def can_build(env, platform):
2+
return platform == "windows"
3+
4+
5+
def configure(env):
6+
pass
7+
8+
9+
def get_doc_classes():
10+
return [
11+
"WindowsMediaFoundation",
12+
]
13+
14+
15+
def get_doc_path():
16+
return "doc_classes"

modules/wmf/register_types.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**************************************************************************/
2+
/* register_types.cpp */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#include "register_types.h"
32+
#include "resource_importer_wmf_video.h"
33+
#include "video_stream_wmf.h"
34+
35+
#include "mfapi.h"
36+
#include <stdio.h>
37+
38+
static Ref<ResourceFormatLoaderWMF> resource_loader_wmf;
39+
40+
void initialize_wmf_module(ModuleInitializationLevel p_level) {
41+
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
42+
return;
43+
}
44+
MFStartup(MF_VERSION, MFSTARTUP_FULL);
45+
46+
resource_loader_wmf.instantiate();
47+
ResourceLoader::add_resource_format_loader(resource_loader_wmf, true);
48+
49+
#ifdef TOOLS_ENABLED
50+
Ref<ResourceImporterWMFVideo> wmfv_import;
51+
wmfv_import.instantiate();
52+
ResourceFormatImporter::get_singleton()->add_importer(wmfv_import);
53+
#endif
54+
GDREGISTER_CLASS(VideoStreamWMF);
55+
}
56+
57+
void uninitialize_wmf_module(ModuleInitializationLevel p_level) {
58+
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
59+
return;
60+
}
61+
ResourceLoader::remove_resource_format_loader(resource_loader_wmf);
62+
resource_loader_wmf.unref();
63+
MFShutdown();
64+
}

modules/wmf/register_types.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**************************************************************************/
2+
/* register_types.h */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#pragma once
32+
33+
#include "modules/register_module_types.h"
34+
35+
void initialize_wmf_module(ModuleInitializationLevel p_level);
36+
void uninitialize_wmf_module(ModuleInitializationLevel p_level);
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**************************************************************************/
2+
/* resource_importer_wmf_video.cpp */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#include "resource_importer_wmf_video.h"
32+
33+
#include "core/error/error_list.h"
34+
#include "core/error/error_macros.h"
35+
#include "core/io/file_access.h"
36+
#include "core/io/resource_saver.h"
37+
#include "video_stream_wmf.h"
38+
39+
String ResourceImporterWMFVideo::get_importer_name() const {
40+
return "WindowsMediaFoundation";
41+
}
42+
43+
String ResourceImporterWMFVideo::get_visible_name() const {
44+
return "WindowsMediaFoundation";
45+
}
46+
47+
void ResourceImporterWMFVideo::get_recognized_extensions(List<String> *p_extensions) const {
48+
p_extensions->push_back("mp4");
49+
p_extensions->push_back("avi");
50+
p_extensions->push_back("mkv");
51+
p_extensions->push_back("webm");
52+
}
53+
54+
String ResourceImporterWMFVideo::get_save_extension() const {
55+
return "wmfvstr";
56+
}
57+
58+
String ResourceImporterWMFVideo::get_resource_type() const {
59+
return "VideoStreamWMF";
60+
}
61+
62+
bool ResourceImporterWMFVideo::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
63+
return true;
64+
}
65+
66+
int ResourceImporterWMFVideo::get_preset_count() const {
67+
return 0;
68+
}
69+
70+
String ResourceImporterWMFVideo::get_preset_name(int p_idx) const {
71+
return String();
72+
}
73+
74+
void ResourceImporterWMFVideo::get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset) const {
75+
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "loop"), false));
76+
}
77+
78+
Error ResourceImporterWMFVideo::import(ResourceUID::ID p_source_id, const String &p_source_file, const String &p_save_path, const HashMap<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
79+
ERR_FAIL_COND_V(p_source_file.is_empty(), ERR_INVALID_PARAMETER);
80+
81+
// Load the video file data into memory
82+
Error err;
83+
Ref<FileAccess> file = FileAccess::open(p_source_file, FileAccess::READ, &err);
84+
ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot open file '" + p_source_file + "'.");
85+
86+
Vector<uint8_t> data;
87+
uint64_t len = file->get_length();
88+
data.resize(len);
89+
uint64_t bytes_read = file->get_buffer(data.ptrw(), len);
90+
ERR_FAIL_COND_V(bytes_read == 0, ERR_FILE_CORRUPT);
91+
ERR_FAIL_COND_V_MSG(bytes_read != len, ERR_FILE_CORRUPT, "Cannot read file '" + p_source_file + "'.");
92+
file.unref();
93+
94+
Ref<VideoStreamWMF> wmfv_stream;
95+
wmfv_stream.instantiate();
96+
wmfv_stream->set_file(p_source_file); // Keep file path for fallback
97+
return ResourceSaver::save(wmfv_stream, p_save_path + ".wmfvstr");
98+
}
99+
100+
ResourceImporterWMFVideo::ResourceImporterWMFVideo() {
101+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**************************************************************************/
2+
/* resource_importer_wmf_video.h */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#pragma once
32+
33+
#include "core/io/resource_importer.h"
34+
35+
class ResourceImporterWMFVideo : public ResourceImporter {
36+
GDCLASS(ResourceImporterWMFVideo, ResourceImporter)
37+
38+
public:
39+
virtual String get_importer_name() const override;
40+
virtual String get_visible_name() const override;
41+
virtual void get_recognized_extensions(List<String> *p_extensions) const override;
42+
virtual String get_save_extension() const override;
43+
virtual String get_resource_type() const override;
44+
45+
virtual int get_preset_count() const override;
46+
virtual String get_preset_name(int p_idx) const override;
47+
virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override;
48+
virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
49+
50+
virtual Error import(ResourceUID::ID p_source_id, const String &p_source_file, const String &p_save_path, const HashMap<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override;
51+
52+
ResourceImporterWMFVideo();
53+
};

0 commit comments

Comments
 (0)