使用 DMA-BUF 分配内存,修复功能bug
This commit is contained in:
parent
03465b6307
commit
79ce131bea
@ -1,3 +1,4 @@
|
|||||||
|
#include <algorithm>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@ -211,13 +212,23 @@ private:
|
|||||||
|
|
||||||
rga_buffer_t src_buf{};
|
rga_buffer_t src_buf{};
|
||||||
rga_buffer_t dst_buf{};
|
rga_buffer_t dst_buf{};
|
||||||
|
DmaBufferPtr src_dma_buf; // Keep alive if we allocate
|
||||||
|
|
||||||
if (frame->dma_fd >= 0) {
|
if (frame->dma_fd >= 0) {
|
||||||
src_buf = wrapbuffer_fd_t(frame->dma_fd, frame->width, frame->height,
|
src_buf = wrapbuffer_fd_t(frame->dma_fd, frame->width, frame->height,
|
||||||
src_wstride, src_hstride, src_fmt_rga);
|
src_wstride, src_hstride, src_fmt_rga);
|
||||||
} else if (frame->data) {
|
} else if (frame->data) {
|
||||||
src_buf = wrapbuffer_virtualaddr_t(frame->data, frame->width, frame->height,
|
// Source doesn't have DMA fd, copy to DMA buffer first to avoid >4GB address issue
|
||||||
src_wstride, src_hstride, src_fmt_rga);
|
size_t src_size = CalcImageSize(frame->width, frame->height, frame->format);
|
||||||
|
src_dma_buf = DmaAlloc(src_size);
|
||||||
|
if (!src_dma_buf || !src_dma_buf->valid()) {
|
||||||
|
std::cerr << "[preprocess] DMA alloc for src failed\n";
|
||||||
|
PushToDownstream(frame);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
memcpy(src_dma_buf->data(), frame->data, std::min(src_size, frame->data_size));
|
||||||
|
src_buf = wrapbuffer_fd_t(src_dma_buf->fd, frame->width, frame->height,
|
||||||
|
src_wstride, src_hstride, src_fmt_rga);
|
||||||
} else {
|
} else {
|
||||||
PushToDownstream(frame);
|
PushToDownstream(frame);
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user