|
@@ -4,7 +4,7 @@
|
|
|
* @Autor: lishengyin
|
|
|
* @Date: 2021-10-13 09:35:37
|
|
|
* @LastEditors: lishengyin
|
|
|
- * @LastEditTime: 2021-12-06 09:53:18
|
|
|
+ * @LastEditTime: 2021-12-09 09:21:18
|
|
|
*/
|
|
|
#include "inference.h"
|
|
|
|
|
@@ -52,6 +52,7 @@ GMutex eos_lock;
|
|
|
|
|
|
GstElement *g_streammux = NULL;
|
|
|
std::shared_ptr<InferInfo> g_InferInfo = NULL;
|
|
|
+
|
|
|
|
|
|
namespace MIVA{
|
|
|
std::shared_ptr<Inference> infer = NULL;
|
|
@@ -211,11 +212,11 @@ namespace MIVA{
|
|
|
this->tiler_src_pad_buffer_probe, NULL, NULL);
|
|
|
gst_object_unref (this->tiler_src_pad);
|
|
|
|
|
|
- this->osd_sink_pad = gst_element_get_static_pad (this->nvosd, "src");
|
|
|
- gst_pad_add_probe (this->osd_sink_pad, GST_PAD_PROBE_TYPE_BUFFER,
|
|
|
- osd_sink_pad_buffer_probe, NULL, NULL);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- gst_object_unref (this->osd_sink_pad);
|
|
|
+
|
|
|
return OK;
|
|
|
}
|
|
|
|
|
@@ -252,6 +253,26 @@ namespace MIVA{
|
|
|
g_main_loop_run(this->loop);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
pool.start();
|
|
|
return OK;
|
|
|
}
|
|
@@ -307,6 +328,10 @@ namespace MIVA{
|
|
|
}
|
|
|
sourceId++;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
NoticeCenter::Instance().emitEvent(NOTICE_RELEASE);
|
|
|
}
|
|
|
|
|
@@ -465,48 +490,57 @@ namespace MIVA{
|
|
|
NvBufSurface *surface = (NvBufSurface *)in_map_info.data;
|
|
|
NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta (buf);
|
|
|
l_frame = batch_meta->frame_meta_list;
|
|
|
-
|
|
|
- if (l_frame) {
|
|
|
+
|
|
|
+ for (l_frame = batch_meta->frame_meta_list; l_frame != NULL;l_frame = l_frame->next)
|
|
|
+ {
|
|
|
NvDsFrameMeta *frame_meta = (NvDsFrameMeta *) (l_frame->data);
|
|
|
|
|
|
src_data = (char*) malloc(surface->surfaceList[frame_meta->batch_id].dataSize);
|
|
|
if(src_data == NULL) {
|
|
|
g_print("Error: failed to malloc src_data \n");
|
|
|
}
|
|
|
- #ifdef PLATFORM_TEGRA
|
|
|
- NvBufSurfaceMap (surface, -1, -1, NVBUF_MAP_READ);
|
|
|
- NvBufSurfacePlaneParams *pParams = &surface->surfaceList[frame_meta->batch_id].planeParams;
|
|
|
- unsigned int offset = 0;
|
|
|
- for(unsigned int num_planes=0; num_planes < pParams->num_planes; num_planes++){
|
|
|
- if(num_planes>0)
|
|
|
- offset += pParams->height[num_planes-1]*(pParams->bytesPerPix[num_planes-1]*pParams->width[num_planes-1]);
|
|
|
- for (unsigned int h = 0; h < pParams->height[num_planes]; h++) {
|
|
|
- memcpy((void *)(src_data+offset+h*pParams->bytesPerPix[num_planes]*pParams->width[num_planes]),
|
|
|
- (void *)((char *)surface->surfaceList[frame_meta->batch_id].mappedAddr.addr[num_planes]+h*pParams->pitch[num_planes]),
|
|
|
- pParams->bytesPerPix[num_planes]*pParams->width[num_planes]
|
|
|
- );
|
|
|
+ #ifdef PLATFORM_TEGRA
|
|
|
+ NvBufSurfaceMap (surface, -1, -1, NVBUF_MAP_READ);
|
|
|
+ NvBufSurfacePlaneParams *pParams = &surface->surfaceList[frame_meta->batch_id].planeParams;
|
|
|
+ unsigned int offset = 0;
|
|
|
+ for(unsigned int num_planes=0; num_planes < pParams->num_planes; num_planes++){
|
|
|
+ if(num_planes>0)
|
|
|
+ offset += pParams->height[num_planes-1]*(pParams->bytesPerPix[num_planes-1]*pParams->width[num_planes-1]);
|
|
|
+ for (unsigned int h = 0; h < pParams->height[num_planes]; h++) {
|
|
|
+ memcpy((void *)(src_data+offset+h*pParams->bytesPerPix[num_planes]*pParams->width[num_planes]),
|
|
|
+ (void *)((char *)surface->surfaceList[frame_meta->batch_id].mappedAddr.addr[num_planes]+h*pParams->pitch[num_planes]),
|
|
|
+ pParams->bytesPerPix[num_planes]*pParams->width[num_planes]
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- NvBufSurfaceSyncForDevice (surface, -1, -1);
|
|
|
- NvBufSurfaceUnMap (surface, -1, -1);
|
|
|
- #else
|
|
|
- cudaMemcpy((void*)src_data,
|
|
|
- (void*)surface->surfaceList[frame_meta->batch_id].dataPtr,
|
|
|
- surface->surfaceList[frame_meta->batch_id].dataSize,
|
|
|
- cudaMemcpyDeviceToHost);
|
|
|
- #endif
|
|
|
-
|
|
|
- gint frame_width = (gint)surface->surfaceList[frame_meta->batch_id].width;
|
|
|
- gint frame_height = (gint)surface->surfaceList[frame_meta->batch_id].height;
|
|
|
- gint frame_step = surface->surfaceList[frame_meta->batch_id].pitch;
|
|
|
- cv::Mat frame = cv::Mat(frame_height, frame_width, CV_8UC4, src_data, frame_step);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- cv::Mat out_mat = cv::Mat (cv::Size(frame_width, frame_height), CV_8UC3);
|
|
|
- cv::cvtColor(frame, out_mat, CV_RGBA2BGR);
|
|
|
- cv::imwrite("test.jpg", out_mat);
|
|
|
+ NvBufSurfaceSyncForDevice (surface, -1, -1);
|
|
|
+ NvBufSurfaceUnMap (surface, -1, -1);
|
|
|
+ #else
|
|
|
+ cudaMemcpy((void*)src_data,
|
|
|
+ (void*)surface->surfaceList[frame_meta->batch_id].dataPtr,
|
|
|
+ surface->surfaceList[frame_meta->batch_id].dataSize,
|
|
|
+ cudaMemcpyDeviceToHost);
|
|
|
+ #endif
|
|
|
+ gint frame_width = (gint)surface->surfaceList[frame_meta->batch_id].width;
|
|
|
+ gint frame_height = (gint)surface->surfaceList[frame_meta->batch_id].height;
|
|
|
+ gint frame_step = surface->surfaceList[frame_meta->batch_id].pitch;
|
|
|
+
|
|
|
+ cv::Mat frame = cv::Mat(frame_height, frame_width, CV_8UC4, src_data, frame_step);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ cv::Mat out_mat = cv::Mat (cv::Size(frame_width, frame_height), CV_8UC3);
|
|
|
+ cv::cvtColor(frame, out_mat, CV_RGBA2BGR);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
if(src_data != NULL) {
|
|
|
free(src_data);
|
|
|
src_data = NULL;
|
|
@@ -514,6 +548,7 @@ namespace MIVA{
|
|
|
}
|
|
|
gst_buffer_unmap (buf, &in_map_info);
|
|
|
return GST_PAD_PROBE_OK;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -634,7 +669,7 @@ namespace MIVA{
|
|
|
g_object_set (object, "enable-max-performance", TRUE, NULL);
|
|
|
g_object_set (object, "bufapi-version", TRUE, NULL);
|
|
|
g_object_set (object, "drop-frame-interval", 0, NULL);
|
|
|
- g_object_set (object, "num-extra-surfaces", 2, NULL);
|
|
|
+
|
|
|
#else
|
|
|
g_object_set (object, "gpu-id", 0, NULL);
|
|
|
#endif
|