Skip to content

Commit 735b7a0

Browse files
authored
Merge pull request #3969 from CodeLinaro:apreetam_7thPost
Modified QcAllocator to store File Descriptor
2 parents d943e1d + d6e2199 commit 735b7a0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

modules/fastcv/include/opencv2/fastcv/allocator.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ class QcResourceManager {
3636
/**
3737
* @brief Qualcomm's custom allocator.
3838
* This allocator uses Qualcomm's memory management functions.
39+
*
40+
* Note: The userdata field of cv::UMatData is used to store the file descriptor (fd) of the allocated memory.
41+
*
3942
*/
4043
class QcAllocator : public cv::MatAllocator {
4144
public:
4245
QcAllocator();
4346
~QcAllocator();
44-
47+
4548
cv::UMatData* allocate(int dims, const int* sizes, int type, void* data0, size_t* step, cv::AccessFlag flags, cv::UMatUsageFlags usageFlags) const CV_OVERRIDE;
4649
bool allocate(cv::UMatData* u, cv::AccessFlag accessFlags, cv::UMatUsageFlags usageFlags) const CV_OVERRIDE;
4750
void deallocate(cv::UMatData* u) const CV_OVERRIDE;

modules/fastcv/src/allocator.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,19 @@ cv::UMatData* QcAllocator::allocate(int dims, const int* sizes, int type,
5555
}
5656
total *= sizes[i];
5757
}
58-
uchar* data = data0 ? (uchar*)data0 : (uchar*)fcvHwMemAlloc(total, 16);
58+
59+
int fd = -1;
60+
uchar* data = data0 ? (uchar*)data0 : (uchar*)fcvHwMemAlloc(total, 16, &fd);
5961
cv::UMatData* u = new cv::UMatData(this);
6062
u->data = u->origdata = data;
6163
u->size = total;
6264
if(data0)
6365
u->flags |= cv::UMatData::USER_ALLOCATED;
6466

67+
// Store FD in userdata (cast to void*)
68+
if (fd >= 0)
69+
u->userdata = reinterpret_cast<void*>(static_cast<intptr_t>(fd));
70+
6571
// Add to active allocations
6672
cv::fastcv::QcResourceManager::getInstance().addAllocation(data);
6773

0 commit comments

Comments
 (0)