I am trying to attach custom type metadata, like string in deepstream_sdk_v4.0_jetson/sources/apps/sample_apps/deepstream-user-metadata-test/deepstream_user_metadata_app.c . For this, I have modified the set_metadata function like this:
void *set_metadata_ptr()
{
int i = 0;
gchar *user_metadata = (gchar*)g_malloc0(USER_ARRAY_SIZE);
char str[20] = "string";
g_print("\n**************** Setting user metadata array of 16 on nvinfer src pad\n");
// for(i = 0; i < USER_ARRAY_SIZE; i++) {
user_metadata[0] = str;
user_metadata[1] = 'K'; // works fine with single character or integer type variables
g_print("user_meta_data [%d] = %s\n", 0, user_metadata[0]);
g_print("user_meta_data [%d] = %c\n", 1, user_metadata[1]);
// }
return (void *)user_metadata;
}
It doesn’t work, results in segmentation fault. I need some different types of variable as user_metadata, like string or float. Could anyone suggest how to attach different type of variable like float, string etc as user_metadata?
char is 8-bit (1 byte) large. It can be observed as an int.
Depending if it is signed or unsigned it can hold following int values:
char 1 byte -128 to 127 or 0 to 255
unsigned char 1 byte 0 to 255
signed char 1 byte -128 to 127
So try to assign 4242 to user_metadata[0] and check what you get.
On the other hand float is 4 bytes long which means any float requires four elements of your array to represent that float.
float 4 byte 1.2E-38 to 3.4E+38 6 decimal places
At the end you could use your array to store floats with pointer arithmetic, but it is not the way you should do it. Nevertheless if you have N floating point numbers your array should be 4*N large.