1
0
mirror of https://github.com/opencv/opencv_contrib.git synced 2025-10-15 12:07:08 +08:00

Merge pull request #3969 from CodeLinaro:apreetam_7thPost

Modified QcAllocator to store File Descriptor
This commit is contained in:
Alexander Smorkalov
2025-07-16 13:35:13 +03:00
committed by GitHub
2 changed files with 11 additions and 2 deletions

View File

@@ -36,6 +36,9 @@ private:
/** /**
* @brief Qualcomm's custom allocator. * @brief Qualcomm's custom allocator.
* This allocator uses Qualcomm's memory management functions. * This allocator uses Qualcomm's memory management functions.
*
* Note: The userdata field of cv::UMatData is used to store the file descriptor (fd) of the allocated memory.
*
*/ */
class QcAllocator : public cv::MatAllocator { class QcAllocator : public cv::MatAllocator {
public: public:

View File

@@ -55,13 +55,19 @@ cv::UMatData* QcAllocator::allocate(int dims, const int* sizes, int type,
} }
total *= sizes[i]; total *= sizes[i];
} }
uchar* data = data0 ? (uchar*)data0 : (uchar*)fcvHwMemAlloc(total, 16);
int fd = -1;
uchar* data = data0 ? (uchar*)data0 : (uchar*)fcvHwMemAlloc(total, 16, &fd);
cv::UMatData* u = new cv::UMatData(this); cv::UMatData* u = new cv::UMatData(this);
u->data = u->origdata = data; u->data = u->origdata = data;
u->size = total; u->size = total;
if(data0) if(data0)
u->flags |= cv::UMatData::USER_ALLOCATED; u->flags |= cv::UMatData::USER_ALLOCATED;
// Store FD in userdata (cast to void*)
if (fd >= 0)
u->userdata = reinterpret_cast<void*>(static_cast<intptr_t>(fd));
// Add to active allocations // Add to active allocations
cv::fastcv::QcResourceManager::getInstance().addAllocation(data); cv::fastcv::QcResourceManager::getInstance().addAllocation(data);