/* * @Description: 推理模块 * @Version: 1.0 * @Autor: lishengyin * @Date: 2021-10-13 09:37:51 * @LastEditors: lishengyin * @LastEditTime: 2022-10-09 09:45:46 */ #pragma once #include #include #include #include #include #include #include #include #include #include "nvdsmeta.h" #include "gstnvdsmeta.h" #include "gst-nvmessage.h" #include "nvbufsurface.h" #include "DataSource.h" #include "InferRange.h" // ZLMediaKit #include "Util/logger.h" #include "Util/NoticeCenter.h" #include "Util/SqlPool.h" #include "Network/TcpClient.h" #include "Poller/Timer.h" #include "TCPClient.h" #include "recorder.h" #include #include #include #include #include // opencv #include #include #include #include #include #include using namespace std; namespace MIVA{ // 基于Deepstream class Inference { private: // Deepstream GMainLoop *loop = NULL; GstElement *pipeline = NULL,*streammux =NULL, *sink = NULL, *pgie = NULL, *queue1, *queue2, *queue3, *queue4, *queue5, *nvvidconv = NULL, *nvosd = NULL,*tiler = NULL; GstElement *transform = NULL; GstBus *bus = NULL; guint bus_watch_id; GstPad *pgie_src_pad = NULL; GstPad *tiler_sink_pad = NULL; guint tiler_rows, tiler_columns; guint pgie_batch_size; public: std::shared_ptr> m_DataList = NULL; std::shared_ptr m_InferInfo = nullptr; std::shared_ptr m_recorder = nullptr; bool Play = false; bool enable = false; int InferNum = 0; Inference(); ~Inference(); public: /** * @description: 创建实例 * @param {*} * @return {*} */ static std::shared_ptr CreateNew(); /** * @description: 推理模块初始化 * @param {vector} DataList 数据源集合 * @return {*} * @author: lishengyin */ int32_t Init(); /** * @description: 启动任务 * @param {*} * @return {*} * @author: lishengyin */ int32_t StartTask(); /** * @description: 停止任务 * @param {*} * @return {*} * @author: lishengyin */ void StopTask(); /** * @description: 重启任务 * @param {*} * @return {*} * @author: lishengyin */ int32_t RestartTask(); /** * @description:记录 * @param {*} * @return {*} */ int32_t Recorder(); /** * @description: 暂停任务 * @param {*} * @return {*} */ void PausedTask(); /** * @description: 检查任务 * @param {*} * @return {*} */ void CheckTask(); /** * @description: Destory() * @return {*} */ void Destory(); /** * @description: QuitLoop * @param {*} * @return {*} */ void QuitLoop(); /** * @description: 状态返回 * @param {*} * @return {*} */ static void StateResulit(GstStateChangeReturn& state_return); public: /** * @description: 获取推理结果 * @param {GstPad *} pad * @param {GstPadProbeInfo *} info * @param {gpointer} u_data * @return {*} * @author: lishengyin */ static GstPadProbeReturn tiler_sink_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * probe_info, gpointer u_data); /** * @description: 监听bus * @param {GstBus *} bus * @param {GstMessage *} msg * @param {gpointer} data * @return {*} * @author: lishengyin */ static gboolean bus_call (GstBus * bus, GstMessage * msg, gpointer data); /** * @description: 解码模块监听child_added * @param {*} * @return {*} * @author: lishengyin */ static void decodebin_child_added (GstChildProxy * child_proxy, GObject * object, gchar * name, gpointer user_data); /** * @description: 创建解码bin * @param {guint} index * @param {gchar *} filename * @return {*} * @author: lishengyin */ static GstElement * create_uridecode_bin (guint index, gchar * filename); /** * @description: 解码模块监听pad-added * @param {GstElement *} decodebin * @param {GstPad *} pad * @param {gpointer} data * @return {*} * @author: lishengyin */ static void cb_newpad (GstElement * decodebin, GstPad * pad, gpointer data); /** * @description: 判断点是否在区域内 * @param {Point} p * @param {int} nCount * @return {*} */ static int PtInPolygon (Point p, vector& ptPolygon, int nCount); /** * @description: 添加数据源 * @param {int} source_Id 数据源ID * @param {string} uri 数据源Url * @return {*} 是否添加成功 * @author: lishengyin */ GstElement* add_sources (int source_Id, std::string uri); /** * @description: 删除数据源 * @param {gint} source_id * @return {*} * @author: lishengyin */ void stop_release_source (gint source_id); /** * @description: 修改数据源地址 * @param {GstElement} *source_bin * @param {string} uri * @return {*} */ void ModifyUri(GstElement *source_bin, std::string uri); /** * @description: 释放元素 * @param {GstElement} *source_bin * @return {*} */ void FreeElement(int source_Id,GstElement *source_bin); /** * @description: 添加数据源 * @param {int} sourceId * @return {*} */ void AddSources(int sourceId); /** * @description: 设置Batch * @param {int} num * @return {*} */ void SetBatch(int num); }; }