Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bindings/docstrings/pydocumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,12 @@ namespace pydsdoc
:arg gst_buffer: address of the Gstbuffer which contains `NvBufSurface`
:arg batchID: batch_id of the frame to be processed. This indicates the frame's index within `NvBufSurface`)pyds";

constexpr const char* unmap_nvds_buf_surface=R"pyds(
Unmap the previously mapped buffer. Do nothing if buffer has not been mapped.

:arg gst_buffer: address of the GstBuffer which contains `NvBufSurface`
:arg batch_id: batch_id of the frame to be unmap. This indicates the frame's index within `NvBufSurface`)pyds";

constexpr const char* nvds_acquire_meta_lock=R"pyds(
Acquire the lock before updating metadata.

Expand Down
28 changes: 28 additions & 0 deletions bindings/src/bindfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,34 @@ namespace pydeepstream {
py::return_value_policy::reference,
pydsdoc::methodsDoc::get_nvds_buf_surface);


/**
* Unmap the previously mapped buffer if it has been mapped.
* It's needed to prevent memory leaks.
* See https://forums.developer.nvidia.com/t/memory-leak-on-xavier-nx/234438 for details.
*/
m.def("unmap_nvds_buf_surface",
[](size_t gst_buffer, int batch_id) {
auto *buffer = reinterpret_cast<GstBuffer *>(gst_buffer);
GstMapInfo map_info;
gst_buffer_map(buffer, &map_info, GST_MAP_READ);
auto *nvsurface = reinterpret_cast<NvBufSurface *>(map_info.data);
gst_buffer_unmap(buffer, &map_info);

// Unmap the buffer if it has been mapped
if (nullptr != nvsurface->surfaceList[batch_id].mappedAddr.addr[0]) {
int ret = NvBufSurfaceUnMap(nvsurface, batch_id, -1);
if (ret < 0) {
throw std::runtime_error(
"unmap_nvds_buf_surface: Failed to unmap buffer");
}
}
},
"gst_buffer"_a,
"batch_id"_a,
pydsdoc::methodsDoc::unmap_nvds_buf_surface
);

//FIXME: Find a better way of doing this
/**
* Type casting to @NvDsBatchMeta
Expand Down
6 changes: 6 additions & 0 deletions docs/PYTHON_API/Methods/methodsdoc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ get_nvds_buf_surface

.. autofunction:: pyds.get_nvds_buf_surface

==============
unmap_nvds_buf_surface
==============

.. autofunction:: pyds.unmap_nvds_buf_surface

==============
nvds_acquire_meta_lock
==============
Expand Down