mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-17 17:35:06 +03:00
py: Switch to non-blocking eventfd
Blocking wait can be easily implemented on top in Python, so rather than supporting only blocking reads, or supporting both non-blocking and blocking reads, let's support only non-blocking reads. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
de7f1aa591
commit
bf3dbaece9
6 changed files with 41 additions and 12 deletions
|
@ -19,8 +19,9 @@ TIMEOUT_SEC = 3
|
|||
|
||||
|
||||
def handle_camera_event(cm):
|
||||
# cm.get_ready_requests() will not block here, as we know there is an event
|
||||
# to read.
|
||||
# cm.get_ready_requests() returns the ready requests, which in our case
|
||||
# should almost always return a single Request, but in some cases there
|
||||
# could be multiple or none.
|
||||
|
||||
reqs = cm.get_ready_requests()
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
import argparse
|
||||
import libcamera as libcam
|
||||
import selectors
|
||||
import sys
|
||||
|
||||
# Number of frames to capture
|
||||
|
@ -107,11 +108,18 @@ def main():
|
|||
# The main loop. Wait for the queued Requests to complete, process them,
|
||||
# and re-queue them again.
|
||||
|
||||
sel = selectors.DefaultSelector()
|
||||
sel.register(cm.event_fd, selectors.EVENT_READ)
|
||||
|
||||
while frames_done < TOTAL_FRAMES:
|
||||
# cm.get_ready_requests() blocks until there is an event and returns
|
||||
# all the ready requests. Here we should almost always get a single
|
||||
# cm.get_ready_requests() does not block, so we use a Selector to wait
|
||||
# for a camera event. Here we should almost always get a single
|
||||
# Request, but in some cases there could be multiple or none.
|
||||
|
||||
events = sel.select()
|
||||
if not events:
|
||||
continue
|
||||
|
||||
reqs = cm.get_ready_requests()
|
||||
|
||||
for req in reqs:
|
||||
|
|
|
@ -88,8 +88,9 @@ class CaptureContext:
|
|||
camera_contexts: list[CameraCaptureContext] = []
|
||||
|
||||
def handle_camera_event(self):
|
||||
# cm.get_ready_requests() will not block here, as we know there is an event
|
||||
# to read.
|
||||
# cm.get_ready_requests() returns the ready requests, which in our case
|
||||
# should almost always return a single Request, but in some cases there
|
||||
# could be multiple or none.
|
||||
|
||||
reqs = self.cm.get_ready_requests()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue