Compilation error in accessing the nvds-analytics meta data in deepstream-app

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU)
Jetson
• DeepStream Version
6.0

Hello, In the deepstream-app, I have enabled the nvds-analytics plugin and trying to access the nvds-analytics meta data. I have modified the all_bbox_generated probe in deepstream_app_main.c similar to the nvdsanalytics_src_pad_buffer_probe in the deepstream_nvdsanalytics_test.cpp. While iterating for each object, I have added the following code:

for (NvDsMetaList *l_user_meta = obj_meta->obj_user_meta_list; l_user_meta != NULL;
                    l_user_meta = l_user_meta->next) {
                NvDsUserMeta *user_meta = (NvDsUserMeta *) (l_user_meta->data);
                if(user_meta->base_meta.meta_type == NVDS_USER_OBJ_META_NVDSANALYTICS)
                {
                    NvDsAnalyticsObjInfo * user_meta_data = (NvDsAnalyticsObjInfo *)user_meta->user_meta_data;
                    if (user_meta_data->dirStatus.length()){
                        g_print ("object %lu moving in %s\n", obj_meta->object_id, user_meta_data->dirStatus.c_str());
                    }
                }
            }

For this to work, I have to import the nvds_analytics_meta.h library, but this library is written in cpp so I am getting compilation error as follows:

cc -c -o deepstream_app_main.o -DPLATFORM_TEGRA -I./ -I../../apps-common/includes -I../../../includes -DDS_VERSION_MINOR=1 -DDS_VERSION_MAJOR=5 -I /usr/local/cuda-10.2/include -pthread -I/usr/include/gstreamer-1.0 -I/usr/include/orc-0.4 -I/usr/include/gstreamer-1.0 -I/usr/include/json-glib-1.0 -I/usr/include/glib-2.0 -I/usr/lib/aarch64-linux-gnu/glib-2.0/include deepstream_app_main.c
In file included from deepstream_app_main.c:38:0:
../../../includes/nvds_analytics_meta.h:30:10: fatal error: vector: No such file or directory
 #include <vector>
          ^~~~~~~~
compilation terminated.
Makefile:67: recipe for target 'deepstream_app_main.o' failed
make: *** [deepstream_app_main.o] Error 1

So, how can I access the nvds-analytics meta data now? Also where is the location of the nvds-analytics plugin within the deepstream-app relative to the all_bbox_generated probe? Can I access the nvds-analytics meta data within this or not?

Could you try to use the CXX complie tool for c file?

%.o: %.c $(INCS) Makefile
	$(CXX) -c -o $@ $(CFLAGS) $<

Hi, I tried using cxx for c file. The compilation gave an error as follows:

g++ -c -o deepstream_app.o -DPLATFORM_TEGRA -I./ -I../../apps-common/includes -I../../../includes -DDS_VERSION_MINOR=1 -DDS_VERSION_MAJOR=5 -I /usr/local/cuda-10.2/include -pthread -I/usr/include/gstreamer-1.0 -I/usr/include/orc-0.4 -I/usr/include/gstreamer-1.0 -I/usr/include/json-glib-1.0 -I/usr/include/glib-2.0 -I/usr/lib/aarch64-linux-gnu/glib-2.0/include deepstream_app.c
deepstream_app.c: In function ‘void write_kitti_output(AppCtx*, NvDsBatchMeta*)’:
deepstream_app.c:244:42: error: invalid conversion from ‘gpointer {aka void*}’ to ‘NvDsFrameMeta* {aka _NvDsFrameMeta*}’ [-fpermissive]
     NvDsFrameMeta *frame_meta = l_frame->data;
                                 ~~~~~~~~~^~~~
deepstream_app.c: In function ‘void write_kitti_track_output(AppCtx*, NvDsBatchMeta*)’:
deepstream_app.c:339:42: error: invalid conversion from ‘gpointer {aka void*}’ to ‘NvDsFrameMeta* {aka _NvDsFrameMeta*}’ [-fpermissive]
     NvDsFrameMeta *frame_meta = l_frame->data;
                                 ~~~~~~~~~^~~~
deepstream_app.c: In function ‘void process_meta(AppCtx*, NvDsBatchMeta*)’:
deepstream_app.c:398:42: error: invalid conversion from ‘gpointer {aka void*}’ to ‘NvDsFrameMeta* {aka _NvDsFrameMeta*}’ [-fpermissive]
     NvDsFrameMeta *frame_meta = l_frame->data;
                                 ~~~~~~~~~^~~~
deepstream_app.c:461:48: error: invalid conversion from ‘gpointer {aka void*}’ to ‘char*’ [-fpermissive]
       obj->text_params.display_text = g_malloc (128);
                                       ~~~~~~~~~^~~~~
Makefile:67: recipe for target 'deepstream_app.o' failed
make: *** [deepstream_app.o] Error 1

