NvDsCustomMsgInfo support for python API mvsmgconv msg2p-newapi=1

Please provide complete information as applicable to your setup.
It seems GitHub - NVIDIA-AI-IOT/deepstream_python_apps: DeepStream SDK Python bindings and sample applications python API current version doesn’t support NvDsCustomMsgInfo which is used as custom data msg type for mvsmgconv while using new config msg2p-newapi=1

any support on it ?
• Hardware Platform (Jetson / GPU)
• DeepStream Version
• JetPack Version (valid for Jetson only)
• TensorRT Version
• NVIDIA GPU Driver Version (valid for GPU only)
• Issue Type( questions, new requirements, bugs)
• How to reproduce the issue ? (This is for bugs. Including which sample app is using, the configuration files content, the command line used and other details for reproducing)
• Requirement details( This is for new requirement. Including the module name-for which plugin or for which sample application, the function description)

There is no python binding for “NvDsCustomMsgInfo”, you can generate the new binding with the code deepstream_python_apps/bindings at master · NVIDIA-AI-IOT/deepstream_python_apps (github.com).

I add NvDsCustomMsgInfo in bindschema.cpp like

        py::class_<NvDsCustomMsgInfo>(m, "NvDsCustomMsgInfo",
                                pydsdoc::metaschema::CustomMsgInfoDoc::descr)
                .def(py::init<>())
                .def_readwrite("message", &NvDsCustomMsgInfo::message)
                .def_readwrite("size", &NvDsCustomMsgInfo::size)
                .def("cast",
                     [](void *data) {
                         return (NvDsCustomMsgInfo *) data;
                     },
                     py::return_value_policy::reference,
                     pydsdoc::metaschema::CustomMsgInfoDoc::cast)

                .def("cast",
                     [](size_t data) {
                         return (NvDsCustomMsgInfo *) data;
                     },
                     py::return_value_policy::reference,
                     pydsdoc::metaschema::CustomMsgInfoDoc::cast);

        m.def("alloc_nvds_custommsginfo",
              []() {
                  auto *mem = (NvDsCustomMsgInfo *) g_malloc0(
                          sizeof(NvDsCustomMsgInfo));
                  return mem;
              },
              py::return_value_policy::reference,
              pydsdoc::methodsDoc::alloc_nvds_custommsginfo);

but error raised when setting message attribute

custom_msg_info = pyds.alloc_nvds_custommsginfo()
custom_msg_info.message = b'abc'

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: (): incompatible function arguments. The following argument types are supported:
    1. (self: pyds.NvDsCustomMsgInfo, arg0: capsule) -> None

Invoked with: <pyds.NvDsCustomMsgInfo object at 0x7fec59734490>, b'abc'

I see message defined type void* in nvdsmeta_schema.h

typedef struct _NvDsCustomMsgInfo {
  void *message;
  guint size;
}NvDsCustomMsgInfo;

I’m not familiar with pybind11, any suggestion to make type convertion to make custom_msg_info.message accept typestring or bytes[] on python side?

There is “void *” in NvDsUserMeta, please refer to NvDsUserMeta sample of how to cast “void *”.

c/c++: NVIDIA DeepStream SDK API Reference: _NvDsUserMeta Struct Reference
python binding: NvDsUserMeta — Deepstream Deepstream Version: 6.1.1 documentation

I added new macro VOID_PROPERTY like STRING_PROPERTY in bind_string_property_definitions.h:

#define VOID_PROPERTY(TYPE, FIELD)                                 \
        [](const TYPE &self)->size_t {                             \
            return (size_t)self.FIELD;                             \
        },                                                         \
        [](TYPE &self, std::string str) {                          \
            int strSize = str.size();                              \
            self.FIELD = (void*)calloc(strSize + 1, sizeof(char)); \
            str.copy((char*)self.FIELD, strSize);                  \
        },                                                         \
        py::return_value_policy::reference

and changed bindschema.cpp like:

        py::class_<NvDsCustomMsgInfo>(m, "NvDsCustomMsgInfo",
                                pydsdoc::metaschema::CustomMsgInfoDoc::descr)
                .def(py::init<>())
                .def_property("message", VOID_PROPERTY(NvDsCustomMsgInfo, message))
                // .def_readwrite("message", &NvDsCustomMsgInfo::message)
                .def_readwrite("size", &NvDsCustomMsgInfo::size)

now it works for setting string value and getting it like:

>>> custom_msg_info = pyds.alloc_nvds_custommsginfo()
>>> custom_msg_info.message = 'abc'
>>> pyds.get_string(custom_msg_info.message)
abc

Glad to hear you got it resolved!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.