Hi,
Thanks for your patience.
Deepstream + VPI can work with the vpiImageCreateHostMemWrapper as below:
diff --git a/gstdsexample.cpp b/gstdsexample.cpp
index 98df7c9..c521c46 100644
--- a/gstdsexample.cpp
+++ b/gstdsexample.cpp
@@ -442,6 +442,7 @@ gst_dsexample_transform_ip (GstBaseTransform * btrans, GstBuffer * inbuf)
VPIImageData img_data;
VPIImage img = NULL;
+ VPIImage out = NULL;
cv::Mat in_mat;
cv::Mat out_mat;
@@ -488,25 +489,42 @@ gst_dsexample_transform_ip (GstBaseTransform * btrans, GstBuffer * inbuf)
//printf("Num planes %d, Width %d, Height %d, Pitch %d, Offset %d, Size %d, bytesPerPix %d \n", surface->surfaceList[0].planeParams.num_planes, surface->surfaceList[0].planeParams.width[
1],surface->surfaceList[0].planeParams.height[1], surface->surfaceList[0].planeParams.pitch[1], surface->surfaceList[0].planeParams.offset[1], surface->surfaceList[0].planeParams.psize[1],s
urface->surfaceList[0].planeParams.bytesPerPix[1]);
//Make every other frame average grey.
+ if (surface->surfaceList[0].mappedAddr.addr[0] == NULL){
+ if (NvBufSurfaceMap (surface, 0, 0, NVBUF_MAP_READ_WRITE) != 0){
+ GST_ELEMENT_ERROR (dsexample, STREAM, FAILED,
+ ("%s:buffer map to be accessed by CPU failed", __func__), (NULL));
+ return GST_FLOW_ERROR;
+ }
+ }
+
+ NvBufSurfaceSyncForCpu (dsexample->inter_buf, 0, 0);
+
memset(&img_data, 0, sizeof(img_data));
img_data.format = VPI_IMAGE_FORMAT_RGBA8;
img_data.numPlanes = surface->surfaceList[0].planeParams.num_planes;
+ if(dsexample->inter_buf->memType == NVBUF_MEM_SURFACE_ARRAY)
+ NvBufSurfaceSyncForCpu (surface, 0, 0);
for(i=0; i<img_data.numPlanes; i++) {
img_data.planes[i].width = surface->surfaceList[0].planeParams.width[i];
img_data.planes[i].height = surface->surfaceList[0].planeParams.height[i];
img_data.planes[i].pitchBytes = surface->surfaceList[0].planeParams.pitch[i];
- img_data.planes[i].data = surface->surfaceList[0].dataPtr;//(void *)&((char *)surface->surfaceList[0].mappedAddr.addr[i])[surface->surfaceList[0].planeParams.offset[1]];
+ img_data.planes[i].data = surface->surfaceList[0].mappedAddr.addr[0];
}
- CHECK_VPI_STATUS(vpiImageCreateCUDAMemWrapper(&img_data, 0, &img));
+ CHECK_VPI_STATUS(vpiImageCreate(img_data.planes[0].width, img_data.planes[0].height, VPI_IMAGE_FORMAT_BGR8, 0, &out));
+ CHECK_VPI_STATUS(vpiImageCreateHostMemWrapper(&img_data, 0, &img));
+ CHECK_VPI_STATUS(vpiSubmitConvertImageFormat(dsexample->vpi_stream, VPI_BACKEND_CUDA, img, out, NULL));
+ CHECK_VPI_STATUS(vpiStreamSync(dsexample->vpi_stream));
- CHECK_VPI_STATUS(vpiSubmitConvertImageFormat(dsexample->vpi_stream, VPI_BACKEND_CUDA, img, img, NULL));
+ VPIImageData data;
+ CHECK_VPI_STATUS(vpiImageLock(out, VPI_LOCK_READ, &data));
+
+ out_mat = cv::Mat (data.planes[0].height, data.planes[0].width, CV_8UC3, data.planes[0].data, data.planes[0].pitchBytes);
+ cv::imwrite("/home/nvidia/output.png", out_mat);
- CHECK_VPI_STATUS(vpiStreamSync(dsexample->vpi_stream));
-
//if (NvBufSurfaceUnMap (surface, 0, -1)){
// goto error;
We are working on feeding the CUDA buffer to VPI with vpiImageCreateCudaMemWrapper directly.
Hope to give you an update soon.
Thanks.