#ifndef DATA_PACKAGE_H #define DATA_PACKAGE_H #include #include #include "../AIManager/inferResult.h" #define RESIZE_WIDTH 640 #define RESIZE_HEIGHT 640 typedef struct DataPackage { int nDeviceID = 0; void *pJpegData{nullptr}; int nJpegSize = 0; void *pRGBData{nullptr}; int nWidth = 0; int nHeight = 0; void *pResizeData{nullptr}; int nResizeWidth = RESIZE_WIDTH; int nResizeHeight = RESIZE_HEIGHT; int nResizeType = 0; // other infomation long nTimeStamp = 0.0; double dDegree = 0.0; // result int id = 0; int count = 0; object_detect_result_list Result; DataPackage(int width, int height) { if (allocResource(width, height)) { nWidth = width; nHeight = height; } else { std::cerr << "allocResource failed" << std::endl; } } bool allocResource(int width, int height) { if (pJpegData == nullptr) { pJpegData = new unsigned char[width * height * 3]; if (pJpegData == nullptr) { return false; } } // if (pRGBData == nullptr) // { // pRGBData = new unsigned char[width * height * 3]; // if (pRGBData == nullptr) // { // return false; // } // } if (pResizeData == nullptr) { pResizeData = new unsigned char[nResizeWidth * nResizeHeight * 3]; if (pResizeData == nullptr) { return false; } } return true; } void freeResource() { if (pJpegData != nullptr) { delete[] (unsigned char *)pJpegData; pJpegData = nullptr; } if (pRGBData != nullptr) { delete[] (unsigned char *)pRGBData; pRGBData = nullptr; } if (pResizeData != nullptr) { delete[] (unsigned char *)pResizeData; pResizeData = nullptr; } } ~DataPackage() { freeResource(); } } DATA_PACKAGE, *PDATA_PACKAGE; typedef DataPackage *DataPackagePtr; #endif // DATA_PACKAGE_H