You need to do some casts for the pointer. Like : NvDsFrameMeta *frame_meta = (NvDsFrameMeta *) l_frame->data;. You can cast the others by yourself.

Hi, thanks for the reply. I have casted a lot of pointers as you mentioned. Now, I am stuck. While compiling, I am getting the error

g++ -c -o ../../apps-common/src/deepstream_c2d_msg_util.o -DPLATFORM_TEGRA -I./ -I../../apps-common/includes -I../../../includes -DDS_VERSION_MINOR=1 -DDS_VERSION_MAJOR=5 -I /usr/local/cuda-10.2/include -pthread -I/usr/include/gstreamer-1.0 -I/usr/include/orc-0.4 -I/usr/include/gstreamer-1.0 -I/usr/include/json-glib-1.0 -I/usr/include/glib-2.0 -I/usr/lib/aarch64-linux-gnu/glib-2.0/include ../../apps-common/src/deepstream_c2d_msg_util.c
../../apps-common/src/deepstream_c2d_msg_util.c:25:0: warning: "__USE_XOPEN" redefined
 #define __USE_XOPEN
 
In file included from /usr/include/aarch64-linux-gnu/bits/libc-header-start.h:33:0,
                 from /usr/include/stdio.h:27,
                 from ../../apps-common/src/deepstream_c2d_msg_util.c:23:
/usr/include/features.h:330:0: note: this is the location of the previous definition
 # define __USE_XOPEN 1
 
../../apps-common/src/deepstream_c2d_msg_util.c: In function ‘NvDsC2DMsg* nvds_c2d_parse_cloud_message(gpointer, guint)’:
../../apps-common/src/deepstream_c2d_msg_util.c:97:63: error: invalid conversion from ‘gpointer {aka void*}’ to ‘const gchar* {aka const char*}’ [-fpermissive]
   ret = json_parser_load_from_data (parser, data, size, &error);
                                                               ^
In file included from /usr/include/json-glib-1.0/json-glib/json-glib.h:33:0,
                 from ../../apps-common/src/deepstream_c2d_msg_util.c:27:
