[libcamera-devel,v5,08/13] py: simple-cam.py: Use new events support
diff mbox series

Message ID 20230603075615.20663-9-tomi.valkeinen@ideasonboard.com
State New
Headers show
Series
  • py: New python bindings event handling
Related show

Commit Message

Tomi Valkeinen June 3, 2023, 7:56 a.m. UTC
Update simple-cam.py to the new event model.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/py/examples/simple-cam.py | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

Comments

Laurent Pinchart June 5, 2023, 5:16 a.m. UTC | #1
Hi Tomi,

Thank you for the patch.

On Sat, Jun 03, 2023 at 10:56:10AM +0300, Tomi Valkeinen wrote:
> Update simple-cam.py to the new event model.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  src/py/examples/simple-cam.py | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/src/py/examples/simple-cam.py b/src/py/examples/simple-cam.py
> index 1cd1019d..2d359cb7 100755
> --- a/src/py/examples/simple-cam.py
> +++ b/src/py/examples/simple-cam.py
> @@ -19,16 +19,17 @@ TIMEOUT_SEC = 3
>  
>  
>  def handle_camera_event(cm):
> -    # 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.
> +    # cm.get_events() returns the ready events, which in our case should
> +    # almost always be a single RequestCompleted event, but in some cases
> +    # there could be multiple ones, other events, or no events at all.

Same comment as for 06/13.

>  
> -    reqs = cm.get_ready_requests()
> +    for ev in cm.get_events():
> +        # We are only interested in RequestCompleted events
> +        if ev.type != libcam.Event.Type.RequestCompleted:
> +            continue
>  
> -    # Process the captured frames
> -
> -    for req in reqs:
> -        process_request(req)
> +        # Process the captured frames
> +        process_request(ev.request)
>  
>  
>  def process_request(request):
> @@ -304,7 +305,7 @@ def main():
>      # CameraManager and an event will be raised using eventfd.
>      #
>      # The list of completed Requests can be retrieved with
> -    # CameraManager.get_ready_requests(), which will also clear the list in the
> +    # CameraManager.get_events(), which will also clear the list in the
>      # CameraManager.
>      #
>      # The eventfd can be retrieved from CameraManager.event_fd, and the fd can

Patch
diff mbox series

diff --git a/src/py/examples/simple-cam.py b/src/py/examples/simple-cam.py
index 1cd1019d..2d359cb7 100755
--- a/src/py/examples/simple-cam.py
+++ b/src/py/examples/simple-cam.py
@@ -19,16 +19,17 @@  TIMEOUT_SEC = 3
 
 
 def handle_camera_event(cm):
-    # 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.
+    # cm.get_events() returns the ready events, which in our case should
+    # almost always be a single RequestCompleted event, but in some cases
+    # there could be multiple ones, other events, or no events at all.
 
-    reqs = cm.get_ready_requests()
+    for ev in cm.get_events():
+        # We are only interested in RequestCompleted events
+        if ev.type != libcam.Event.Type.RequestCompleted:
+            continue
 
-    # Process the captured frames
-
-    for req in reqs:
-        process_request(req)
+        # Process the captured frames
+        process_request(ev.request)
 
 
 def process_request(request):
@@ -304,7 +305,7 @@  def main():
     # CameraManager and an event will be raised using eventfd.
     #
     # The list of completed Requests can be retrieved with
-    # CameraManager.get_ready_requests(), which will also clear the list in the
+    # CameraManager.get_events(), which will also clear the list in the
     # CameraManager.
     #
     # The eventfd can be retrieved from CameraManager.event_fd, and the fd can