[libcamera-devel,v3,16/17] py: simple-cam.py: Use new events support
diff mbox series

Message ID 20220701084521.31831-17-tomi.valkeinen@ideasonboard.com
State Superseded
Headers show
Series
  • Python bindings event handling
Related show

Commit Message

Tomi Valkeinen July 1, 2022, 8:45 a.m. UTC
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 src/py/examples/simple-cam.py | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

Comments

Jacopo Mondi Aug. 18, 2022, 3:53 p.m. UTC | #1
Hi Tomi

Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Thanks
   j
On Fri, Jul 01, 2022 at 11:45:20AM +0300, Tomi Valkeinen wrote:
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  src/py/examples/simple-cam.py | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/src/py/examples/simple-cam.py b/src/py/examples/simple-cam.py
> index 1cd1019d..2dcf962a 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 return a single RequestCompleted event, but in some
> +    # cases there could be multiple or none.
>
> -    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):
> --
> 2.34.1
>
Laurent Pinchart Aug. 18, 2022, 9:05 p.m. UTC | #2
Hi Tomi,

Thank you for the patch.

On Fri, Jul 01, 2022 at 11:45:20AM +0300, Tomi Valkeinen wrote:

With the comments on 14/17 addressed here too,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  src/py/examples/simple-cam.py | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/src/py/examples/simple-cam.py b/src/py/examples/simple-cam.py
> index 1cd1019d..2dcf962a 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 return a single RequestCompleted event, but in some
> +    # cases there could be multiple or none.
>  
> -    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):

Patch
diff mbox series

diff --git a/src/py/examples/simple-cam.py b/src/py/examples/simple-cam.py
index 1cd1019d..2dcf962a 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 return a single RequestCompleted event, but in some
+    # cases there could be multiple or none.
 
-    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):