/usr/include/json-glib-1.0/json-glib/json-parser.h:157:13: note:   initializing argument 2 of ‘gboolean json_parser_load_from_data(JsonParser*, const gchar*, gssize, GError**)’
 gboolean    json_parser_load_from_data          (JsonParser           *parser,
             ^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/glib-2.0/glib/glist.h:32:0,
                 from /usr/include/glib-2.0/glib/ghash.h:33,
                 from /usr/include/glib-2.0/glib.h:50,
                 from /usr/include/glib-2.0/gobject/gbinding.h:28,
                 from /usr/include/glib-2.0/glib-object.h:23,
                 from /usr/include/json-glib-1.0/json-glib/json-types.h:31,
                 from /usr/include/json-glib-1.0/json-glib/json-glib.h:29,
                 from ../../apps-common/src/deepstream_c2d_msg_util.c:27:
/usr/include/glib-2.0/glib/gmem.h:240:74: error: cannot convert ‘gchar* {aka char*}’ to ‘NvDsC2DMsgSR*’ in initialization
         ((struct_type *) g_##func##_n ((n_structs), sizeof (struct_type)))
                                                                          ^
/usr/include/glib-2.0/glib/gmem.h:279:42: note: in expansion of macro ‘_G_NEW’
 #define g_new0(struct_type, n_structs)   _G_NEW (struct_type, n_structs, malloc0)
                                          ^~~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:190:33: note: in expansion of macro ‘g_new0’
   NvDsC2DMsgSR *srMsg =(gchar *)g_new0 (NvDsC2DMsgSR, 1);
                                 ^~~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:209:1: error: jump to label ‘error’ [-fpermissive]
 error:
 ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:173:16: note:   from here
           goto error;
                ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:190:17: note:   crosses initialization of ‘NvDsC2DMsgSR* srMsg’
   NvDsC2DMsgSR *srMsg =(gchar *)g_new0 (NvDsC2DMsgSR, 1);
                 ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:209:1: error: jump to label ‘error’ [-fpermissive]
 error:
 ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:156:16: note:   from here
           goto error;
                ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:190:17: note:   crosses initialization of ‘NvDsC2DMsgSR* srMsg’
   NvDsC2DMsgSR *srMsg =(gchar *)g_new0 (NvDsC2DMsgSR, 1);
                 ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:209:1: error: jump to label ‘error’ [-fpermissive]
 error:
 ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:131:16: note:   from here
           goto error;
                ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:190:17: note:   crosses initialization of ‘NvDsC2DMsgSR* srMsg’
   NvDsC2DMsgSR *srMsg =(gchar *)g_new0 (NvDsC2DMsgSR, 1);
                 ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:209:1: error: jump to label ‘error’ [-fpermissive]
 error:
 ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:118:14: note:   from here
         goto error;
              ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:190:17: note:   crosses initialization of ‘NvDsC2DMsgSR* srMsg’
   NvDsC2DMsgSR *srMsg =(gchar *)g_new0 (NvDsC2DMsgSR, 1);
                 ^~~~~
Makefile:67: recipe for target '../../apps-common/src/deepstream_c2d_msg_util.o' failed
make: *** [../../apps-common/src/deepstream_c2d_msg_util.o] Error 1

As you can see I’ve already casted the void pointer returned by g_new0 to gchar* here, If I cast it to NvDsC2DMsgSR *, it is throwing error from different line

g++ -c -o ../../apps-common/src/deepstream_c2d_msg_util.o -DPLATFORM_TEGRA -I./ -I../../apps-common/includes -I../../../includes -DDS_VERSION_MINOR=1 -DDS_VERSION_MAJOR=5 -I /usr/local/cuda-10.2/include -pthread -I/usr/include/gstreamer-1.0 -I/usr/include/orc-0.4 -I/usr/include/gstreamer-1.0 -I/usr/include/json-glib-1.0 -I/usr/include/glib-2.0 -I/usr/lib/aarch64-linux-gnu/glib-2.0/include ../../apps-common/src/deepstream_c2d_msg_util.c
../../apps-common/src/deepstream_c2d_msg_util.c:25:0: warning: "__USE_XOPEN" redefined
 #define __USE_XOPEN
 
In file included from /usr/include/aarch64-linux-gnu/bits/libc-header-start.h:33:0,
                 from /usr/include/stdio.h:27,
                 from ../../apps-common/src/deepstream_c2d_msg_util.c:23:
/usr/include/features.h:330:0: note: this is the location of the previous definition
 # define __USE_XOPEN 1
 
../../apps-common/src/deepstream_c2d_msg_util.c: In function ‘NvDsC2DMsg* nvds_c2d_parse_cloud_message(gpointer, guint)’:
../../apps-common/src/deepstream_c2d_msg_util.c:97:63: error: invalid conversion from ‘gpointer {aka void*}’ to ‘const gchar* {aka const char*}’ [-fpermissive]
   ret = json_parser_load_from_data (parser, data, size, &error);
                                                               ^
In file included from /usr/include/json-glib-1.0/json-glib/json-glib.h:33:0,
                 from ../../apps-common/src/deepstream_c2d_msg_util.c:27:
/usr/include/json-glib-1.0/json-glib/json-parser.h:157:13: note:   initializing argument 2 of ‘gboolean json_parser_load_from_data(JsonParser*, const gchar*, gssize, GError**)’
 gboolean    json_parser_load_from_data          (JsonParser           *parser,
             ^~~~~~~~~~~~~~~~~~~~~~~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:209:1: error: jump to label ‘error’ [-fpermissive]
 error:
 ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:173:16: note:   from here
           goto error;
                ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:190:17: note:   crosses initialization of ‘NvDsC2DMsgSR* srMsg’
   NvDsC2DMsgSR *srMsg =(NvDsC2DMsgSR *)g_new0 (NvDsC2DMsgSR, 1);
                 ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:209:1: error: jump to label ‘error’ [-fpermissive]
 error:
 ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:156:16: note:   from here
           goto error;
                ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:190:17: note:   crosses initialization of ‘NvDsC2DMsgSR* srMsg’
   NvDsC2DMsgSR *srMsg =(NvDsC2DMsgSR *)g_new0 (NvDsC2DMsgSR, 1);
                 ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:209:1: error: jump to label ‘error’ [-fpermissive]
 error:
 ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:131:16: note:   from here
           goto error;
                ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:190:17: note:   crosses initialization of ‘NvDsC2DMsgSR* srMsg’
   NvDsC2DMsgSR *srMsg =(NvDsC2DMsgSR *)g_new0 (NvDsC2DMsgSR, 1);
                 ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:209:1: error: jump to label ‘error’ [-fpermissive]
 error:
 ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:118:14: note:   from here
         goto error;
              ^~~~~
../../apps-common/src/deepstream_c2d_msg_util.c:190:17: note:   crosses initialization of ‘NvDsC2DMsgSR* srMsg’
   NvDsC2DMsgSR *srMsg =(NvDsC2DMsgSR *)g_new0 (NvDsC2DMsgSR, 1);
                 ^~~~~
Makefile:67: recipe for target '../../apps-common/src/deepstream_c2d_msg_util.o' failed
make: *** [../../apps-common/src/deepstream_c2d_msg_util.o] Error 1

If C/C++ compilation is not very clear, the whole changes may be very complex. Could you just refer to our open source: deepstream-nvdsanalytics-test?

1 Like

Hi, thanks for the reply. Now I am working on the deepstream_app_main.c in the deepstream-nvdsanalytics-test app. However, I am facing an issue, could you please look into that?
https://forums.developer.nvidia.com/t/how-to-access-the-bin-to-trigger-smart-recording-from-within-a-probe/246822