Skip to content

Commit 3158cab

Browse files
New data structures added. Serialization function updated
1 parent d29c3a2 commit 3158cab

File tree

7 files changed

+483
-71
lines changed

7 files changed

+483
-71
lines changed

README.md

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11

22

3-
4-
53
![logo](_static/vsource_logo.png)
64

7-
# **VSource interface C++ library**
5+
# VSource interface C++ library
86

9-
**v1.3.2**
7+
**v1.4.0**
108

119
------
1210

@@ -36,8 +34,8 @@
3634
- [VSourceParam enum](#VSourceParam-enum)
3735
- [VSourceParams class description](#VSourceParams-class-description)
3836
- [VSourceParams class declaration](#VSourceParams-class-declaration)
39-
- [Encode video source params](#Encode-video-source-params)
40-
- [Decode video source params](#Decode-video-source-params)
37+
- [Serialize video source params](#Serialize-video-source-params)
38+
- [Deserialize video source params](#Deserialize-video-source-params)
4139
- [Read params from JSON file and write to JSON file](#Read-params-from-JSON-file-and-write-to-JSON-file)
4240
- [Build and connect to your project](#Build-and-connect-to-your-project)
4341

@@ -64,6 +62,7 @@
6462
| 1.3.0 | 05.07.2023 | - VSourceParams class updated (initString replaced by source).<br />- decode(...) method in VSourceParams class updated. |
6563
| 1.3.1 | 06.07.2023 | - gain, exposure and focusPos fields of VSourceParams excluded from JSOM reading/writing. |
6664
| 1.3.2 | 06.07.2023 | - Frame library version updated. |
65+
| 1.4.0 | 11.07.2023 | - Added VSourceParamsMask structure.<br />- Added params mask in encode(...) method of VSourceParams class. |
6766

6867

6968

@@ -191,7 +190,7 @@ std::cout << "VSource class version: " << VSource::getVersion() << std::endl;
191190
Console output:
192191

193192
```bash
194-
VSource class version: 1.3.0
193+
VSource class version: 1.4.0
195194
```
196195

197196

@@ -610,8 +609,9 @@ public:
610609
* source and fourcc fields.
611610
* @param data Pointer to data buffer.
612611
* @param size Size of data.
612+
* @param mask Pointer to parameters mask.
613613
*/
614-
void encode(uint8_t* data, int& size);
614+
void encode(uint8_t* data, int& size, VSourceParamsMask* mask = nullptr);
615615
/**
616616
* @brief Decode params. The method doesn't decode params:
617617
* source and fourcc fields.
@@ -648,52 +648,82 @@ public:
648648
649649
650650
651-
## Encode video source params
651+
## Serialize video source params
652652
653-
**VSourceParams** class provides method **encode(...)** to serialize video source params (fields of VSourceParams class, see Table 4). Serialization of video source params necessary in case when you need to send video source params via communication channels. Method doesn't encode fields: **initString** and **fourcc**. Method declaration:
653+
**VSourceParams** class provides method **encode(...)** to serialize video source params (fields of VSourceParams class, see Table 4). Serialization of video source params necessary in case when you need to send video source params via communication channels. Method doesn't encode fields: **initString** and **fourcc**. Method provides options to exclude particular parameters from serialization. To do this method inserts binary mask (2 bytes) where each bit represents particular parameter and **decode(...)** method recognizes it. Method declaration:
654654
655655
```cpp
656-
void encode(uint8_t* data, int& size);
656+
void encode(uint8_t* data, int& size, VSourceParamsMask* mask = nullptr);
657657
```
658658

659659
| Parameter | Value |
660660
| --------- | ------------------------------------------------------------ |
661661
| data | Pointer to data buffer. Buffer size should be at least **43** bytes. |
662662
| size | Size of encoded data. 43 bytes by default. |
663+
| mask | Parameters mask - pointer to **VSourceParamsMask** structure. **VSourceParamsMask** (declared in VSource.h file) determines flags for each field (parameter) declared in **VSourceParams** class. If the user wants to exclude any parameters from serialization, he can put a pointer to the mask. If the user wants to exclude a particular parameter from serialization, he should set the corresponding flag in the VSourceParamsMask structure. |
663664

664-
Example:
665+
**VSourceParamsMask** structure declaration:
666+
667+
```cpp
668+
typedef struct VSourceParamsMask
669+
{
670+
bool logLevel{true};
671+
bool width{true};
672+
bool height{true};
673+
bool gainMode{true};
674+
bool gain{true};
675+
bool exposureMode{true};
676+
bool exposure{true};
677+
bool focusMode{true};
678+
bool focusPos{true};
679+
bool cycleTimeMks{true};
680+
bool fps{true};
681+
bool isOpen{true};
682+
bool custom1{true};
683+
bool custom2{true};
684+
bool custom3{true};
685+
} VSourceParamsMask;
686+
```
687+
688+
Example without parameters mask:
665689

666690
```cpp
667691
// Prepare random params.
668692
VSourceParams in;
669693
in.initString = "alsfghljb";
670-
in.fourcc = "skdfjhvk";
671-
in.logLevel = "dsglbjlkfjwjgre";
672-
in.cycleTimeMks = rand() % 255;
673-
in.exposure = rand() % 255;
674-
in.exposureMode = rand() % 255;
675-
in.gainMode = rand() % 255;
676-
in.gain = rand() % 255;
677-
in.focusMode = rand() % 255;
678-
in.focusPos = rand() % 255;
679-
in.fps = rand() % 255;
680-
in.width = rand() % 255;
681-
in.height = rand() % 255;
682-
in.isOpen = true;
694+
in.logLevel = 0;
683695

684696
// Encode data.
685697
uint8_t data[1024];
686698
int size = 0;
687699
in.encode(data, size);
700+
cout << "Encoded data size: " << size << " bytes" << endl;
701+
```
702+
703+
Example without parameters mask:
688704

705+
```cpp
706+
// Prepare random params.
707+
VSourceParams in;
708+
in.initString = "alsfghljb";
709+
in.logLevel = 0;
710+
711+
// Prepare params mask.
712+
VSourceParamsMask mask;
713+
mask.logLevel = false; // Exclude logLevel. Others by default.
714+
715+
// Encode data.
716+
uint8_t data[1024];
717+
int size = 0;
718+
in.encode(data, size, &mask);
689719
cout << "Encoded data size: " << size << " bytes" << endl;
690720
```
691721

692722

693723

694-
## Decode video source params
724+
## Deserialize video source params
695725

696-
**VSourceParams** class provides method **decode(...)** to deserialize video source params (fields of VSourceParams class, see Table 4). Deserialization of video source params necessary in case when you need to receive video source params via communication channels. Method doesn't decode fields: **initString** and **fourcc**. Method declaration:
726+
**VSourceParams** class provides method **decode(...)** to deserialize video source params (fields of VSourceParams class, see Table 4). Deserialization of video source params necessary in case when you need to receive video source params via communication channels. Method doesn't decode fields: **initString** and **fourcc**. Method automatically recognizes which parameters were serialized by **encode(...)** method. Method declaration:
697727

698728
```cpp
699729
bool decode(uint8_t* data);

README.pdf

5.08 KB
Binary file not shown.

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.13)
66
## LIBRARY-PROJECT
77
## name and version
88
###############################################################################
9-
project(VSource VERSION 1.3.1 LANGUAGES CXX)
9+
project(VSource VERSION 1.4.0 LANGUAGES CXX)
1010

1111

1212

0 commit comments

Comments
 (0)