修复花屏
Some checks are pending
CI / host-build (push) Waiting to run
CI / rk3588-cross-build (push) Waiting to run

This commit is contained in:
sladro 2026-01-05 18:36:53 +08:00
parent b4c6cb58ca
commit c5abff62a0
4 changed files with 41 additions and 0 deletions

View File

@ -35,4 +35,8 @@ DmaBufferPtr DmaAlloc(size_t size);
void DmaSyncStart(DmaBuffer* buf);
void DmaSyncEnd(DmaBuffer* buf);
// Sync DMA-BUF fd for CPU access (when only fd is available on Frame)
void DmaSyncStartFd(int fd);
void DmaSyncEndFd(int fd);
} // namespace rk3588

View File

@ -8,6 +8,8 @@
#include <iostream>
#include <sstream>
#include "utils/dma_alloc.h"
#if defined(RK3588_ENABLE_FFMPEG)
extern "C" {
#include <libavcodec/avcodec.h>
@ -207,7 +209,10 @@ void SnapshotAction::Execute(AlarmEvent& event, std::shared_ptr<Frame> frame) {
return;
}
const int dma_fd = frame->dma_fd;
if (dma_fd >= 0) DmaSyncStartFd(dma_fd);
auto jpeg_data = EncodeJpeg(frame);
if (dma_fd >= 0) DmaSyncEndFd(dma_fd);
if (jpeg_data.empty()) {
std::cerr << "[SnapshotAction] failed to encode JPEG\n";
return;

View File

@ -16,6 +16,7 @@
#include "actions/http_action.h"
#include "actions/snapshot_action.h"
#include "actions/clip_action.h"
#include "utils/dma_alloc.h"
namespace rk3588 {
@ -31,6 +32,15 @@ private:
if (src->width <= 0 || src->height <= 0) return nullptr;
if (!src->data) return nullptr;
const int dma_fd = src->dma_fd;
if (dma_fd >= 0) DmaSyncStartFd(dma_fd);
struct SyncGuard {
int fd;
~SyncGuard() {
if (fd >= 0) DmaSyncEndFd(fd);
}
} guard{dma_fd};
auto out = std::make_shared<Frame>();
out->width = src->width;
out->height = src->height;

View File

@ -260,4 +260,26 @@ void DmaSyncEnd(DmaBuffer* buf) {
#endif
}
void DmaSyncStartFd(int fd) {
#if defined(__linux__)
if (fd < 0) return;
dma_buf_sync sync{};
sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_READ | DMA_BUF_SYNC_WRITE;
ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync);
#else
(void)fd;
#endif
}
void DmaSyncEndFd(int fd) {
#if defined(__linux__)
if (fd < 0) return;
dma_buf_sync sync{};
sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_READ | DMA_BUF_SYNC_WRITE;
ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync);
#else
(void)fd;
#endif
}
} // namespace rk3588