diff --git a/utils/cam-configs/dra76-fpd.py b/utils/cam-configs/dra76-fpd.py index 66d8917..49cb2de 100644 --- a/utils/cam-configs/dra76-fpd.py +++ b/utils/cam-configs/dra76-fpd.py @@ -21,13 +21,13 @@ fmt_pix_ov10635 = (ov10635_w, ov10635_h, ov10635_pix_fmt) mbus_fmt_ov10635_meta = (ov10635_w, ov10635_meta_h, v4l2.BusFormat.META_8) -fmt_pix_ov10635_meta = (ov10635_w, ov10635_meta_h, v4l2.PixelFormat.META_FMT_GENERIC_8) +fmt_pix_ov10635_meta = (ov10635_w, ov10635_meta_h, v4l2.MetaFormat.GENERIC_8) mbus_fmt_imx390 = (imx390_w, imx390_h, imx390_bus_fmt) fmt_pix_imx390 = (imx390_w, imx390_h, imx390_pix_fmt) mbus_fmt_imx390_meta = (imx390_w, imx390_meta_h, v4l2.BusFormat.META_12) -fmt_pix_imx390_meta = (imx390_w, imx390_meta_h, v4l2.PixelFormat.META_FMT_GENERIC_CSI2_12) +fmt_pix_imx390_meta = (imx390_w, imx390_meta_h, v4l2.MetaFormat.GENERIC_CSI2_12) mbus_fmt_tpg = (1920, 1024, v4l2.BusFormat.UYVY8_1X16) fmt_tpg = (1920, 1024, v4l2.PixelFormat.UYVY) diff --git a/utils/cam.py b/utils/cam.py index 5a267df..5c5d7e4 100755 --- a/utils/cam.py +++ b/utils/cam.py @@ -4,7 +4,6 @@ from collections import deque import argparse import kms -import mmap import pprint import selectors import sys @@ -93,9 +92,9 @@ res.reserve_generic_plane(crtc, kms.PixelFormat.RGB565) if not "kms-fourcc" in stream: - if stream["fourcc"] == v4l2.PixelFormat.META_FMT_GENERIC_8: + if stream["fourcc"] == v4l2.MetaFormat.GENERIC_8: stream["kms-fourcc"] = kms.PixelFormat.RGB565 - elif stream["fourcc"] == v4l2.PixelFormat.META_FMT_GENERIC_CSI2_12: + elif stream["fourcc"] == v4l2.MetaFormat.GENERIC_CSI2_12: stream["kms-fourcc"] = kms.PixelFormat.RGB565 else: #kms_fourcc = v4l2.pixelformat_to_drm_fourcc(stream["fourcc"]) @@ -237,7 +236,8 @@ "MODE_ID": modeb.id}) for stream in streams: - req.add(stream["plane"], "FB_ID", stream["kms_fb"].id) + if "plane" in stream: + req.add(stream["plane"], "FB_ID", stream["kms_fb"].id) req.commit_sync(allow_modeset = True) diff --git a/utils/cam_helpers.py b/utils/cam_helpers.py index 6745707..aaec5b8 100644 --- a/utils/cam_helpers.py +++ b/utils/cam_helpers.py @@ -54,13 +54,13 @@ def link(md: v4l2.MediaDevice, source, sink): md.link_setup(link.source, link.sink, v4l2.uapi.MEDIA_LNK_FL_ENABLED) def embedded_fourcc_to_bytes_per_pixel(fmt): - if fmt == v4l2.PixelFormat.META_CSI2_12: + if fmt == v4l2.MetaFormat.GENERIC_CSI2_12: return 12 - elif fmt == v4l2.PixelFormat.META_CSI2_10: + elif fmt == v4l2.MetaFormat.GENERIC_CSI2_10: return 10 - elif fmt == v4l2.PixelFormat.META_8: + elif fmt == v4l2.MetaFormat.GENERIC_8: return 8 - elif fmt == v4l2.PixelFormat.SENSOR_DATA: + elif fmt == v4l2.MetaFormat.SENSOR_DATA: return 8 else: assert(False) diff --git a/v4l2/__init__.py b/v4l2/__init__.py index cf1d9fb..5deb9e7 100644 --- a/v4l2/__init__.py +++ b/v4l2/__init__.py @@ -2,8 +2,8 @@ import v4l2.uapi from v4l2.uapi import fourcc_to_str +from v4l2.pixelformats import * +from v4l2.mbusformats import * from v4l2.media import * from v4l2.subdev import * from v4l2.videodev import * -from v4l2.pixelformats import * -from v4l2.mbusformats import * diff --git a/v4l2/mbusformats.py b/v4l2/mbusformats.py index f445537..72f1b0c 100644 --- a/v4l2/mbusformats.py +++ b/v4l2/mbusformats.py @@ -84,5 +84,7 @@ class BusFormat(IntEnum): S5C_UYVY_JPEG_1X8 = v4l2.uapi.V4L2_MBUS_FMT_S5C_UYVY_JPEG_1X8 AHSV8888_1X32 = v4l2.uapi.V4L2_MBUS_FMT_AHSV8888_1X32 - META_8 = 0 # XXX - META_12 = 0 # XXX + # XXX Manually added entries + META_8 = 0x8001 + META_10 = 0x8002 + META_12 = 0x8003 diff --git a/v4l2/pixelformats.py b/v4l2/pixelformats.py index 9dcb61d..420fd19 100644 --- a/v4l2/pixelformats.py +++ b/v4l2/pixelformats.py @@ -241,9 +241,8 @@ class PixelFormat(IntEnum): HM12 = v4l2.uapi.V4L2_PIX_FMT_HM12 SUNXI_TILED_NV12 = v4l2.uapi.V4L2_PIX_FMT_SUNXI_TILED_NV12 - META_8 = 0 # XXX - META_CSI2_10 = 0 # XXX - META_CSI2_12 = 0 # XXX - SENSOR_DATA = 0 # XXX - META_FMT_GENERIC_8 = 0 # XXX - META_FMT_GENERIC_CSI2_12 = 0 # XXX +# XXX Manually added +class MetaFormat(IntEnum): + GENERIC_8 = v4l2.uapi.v4l2_fourcc('M', 'E', 'T', '8') + GENERIC_CSI2_10 = v4l2.uapi.v4l2_fourcc('M', 'C', '1', 'A') + GENERIC_CSI2_12 = v4l2.uapi.v4l2_fourcc('M', 'C', '1', 'C') diff --git a/v4l2/videodev.py b/v4l2/videodev.py index f555fc6..124813f 100644 --- a/v4l2/videodev.py +++ b/v4l2/videodev.py @@ -3,8 +3,8 @@ import ctypes import fcntl import os -import v4l2 import v4l2.uapi +import v4l2.pixelformats class VideoDevice: def __init__(self, entity: v4l2.MediaEntity) -> None: @@ -66,7 +66,8 @@ def get_capture_streamer(self, mem_type): return CaptureStreamer(self, mem_type, v4l2.uapi.V4L2_BUF_TYPE_VIDEO_CAPTURE) def get_meta_capture_streamer(self, mem_type): - raise NotImplementedError() + assert(self.has_meta_capture) + return MetaCaptureStreamer(self, mem_type, v4l2.uapi.V4L2_BUF_TYPE_META_CAPTURE) class CaptureStreamer: @@ -285,8 +286,33 @@ def dequeue(self): return vfb -class MetaCaptureStreamer: - pass +class MetaCaptureStreamer(CaptureStreamer): + _fourcc_bitspp_map = { + v4l2.pixelformats.MetaFormat.GENERIC_8: 16, + v4l2.pixelformats.MetaFormat.GENERIC_CSI2_10: 10, + v4l2.pixelformats.MetaFormat.GENERIC_CSI2_12: 12, + } + + def __init__(self, vdev: VideoDevice, mem_type, buf_type) -> None: + super().__init__(vdev, mem_type, buf_type) + + def set_format(self, fourcc, size): + global __fourcc_bitspp_map + + v4lfmt = v4l2.uapi.v4l2_format() + + v4lfmt.type = self.buf_type + fcntl.ioctl(self.fd, v4l2.uapi.VIDIOC_G_FMT, v4lfmt, True) + + if fourcc not in MetaCaptureStreamer._fourcc_bitspp_map: + print("Missing support for fourcc", v4l2.uapi.fourcc_to_str(fourcc)) + assert(fourcc in MetaCaptureStreamer._fourcc_bitspp_map) + + v4lfmt.fmt.meta.dataformat = fourcc + v4lfmt.fmt.meta.buffersize = size + + fcntl.ioctl(self.fd, v4l2.uapi.VIDIOC_S_FMT, v4lfmt, True) + class VideoBuffer: def __init__(self, mem_type) -> None: