Skip to content

Commit

Permalink
metadata fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
tomba committed Dec 13, 2023
1 parent fe8417b commit 82dcfca
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 24 deletions.
4 changes: 2 additions & 2 deletions utils/cam-configs/dra76-fpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions utils/cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from collections import deque
import argparse
import kms
import mmap
import pprint
import selectors
import sys
Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions utils/cam_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions v4l2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
6 changes: 4 additions & 2 deletions v4l2/mbusformats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 5 additions & 6 deletions v4l2/pixelformats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
34 changes: 30 additions & 4 deletions v4l2/videodev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 82dcfca

Please sign in to comment.