9static constexpr int toInt(T value)
11 if constexpr (
sizeof(T) >=
sizeof(
int)) {
12 if (
std::is_signed_v<T>) {
13 return static_cast<
int>(std::clamp<T>(value,
14 std::numeric_limits<
int>::min(), std::numeric_limits<
int>::max()));
16 return static_cast<
int>(
std::min<T>(value,
std::numeric_limits<
int>::max()));
19 return static_cast<
int>(value);
26 return { toInt(frame.width), toInt(frame.height) };
32 case CAMERA_FRAMETYPE_NV12:
33 return QVideoFrameFormat::Format_NV12;
34 case CAMERA_FRAMETYPE_RGB8888:
35 return QVideoFrameFormat::Format_ARGB8888;
36 case CAMERA_FRAMETYPE_GRAY8:
37 return QVideoFrameFormat::Format_Y8;
38 case CAMERA_FRAMETYPE_CBYCRY:
39 return QVideoFrameFormat::Format_UYVY;
40 case CAMERA_FRAMETYPE_YCBCR420P:
41 return QVideoFrameFormat::Format_YUV420P;
42 case CAMERA_FRAMETYPE_YCBYCR:
43 return QVideoFrameFormat::Format_YUYV;
48 return QVideoFrameFormat::Format_Invalid;
53 return frame.uv_offset + frame.uv_stride * frame.height / 2;
58 return frame.stride * frame.height;
63 return frame.stride * frame.height;
73 return frame.cr_offset + frame.cr_stride * frame.height / 2;
78 return frame.stride * frame.height;
83 switch (buffer->frametype) {
84 case CAMERA_FRAMETYPE_NV12:
85 return bufferDataSize(buffer->framedesc.nv12);
86 case CAMERA_FRAMETYPE_RGB8888:
87 return bufferDataSize(buffer->framedesc.rgb8888);
88 case CAMERA_FRAMETYPE_GRAY8:
89 return bufferDataSize(buffer->framedesc.gray8);
90 case CAMERA_FRAMETYPE_CBYCRY:
91 return bufferDataSize(buffer->framedesc.cbycry);
92 case CAMERA_FRAMETYPE_YCBCR420P:
93 return bufferDataSize(buffer->framedesc.ycbcr420p);
94 case CAMERA_FRAMETYPE_YCBYCR:
95 return bufferDataSize(buffer->framedesc.ycbycr);
104 unsigned char *baseAddress)
111 toInt(frame.uv_stride)
115 baseAddress + frame.uv_offset
118 toInt(frame.stride * frame.height),
119 toInt(frame.uv_stride * frame.height / 2)
125 unsigned char *baseAddress)
136 toInt(frame.stride * frame.height),
142 unsigned char *baseAddress)
153 toInt(frame.stride * frame.height)
159 unsigned char *baseAddress)
170 toInt(frame.bufsize),
176 unsigned char *baseAddress)
181 toInt(frame.y_stride),
187 baseAddress + frame.cb_offset,
188 baseAddress + frame.cr_offset,
191 toInt(frame.y_stride * frame.height),
192 toInt(frame.cb_stride * frame.height / 2),
193 toInt(frame.cr_stride * frame.height / 2)
199 unsigned char *baseAddress)
210 toInt(frame.stride * frame.height)
216 unsigned char *baseAddress)
218 switch (buffer->frametype) {
219 case CAMERA_FRAMETYPE_NV12:
220 return mapData(buffer->framedesc.nv12, baseAddress);
221 case CAMERA_FRAMETYPE_RGB8888:
222 return mapData(buffer->framedesc.rgb8888, baseAddress);
223 case CAMERA_FRAMETYPE_GRAY8:
224 return mapData(buffer->framedesc.gray8, baseAddress);
225 case CAMERA_FRAMETYPE_CBYCRY:
226 return mapData(buffer->framedesc.cbycry, baseAddress);
227 case CAMERA_FRAMETYPE_YCBCR420P:
228 return mapData(buffer->framedesc.ycbcr420p, baseAddress);
229 case CAMERA_FRAMETYPE_YCBYCR:
230 return mapData(buffer->framedesc.ycbycr, baseAddress);
240 switch (buffer->frametype) {
241 case CAMERA_FRAMETYPE_NV12:
242 return frameSize(buffer->framedesc.nv12);
243 case CAMERA_FRAMETYPE_RGB8888:
244 return frameSize(buffer->framedesc.rgb8888);
245 case CAMERA_FRAMETYPE_GRAY8:
246 return frameSize(buffer->framedesc.gray8);
247 case CAMERA_FRAMETYPE_CBYCRY:
248 return frameSize(buffer->framedesc.cbycry);
249 case CAMERA_FRAMETYPE_YCBCR420P:
250 return frameSize(buffer->framedesc.ycbcr420p);
251 case CAMERA_FRAMETYPE_YCBYCR:
252 return frameSize(buffer->framedesc.ycbycr);
262QQnxCameraFrameBuffer::QQnxCameraFrameBuffer(
const camera_buffer_t *buffer)
263 : QHwVideoBuffer(QVideoFrame::NoHandle),
264 m_pixelFormat(::frameTypeToPixelFormat(buffer->frametype)),
265 m_dataSize(::bufferDataSize(buffer))
270 m_data = std::make_unique<
unsigned char[]>(m_dataSize);
272 memcpy(m_data.get(), buffer->framebuf, m_dataSize);
274 m_mapData = ::mapData(buffer, m_data.get());
276 m_frameSize = ::frameSize(buffer);
290 return m_pixelFormat;
QVideoFrameFormat::PixelFormat pixelFormat() const
MapData map(QVideoFrame::MapMode mode) override
Maps the planes of a video buffer to memory.
void unmap() override
Releases the memory mapped by the map() function.
static constexpr int toInt(T value)
static QAbstractVideoBuffer::MapData mapData(const camera_buffer_t *buffer, unsigned char *baseAddress)
static QAbstractVideoBuffer::MapData mapData(const camera_frame_nv12_t &frame, unsigned char *baseAddress)
static constexpr QSize frameSize(const T &frame)
static constexpr size_t bufferDataSize(const camera_frame_nv12_t &frame)
static constexpr QVideoFrameFormat::PixelFormat frameTypeToPixelFormat(camera_frametype_t type)
static constexpr size_t bufferDataSize(const camera_buffer_t *buffer)
static constexpr QSize frameSize(const camera_buffer_t *buffer)