| 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 | /** @file | ||
| 30 | * @brief Video devices and video frame structures | ||
| 31 | * @ingroup gateio | ||
| 32 | */ | ||
| 33 | |||
| 34 | #ifndef GATE_IO_VIDEOSOURCES_H_INCLUDED | ||
| 35 | #define GATE_IO_VIDEOSOURCES_H_INCLUDED | ||
| 36 | |||
| 37 | #include "gate/io/gate_io_api.h" | ||
| 38 | #include "gate/gatetypes.h" | ||
| 39 | #include "gate/strings.h" | ||
| 40 | #include "gate/streams.h" | ||
| 41 | #include "gate/delegates.h" | ||
| 42 | #include "gate/comparers.h" | ||
| 43 | #include "gate/inputs.h" | ||
| 44 | #include "gate/graphics/images.h" | ||
| 45 | |||
| 46 | #if defined(__cplusplus) | ||
| 47 | extern "C" { | ||
| 48 | #endif | ||
| 49 | |||
| 50 | typedef struct gate_video_format_class | ||
| 51 | { | ||
| 52 | gate_uint32_t encoding_id; | ||
| 53 | gate_uint32_t compression; | ||
| 54 | gate_real32_t frames_per_second; | ||
| 55 | gate_uint32_t width; | ||
| 56 | gate_uint32_t height; | ||
| 57 | gate_uint32_t bits_per_pixel; | ||
| 58 | } gate_video_format_t; | ||
| 59 | |||
| 60 | |||
| 61 | /** | ||
| 62 | * @brief | ||
| 63 | */ | ||
| 64 | GATE_IO_API gate_hash_code_t gate_video_format_hash( | ||
| 65 | gate_video_format_t const* format | ||
| 66 | ); | ||
| 67 | |||
| 68 | |||
| 69 | /** | ||
| 70 | * @brief | ||
| 71 | */ | ||
| 72 | GATE_IO_API gate_intptr_t gate_compare_video_format( | ||
| 73 | void const* item1, | ||
| 74 | void const* item2 | ||
| 75 | ); | ||
| 76 | |||
| 77 | |||
| 78 | /** | ||
| 79 | * @brief | ||
| 80 | */ | ||
| 81 | GATE_IO_API gate_video_format_t const* gate_video_format_choose( | ||
| 82 | gate_video_format_t const* formats, | ||
| 83 | gate_size_t format_count, | ||
| 84 | gate_uint32_t const* desired_width, | ||
| 85 | gate_uint32_t const* desired_height, | ||
| 86 | gate_uint32_t const* desired_bit_per_pixel, | ||
| 87 | gate_real32_t const* desired_fps | ||
| 88 | ); | ||
| 89 | |||
| 90 | |||
| 91 | typedef struct gate_video_frame_class | ||
| 92 | { | ||
| 93 | gate_video_format_t format; | ||
| 94 | gate_rasterimage_t image; | ||
| 95 | gate_int64_t record_time; | ||
| 96 | } gate_video_frame_t; | ||
| 97 | |||
| 98 | |||
| 99 | /** | ||
| 100 | * @brief | ||
| 101 | */ | ||
| 102 | GATE_IO_API void gate_video_frame_init( | ||
| 103 | gate_video_frame_t* frame, | ||
| 104 | gate_video_format_t const* format | ||
| 105 | ); | ||
| 106 | |||
| 107 | |||
| 108 | /** | ||
| 109 | * @brief | ||
| 110 | */ | ||
| 111 | GATE_IO_API gate_video_frame_t* gate_video_frame_copy( | ||
| 112 | gate_video_frame_t* dest, | ||
| 113 | gate_video_frame_t const* source | ||
| 114 | ); | ||
| 115 | |||
| 116 | |||
| 117 | /** | ||
| 118 | * @brief | ||
| 119 | */ | ||
| 120 | GATE_IO_API void gate_video_frame_release( | ||
| 121 | gate_video_frame_t* frame | ||
| 122 | ); | ||
| 123 | |||
| 124 | |||
| 125 | #define GATE_INTERFACE_NAME_VIDEO_READER GATE_INTERFACE_NAME_OBJECT GATE_INTERFACE_NAME_SEPARATOR "videoreader" | ||
| 126 | |||
| 127 | GATE_INTERFACE(gate_video_reader) | ||
| 128 | { | ||
| 129 | GATE_METHOD0(char const*, get_interface_name); | ||
| 130 | GATE_METHOD0(void, release); | ||
| 131 | GATE_METHOD0(int, retain); | ||
| 132 | |||
| 133 | GATE_METHOD1(gate_result_t, read, gate_video_frame_t * frame); | ||
| 134 | }; | ||
| 135 | |||
| 136 | /** | ||
| 137 | * @interface gate_video_reader_t | ||
| 138 | * @implements gate_object_t | ||
| 139 | * @brief General video frame reader interface | ||
| 140 | */ | ||
| 141 | |||
| 142 | /** | ||
| 143 | * @fn gate_result_t read(gate_video_frame_t * frame) | ||
| 144 | * @memberof gate_video_reader_t | ||
| 145 | * @brief Reads one frame from a video frame source | ||
| 146 | * @param[out] frame Pointer to frame to be initialized with frame data | ||
| 147 | * @return GATE_RESULT_* result codes | ||
| 148 | */ | ||
| 149 | |||
| 150 | |||
| 151 | |||
| 152 | |||
| 153 | #define GATE_INTERFACE_NAME_VIDEO_SOURCE GATE_INTERFACE_NAME_VIDEO_READER GATE_INTERFACE_NAME_SEPARATOR "source" | ||
| 154 | |||
| 155 | GATE_INTERFACE(gate_video_source) | ||
| 156 | { | ||
| 157 | GATE_METHOD0(char const*, get_interface_name); | ||
| 158 | GATE_METHOD0(void, release); | ||
| 159 | GATE_METHOD0(int, retain); | ||
| 160 | |||
| 161 | GATE_METHOD1(gate_result_t, read, gate_video_frame_t * frame); | ||
| 162 | |||
| 163 | GATE_METHOD0(char const*, get_id); | ||
| 164 | GATE_METHOD0(char const*, get_name); | ||
| 165 | GATE_METHOD0(gate_intptr_t, get_handle); | ||
| 166 | GATE_METHOD2(gate_size_t, get_supported_formats, gate_video_format_t * format_buffer, gate_size_t format_buffer_count); | ||
| 167 | |||
| 168 | GATE_METHOD1(gate_result_t, open, gate_video_format_t const* format); | ||
| 169 | GATE_METHOD0(gate_result_t, close); | ||
| 170 | |||
| 171 | }; | ||
| 172 | |||
| 173 | /** | ||
| 174 | * @interface gate_video_source_t | ||
| 175 | * @implements gate_video_reader_t | ||
| 176 | * @brief General video frame reader interface | ||
| 177 | */ | ||
| 178 | |||
| 179 | /** | ||
| 180 | * @fn char const* get_id() | ||
| 181 | * @memberof gate_video_source_t | ||
| 182 | * @brief Returns a system-unique-ID about the video source | ||
| 183 | * @return 0-terminated string representing a unique ID | ||
| 184 | * | ||
| 185 | * @fn char const* get_name() | ||
| 186 | * @memberof gate_video_source_t | ||
| 187 | * @brief Returns a human readable name of the video source | ||
| 188 | * @return 0-terminated string representing the name | ||
| 189 | * | ||
| 190 | * @fn gate_intptr_t get_handle() | ||
| 191 | * @memberof gate_video_source_t | ||
| 192 | * @brief Returns the native handle of the internal implementation resouce | ||
| 193 | * @return Handle to resource | ||
| 194 | * | ||
| 195 | * @fn gate_size_t get_supported_formats(gate_video_format_t* format_buffer, gate_size_t format_buffer_count) | ||
| 196 | * @memberof gate_video_source_t | ||
| 197 | * @brief Fills the given buffer with different supported frame formats (that can be used in open() method) | ||
| 198 | * @param[in,out] format_buffer Pointer to array of format, to be initialized with available supported formats | ||
| 199 | * @param[in] format_buffer_count Maximum capacity of `format_buffer` | ||
| 200 | * @return Amount of format-structs in the buffer, that were initialized with format informations. | ||
| 201 | * | ||
| 202 | * @fn gate_result_t open(gate_video_format_t const* format) | ||
| 203 | * @memberof gate_video_source_t | ||
| 204 | * @brief Openes a video frame stream source to read frames in a specific format | ||
| 205 | * @param[in] format Pointer to format information describing desired frame details (e.g. dimensions, color depth) | ||
| 206 | * @return GATE_RESULT_* result codes | ||
| 207 | * | ||
| 208 | * @fn gate_result_t close() | ||
| 209 | * @memberof gate_video_source_t | ||
| 210 | * @brief Closes an opened video frame stream source | ||
| 211 | * @return GATE_RESULT_* result codes | ||
| 212 | */ | ||
| 213 | |||
| 214 | |||
| 215 | #define gate_video_source_get_id(source) (source)->vtbl->get_id((source)) | ||
| 216 | #define gate_video_source_get_name(source) (source)->vtbl->get_name((source)) | ||
| 217 | #define gate_video_source_get_handle(source) (source)->vtbl->get_handle((source)) | ||
| 218 | #define gate_video_source_get_supported_formats(source, buffer, buffer_size) \ | ||
| 219 | (source)->vtbl->get_supported_formats((source), (buffer), (buffer_size)) | ||
| 220 | |||
| 221 | #define gate_video_source_open(source, format) (source)->vtbl->open((source), (format)) | ||
| 222 | #define gate_video_source_close(source) (source)->vtbl->close((source)) | ||
| 223 | |||
| 224 | #define gate_video_source_read(source, frame) (source)->vtbl->read((source), (frame)) | ||
| 225 | |||
| 226 | ✗ | GATE_DELEGATE_DECLARE_2(gate_video_sources_enum_callback, gate_video_source_t*, void*); | |
| 227 | |||
| 228 | |||
| 229 | /** | ||
| 230 | * @brief | ||
| 231 | */ | ||
| 232 | GATE_IO_API gate_result_t gate_video_sources_enum( | ||
| 233 | gate_delegate_t const* callback, | ||
| 234 | void* param | ||
| 235 | ); | ||
| 236 | |||
| 237 | |||
| 238 | /** | ||
| 239 | * @brief | ||
| 240 | */ | ||
| 241 | GATE_IO_API gate_result_t gate_video_source_by_id( | ||
| 242 | char const* id, | ||
| 243 | gate_video_source_t** ptr_source | ||
| 244 | ); | ||
| 245 | |||
| 246 | |||
| 247 | |||
| 248 | #define GATE_INTERFACE_NAME_VIDEO_SOURCE_SCREENCONTROL GATE_INTERFACE_NAME_VIDEO_SOURCE GATE_INTERFACE_NAME_SEPARATOR "screencontrol" | ||
| 249 | |||
| 250 | |||
| 251 | #define GATE_VIDEO_SCREENCONTROL_BUTTON_LEFT 1 | ||
| 252 | #define GATE_VIDEO_SCREENCONTROL_BUTTON_MIDDLE 2 | ||
| 253 | #define GATE_VIDEO_SCREENCONTROL_BUTTON_RIGHT 3 | ||
| 254 | |||
| 255 | #define GATE_VIDEO_SCREENCONTROL_STATE_UP 0x01 /* key/button is up (released) */ | ||
| 256 | #define GATE_VIDEO_SCREENCONTROL_STATE_DOWN 0x02 /* key/button is down (pressed) */ | ||
| 257 | #define GATE_VIDEO_SCREENCONTROL_STATE_CTRL 0x10 /* control modifier is active (e.g. CTRL key pressed) */ | ||
| 258 | #define GATE_VIDEO_SCREENCONTROL_STATE_MENU 0x20 /* menu modifier is active (e.g. ALT key is pressed)*/ | ||
| 259 | #define GATE_VIDEO_SCREENCONTROL_STATE_SHIFT 0x40 /* shift modifier is active (e.g. SHIFT key is pressed)*/ | ||
| 260 | |||
| 261 | |||
| 262 | GATE_INTERFACE(gate_video_screencontrol) | ||
| 263 | { | ||
| 264 | GATE_METHOD0(char const*, get_interface_name); | ||
| 265 | GATE_METHOD0(void, release); | ||
| 266 | GATE_METHOD0(int, retain); | ||
| 267 | |||
| 268 | GATE_METHOD1(gate_result_t, read, gate_video_frame_t * frame); | ||
| 269 | |||
| 270 | GATE_METHOD0(char const*, get_id); | ||
| 271 | GATE_METHOD0(char const*, get_name); | ||
| 272 | GATE_METHOD0(gate_intptr_t, get_handle); | ||
| 273 | GATE_METHOD2(gate_size_t, get_supported_formats, gate_video_format_t * format_buffer, gate_size_t format_buffer_count); | ||
| 274 | |||
| 275 | GATE_METHOD1(gate_result_t, open, gate_video_format_t const* format); | ||
| 276 | GATE_METHOD0(gate_result_t, close); | ||
| 277 | |||
| 278 | GATE_METHOD2(gate_result_t, get_cursor_pos, gate_int32_t * ptr_x, gate_int32_t * ptr_y); | ||
| 279 | GATE_METHOD2(gate_result_t, move_cursor, gate_int32_t x, gate_int32_t y); | ||
| 280 | GATE_METHOD4(gate_result_t, change_cursor_button_state, gate_int32_t x, gate_int32_t y, gate_enumint_t button_id, gate_enumint_t button_state); | ||
| 281 | GATE_METHOD2(gate_result_t, change_key_state, gate_input_keycode_t key_code, gate_enumint_t key_state); | ||
| 282 | }; | ||
| 283 | |||
| 284 | /** | ||
| 285 | * @interface gate_video_screencontrol_t | ||
| 286 | * @implements gate_video_source_t | ||
| 287 | * @brief General video frame reader interface | ||
| 288 | */ | ||
| 289 | |||
| 290 | /** | ||
| 291 | * @fn gate_result_t get_cursor_pos(gate_int32_t* ptr_x, gate_int32_t* ptr_y); | ||
| 292 | * @memberof gate_video_screencontrol_t | ||
| 293 | * @brief Returns the current cursor position on the screen (e.g. mouse pointer) | ||
| 294 | * @param[out] ptr_x Pointer to integer receiving the x-coordinate on screen | ||
| 295 | * @param[out] ptr_y Pointer to integer receiving the y-coordinate on screen | ||
| 296 | * @return GATE_RESULT_* result codes | ||
| 297 | * | ||
| 298 | * @fn gate_result_t move_cursor(gate_int32_t x, gate_int32_t y); | ||
| 299 | * @memberof gate_video_screencontrol_t | ||
| 300 | * @brief Move the main cursor to the given coordinates on screen | ||
| 301 | * @param[in] x x coordinate on screen | ||
| 302 | * @param[in] y y coordinate on screen | ||
| 303 | * @return GATE_RESULT_* result codes | ||
| 304 | * | ||
| 305 | * @fn gate_result_t change_cursor_button_state(gate_int32_t x, gate_int32_t y, gate_enumint_t button_id, gate_enumint_t button_state); | ||
| 306 | * @memberof gate_video_screencontrol_t | ||
| 307 | * @brief Sends a cursor-button-state change event (e.g. mouse-button-down) | ||
| 308 | * @param[in] x desired x coordinate of cursor on screen | ||
| 309 | * @param[in] y desired y coordinate of cursor on screen | ||
| 310 | * @param[in] button_id Button ID that's state is required to change, see GATE_VIDEO_SCREENCONTROL_BUTTON_* (e.g. left/middle/right mouse button) | ||
| 311 | * @param[in] button_state New button state to be applied, see GATE_VIDEO_SCREENCONTROL_STATE_* (e.g. down-pressed, up-released) | ||
| 312 | * @return GATE_RESULT_* result codes | ||
| 313 | * | ||
| 314 | * @fn gate_result_t change_key_state(gate_input_keycode_t key_code, gate_enumint_t key_state) | ||
| 315 | * @memberof gate_video_screencontrol_t | ||
| 316 | * @brief Sends a keyboard-key state-change event (e.g. key-pressed) | ||
| 317 | * @param[in] key_code Generic key-code of key to be sent | ||
| 318 | * @param[in] key_state New state to be applied, see GATE_VIDEO_SCREENCONTROL_STATE_* (e.g. key-down) | ||
| 319 | * @return GATE_RESULT_* result codes | ||
| 320 | */ | ||
| 321 | |||
| 322 | |||
| 323 | |||
| 324 | #define gate_video_screencontrol_get_cursor_pos(source, ptr_x, ptr_y) (source)->vtbl->get_cursor_pos((source), (ptr_x), (ptr_y)) | ||
| 325 | #define gate_video_screencontrol_move_cursor(source, x, y) (source)->vtbl->move_cursor((source), (x), (y)) | ||
| 326 | #define gate_video_screencontrol_change_cursor_button_state(source, x, y, button_id, button_state) (source)->vtbl->change_cursor_button_state((source), (x), (y), (button_id), (button_state)) | ||
| 327 | #define gate_video_screencontrol_change_key_state(source, key_code, key_state) (source)->vtbl->change_key_state((source), (key_code), (key_state)) | ||
| 328 | |||
| 329 | |||
| 330 | /** | ||
| 331 | * @brief | ||
| 332 | */ | ||
| 333 | GATE_IO_API gate_result_t gate_video_screencontrol_create( | ||
| 334 | gate_video_screencontrol_t** ptr_source | ||
| 335 | ); | ||
| 336 | |||
| 337 | |||
| 338 | |||
| 339 | #define GATE_INTERFACE_NAME_VIDEO_WRITER GATE_INTERFACE_NAME_OBJECT GATE_INTERFACE_NAME_SEPARATOR "videowriter" | ||
| 340 | |||
| 341 | GATE_INTERFACE(gate_video_writer) | ||
| 342 | { | ||
| 343 | GATE_METHOD0(char const*, get_interface_name); | ||
| 344 | GATE_METHOD0(void, release); | ||
| 345 | GATE_METHOD0(int, retain); | ||
| 346 | |||
| 347 | GATE_METHOD1(gate_result_t, write, gate_video_frame_t const* frame); | ||
| 348 | }; | ||
| 349 | |||
| 350 | #define gate_video_writer_write(writer, frame) (writer)->vtbl->write((writer), (frame)) | ||
| 351 | |||
| 352 | |||
| 353 | #define GATE_VIDEO_FILEWRITER_TYPE_PNG 0x01 /* multiple PNG frame files in folder */ | ||
| 354 | #define GATE_VIDEO_FILEWRITER_TYPE_JPEG 0x02 /* multiple JPEG frame files in folder */ | ||
| 355 | #define GATE_VIDEO_FILEWRITER_TYPE_GIF 0x03 /* one GIF animation file */ | ||
| 356 | #define GATE_VIDEO_FILEWRITER_TYPE_AVI 0x04 /* one AVI file without compression */ | ||
| 357 | |||
| 358 | |||
| 359 | /** | ||
| 360 | * @brief | ||
| 361 | */ | ||
| 362 | GATE_IO_API gate_result_t gate_video_filewriter_create( | ||
| 363 | gate_enumint_t filetype, | ||
| 364 | gate_string_t const* path, | ||
| 365 | gate_video_format_t const* ptr_format, | ||
| 366 | gate_video_writer_t** ptr_writer | ||
| 367 | ); | ||
| 368 | |||
| 369 | |||
| 370 | #if defined(__cplusplus) | ||
| 371 | } | ||
| 372 | #endif | ||
| 373 | |||
| 374 | #endif | ||
| 375 |