-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathvideo_stream_ffmpeg_loader.cpp
112 lines (100 loc) · 4.85 KB
/
video_stream_ffmpeg_loader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**************************************************************************/
/* video_stream_ffmpeg_loader.cpp */
/**************************************************************************/
/* This file is part of: */
/* EIRTeam.FFmpeg */
/* https://ph.eirteam.moe */
/**************************************************************************/
/* Copyright (c) 2023-present Álex Román (EIRTeam) & contributors. */
/* */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "video_stream_ffmpeg_loader.h"
extern "C" {
#include "libavformat/avformat.h"
}
#include "ffmpeg_video_stream.h"
void VideoStreamFFMpegLoader::_update_recognized_extension_cache() const {
if (recognized_extension_cache.size() > 0) {
return;
}
void *iteration_state = nullptr;
const AVInputFormat *current_fmt = nullptr;
while ((current_fmt = av_demuxer_iterate(&iteration_state)) != nullptr) {
if (current_fmt->extensions == nullptr) {
continue;
}
PackedStringArray demuxer_exts = String(current_fmt->extensions).split(",", false);
const_cast<VideoStreamFFMpegLoader *>(this)->recognized_extension_cache.append_array(demuxer_exts);
}
}
String VideoStreamFFMpegLoader::get_resource_type_internal(const String &p_path) const {
_update_recognized_extension_cache();
if (recognized_extension_cache.has(p_path.get_extension())) {
return "VideoStreamFFMpegLoader";
}
return "";
}
Ref<Resource> VideoStreamFFMpegLoader::load_internal(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) const {
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
if (f.is_null()) {
if (r_error) {
*r_error = ERR_CANT_OPEN;
}
return Ref<Resource>();
}
Ref<FFmpegVideoStream> stream;
stream.instantiate();
stream->set_file(p_path);
if (r_error) {
*r_error = OK;
}
return stream;
}
bool VideoStreamFFMpegLoader::handles_type_internal(const String &p_type) const {
#ifdef GDEXTENSION
return p_type == "VideoStream";
#else
return ClassDB::is_parent_class(p_type, "VideoStreamFFMpegLoader");
#endif
}
#ifdef GDEXTENSION
PackedStringArray VideoStreamFFMpegLoader::_get_recognized_extensions() const {
_update_recognized_extension_cache();
return recognized_extension_cache;
}
bool VideoStreamFFMpegLoader::_handles_type(const StringName &p_type) const {
return VideoStreamFFMpegLoader::handles_type_internal(p_type);
}
Variant VideoStreamFFMpegLoader::_load(const String &p_path, const String &p_original_path, bool p_use_sub_threads, int32_t p_cache_mode) const {
return load_internal(p_path, p_original_path, nullptr, p_use_sub_threads, nullptr, (CacheMode)p_cache_mode);
}
#else
void VideoStreamFFMpegLoader::get_recognized_extensions(List<String> *p_extensions) const {
_update_recognized_extension_cache();
for (String ext : recognized_extension_cache) {
p_extensions->push_back(ext);
}
}
Ref<Resource> VideoStreamFFMpegLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
return load_internal(p_path, p_original_path, r_error, p_use_sub_threads, r_progress, p_cache_mode);
}
#endif