safesight-edge/include/frame/frame.h

73 lines
1.4 KiB
C++

#pragma once
#include <array>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
namespace rk3588 {
enum class PixelFormat {
NV12,
YUV420,
RGB,
BGR,
UNKNOWN
};
struct Rect {
float x = 0.0f;
float y = 0.0f;
float w = 0.0f;
float h = 0.0f;
};
struct Detection {
int cls_id = -1;
float score = 0.0f;
Rect bbox{};
int track_id = -1;
};
struct DetectionResult {
std::vector<Detection> items;
int img_w = 0;
int img_h = 0;
std::string model_name;
};
struct FramePlane {
uint8_t* data = nullptr;
int stride = 0; // bytes per row
int size = 0; // valid bytes in this plane
int offset = 0; // offset from base data pointer
};
struct Frame {
int width = 0;
int height = 0;
PixelFormat format = PixelFormat::UNKNOWN;
// Fallback stride for single-plane formats; prefer per-plane stride.
int stride = 0;
int dma_fd = -1;
uint64_t pts = 0;
uint64_t frame_id = 0;
uint8_t* data = nullptr; // base pointer if mapped to CPU
size_t data_size = 0; // total mapped buffer size
int plane_count = 0;
std::array<FramePlane, 3> planes{};
// Optional owner to keep underlying buffer alive (e.g., shared_ptr<vector<uint8_t>> or MPP buffer).
std::shared_ptr<void> data_owner;
std::shared_ptr<DetectionResult> det;
std::shared_ptr<void> user_meta;
};
} // namespace rk3588