DriveWorks SDK Reference
3.0.4260 Release
For Test and Development only

sensors/docs/usecase3.md
Go to the documentation of this file.
1 # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
2 
3 @page sensors_usecase3 Sensors Serialization
4 
5 @note SW Release Applicability: This tutorial is applicable to modules in both **NVIDIA DriveWorks** and **NVIDIA DRIVE Software** releases.
6 
7 Sensor serialization is useful for saving sensor information for future playback and analysis.
8 
9 **Initialization**
10 
11 In order to initialize a sensor serializer, first serialization parameters must be populated. These are as follows:
12 ```{.cpp}
13 const char* parameters;
14 dwSensorSerializerOnDataFunc_t onData;
15 ```
16 The parameters is a string containing `type`, `file`, `file-buffer-size`, `format`, `bitrate`, and `framerate`. Each of the listed are key/value pairs that are specified in the string as `"key1=value1,key2=value2,key3=value3"`.
17 
18 * `type` - Required. Specifies data-sink settings. If the value of `type` is `disk`, the serializer streams data to the file specified in the `file` key. If the value of `type` is `user`, the serializer uses the provided callback to stream data. When new data is available, the serializer calls the function provided in `onData` and puts the data in the buffer provided by `userData`.
19 * `file` - See description for `type`.
20 * `file-buffer-size` - Size of output buffer to use for file operations.
21 * `format` - Required. Specifies the video format. Supported values are `h264` and `raw`. Only applies to camera sensors.
22 * `bitrate` - Required if `format` is `h264`; optional if it is `raw`. This only applies to camera sensors.
23 * `framerate` - Optional. Controls the framerate of the recorded stream and only applies to camera sensors.
24 
25 The `onData` parameter is a callback when specifying a sensor serializer with the `type=user`.
26 
27 Once the parameters are set, the sensor serializer can be initialized via the following function:
28 ```{.cpp}
29 dwSensorSerializer_initialize()
30 ```
31 In addition to passing the parameters, the sensor that is being serialized must be passed into this function.
32 
33 The serializer can run in async mode (on its own thread) or in non-async mode. Async mode allows the serializer to put the work of i/o on another thread. To run in async mode, the following methods must be used:
34 
35 ```{.cpp}
36 dwSensorSerializer_start() // called to start the i/o thread.
37 dwSensorSerializer_serializeDataAsync() // for generalized sensor data
38 dwSensorSerializer_serializeCameraFrameAsync() // for camera data
39 dwSensorSerializer_stop() // called to stop the i/o thread.
40 ```
41 If running the serializer in async mode and multiple serializers are running together (for multiple sensors), one serializer can share its I/O thread with other serializers so that I/O happens for all serializers on the same thread. This is accomplished by attaching one serializer to another via the `dwSensorSerializer_attachTo()` method where one serializer is specified as the master serialzier and another is the slave.
42 
43 
44 If running the serializer in non-async mode, the following methods are used for serialization:
45 ```{.cpp}
46 dwSensorSerializer_serializeData() // for general sensor data
47 dwSensorSerializer_serializeCameraFrame() // for camera data
48 ```
49 
50 The following is an example of how instatiate a serializer with a camera sensor and save camera frames to an h264 elementary stream file:
51 ```{.cpp}
52 dwSAL_initialize(&sal, sdk);
53 
54 dwSensorHandle_t cameraSensor = DW_NULL_HANDLE;
55 dwSensorParams params;
56 std::string parameterString = "output-format=yuv";
57 // CODE: other sensor specific parameters
58 params.protocol = "camera.gmsl";
59 dwSAL_createSensor(&cameraSensor, params, sal);
60 
61 dwSensorSerializerHandle_t serializer;
62 dwSerializerParams serializerParams;
63 serializerParams.parameters = "format=h264,bitrate=800000,framerate=30,type=disk,file=out.h264";
64 
65 dwSensorSerializer_initialize(&serializer, &serializerParams, cameraSensor);
66 dwSensorSerializer_start(serializer);
67 
68 while(loop) {
69  dwSensorCamera_readFrame(...);
70  dwImageHandle_t image;
71  dwSensorCamera_getImage(&image, DW_CAMERA_OUTPUT_NATIVE_PROCESSED,...);
72 
73  dwSensorSerializer_serializeCameraFrameAsync(image,...);
74 
75  // CODE: use and return frame
76 }
77 
78 dwSensorSerializer_stop(serializer);
79 dwSensorSerializer_release(&serializer);
80 
81 dwSAL_releaseSensor(&cameraSensor);
82 dwSAL_release(&sal);
83 ```
84 
85 For more examples of sensor serialization refer to:
86 - @ref dwx_camera_gmsl_custom_sample