summaryrefslogtreecommitdiff
path: root/py/tests
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ideasonboard.com>2022-10-04 10:03:53 +0300
committerTomi Valkeinen <tomi.valkeinen@ideasonboard.com>2022-10-04 11:03:43 +0300
commit0f3534d3be5750ff9cb03cb997a8efc91de07347 (patch)
treee50da3df42c682cda7387bb288fa9812f088548c /py/tests
parent949a6ffc7968bd508365177d11a1d644221b4d9c (diff)
py: cam.py: fixes
Fix cam.py to get it working again and add a bunch of small improvements. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Diffstat (limited to 'py/tests')
-rwxr-xr-xpy/tests/cam.py71
1 files changed, 56 insertions, 15 deletions
diff --git a/py/tests/cam.py b/py/tests/cam.py
index 957eb11..b2d88c4 100755
--- a/py/tests/cam.py
+++ b/py/tests/cam.py
@@ -3,24 +3,32 @@
import sys
import selectors
import pykms
+import pyv4l2 as v4l2
import argparse
import time
parser = argparse.ArgumentParser()
parser.add_argument("width", type=int)
parser.add_argument("height", type=int)
-parser.add_argument("fourcc", type=str, nargs="?", default="YUVY")
+parser.add_argument("fourcc", type=str, nargs="?", default="UYVY")
+parser.add_argument("-t", "--type", type=str, default="drm", help="buffer type (drm/v4l2)")
args = parser.parse_args()
+if not args.type in ["drm", "v4l2"]:
+ print("Bad buffer type", args.type)
+ exit(-1)
+
w = args.width
h = args.height
fmt = pykms.fourcc_to_pixelformat(args.fourcc)
+vfmt = v4l2.drm_fourcc_to_pixelformat(pykms.pixelformat_to_fourcc(fmt))
-print("Capturing in {}x{}".format(w, h))
+print("Capturing in {}x{}, drm fmt {} ({}), v4l2 fmt {} ({})".format(w, h,
+ fmt, pykms.pixelformat_to_fourcc(fmt), vfmt, v4l2.pixelformat_to_fourcc(vfmt)))
card = pykms.Card()
res = pykms.ResourceManager(card)
-conn = res.reserve_connector()
+conn = res.reserve_connector("hdmi")
crtc = res.reserve_crtc(conn)
plane = res.reserve_overlay_plane(crtc, fmt)
@@ -35,27 +43,60 @@ req.commit_sync(allow_modeset = True)
NUM_BUFS = 5
+vidpath = v4l2.VideoDevice.get_capture_devices()[0]
+
+vid = v4l2.VideoDevice(vidpath)
+cap = vid.capture_streamer
+cap.set_port(0)
+cap.set_format(vfmt, w, h)
+cap.set_queue_size(NUM_BUFS, v4l2.VideoMemoryType.DMABUF if args.type == "drm" else v4l2.VideoMemoryType.MMAP)
+
fbs = []
+
+def export_v4l2_buf_to_drm(card, i, vfmt):
+ finfo = pykms.get_pixel_format_info(fmt)
+
+ if fmt == pykms.PixelFormat.NV12:
+ fd = cap.export_buffer(i)
+ buf_fds = [fd, fd]
+ pitches = [w * finfo.plane(0).bitspp // 8, w * finfo.plane(1).bitspp // 8]
+ offsets = [0, w * h * finfo.plane(0).bitspp // 8]
+ else:
+ buf_fds = [cap.export_buffer(i)]
+ pitches = [w * finfo.plane(0).bitspp // 8]
+ offsets = [0]
+
+ fb = pykms.DmabufFramebuffer(card, w, h, fmt,
+ buf_fds, pitches, offsets)
+
+ return fb
+
+
for i in range(NUM_BUFS):
- fb = pykms.DumbFramebuffer(card, w, h, fmt)
- fbs.append(fb)
+ if args.type == "drm":
+ fb = pykms.DumbFramebuffer(card, w, h, fmt)
+ else:
+ fb = export_v4l2_buf_to_drm(card, i, vfmt)
-vidpath = pykms.VideoDevice.get_capture_devices()[0]
+ print(fb)
-vid = pykms.VideoDevice(vidpath)
-cap = vid.capture_streamer
-cap.set_port(0)
-cap.set_format(fmt, w, h)
-cap.set_queue_size(NUM_BUFS)
+ fbs.append(fb)
-for fb in fbs:
- cap.queue(fb)
+for i in range(NUM_BUFS):
+ if args.type == "drm":
+ vbuf = v4l2.create_dmabuffer(fbs[i].fd(0))
+ else:
+ vbuf = v4l2.create_mmapbuffer()
+ cap.queue(vbuf)
cap.stream_on()
def readvid(conn, mask):
- fb = cap.dequeue()
+ vbuf = cap.dequeue()
+
+ fb = fbs[vbuf.index]
+ assert(fb != None)
if card.has_atomic:
plane.set_props({
@@ -70,7 +111,7 @@ def readvid(conn, mask):
crtc.set_plane(plane, fb, 0, 0, fb.width, fb.height,
0, 0, fb.width, fb.height)
- cap.queue(fb)
+ cap.queue(vbuf)
def readkey(conn, mask):
#print("KEY EVENT");