From 84d89b1659b6eb3e7707f2fe107b9cada516f053 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Tue, 14 Jun 2016 22:20:08 +0300 Subject: add ResourceManager --- py/pykmsutil.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'py') diff --git a/py/pykmsutil.cpp b/py/pykmsutil.cpp index 5ee1d4e..ab9f5a8 100644 --- a/py/pykmsutil.cpp +++ b/py/pykmsutil.cpp @@ -20,6 +20,24 @@ void init_pykmstest(py::module &m) .def_property_readonly("rgb565", &RGB::rgb565) ; + py::class_(m, "ResourceManager") + .def(py::init()) + .def("reset", &ResourceManager::reset) + .def("reserve_connector", &ResourceManager::reserve_connector, + py::arg("name") = string()) + .def("reserve_crtc", &ResourceManager::reserve_crtc) + .def("reserve_plane", &ResourceManager::reserve_plane, + py::arg("crtc"), + py::arg("type"), + py::arg("format") = PixelFormat::Undefined) + .def("reserve_primary_plane", &ResourceManager::reserve_primary_plane, + py::arg("crtc"), + py::arg("format") = PixelFormat::Undefined) + .def("reserve_overlay_plane", &ResourceManager::reserve_overlay_plane, + py::arg("crtc"), + py::arg("format") = PixelFormat::Undefined) + ; + // Use lambdas to handle IMappedFramebuffer m.def("draw_test_pattern", [](DumbFramebuffer& fb) { draw_test_pattern(fb); } ); m.def("draw_color_bar", [](DumbFramebuffer& fb, int old_xpos, int xpos, int width) { -- cgit v1.2.3 From 7881bfd6586bd8ffa9b766cdba332c7a1015c9dd Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Tue, 14 Jun 2016 22:20:50 +0300 Subject: py: use ResourceManager --- py/alpha-test.py | 6 +++--- py/db.py | 5 +++-- py/functest.py | 7 +++---- py/gamma.py | 6 +++--- py/helpers.py | 12 ------------ py/iact.py | 7 +++---- py/test.py | 7 +++---- py/trans-test.py | 6 +++--- 8 files changed, 21 insertions(+), 35 deletions(-) (limited to 'py') diff --git a/py/alpha-test.py b/py/alpha-test.py index 113fab0..c6ec8ee 100755 --- a/py/alpha-test.py +++ b/py/alpha-test.py @@ -9,10 +9,10 @@ card = pykms.Card() card = 0 card = pykms.Card() - -conn = card.get_first_connected_connector() +res = pykms.ResourceManager(card) +conn = res.reserve_connector() +crtc = res.reserve_crtc(conn) mode = conn.get_default_mode() -crtc = get_crtc_for_connector(conn) planes = [] for p in card.planes: diff --git a/py/db.py b/py/db.py index 6073765..3ffb716 100755 --- a/py/db.py +++ b/py/db.py @@ -41,9 +41,10 @@ class FlipHandler(pykms.PageFlipHandlerBase): card = pykms.Card() -conn = card.get_first_connected_connector() +res = pykms.ResourceManager(card) +conn = res.reserve_connector() +crtc = res.reserve_crtc(conn) mode = conn.get_default_mode() -crtc = get_crtc_for_connector(conn) fliphandler = FlipHandler() diff --git a/py/functest.py b/py/functest.py index c2548fa..44c29fb 100755 --- a/py/functest.py +++ b/py/functest.py @@ -4,16 +4,15 @@ import pykms from helpers import * card = pykms.Card() - -conn = card.get_first_connected_connector() +res = pykms.ResourceManager(card) +conn = res.reserve_connector() +crtc = res.reserve_crtc(conn) mode = conn.get_default_mode() fb = pykms.DumbFramebuffer(card, mode.hdisplay, mode.vdisplay, "XR24"); pykms.draw_test_pattern(fb); -crtc = get_crtc_for_connector(conn) - crtc.set_mode(conn, fb, mode) print("OK") diff --git a/py/gamma.py b/py/gamma.py index e1daa43..a6b68cc 100755 --- a/py/gamma.py +++ b/py/gamma.py @@ -8,10 +8,10 @@ card = pykms.Card() card = 0 card = pykms.Card() - -conn = card.get_first_connected_connector() +res = pykms.ResourceManager(card) +conn = res.reserve_connector() +crtc = res.reserve_crtc(conn) mode = conn.get_default_mode() -crtc = get_crtc_for_connector(conn) fb = pykms.DumbFramebuffer(card, mode.hdisplay, mode.vdisplay, "XR24"); pykms.draw_test_pattern(fb); diff --git a/py/helpers.py b/py/helpers.py index e92163c..fd67d41 100644 --- a/py/helpers.py +++ b/py/helpers.py @@ -52,15 +52,3 @@ def disable_planes(card): if areq.commit_sync() != 0: print("disabling planes failed") - -def get_crtc_for_connector(conn): - crtc = conn.get_current_crtc() - - if crtc != None: - return crtc - - for crtc in conn.get_possible_crtcs(): - if crtc.mode_valid == False: - return crtc - - raise RuntimeError("No free crtc found") diff --git a/py/iact.py b/py/iact.py index 518dbfa..fecd899 100755 --- a/py/iact.py +++ b/py/iact.py @@ -9,16 +9,15 @@ from math import cos from helpers import * card = pykms.Card() - -conn = card.get_first_connected_connector() +res = pykms.ResourceManager(card) +conn = res.reserve_connector() +crtc = res.reserve_crtc(conn) mode = conn.get_default_mode() fb = pykms.DumbFramebuffer(card, 200, 200, "XR24"); pykms.draw_test_pattern(fb); -crtc = get_crtc_for_connector(conn) - #crtc.set_mode(conn, fb, mode) i = 0 diff --git a/py/test.py b/py/test.py index 7625f10..9c23b5b 100755 --- a/py/test.py +++ b/py/test.py @@ -4,16 +4,15 @@ import pykms from helpers import * card = pykms.Card() - -conn = card.get_first_connected_connector() +res = pykms.ResourceManager(card) +conn = res.reserve_connector() +crtc = res.reserve_crtc(conn) mode = conn.get_default_mode() fb = pykms.DumbFramebuffer(card, mode.hdisplay, mode.vdisplay, "XR24"); pykms.draw_test_pattern(fb); -crtc = get_crtc_for_connector(conn) - crtc.set_mode(conn, fb, mode) input("press enter to exit\n") diff --git a/py/trans-test.py b/py/trans-test.py index e80802b..8c1f964 100755 --- a/py/trans-test.py +++ b/py/trans-test.py @@ -9,10 +9,10 @@ card = pykms.Card() card = 0 card = pykms.Card() - -conn = card.get_first_connected_connector() +res = pykms.ResourceManager(card) +conn = res.reserve_connector() +crtc = res.reserve_crtc(conn) mode = conn.get_default_mode() -crtc = get_crtc_for_connector(conn) planes = [] for p in card.planes: -- cgit v1.2.3 From a779ec31224ab217572a20587e89ce393e62b033 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Sat, 11 Jun 2016 23:42:06 +0300 Subject: py: add pyvid --- py/CMakeLists.txt | 2 +- py/pykms.cpp | 3 +++ py/pyvid.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 py/pyvid.cpp (limited to 'py') diff --git a/py/CMakeLists.txt b/py/CMakeLists.txt index 562a3cf..1349ea5 100644 --- a/py/CMakeLists.txt +++ b/py/CMakeLists.txt @@ -10,7 +10,7 @@ endif() include_directories(${PROJECT_SOURCE_DIR}/ext/pybind11/include) -add_library(pykms SHARED pykms.cpp pykmsbase.cpp pykmsutil.cpp) +add_library(pykms SHARED pykms.cpp pykmsbase.cpp pykmsutil.cpp pyvid.cpp) target_link_libraries(pykms kms++ kms++util ${LIBDRM_LIBRARIES}) # Don't add a 'lib' prefix to the shared library diff --git a/py/pykms.cpp b/py/pykms.cpp index 57ca363..c759d23 100644 --- a/py/pykms.cpp +++ b/py/pykms.cpp @@ -9,6 +9,7 @@ using namespace std; void init_pykmstest(py::module &m); void init_pykmsbase(py::module &m); +void init_pyvid(py::module &m); class PyPageFlipHandlerBase : PageFlipHandlerBase { @@ -39,5 +40,7 @@ PYBIND11_PLUGIN(pykms) { init_pykmstest(m); + init_pyvid(m); + return m.ptr(); } diff --git a/py/pyvid.cpp b/py/pyvid.cpp new file mode 100644 index 0000000..01177d5 --- /dev/null +++ b/py/pyvid.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include + +namespace py = pybind11; + +using namespace kms; +using namespace std; + +void init_pyvid(py::module &m) +{ + py::class_(m, "VideoDevice") + .def(py::init()) + .def_property_readonly("fd", &VideoDevice::fd) + .def_property_readonly("has_capture", &VideoDevice::has_capture) + .def_property_readonly("has_output", &VideoDevice::has_output) + .def_property_readonly("has_m2m", &VideoDevice::has_m2m) + .def_property_readonly("capture_streamer", &VideoDevice::get_capture_streamer) + .def_property_readonly("output_streamer", &VideoDevice::get_output_streamer) + .def_property_readonly("discrete_frame_sizes", &VideoDevice::get_discrete_frame_sizes) + .def_property_readonly("frame_sizes", &VideoDevice::get_frame_sizes) + .def("get_capture_devices", &VideoDevice::get_capture_devices) + ; + + py::class_(m, "VideoStreamer") + .def_property_readonly("fd", &VideoStreamer::fd) + .def_property_readonly("ports", &VideoStreamer::get_ports) + .def("set_port", &VideoStreamer::set_port) + .def_property_readonly("formats", &VideoStreamer::get_formats) + .def("set_format", &VideoStreamer::set_format) + .def("set_queue_size", &VideoStreamer::set_queue_size) + .def("queue", &VideoStreamer::queue) + .def("dequeue", &VideoStreamer::dequeue) + .def("stream_on", &VideoStreamer::stream_on) + ; +} -- cgit v1.2.3 From 0bf62a2f4f724dafb77230bf2a1ca37dd7420e94 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Sat, 11 Jun 2016 23:42:58 +0300 Subject: py: add cam.py --- py/cam.py | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 py/cam.py (limited to 'py') diff --git a/py/cam.py b/py/cam.py new file mode 100755 index 0000000..b44f8f9 --- /dev/null +++ b/py/cam.py @@ -0,0 +1,78 @@ +#!/usr/bin/python3 + +import sys +import selectors +import pykms +from helpers import * + + +w = 640 +h = 480 +fmt = pykms.PixelFormat.YUYV + + +# This hack makes drm initialize the fbcon, setting up the default connector +card = pykms.Card() +card = 0 + +card = pykms.Card() +res = pykms.ResourceManager(card) +conn = res.reserve_connector() +crtc = res.reserve_crtc(conn) +plane = res.reserve_overlay_plane(crtc, fmt) + +mode = conn.get_default_mode() + +NUM_BUFS = 5 + +fbs = [] +for i in range(NUM_BUFS): + fb = pykms.DumbFramebuffer(card, w, h, fmt) + fbs.append(fb) + +vidpath = pykms.VideoDevice.get_capture_devices()[0] + +vid = pykms.VideoDevice(vidpath) +cap = vid.capture_streamer +cap.set_port(0) +cap.set_format(fmt, w, h) +cap.set_queue_size(NUM_BUFS) + +for fb in fbs: + cap.queue(fb) + +cap.stream_on() + + +def readvid(conn, mask): + fb = cap.dequeue() + + if card.has_atomic: + set_props(plane, { + "FB_ID": fb.id, + "CRTC_ID": crtc.id, + "SRC_W": fb.width << 16, + "SRC_H": fb.height << 16, + "CRTC_W": fb.width, + "CRTC_H": fb.height, + }) + else: + crtc.set_plane(plane, fb, 0, 0, fb.width, fb.height, + 0, 0, fb.width, fb.height) + + cap.queue(fb) + +def readkey(conn, mask): + #print("KEY EVENT"); + sys.stdin.readline() + exit(0) + +sel = selectors.DefaultSelector() +sel.register(cap.fd, selectors.EVENT_READ, readvid) +sel.register(sys.stdin, selectors.EVENT_READ, readkey) + +while True: + events = sel.select() + for key, mask in events: + callback = key.data + callback(key.fileobj, mask) -- cgit v1.2.3