DriveWorks SDK Reference
5.8.83 Release
For Test and Development only

Sensors Serialization

Sensor serialization is useful for saving sensor information for future playback and analysis.

Initialization

In order to initialize a sensor serializer, first serialization parameters must be populated. These are as follows:

const char* parameters;
void(* dwSensorSerializerOnDataFunc_t)(const uint8_t *data, size_t size, void *userData)
Callback type for getting data from sensor serializer.

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".

  • 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.
  • file - See description for type.
  • file-buffer-size - Size of output buffer to use for file operations.
  • format - Required. Specifies the video format. Supported values are h264 and raw. Only applies to camera sensors.
  • bitrate - Required if format is h264; optional if it is raw. This only applies to camera sensors.
  • framerate - Optional. Controls the framerate of the recorded stream and only applies to camera sensors.

The onData parameter is a callback when specifying a sensor serializer with the type=user.

Once the parameters are set, the sensor serializer can be initialized via the following function:

DW_API_PUBLIC dwStatus dwSensorSerializer_initialize(dwSensorSerializerHandle_t *const serializer, dwSerializerParams const *const params, dwSensorHandle_t const sensor)
Initializes a sensor serializer with the parameters provided.

In addition to passing the parameters, the sensor that is being serialized must be passed into this function.

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:

dwSensorSerializer_start() // called to start the i/o thread.
dwSensorSerializer_serializeDataAsync() // for generalized sensor data
dwSensorSerializer_stop() // called to stop the i/o thread.
DW_API_PUBLIC dwStatus dwSensorSerializer_start(dwSensorSerializerHandle_t const serializer)
Starts serialization of sensor.
DW_API_PUBLIC dwStatus dwSensorSerializer_stop(dwSensorSerializerHandle_t const serializer)
Starts serialization of sensor.
DW_API_PUBLIC dwStatus dwSensorSerializer_serializeCameraFrameAsync(dwCameraFrameHandle_t const frame, dwSensorSerializerHandle_t const serializer)
Pushes a camera frame to the serializer.
DW_API_PUBLIC dwStatus dwSensorSerializer_serializeDataAsync(uint8_t const *const data, size_t const size, dwSensorSerializerHandle_t const serializer)
Pushes data to the serializer.

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.

If running the serializer in non-async mode, the following methods are used for serialization:

dwSensorSerializer_serializeData() // for general sensor data
DW_API_PUBLIC dwStatus dwSensorSerializer_serializeCameraFrame(dwCameraFrameHandle_t const frame, dwSensorSerializerHandle_t const serializer)
Pushes a camera frame to the serializer.This method must only be used if 'dwSensorSerializer_start' i...
DW_API_PUBLIC dwStatus dwSensorSerializer_serializeData(uint8_t const *const data, size_t const size, dwSensorSerializerHandle_t const serializer)
Pushes data to the serializer.

The following is an example of how instatiate a serializer with a camera sensor and save camera frames to an h264 elementary stream file:

dwSAL_initialize(&sal, sdk);
std::string parameterString = "output-format=yuv";
// CODE: other sensor specific parameters
params.protocol = "camera.gmsl";
dwSAL_createSensor(&cameraSensor, params, sal);
dwSerializerParams serializerParams;
serializerParams.parameters = "format=h264,bitrate=800000,framerate=30,type=disk,file=out.h264";
dwSensorSerializer_initialize(&serializer, &serializerParams, cameraSensor);
while(loop) {
// CODE: use and return frame
}
dwSAL_releaseSensor(&cameraSensor);
DW_API_PUBLIC dwStatus dwSensorCamera_readFrame(dwCameraFrameHandle_t *const frameHandle, dwTime_t const timeoutUs, dwSensorHandle_t const sensor)
Reads a frame handle from the camera sensor.
DW_API_PUBLIC dwStatus dwSensorCamera_getImage(dwImageHandle_t *const image, dwCameraOutputType const type, dwCameraFrameHandle_t const frame)
Gets the output image/s image in a format specified by the output type.
@ DW_CAMERA_OUTPUT_NATIVE_PROCESSED
processed images (usually be YUV420 planar or RGB planar)
Definition: Camera.h:80
#define DW_NULL_HANDLE
Definition: Types.h:96
struct dwImageObject * dwImageHandle_t
Definition: Image.h:110
const char8_t * parameters
Array for additional parameters provided to sensor serializer creation.
DW_API_PUBLIC dwStatus dwSensorSerializer_release(dwSensorSerializerHandle_t const serializer)
Releases a sensor serializer.
struct dwSensorSerializerObject * dwSensorSerializerHandle_t
Handle representing a sensor serializer.
Holds the parameters for sensor serializer creation.
const char8_t * protocol
Name of the protocol.
Definition: Sensors.h:99
DW_API_PUBLIC dwStatus dwSAL_createSensor(dwSensorHandle_t *const sensor, dwSensorParams const params, dwSALHandle_t const sal)
Creates a new sensor managed by the SAL module with the given parameters.
DW_API_PUBLIC dwStatus dwSAL_release(dwSALHandle_t const sal)
Releases the SAL (sensor abstraction layer) module.
DW_API_PUBLIC dwStatus dwSAL_initialize(dwSALHandle_t *const sal, dwContextHandle_t const context)
Creates and initializes a SAL (sensor abstraction layer) module.
DW_API_PUBLIC dwStatus dwSAL_releaseSensor(dwSensorHandle_t const sensor)
Releases a sensor managed by the SAL module.
struct dwSensorObject * dwSensorHandle_t
Handle representing a sensor.
Definition: Sensors.h:86
Holds sets of parameters for sensor creation.
Definition: Sensors.h:95

For more examples of sensor serialization refer to: