1#!/usr/bin/python3 2 3import sys 4import selectors 5import pykms 6import argparse 7import time 8 9iw = 640 10ih = 480 11ifmt = pykms.PixelFormat.XRGB8888 12 13ow = 640 14oh = 480 15ofmt = pykms.PixelFormat.XRGB8888 16 17card = pykms.Card() 18res = pykms.ResourceManager(card) 19conn = res.reserve_connector() 20crtc = res.reserve_crtc(conn) 21plane1 = res.reserve_overlay_plane(crtc, ifmt) 22plane2 = res.reserve_overlay_plane(crtc, ofmt) 23 24print("{}, {}".format(plane1.id, plane2.id)) 25 26mode = conn.get_default_mode() 27modeb = mode.to_blob(card) 28 29card.disable_planes() 30 31req = pykms.AtomicReq(card) 32req.add(conn, "CRTC_ID", crtc.id) 33req.add(crtc, {"ACTIVE": 1, 34 "MODE_ID": modeb.id}) 35req.commit_sync(allow_modeset = True) 36 37NUM_BUFS = 4 38 39src_fbs = [] 40dst_fbs = [] 41 42for i in range(NUM_BUFS): 43 fb = pykms.DumbFramebuffer(card, iw, ih, ifmt) 44 pykms.draw_test_pattern(fb); 45 pykms.draw_text(fb, iw // 2, 2, str(i), pykms.white); 46 src_fbs.append(fb) 47 48 fb = pykms.DumbFramebuffer(card, ow, oh, ofmt) 49 dst_fbs.append(fb) 50 51# put the planes on the screen, so that WB doesn't take them 52req = pykms.AtomicReq(card) 53req.add_plane(plane1, src_fbs[0], crtc, dst=(0, 0, 400, 480)) 54req.add_plane(plane2, dst_fbs[1], crtc, dst=(400, 0, 400, 480)) 55r = req.commit_sync(allow_modeset = True) 56assert r == 0 57 58vid = pykms.VideoDevice("/dev/video10") 59 60src_streamer = vid.output_streamer 61dst_streamer = vid.capture_streamer 62 63src_streamer.set_format(ifmt, iw, ih) 64(left, top, width, height) = src_streamer.get_selection() 65print("get: crop -> {},{}-{}x{}".format(left, top, width, height)) 66(left, top, width, height) = src_streamer.set_selection(160, 0, 320, 240) 67print("set: crop -> {},{}-{}x{}".format(left, top, width, height)) 68 69dst_streamer.set_format(ofmt, ow, oh) 70 71src_streamer.set_queue_size(NUM_BUFS) 72dst_streamer.set_queue_size(NUM_BUFS) 73 74for fb in src_fbs: 75 src_streamer.queue(fb) 76 77for fb in dst_fbs: 78 dst_streamer.queue(fb) 79 80input("press enter\n") 81 82src_streamer.stream_on() 83dst_streamer.stream_on() 84 85loop_count = 0 86 87def readvid(conn, mask): 88 global loop_count 89 print("VID EVENT"); 90 91 ifb = src_streamer.dequeue() 92 ofb = dst_streamer.dequeue() 93 94 req = pykms.AtomicReq(card) 95 req.add_plane(plane1, ifb, crtc, dst=(0, 0, 400, 480)) 96 req.add_plane(plane2, ofb, crtc, dst=(400, 0, 400, 480)) 97 req.commit_sync(allow_modeset = True) 98 time.sleep(1) 99 loop_count += 1 100 if loop_count >= 10: 101 exit(0) 102 print("loop #", loop_count) 103 src_streamer.queue(ifb) 104 dst_streamer.queue(ofb) 105 106 107def readkey(conn, mask): 108 print("KEY EVENT"); 109 sys.stdin.readline() 110 exit(0) 111 112sel = selectors.PollSelector() 113sel.register(vid.fd, selectors.EVENT_READ, readvid) 114sel.register(sys.stdin, selectors.EVENT_READ, readkey) 115 116while True: 117 events = sel.select() 118 for key, mask in events: 119 callback = key.data 120 callback(key.fileobj, mask) 121 122print("done"); 123exit(0) 124