Skip to content

Commit 2a48215

Browse files
Merge pull request #2 from faceterteam/release_1.2.0
Release 1.2.0
2 parents bfea69a + 6f99d95 commit 2a48215

37 files changed

+391
-959
lines changed

Diff for: README.md

+195-94
Original file line numberDiff line numberDiff line change
@@ -28,71 +28,65 @@ An example of code with stubs describing intergation process is shown in [integr
2828
* Registration reset
2929
* Serial number
3030
* LED indication
31+
* OTA firmware update
3132

3233
### Initialization
3334

3435
First step of integration process is library initialization
3536

3637
```
37-
const char* settingsPath = "/etc/faceter-client-settings.json";
3838
const char* serialNumber = GetSerialNumber();
39-
39+
40+
ClientSettings settings = {
41+
.cameraModel = "MyModel",
42+
.cameraVendor = "Vision",
43+
.appVersion = "1.0.0",
44+
.firmwareVersion = "Camera_1.0.3",
45+
.hardwareId = "t31_gc2053",
46+
.certFilePath = "/etc/ssl/certs/ca-certificates.crt",
47+
.confFilePath = "/etc/faceter-camera.conf",
48+
.rtspMainUrl = "rtsp://127.0.0.1/stream=0",
49+
.rtspCredentials = "root:12345",
50+
};
51+
strcpy(settings.serialNumber, serialNumber);
52+
4053
//library initialization
41-
if (FaceterClientInit(ControlHandler, settingsPath, serialNumber) < 0) {
42-
return 0;
54+
if (FaceterClientInit(ControlHandler, settings) < 0) {
55+
return 0;
4356
}
4457
```
4558

46-
FaceterClientInit accepts 3 parameters:
59+
FaceterClientInit accepts 2 parameters:
4760

4861
- **ControlFunction** - callback from library with control code and parameters
49-
- **settingsPath** - path to the settings file in json format that will be parsed and validated
50-
- **serialNumber** - unique device id, could be NULL (it will be generated from MAC address)
62+
- **settings** - ClientSettings for library initalization
5163

5264
Returns 0 on success and -1 if some error value occurs
5365

54-
#### Settings file structure
55-
An example of settings file is [faceter-client-settings.json](faceter-client-settings.json)
56-
57-
* rtspMainUrl - url of the RTSP stream from local RTSP server with user and password
58-
> "rtspMainUrl": "rtsp://root:12345@127.0.0.1/stream=0"
59-
* rtspSubUrl - secondary stream url, could be empty
60-
> "rtspSubUrl": ""
61-
* cameraModel - camera model name, shown in application
62-
> "cameraModel": "Faceter"
63-
* firmwareSaveDir - writable location where firmware update will be downloaded
64-
> "firmwareSaveDir": "/tmp"
65-
* endroidPort - port for internal library http server (optional, default 7654)
66-
* discoveryPort - port for WS-Discovery (optional, default 3702)
67-
* certFilePath - path to the CA certificate file, becase library uses HTTPS requests
68-
> "certFilePath": "/etc/ssl/certs/ca-certificates.crt"
69-
* confFilePath - file where camera registration parameters will be stored (optional, default is dir where settings file located)
70-
> "/etc/faceter-camera.conf"
71-
* cameraConfig - describes video, audio and other settings. Can be used for setting up camera parameters
72-
* audio - audio config describes sample rate, codec, microphone and speaker activity
73-
* mainStream - video config describes frame rate, codec, bitrate and image size of main stream
74-
* subStream - same for substream
75-
* image - image rotation
76-
* detector - motion detector state
77-
* osd - OSD visibility
78-
* nightMode - enable or disable night mode
79-
* customConfig - here can be stored any other necessary settings in json format
66+
#### ClientSettings description
67+
* cameraModel - camera model name ("MyModel")
68+
* cameraVendor - device manufacturer ("Vision")
69+
* serialNumber - unique stable camera serial number
70+
* appVersion - version of the applcation using library ("1.0.0")
71+
* firmwareVersion - camera firmware version ("Camera_1.0.3")
72+
* hardwareId - information about hardware, such as processor and sensor ("t31_gc2053")
73+
* certFilePath - path to the SSL certificate file, used in HTTPS connections ("/etc/ssl/certs/ca-certificates.crt")
74+
* confFilePath - path to the file in the writable location where library will store it's state ("/etc/faceter-camera.conf")
75+
* rtspMainUrl - main stream RTSP url without credentials ("rtsp://127.0.0.1/stream=0")
76+
Library currently supports only video codec H264 and audio codec AAC
77+
* rtspSubUrl - second RTSP stream, could be empty
78+
* rtspCredentials - user name and password for acessing RTSP stream ("root:12345")
8079

8180
### Registration
8281

8382
WiFi cameras require QR scanner. Also connection to WiFi network with ssid and password should be implemented. Registration process in this case consists of 3 steps:
84-
1. Library sends operation code **ControlCodeScanQr** with _not NULL_ parameter to start QR scanner
83+
1. Library sends operation code **ControlCodeStartScanQr** to start QR scanner
8584

8685
```
87-
case ControlCodeScanQr: {
88-
if (param != NULL) {
89-
//start QR code scanning
90-
QrScannerStart();
91-
} else {
92-
//stop QR code scanning
93-
QrScannerStop();
94-
}
95-
break;
86+
case ControlCodeStartScanQr: {
87+
//start QR code scanning
88+
QrScannerStart();
89+
break;
9690
}
9791
```
9892

@@ -107,7 +101,15 @@ WiFi cameras require QR scanner. Also connection to WiFi network with ssid and p
107101
}
108102
```
109103

110-
4. If QR code is correct, code **ControlCodeScanQr** with _NULL_ parameter will be sent to stop QR scanner
104+
4. If QR code is correct, code **ControlCodeStopScanQr** will be sent to stop QR scanner
105+
106+
```
107+
case ControlCodeStopScanQr: {
108+
//stop QR code scanning
109+
QrScannerStop();
110+
break;
111+
}
112+
```
111113
5. Library will sent **ControlCodeSetupWifi** with param _WifiConfig*_ to setup WiFi network
112114

113115
```
@@ -138,19 +140,21 @@ Library will send control code ControlCodeMicrophone
138140
//control handler fragment
139141
...
140142
case ControlCodeMicrophone: {
141-
//control microphone
142-
if (param != NULL) {
143-
//enable microphone on camera
144-
} else {
145-
//disable microphone on camera
146-
}
147-
break;
148-
}
143+
//control microphone
144+
AudioConfig* audioConfig = (AudioConfig*)param;
145+
if (audioConfig->micEnabled) {
146+
//enable microphone on camera
147+
} else {
148+
//disable microphone on camera
149+
}
150+
break;
151+
}
149152
```
150153
After operation completes application must call `FaceterClientSetControlStatus(controlCode, statusCode)`
151154
where statusCode is **StatusCodeOk** if operation succeed or other on fail.
152-
If operation not supported statusCode can be set to **StatusCodeNotSupported**.
153-
For example if camera not supports playing audio, it will return status without processing operation
155+
If operation not supported statusCode **MUST** be set to **StatusCodeNotSupported**.
156+
if operation not implemented yet use **StatusCodeNotImplemented**.
157+
For example if camera not supports audio playback, it will return status without processing operation
154158
```
155159
case ControlCodePlayAudio: {
156160
//play audio PCM buffer
@@ -159,20 +163,110 @@ case ControlCodePlayAudio: {
159163
break;
160164
}
161165
```
166+
If camera can play audio - status code will be **StatusCodeOk**
167+
```
168+
case ControlCodePlayAudio: {
169+
//play audio PCM buffer
170+
BufferParam* audioBuffer = (BufferParam*)param;
171+
PlayAudio(audioBuffer);
172+
statusCode = StatusCodeOk;
173+
break;
174+
}
175+
```
162176

163177
### Motion detection events
164178

165-
When Motion Detector on camera detects motions events, they should be passed to library with `FaceterClientOnMotion`
179+
When Motion Detector on camera detects motions events, they should be passed to library with `FaceterClientOnVideoEvent`.
180+
```
181+
typedef enum VideoEventType
182+
{
183+
VideoEventMotion,
184+
VideoEventLineCrossing,
185+
VideoEventIntrusion,
186+
VideoEventZoneEnter,
187+
VideoEventZoneLeave,
188+
VideoEventLoitering
189+
} VideoEventType;
190+
191+
typedef enum ObjectType
192+
{
193+
ObjectHuman,
194+
ObjectVehicle,
195+
ObjectAnimal,
196+
ObjectFire,
197+
ObjectSmoke,
198+
ObjectOther
199+
} ObjectType;
200+
201+
void FaceterClientOnVideoEvent(VideoEventType eventType, ObjectType objectType,
202+
DetectionAttribute *attributesList, DetectionRect *relativeBoundingRectList,
203+
char* snapshotImage, long int snapshotBytesCount)
204+
```
205+
Each video event has VideoEventType if can be recognized, otherwise use **VideoEventMotion**.
206+
If object can be detected it's type passed as second parameters, otherwise use **ObjectOther**.
207+
208+
Also detector may provide object's attributes, that can be passed linked list of **DetectionAttribute**.
209+
Parameter can be NULL if no information about object attributes provided.
210+
DetectionAttribute is key-value structure of string type. Use PushDetectionAttribute to add object attribute.
211+
Helper function PushHumanAttibutes creates DetectionAttribute list for human with gender and age fields.
212+
Helper function PushVehicleAttributes creates DetectionAttribute list for vehicle with type and license plate fields
213+
214+
For describing objects bounding rects use **DetectionRect** list. Parameter can be NULL if no information about rect provided.
215+
Rect coordinates (top left corner, width and height) are relative to image size and must be set as integers in the range [0..99].
216+
For adding next DetectionRect to list PushDetectionRect use PushDetectionRect
217+
218+
Last two parameters - camera snapshot of detected event in jpeg format and snapshot bytes count. Can be NULL.
219+
220+
```
221+
//get detected event snapshot
222+
long int snapshotJpegBytesCount = 100;
223+
char snapshotJpegImage[snapshotJpegBytesCount];
224+
225+
//simple motion event
226+
FaceterClientOnVideoEvent(VideoEventMotion, ObjectOther, NULL, NULL, NULL, 0);
227+
228+
//human motion event
229+
DetectionAttribute* humanAttrList = NULL;
230+
PushHumanAttibutes(&humanAttrList, GenderMale, 30);
231+
DetectionRect* humanRect = NULL;
232+
PushDetectionRect(&humanRect, 10, 15, 25, 49);
233+
FaceterClientOnVideoEvent(VideoEventMotion, ObjectHuman, humanAttrList, humanRect, snapshotJpegImage, snapshotJpegBytesCount);
234+
235+
//animal motion event
236+
DetectionAttribute* animalAttrList = NULL;
237+
PushDetectionAttribute(&animalAttrList, "kind", "cat");
238+
FaceterClientOnVideoEvent(VideoEventMotion, ObjectAnimal, animalAttrList, NULL, snapshotJpegImage, snapshotJpegBytesCount);
239+
240+
//line crossing event
241+
DetectionRect* crossRects = NULL;
242+
PushDetectionRect(&crossRects, 1, 5, 25, 49);
243+
PushDetectionRect(&crossRects, 30, 45, 5, 17);
244+
FaceterClientOnVideoEvent(VideoEventLineCrossing, ObjectOther, NULL, crossRects, snapshotJpegImage, snapshotJpegBytesCount);
245+
246+
//vehicle line crossing event
247+
DetectionAttribute* vehicleAttrList = NULL;
248+
PushVehicleAttributes(&vehicleAttrList, VehicleCar, "AB123");
249+
FaceterClientOnVideoEvent(VideoEventLineCrossing, ObjectVehicle, vehicleAttrList, NULL, snapshotJpegImage, snapshotJpegBytesCount);
250+
251+
//loitering event
252+
FaceterClientOnVideoEvent(VideoEventLoitering, ObjectHuman, NULL, NULL, NULL, 0);
253+
```
254+
255+
Audio events from sound detector can be also send to library using `FaceterClientOnAudioEvent` with corresponding type.
256+
If type cannot be recognized or not matches to AudioEventType use **AudioEventNoise**
166257

167258
```
168-
/*
169-
* Callback from Motion Detector
170-
*/
171-
void OnMotionDetected()
259+
typedef enum AudioEventType
172260
{
173-
//send motion detection event to library
174-
FaceterClientOnMotion();
175-
}
261+
AudioEventCry,
262+
AudioEventScream,
263+
AudioEventShot,
264+
AudioEventClap,
265+
AudioEventNoise
266+
} AudioEventType;
267+
268+
//baby cry audio event
269+
FaceterClientOnAudioEvent(AudioEventCry);
176270
```
177271

178272
### Service functions
@@ -181,45 +275,42 @@ Application must provide these service functions if they supported:
181275
+ **Jpeg snapshot** - library sometime needs camera preivew jpeg image. ControlHandler with code **ControlCodeGetSnapshot**
182276
will be called. In response application should call `FaceterClientOnSnapshot` with snapshot jpeg bytes array
183277

184-
```
185-
case ControlCodeGetSnapshot: {
186-
//get camera snapshot
187-
char* snapshotJpegImage = "";
188-
long int snapshotJpegSize = 100;
189-
FaceterClientOnSnapshot(snapshotJpegImage, snapshotJpegSize);
190-
break;
191-
}
192-
```
278+
```
279+
case ControlCodeGetSnapshot: {
280+
//get camera snapshot
281+
char* snapshotJpegImage = "";
282+
long int snapshotJpegBytesCount = 100;
283+
FaceterClientOnSnapshot(snapshotJpegImage, snapshotJpegBytesCount);
284+
break;
285+
}
286+
```
193287

194288
+ **Registration reset** - if camera has _RESET_ button it can be used to reset registration state to initial.
195289
When button _RESET_ pressed longer than 3 seconds, apllication should call `FaceterClientReset` and reboot camera.
196290

197-
```
198-
/*
199-
* Handler of reset button pressed more than 3 seconds
200-
*/
201-
void OnResetButtonPressed()
202-
{
203-
//reset registration
204-
FaceterClientReset();
205-
RebootSystem();
206-
}
207-
```
291+
```
292+
/*
293+
* Handler of reset button pressed more than 3 seconds
294+
*/
295+
void OnResetButtonPressed()
296+
{
297+
//reset registration
298+
FaceterClientReset();
299+
RebootSystem();
300+
}
301+
```
208302

209-
Also for resetting registration state library can call ControlFunction with **ControlCodeRestartCamera** and _not NULL_ param
303+
Also for resetting registration state library can call ControlFunction with **ControlCodeResetState**
210304

211-
```
212-
case ControlCodeRestartCamera: {
213-
if (param != NULL) {
214-
OnResetButtonPressed();
215-
} else {
216-
RebootSystem();
217-
}
218-
break;
219-
}
220-
```
305+
```
306+
case ControlCodeResetState: {
307+
//reset registration state to initial
308+
OnResetButtonPressed();
309+
break;
310+
}
311+
```
221312
+ **Serial number** - unique serial number needed for camera identification.
222-
Application must provide serial number string that will be the same after camera restarted. If no serial number provided camera will use MAC address as serial number
313+
Application must provide serial number string that will be the same after camera restarted. If no serial number provided SDK will use MAC address for identification instead
223314
+ **LED indication** - if camera has LED indicators they can be used to inform USER about current camera streaming state.
224315
Current state will be updated with ControlFunction code **ControlCodeStreamStatus**. If camera has two LED with different colors they should be used as follows
225316
```
@@ -237,6 +328,16 @@ Application must provide these service functions if they supported:
237328
```
238329
Where **green** LED is main indication color (could be any supported color) and **red** is additional color (if present)
239330

331+
+ **OTA firmware update** - after command from Faceter application SDK will download and save firmware update
332+
to '/tmp' directory and then call ControlFunction with code **ControlCodeUpdateFirmware** and path to the file as param
333+
```
334+
case ControlCodeUpdateFirmware: {
335+
//upgrade firmware from file in tmp dir
336+
char* firmwareUpdate = (char*)param;
337+
break;
338+
}
339+
```
340+
240341
## Library dependencies
241342

242343
Faceter CloudCam SDK depends on external libraries

0 commit comments

Comments
 (0)