Debian Codegraph @

scene/resources/video_stream.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* video_stream.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 "video_stream.h"
32
33 // VideoStreamPlayback starts here.
34
35 void VideoStreamPlayback::_bind_methods() {
36 ClassDB::bind_method(D_METHOD("mix_audio", "num_frames", "buffer", "offset"), &VideoStreamPlayback::mix_audio, DEFVAL(PackedFloat32Array()), DEFVAL(0));
37 GDVIRTUAL_BIND(_stop);
38 GDVIRTUAL_BIND(_play);
39 GDVIRTUAL_BIND(_is_playing);
40 GDVIRTUAL_BIND(_set_paused, "paused");
41 GDVIRTUAL_BIND(_is_paused);
42 GDVIRTUAL_BIND(_get_length);
43 GDVIRTUAL_BIND(_get_playback_position);
44 GDVIRTUAL_BIND(_seek, "time");
45 GDVIRTUAL_BIND(_set_audio_track, "idx");
46 GDVIRTUAL_BIND(_get_texture);
47 GDVIRTUAL_BIND(_update, "delta");
48 GDVIRTUAL_BIND(_get_channels);
49 GDVIRTUAL_BIND(_get_mix_rate);
50 }
51
52 VideoStreamPlayback::VideoStreamPlayback() {
53 }
54
55 VideoStreamPlayback::~VideoStreamPlayback() {
56 }
57
58 void VideoStreamPlayback::stop() {
59 GDVIRTUAL_CALL(_stop);
60 }
61
62 void VideoStreamPlayback::play() {
63 GDVIRTUAL_CALL(_play);
64 }
65
66 bool VideoStreamPlayback::is_playing() const {
67 bool ret;
68 if (GDVIRTUAL_CALL(_is_playing, ret)) {
69 return ret;
70 }
71 return false;
72 }
73
74 void VideoStreamPlayback::set_paused(bool p_paused) {
75 GDVIRTUAL_CALL(_set_paused, p_paused);
76 }
77
78 bool VideoStreamPlayback::is_paused() const {
79 bool ret;
80 if (GDVIRTUAL_CALL(_is_paused, ret)) {
81 return ret;
82 }
83 return false;
84 }
85
86 double VideoStreamPlayback::get_length() const {
87 double ret;
88 if (GDVIRTUAL_CALL(_get_length, ret)) {
89 return ret;
90 }
91 return 0;
92 }
93
94 double VideoStreamPlayback::get_playback_position() const {
95 double ret;
96 if (GDVIRTUAL_CALL(_get_playback_position, ret)) {
97 return ret;
98 }
99 return 0;
100 }
101
102 void VideoStreamPlayback::seek(double p_time) {
103 GDVIRTUAL_CALL(_seek, p_time);
104 }
105
106 void VideoStreamPlayback::set_audio_track(int p_idx) {
107 GDVIRTUAL_CALL(_set_audio_track, p_idx);
108 }
109
110 Ref<Texture2D> VideoStreamPlayback::get_texture() const {
111 Ref<Texture2D> ret;
112 if (GDVIRTUAL_CALL(_get_texture, ret)) {
113 return ret;
114 }
115 return nullptr;
116 }
117
118 void VideoStreamPlayback::update(double p_delta) {
119 GDVIRTUAL_CALL(_update, p_delta);
120 }
121
122 void VideoStreamPlayback::set_mix_callback(AudioMixCallback p_callback, void *p_userdata) {
123 mix_callback = p_callback;
124 mix_udata = p_userdata;
125 }
126
127 int VideoStreamPlayback::get_channels() const {
128 int ret;
129 if (GDVIRTUAL_CALL(_get_channels, ret)) {
130 _channel_count = ret;
131 return ret;
132 }
133 return 0;
134 }
135
136 int VideoStreamPlayback::get_mix_rate() const {
137 int ret;
138 if (GDVIRTUAL_CALL(_get_mix_rate, ret)) {
139 return ret;
140 }
141 return 0;
142 }
143
144 int VideoStreamPlayback::mix_audio(int num_frames, PackedFloat32Array buffer, int offset) {
145 if (num_frames <= 0) {
146 return 0;
147 }
148 if (!mix_callback) {
149 return -1;
150 }
151 ERR_FAIL_INDEX_V(offset, buffer.size(), -1);
152 ERR_FAIL_INDEX_V((_channel_count < 1 ? 1 : _channel_count) * num_frames - 1, buffer.size() - offset, -1);
153 return mix_callback(mix_udata, buffer.ptr() + offset, num_frames);
154 }
155
156 /* --- NOTE VideoStream starts here. ----- */
157
158 Ref<VideoStreamPlayback> VideoStream::instantiate_playback() {
159 Ref<VideoStreamPlayback> ret;
160 if (GDVIRTUAL_CALL(_instantiate_playback, ret)) {
161 ERR_FAIL_COND_V_MSG(ret.is_null(), nullptr, "Plugin returned null playback");
162 ret->set_audio_track(audio_track);
163 return ret;
164 }
165 return nullptr;
166 }
167
168 void VideoStream::set_file(const String &p_file) {
169 file = p_file;
170 emit_changed();
171 }
172
173 String VideoStream::get_file() {
174 return file;
175 }
176
177 void VideoStream::_bind_methods() {
178 ClassDB::bind_method(D_METHOD("set_file", "file"), &VideoStream::set_file);
179 ClassDB::bind_method(D_METHOD("get_file"), &VideoStream::get_file);
180
181 ADD_PROPERTY(PropertyInfo(Variant::STRING, "file"), "set_file", "get_file");
182
183 GDVIRTUAL_BIND(_instantiate_playback);
184 }
185
186 VideoStream::VideoStream() {
187 }
188
189 VideoStream::~VideoStream() {
190 }
191
192 void VideoStream::set_audio_track(int p_track) {
193 audio_track = p_track;
194 }