summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
Diffstat (limited to 'py')
-rw-r--r--py/CMakeLists.txt2
-rwxr-xr-xpy/alpha-test.py6
-rwxr-xr-xpy/cam.py78
-rwxr-xr-xpy/db.py5
-rwxr-xr-xpy/functest.py7
-rwxr-xr-xpy/gamma.py6
-rw-r--r--py/helpers.py12
-rwxr-xr-xpy/iact.py7
-rw-r--r--py/pykms.cpp3
-rw-r--r--py/pykmsutil.cpp18
-rw-r--r--py/pyvid.cpp38
-rwxr-xr-xpy/test.py7
-rwxr-xr-xpy/trans-test.py6
13 files changed, 159 insertions, 36 deletions
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/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/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)
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/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/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_<ResourceManager>(m, "ResourceManager")
+ .def(py::init<Card&>())
+ .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) {
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 <pybind11/pybind11.h>
+#include <pybind11/stl.h>
+#include <kms++/kms++.h>
+#include <kms++util/kms++util.h>
+#include <kms++util/videodevice.h>
+
+namespace py = pybind11;
+
+using namespace kms;
+using namespace std;
+
+void init_pyvid(py::module &m)
+{
+ py::class_<VideoDevice, VideoDevice*>(m, "VideoDevice")
+ .def(py::init<const string&>())
+ .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_<VideoStreamer, VideoStreamer*>(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)
+ ;
+}
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: