GCC Code Coverage Report


Directory: src/gate/
File: src/gate/io/cxx_videosources.cpp
Date: 2026-12-03 19:36:00
Exec Total Coverage
Lines: 85 173 49.1%
Functions: 24 45 53.3%
Branches: 13 92 14.1%

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 2 VideoFormat::VideoFormat()
37 {
38 2 gate_video_format_t& fmt = *this;
39 2 Mem::clear(fmt);
40 2 }
41 2 VideoFormat::VideoFormat(uint32_t width, uint32_t height, uint32_t bitsperpixel, real32_t fps, uint32_t encodeId, uint32_t compressId)
42 {
43 2 gate_video_format_t& fmt = *this;
44 2 Mem::clear(fmt);
45 2 fmt.width = width;
46 2 fmt.height = height;
47 2 fmt.bits_per_pixel = bitsperpixel;
48 2 fmt.frames_per_second = fps;
49 2 fmt.encoding_id = encodeId;
50 2 fmt.compression = compressId;
51 2 }
52
53 1 VideoFormat::VideoFormat(VideoFormat const& source)
54 {
55 1 gate_video_format_t const& src = source;
56 1 gate_video_format_t& dst = *this;
57 1 Mem::copy(dst, src);
58 1 }
59 3 VideoFormat::VideoFormat(gate_video_format_t const& src)
60 {
61 3 gate_video_format_t& dst = *this;
62 3 Mem::copy(dst, src);
63 3 }
64 2 VideoFormat& VideoFormat::operator=(VideoFormat const& source)
65 {
66 2 gate_video_format_t const& src = source;
67 2 gate_video_format_t& dst = *this;
68 2 Mem::copy(dst, src);
69 2 return *this;
70 }
71 ✗ VideoFormat& VideoFormat::operator=(gate_video_format_t const& src)
72 {
73 ✗ gate_video_format_t& dst = *this;
74 ✗ Mem::copy(dst, src);
75 ✗ return *this;
76 }
77 8 VideoFormat::~VideoFormat() noexcept
78 {
79 8 }
80
81
82 3 hash_code_t VideoFormat::hashCode() const
83 {
84 3 return gate_video_format_hash(this);
85 }
86
87
88
89
90
91
92
93 2 VideoFrame::VideoFrame(VideoFormat const& format)
94 {
95 2 gate_video_frame_init(&this->impl, &format);
96 2 }
97 6 VideoFrame::VideoFrame(VideoFormat const& format, RasterImage const& image)
98 {
99 6 gate_video_frame_init(&this->impl, &format);
100
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if (NULL == gate_rasterimage_duplicate(&this->impl.image, image.c_impl()))
101 {
102 ✗ GATEXX_RAISE_ERROR(results::OutOfMemory);
103 }
104 6 }
105 2 VideoFrame::VideoFrame(VideoFrame const& src)
106 {
107 2 gate_video_frame_copy(&this->impl, &src.impl);
108 2 }
109 1 VideoFrame& VideoFrame::operator=(VideoFrame const& src)
110 {
111
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 VideoFrame that(src);
112 1 this->swap(that);
113 2 return *this;
114 }
115 20 VideoFrame::~VideoFrame() noexcept
116 {
117 10 gate_video_frame_release(&this->impl);
118 10 }
119 1 void VideoFrame::swap(VideoFrame& that) noexcept
120 {
121 1 gate::swapRefsNoExcept(this->impl, that.impl);
122 1 }
123
124 3 VideoFormat VideoFrame::getFormat() const
125 {
126 3 return VideoFormat(this->impl.format);
127 }
128 1 VideoFrame::RasterImage VideoFrame::getImage() const
129 {
130 1 return RasterImage(&this->impl.image);
131 }
132 1 int64_t const& VideoFrame::getRecordTime() const
133 {
134 1 return this->impl.record_time;
135 }
136 1 gate_video_frame_t* VideoFrame::c_impl()
137 {
138 1 return &this->impl;
139 }
140 6 gate_video_frame_t const* VideoFrame::c_impl() const
141 {
142 6 return &this->impl;
143 }
144
145
146
147
148 ✗ VideoReader::VideoReader(gate_video_reader_t* impl)
149 ✗ : object_impl_t(impl)
150 {
151 ✗ }
152
153 ✗ void VideoReader::read(VideoFrame& frame)
154 {
155 ✗ result_t result = gate_video_source_read(this->c_impl(), frame.c_impl());
156 ✗ GATEXX_CHECK_EXCEPTION(result);
157 ✗ }
158
159
160
161
162 ✗ VideoSource::VideoSource(gate_video_source_t* impl)
163 ✗ : VideoReader((gate_video_reader_t*)impl)
164 {
165 ✗ }
166
167 ✗ gate_video_source_t* VideoSource::c_impl() const noexcept
168 {
169 ✗ return (gate_video_source_t*)VideoReader::c_impl();
170 }
171
172
173 ✗ String VideoSource::getId() const
174 {
175 ✗ String str(gate_video_source_get_id(this->c_impl()));
176 ✗ return str;
177 }
178 ✗ String VideoSource::getName() const
179 {
180 ✗ String str(gate_video_source_get_name(this->c_impl()));
181 ✗ return str;
182 }
183 ✗ intptr_t VideoSource::getHandle() const
184 {
185 ✗ return gate_video_source_get_handle(this->c_impl());
186 }
187
188 ✗ Array<VideoFormat> VideoSource::getSupportedFormats()
189 {
190 gate_video_format_t formats[256];
191 ✗ gate_size_t formats_count = sizeof(formats) / sizeof(formats[0]);
192 ✗ formats_count = gate_video_source_get_supported_formats(this->c_impl(), formats, formats_count);
193
194 ✗ ArrayList<VideoFormat> formatList(formats_count);
195 ✗ formatList.addItems(&formats[0], &formats[formats_count]);
196 ✗ return formatList.toArray();
197 }
198
199 ✗ void VideoSource::open(VideoFormat const& format)
200 {
201 ✗ result_t result = gate_video_source_open(this->c_impl(), &format);
202 ✗ GATEXX_CHECK_EXCEPTION(result);
203 ✗ }
204 ✗ void VideoSource::close()
205 {
206 ✗ result_t result = gate_video_source_close(this->c_impl());
207 ✗ GATEXX_CHECK_EXCEPTION(result);
208 ✗ }
209
210
211 struct GATE_API_LOCAL VideoSourcesDispatcherData
212 {
213 VideoSources::EnumCallback const* cb;
214 void* param;
215 };
216
217 ✗ static gate_result_t VideoSources_enumSources_callback(gate_video_source_t* source, void* param)
218 {
219 ✗ VideoSourcesDispatcherData* data = static_cast<VideoSourcesDispatcherData*>(param);
220 ✗ VideoSource vsrc(source);
221 ✗ gate_object_retain(source);
222 ✗ ExceptionInfo xcptInfo;
223 ✗ GATEXX_TRY_CATCHINFO(xcptInfo, {
224 data->cb->invoke(vsrc, data->param);
225 });
226 ✗ return xcptInfo.result_code;
227 }
228
229 ✗ void VideoSources::enumSources(EnumCallback const& callback, void* param)
230 {
231 VideoSourcesDispatcherData dispatcher_data;
232 ✗ dispatcher_data.cb = &callback;
233 ✗ dispatcher_data.param = param;
234
235 gate_delegate_t dispatcher_callback;
236 ✗ GATE_DELEGATE_BIND_FUNC(gate_video_sources_enum_callback, &dispatcher_callback, VideoSources_enumSources_callback);
237
238 ✗ result_t result = gate_video_sources_enum(&dispatcher_callback, &dispatcher_data);
239 ✗ GATEXX_CHECK_EXCEPTION(result);
240 ✗ }
241
242
243 ✗ static gate_result_t VideoSources_enumSources_array_callback(gate_video_source_t* source, void* param)
244 {
245 ✗ ArrayList<VideoSource>* ptr_sources = static_cast<ArrayList<VideoSource>*>(param);
246 ✗ ExceptionInfo xcptInfo;
247 ✗ GATEXX_TRY_CATCHINFO(xcptInfo, {
248 VideoSource vsrc(source);
249 gate_object_retain(source);
250 ptr_sources->add(vsrc);
251 });
252 ✗ return xcptInfo.result_code;
253 }
254
255 1 Array<VideoSource> VideoSources::enumSources()
256 {
257
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 ArrayList<VideoSource> sources;
258
259 gate_delegate_t dispatcher_callback;
260
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 GATE_DELEGATE_BIND_FUNC(gate_video_sources_enum_callback, &dispatcher_callback, VideoSources_enumSources_array_callback);
261
262
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t result = gate_video_sources_enum(&dispatcher_callback, &sources);
263
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
264
265 ✗ return sources.toArray();
266 }
267
268
269 ✗ VideoSource VideoSources::getSource(String const& id)
270 {
271 char id_buffer[4096];
272 gate_size_t len_used;
273 ✗ gate_video_source_t* ptr_source = NULL;
274
275 ✗ len_used = id.copyTo(id_buffer, sizeof(id_buffer));
276
277 ✗ gate_result_t result = gate_video_source_by_id(id_buffer, &ptr_source);
278 ✗ GATEXX_CHECK_EXCEPTION(result);
279 ✗ return VideoSource(ptr_source);
280 }
281
282
283 1 static gate_video_screencontrol_t* create_video_screencontrol_instance()
284 {
285 1 gate_video_screencontrol_t* ret = NULL;
286
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gate_result_t result = gate_video_screencontrol_create(&ret);
287
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
288 ✗ return ret;
289 }
290
291 1 VideoScreenControl::VideoScreenControl()
292 1 : VideoSource((gate_video_source_t*)create_video_screencontrol_instance())
293 {
294
295 ✗ }
296
297 ✗ VideoScreenControl::VideoScreenControl(gate_video_screencontrol_t* ptr_screen)
298 ✗ : VideoSource((gate_video_source_t*)ptr_screen)
299 {
300 ✗ }
301
302 ✗ gate_video_screencontrol_t* VideoScreenControl::c_impl() const noexcept
303 {
304 ✗ return (gate_video_screencontrol_t*)VideoSource::c_impl();
305 }
306
307
308 ✗ void VideoScreenControl::getCursorPos(int32_t& x, int32_t& y)
309 {
310 ✗ result_t result = gate_video_screencontrol_get_cursor_pos(this->c_impl(), &x, &y);
311 ✗ GATEXX_CHECK_EXCEPTION(result);
312 ✗ }
313
314 ✗ void VideoScreenControl::moveCurspor(int32_t x, int32_t y)
315 {
316 ✗ result_t result = gate_video_screencontrol_move_cursor(this->c_impl(), x, y);
317 ✗ GATEXX_CHECK_EXCEPTION(result);
318 ✗ }
319
320 ✗ void VideoScreenControl::changeCursorButtonState(int32_t x, int32_t y, enumint_t buttonId, enumint_t buttonState)
321 {
322 ✗ result_t result = gate_video_screencontrol_change_cursor_button_state(this->c_impl(), x, y, buttonId, buttonState);
323 ✗ GATEXX_CHECK_EXCEPTION(result);
324 ✗ }
325
326 ✗ void VideoScreenControl::changeKeyState(gate_input_keycode_t key_code, gate_enumint_t key_state)
327 {
328 ✗ result_t result = gate_video_screencontrol_change_key_state(this->c_impl(), key_code, key_state);
329 ✗ GATEXX_CHECK_EXCEPTION(result);
330 ✗ }
331
332
333
334 2 VideoWriter::VideoWriter(gate_video_writer_t* impl)
335 2 : object_impl_t(impl)
336 {
337 2 }
338
339 6 void VideoWriter::write(VideoFrame const& frame)
340 {
341 6 result_t result = gate_video_writer_write(this->c_impl(), frame.c_impl());
342
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 GATEXX_CHECK_EXCEPTION(result);
343 6 }
344
345
346
347
348 2 VideoWriter VideoFileWriter::create(FileTypeEnum fileType, String const& path, VideoFormat const& format)
349 {
350 2 gate_video_writer_t* ptr_writer = NULL;
351
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 result_t result = gate_video_filewriter_create((gate_enumint_t)fileType, path.c_impl(), &format, &ptr_writer);
352
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
2 GATEXX_CHECK_EXCEPTION(result);
353 4 return VideoWriter(ptr_writer);
354 }
355
356
357 } // end of namespace io
358 } // end of namespace gate
359