使用 DMA-BUF 分配内存,修复功能bug
This commit is contained in:
parent
c747942855
commit
cee65540d8
@ -80,27 +80,43 @@ DmaBuffer& DmaBuffer::operator=(DmaBuffer&& other) noexcept {
|
||||
|
||||
DmaBufferPtr DmaAlloc(size_t alloc_size) {
|
||||
#if defined(__linux__)
|
||||
// Try different dma_heap devices
|
||||
// Try different dma_heap devices - prefer CMA for RGA compatibility (<4GB)
|
||||
const char* heap_paths[] = {
|
||||
"/dev/dma_heap/cma",
|
||||
"/dev/dma_heap/cma-uncached",
|
||||
"/dev/dma_heap/linux,cma",
|
||||
"/dev/dma_heap/reserved",
|
||||
"/dev/dma_heap/system-uncached",
|
||||
"/dev/dma_heap/system",
|
||||
"/dev/dma_heap/cma",
|
||||
nullptr
|
||||
};
|
||||
|
||||
int heap_fd = -1;
|
||||
const char* used_heap = nullptr;
|
||||
for (int i = 0; heap_paths[i] != nullptr; ++i) {
|
||||
heap_fd = open(heap_paths[i], O_RDWR | O_CLOEXEC);
|
||||
if (heap_fd >= 0) {
|
||||
used_heap = heap_paths[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (heap_fd < 0) {
|
||||
std::cerr << "[DmaAlloc] failed to open dma_heap device: " << strerror(errno) << "\n";
|
||||
std::cerr << "[DmaAlloc] tried: ";
|
||||
for (int i = 0; heap_paths[i] != nullptr; ++i) {
|
||||
std::cerr << heap_paths[i] << " ";
|
||||
}
|
||||
std::cerr << "\n";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static bool first_alloc = true;
|
||||
if (first_alloc) {
|
||||
std::cout << "[DmaAlloc] using heap: " << used_heap << "\n";
|
||||
first_alloc = false;
|
||||
}
|
||||
|
||||
dma_heap_allocation_data alloc_data{};
|
||||
alloc_data.len = alloc_size;
|
||||
alloc_data.fd_flags = O_RDWR | O_CLOEXEC;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user