|
| 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 | +} |
0 commit comments