GCC Code Coverage Report


Directory: src/gate/
File: src/gate/io/cxx_videosources.cpp
Date: 2026-03-20 22:56:14
Exec Total Coverage
Lines: 0 158 0.0%
Functions: 0 43 0.0%
Branches: 0 90 0.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright (c) 2018-2026, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/io/videosources.hpp"
30
31 namespace gate
32 {
33 namespace io
34 {
35
36 VideoFormat::VideoFormat()
37 {
38 gate_video_format_t& fmt = *this;
39 Mem::clear(fmt);
40 }
41 VideoFormat::VideoFormat(VideoFormat const& source)
42 {
43 gate_video_format_t const& src = source;
44 gate_video_format_t& dst = *this;
45 Mem::copy(dst, src);
46 }
47 VideoFormat::VideoFormat(gate_video_format_t const& src)
48 {
49 gate_video_format_t& dst = *this;
50 Mem::copy(dst, src);
51 }
52 VideoFormat& VideoFormat::operator=(VideoFormat const& source)
53 {
54 gate_video_format_t const& src = source;
55 gate_video_format_t& dst = *this;
56 Mem::copy(dst, src);
57 return *this;
58 }
59 VideoFormat& VideoFormat::operator=(gate_video_format_t const& src)
60 {
61 gate_video_format_t& dst = *this;
62 Mem::copy(dst, src);
63 return *this;
64 }
65 VideoFormat::~VideoFormat() noexcept
66 {
67 }
68
69
70 hash_code_t VideoFormat::hashCode() const
71 {
72 return gate_video_format_hash(this);
73 }
74
75
76
77
78
79
80
81 VideoFrame::VideoFrame(VideoFormat const& format)
82 {
83 gate_video_frame_init(&this->impl, &format);
84 }
85 VideoFrame::VideoFrame(VideoFrame const& src)
86 {
87 gate_video_frame_copy(&this->impl, &src.impl);
88 }
89 VideoFrame& VideoFrame::operator=(VideoFrame const& src)
90 {
91 VideoFrame that(src);
92 this->swap(that);
93 return *this;
94 }
95 VideoFrame::~VideoFrame() noexcept
96 {
97 gate_video_frame_release(&this->impl);
98 }
99 void VideoFrame::swap(VideoFrame& that) noexcept
100 {
101 gate::swapRefsNoExcept(this->impl, that.impl);
102 }
103
104 VideoFormat VideoFrame::getFormat() const
105 {
106 return VideoFormat(this->impl.format);
107 }
108 VideoFrame::RasterImage VideoFrame::getImage() const
109 {
110 return RasterImage(&this->impl.image);
111 }
112 int64_t const& VideoFrame::getRecordTime() const
113 {
114 return this->impl.record_time;
115 }
116 gate_video_frame_t* VideoFrame::c_impl()
117 {
118 return &this->impl;
119 }
120 gate_video_frame_t const* VideoFrame::c_impl() const
121 {
122 return &this->impl;
123 }
124
125
126
127
128 VideoReader::VideoReader(gate_video_reader_t* impl)
129 : object_impl_t(impl)
130 {
131 }
132
133 void VideoReader::read(VideoFrame& frame)
134 {
135 result_t result = gate_video_source_read(this->c_impl(), frame.c_impl());
136 GATEXX_CHECK_EXCEPTION(result);
137 }
138
139
140
141
142 VideoSource::VideoSource(gate_video_source_t* impl)
143 : VideoReader((gate_video_reader_t*)impl)
144 {
145 }
146
147 gate_video_source_t* VideoSource::c_impl() const noexcept
148 {
149 return (gate_video_source_t*)VideoReader::c_impl();
150 }
151
152
153 String VideoSource::getId() const
154 {
155 String str(gate_video_source_get_id(this->c_impl()));
156 return str;
157 }
158 String VideoSource::getName() const
159 {
160 String str(gate_video_source_get_name(this->c_impl()));
161 return str;
162 }
163 intptr_t VideoSource::getHandle() const
164 {
165 return gate_video_source_get_handle(this->c_impl());
166 }
167
168 Array<VideoFormat> VideoSource::getSupportedFormats()
169 {
170 gate_video_format_t formats[256];
171 gate_size_t formats_count = sizeof(formats) / sizeof(formats[0]);
172 formats_count = gate_video_source_get_supported_formats(this->c_impl(), formats, formats_count);
173
174 ArrayList<VideoFormat> formatList(formats_count);
175 formatList.addItems(&formats[0], &formats[formats_count]);
176 return formatList.toArray();
177 }
178
179 void VideoSource::open(VideoFormat const& format)
180 {
181 result_t result = gate_video_source_open(this->c_impl(), &format);
182 GATEXX_CHECK_EXCEPTION(result);
183 }
184 void VideoSource::close()
185 {
186 result_t result = gate_video_source_close(this->c_impl());
187 GATEXX_CHECK_EXCEPTION(result);
188 }
189
190
191 struct GATE_API_LOCAL VideoSourcesDispatcherData
192 {
193 VideoSources::EnumCallback const* cb;
194 void* param;
195 };
196
197 static gate_result_t VideoSources_enumSources_callback(gate_video_source_t* source, void* param)
198 {
199 VideoSourcesDispatcherData* data = static_cast<VideoSourcesDispatcherData*>(param);
200 VideoSource vsrc(source);
201 gate_object_retain(source);
202 ExceptionInfo xcptInfo;
203 GATEXX_TRY_CATCHINFO(xcptInfo, {
204 data->cb->invoke(vsrc, data->param);
205 });
206 return xcptInfo.result_code;
207 }
208
209 void VideoSources::enumSources(EnumCallback const& callback, void* param)
210 {
211 VideoSourcesDispatcherData dispatcher_data;
212 dispatcher_data.cb = &callback;
213 dispatcher_data.param = param;
214
215 gate_delegate_t dispatcher_callback;
216 GATE_DELEGATE_BIND_FUNC(gate_video_sources_enum_callback, &dispatcher_callback, VideoSources_enumSources_callback);
217
218 result_t result = gate_video_sources_enum(&dispatcher_callback, &dispatcher_data);
219 GATEXX_CHECK_EXCEPTION(result);
220 }
221
222
223 static gate_result_t VideoSources_enumSources_array_callback(gate_video_source_t* source, void* param)
224 {
225 ArrayList<VideoSource>* ptr_sources = static_cast<ArrayList<VideoSource>*>(param);
226 ExceptionInfo xcptInfo;
227 GATEXX_TRY_CATCHINFO(xcptInfo, {
228 VideoSource vsrc(source);
229 gate_object_retain(source);
230 ptr_sources->add(vsrc);
231 });
232 return xcptInfo.result_code;
233 }
234
235 Array<VideoSource> VideoSources::enumSources()
236 {
237 ArrayList<VideoSource> sources;
238
239 gate_delegate_t dispatcher_callback;
240 GATE_DELEGATE_BIND_FUNC(gate_video_sources_enum_callback, &dispatcher_callback, VideoSources_enumSources_array_callback);
241
242 result_t result = gate_video_sources_enum(&dispatcher_callback, &sources);
243 GATEXX_CHECK_EXCEPTION(result);
244
245 return sources.toArray();
246 }
247
248
249 VideoSource VideoSources::getSource(String const& id)
250 {
251 char id_buffer[4096];
252 gate_size_t len_used;
253 gate_video_source_t* ptr_source = NULL;
254
255 len_used = id.copyTo(id_buffer, sizeof(id_buffer));
256
257 gate_result_t result = gate_video_source_by_id(id_buffer, &ptr_source);
258 GATEXX_CHECK_EXCEPTION(result);
259 return VideoSource(ptr_source);
260 }
261
262
263 static gate_video_screencontrol_t* create_video_screencontrol_instance()
264 {
265 gate_video_screencontrol_t* ret = NULL;
266 gate_result_t result = gate_video_screencontrol_create(&ret);
267 GATEXX_CHECK_EXCEPTION(result);
268 return ret;
269 }
270
271 VideoScreenControl::VideoScreenControl()
272 : VideoSource((gate_video_source_t*)create_video_screencontrol_instance())
273 {
274
275 }
276
277 VideoScreenControl::VideoScreenControl(gate_video_screencontrol_t* ptr_screen)
278 : VideoSource((gate_video_source_t*)ptr_screen)
279 {
280 }
281
282 gate_video_screencontrol_t* VideoScreenControl::c_impl() const noexcept
283 {
284 return (gate_video_screencontrol_t*)VideoSource::c_impl();
285 }
286
287
288 void VideoScreenControl::getCursorPos(int32_t& x, int32_t& y)
289 {
290 result_t result = gate_video_screencontrol_get_cursor_pos(this->c_impl(), &x, &y);
291 GATEXX_CHECK_EXCEPTION(result);
292 }
293
294 void VideoScreenControl::moveCurspor(int32_t x, int32_t y)
295 {
296 result_t result = gate_video_screencontrol_move_cursor(this->c_impl(), x, y);
297 GATEXX_CHECK_EXCEPTION(result);
298 }
299
300 void VideoScreenControl::changeCursorButtonState(int32_t x, int32_t y, enumint_t buttonId, enumint_t buttonState)
301 {
302 result_t result = gate_video_screencontrol_change_cursor_button_state(this->c_impl(), x, y, buttonId, buttonState);
303 GATEXX_CHECK_EXCEPTION(result);
304 }
305
306 void VideoScreenControl::changeKeyState(gate_input_keycode_t key_code, gate_enumint_t key_state)
307 {
308 result_t result = gate_video_screencontrol_change_key_state(this->c_impl(), key_code, key_state);
309 GATEXX_CHECK_EXCEPTION(result);
310 }
311
312
313
314 VideoWriter::VideoWriter(gate_video_writer_t* impl)
315 : object_impl_t(impl)
316 {
317 }
318
319 void VideoWriter::write(VideoFrame const& frame)
320 {
321 result_t result = gate_video_writer_write(this->c_impl(), frame.c_impl());
322 GATEXX_CHECK_EXCEPTION(result);
323 }
324
325
326
327
328 VideoWriter VideoFileWriter::create(FileTypeEnum fileType, String const& path, VideoFormat const& format)
329 {
330 gate_video_writer_t* ptr_writer = NULL;
331 result_t result = gate_video_filewriter_create((gate_enumint_t)fileType, path.c_impl(), &format, &ptr_writer);
332 GATEXX_CHECK_EXCEPTION(result);
333 return VideoWriter(ptr_writer);
334 }
335
336
337 } // end of namespace io
338 } // end of namespace gate
339