GCC Code Coverage Report


Directory: src/gate/
File: src/gate/io/cxx_videosources.cpp
Date: 2025-09-22 22:57:09
Exec Total Coverage
Lines: 0 166 0.0%
Functions: 0 43 0.0%
Branches: 0 76 0.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, 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 try
203 {
204 ✗ data->cb->invoke(vsrc, data->param);
205 ✗ return results::Ok;
206 }
207 ✗ catch (Throwable const& xcpt)
208 {
209 ✗ return xcpt.getResult();
210 }
211 ✗ catch (...)
212 {
213 ✗ return results::UnknownException;
214 }
215 }
216
217 ✗ void VideoSources::enumSources(EnumCallback const& callback, void* param)
218 {
219 VideoSourcesDispatcherData dispatcher_data;
220 ✗ dispatcher_data.cb = &callback;
221 ✗ dispatcher_data.param = param;
222
223 gate_delegate_t dispatcher_callback;
224 ✗ GATE_DELEGATE_BIND_FUNC(gate_video_sources_enum_callback, &dispatcher_callback, VideoSources_enumSources_callback);
225
226 ✗ result_t result = gate_video_sources_enum(&dispatcher_callback, &dispatcher_data);
227 ✗ GATEXX_CHECK_EXCEPTION(result);
228 ✗ }
229
230
231 ✗ static gate_result_t VideoSources_enumSources_array_callback(gate_video_source_t* source, void* param)
232 {
233 ✗ ArrayList<VideoSource>* ptr_sources = static_cast<ArrayList<VideoSource>*>(param);
234 try
235 {
236 ✗ VideoSource vsrc(source);
237 ✗ gate_object_retain(source);
238 ✗ ptr_sources->add(vsrc);
239 ✗ return results::Ok;
240 }
241 ✗ catch (Throwable const& xcpt)
242 {
243 ✗ return xcpt.getResult();
244 }
245 ✗ catch (...)
246 {
247 ✗ return results::UnknownException;
248 }
249 }
250
251 ✗ Array<VideoSource> VideoSources::enumSources()
252 {
253 ✗ ArrayList<VideoSource> sources;
254
255 gate_delegate_t dispatcher_callback;
256 ✗ GATE_DELEGATE_BIND_FUNC(gate_video_sources_enum_callback, &dispatcher_callback, VideoSources_enumSources_array_callback);
257
258 ✗ result_t result = gate_video_sources_enum(&dispatcher_callback, &sources);
259 ✗ GATEXX_CHECK_EXCEPTION(result);
260
261 ✗ return sources.toArray();
262 }
263
264
265 ✗ VideoSource VideoSources::getSource(String const& id)
266 {
267 char id_buffer[4096];
268 gate_size_t len_used;
269 ✗ gate_video_source_t* ptr_source = NULL;
270
271 ✗ len_used = id.copyTo(id_buffer, sizeof(id_buffer));
272
273 ✗ gate_result_t result = gate_video_source_by_id(id_buffer, &ptr_source);
274 ✗ GATEXX_CHECK_EXCEPTION(result);
275 ✗ return VideoSource(ptr_source);
276 }
277
278
279 ✗ static gate_video_screencontrol_t* create_video_screencontrol_instance()
280 {
281 ✗ gate_video_screencontrol_t* ret = NULL;
282 ✗ gate_result_t result = gate_video_screencontrol_create(&ret);
283 ✗ GATEXX_CHECK_EXCEPTION(result);
284 ✗ return ret;
285 }
286
287 ✗ VideoScreenControl::VideoScreenControl()
288 ✗ : VideoSource((gate_video_source_t*)create_video_screencontrol_instance())
289 {
290
291 ✗ }
292
293 ✗ VideoScreenControl::VideoScreenControl(gate_video_screencontrol_t* ptr_screen)
294 ✗ : VideoSource((gate_video_source_t*)ptr_screen)
295 {
296 ✗ }
297
298 ✗ gate_video_screencontrol_t* VideoScreenControl::c_impl() const noexcept
299 {
300 ✗ return (gate_video_screencontrol_t*)VideoSource::c_impl();
301 }
302
303
304 ✗ void VideoScreenControl::getCursorPos(int32_t& x, int32_t& y)
305 {
306 ✗ result_t result = gate_video_screencontrol_get_cursor_pos(this->c_impl(), &x, &y);
307 ✗ GATEXX_CHECK_EXCEPTION(result);
308 ✗ }
309
310 ✗ void VideoScreenControl::moveCurspor(int32_t x, int32_t y)
311 {
312 ✗ result_t result = gate_video_screencontrol_move_cursor(this->c_impl(), x, y);
313 ✗ GATEXX_CHECK_EXCEPTION(result);
314 ✗ }
315
316 ✗ void VideoScreenControl::changeCursorButtonState(int32_t x, int32_t y, enumint_t buttonId, enumint_t buttonState)
317 {
318 ✗ result_t result = gate_video_screencontrol_change_cursor_button_state(this->c_impl(), x, y, buttonId, buttonState);
319 ✗ GATEXX_CHECK_EXCEPTION(result);
320 ✗ }
321
322 ✗ void VideoScreenControl::changeKeyState(gate_input_keycode_t key_code, gate_enumint_t key_state)
323 {
324 ✗ result_t result = gate_video_screencontrol_change_key_state(this->c_impl(), key_code, key_state);
325 ✗ GATEXX_CHECK_EXCEPTION(result);
326 ✗ }
327
328
329
330 ✗ VideoWriter::VideoWriter(gate_video_writer_t* impl)
331 ✗ : object_impl_t(impl)
332 {
333 ✗ }
334
335 ✗ void VideoWriter::write(VideoFrame const& frame)
336 {
337 ✗ result_t result = gate_video_writer_write(this->c_impl(), frame.c_impl());
338 ✗ GATEXX_CHECK_EXCEPTION(result);
339 ✗ }
340
341
342
343
344 ✗ VideoWriter VideoFileWriter::create(FileTypeEnum fileType, String const& path, VideoFormat const& format)
345 {
346 ✗ gate_video_writer_t* ptr_writer = NULL;
347 ✗ result_t result = gate_video_filewriter_create((gate_enumint_t)fileType, path.c_impl(), &format, &ptr_writer);
348 ✗ GATEXX_CHECK_EXCEPTION(result);
349 ✗ return VideoWriter(ptr_writer);
350 }
351
352
353 } // end of namespace io
354 } // end of namespace gate
355