#ifndef __DVPP_DATA_MEMORY_HPP__ #define __DVPP_DATA_MEMORY_HPP__ #include #include "depend_headers.h" #include "dvpp_headers.h" #include using namespace std; // static int snap_free = 0; class DvppDataMemory : public DeviceMemory { public: DvppDataMemory(int _channel, int _width, int _width_stride, int _height, int _height_stride, int _size, string _id, string _dev_id, bool _key_frame, unsigned long long frame_nb) :DeviceMemory(_channel, _width, _width_stride, _height, _height_stride, _size, _id, _dev_id, _key_frame, frame_nb, false){ data_type = 0; int ret = acldvppMalloc((void **)&pHwRgb, data_size); if(ret != ACL_ERROR_NONE){ LOG_ERROR("[{}]- acldvppMalloc failed", id); } } DvppDataMemory( int _width, int _width_stride, int _height, int _height_stride, int _size, string _id, string _dev_id, bool _key_frame, unsigned long long frame_nb, unsigned char * pHwData) :DeviceMemory(3, _width, _width_stride, _height, _height_stride, _size, _id, _dev_id, _key_frame, frame_nb, false){ data_type = 0; pHwRgb = pHwData; } DvppDataMemory(DvppDataMemory* pSrc):DeviceMemory(3, pSrc->getWidth(), pSrc->getWidthStride(), pSrc->getHeight(), pSrc->getHeightStride(), pSrc->getSize(), pSrc->getId(), pSrc->getDeviceId(), pSrc->isKeyFrame(), pSrc->getFrameNb(), false){ if(pSrc == nullptr) { LOG_ERROR("[{}]- pSrc is nullptr", pSrc->getId()); return; } int ret = acldvppMalloc((void **)&pHwRgb, data_size); if(ret != ACL_ERROR_NONE){ LOG_ERROR("[{}]- acldvppMalloc failed", pSrc->getId()); return; } ret = aclrtMemcpy(pHwRgb, data_size, pSrc->getMem(), pSrc->getSize(), ACL_MEMCPY_DEVICE_TO_DEVICE); if(ret != ACL_ERROR_NONE){ acldvppFree(pHwRgb); LOG_ERROR("[{}]- aclrtMemcpy failed", pSrc->getId()); return; } data_type = 0; timestamp = UtilTools::get_cur_time_ms(); } ~DvppDataMemory(){ // if (data_type == 2) // { // snap_free++; // LOG_INFO("[{}]- snap_free: {}", getId(), snap_free); // } if (pHwRgb) { int ret = acldvppFree(pHwRgb); if(ret != ACL_ERROR_NONE){ LOG_ERROR("[{}]- acldvppFree failed", id); } pHwRgb = nullptr; } } HostData* memCpy2Host() { HostData* hostData = new HostData(getWidth(), getWidthStride(), getHeight(), getHeightStride(), getSize(), getId()); int _size = getSize(); int ret = aclrtMemcpy(hostData->pData, getSize(), getMem(), getSize(), ACL_MEMCPY_DEVICE_TO_HOST); if(ret != ACL_ERROR_NONE){ LOG_ERROR("[{}]- aclrtMemcpy failed", getId()); return nullptr; } return hostData; } virtual DeviceMemory* clone() { DvppDataMemory* pData = new DvppDataMemory(this); return pData; } public: int data_type; // 0: rgb , 1: NV12 }; // typedef std::shared_ptr DvppDataMemoryPtr; #endif // __DVPP_DATA_MEMORY_HPP__