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

Message ID 20220701084521.31831-15-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-capture.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

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

We usually add a commit message, even if a simple one.

On Fri, Jul 01, 2022 at 11:45:18AM +0300, Tomi Valkeinen wrote:
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

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

Thanks
   j

> ---
>  src/py/examples/simple-capture.py | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/src/py/examples/simple-capture.py b/src/py/examples/simple-capture.py
> index 4b85408f..c26e638b 100755
> --- a/src/py/examples/simple-capture.py
> +++ b/src/py/examples/simple-capture.py
> @@ -107,7 +107,7 @@ def main():
>      sel.register(cm.event_fd, selectors.EVENT_READ)
>
>      while frames_done < TOTAL_FRAMES:
> -        # cm.get_ready_requests() does not block, so we use a Selector to wait
> +        # cm.get_events() 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.
>
> @@ -115,9 +115,13 @@ def main():
>          if not events:
>              continue
>
> -        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
> +
> +            req = ev.request
>
> -        for req in reqs:
>              frames_done += 1
>
>              buffers = req.buffers
> --
> 2.34.1
>
Laurent Pinchart Aug. 18, 2022, 9:03 p.m. UTC | #2
Hi Tomi,

Thank you for the patch.

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

A commit message would be nice here too.

> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
>  src/py/examples/simple-capture.py | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/src/py/examples/simple-capture.py b/src/py/examples/simple-capture.py
> index 4b85408f..c26e638b 100755
> --- a/src/py/examples/simple-capture.py
> +++ b/src/py/examples/simple-capture.py
> @@ -107,7 +107,7 @@ def main():
>      sel.register(cm.event_fd, selectors.EVENT_READ)
>  
>      while frames_done < TOTAL_FRAMES:
> -        # cm.get_ready_requests() does not block, so we use a Selector to wait
> +        # cm.get_events() 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.

"Here we should almost always get a single request completion event, but
in some cases there could be multiple ones, other events, or no events
at all."

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

>  
> @@ -115,9 +115,13 @@ def main():
>          if not events:
>              continue
>  
> -        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
> +
> +            req = ev.request
>  
> -        for req in reqs:
>              frames_done += 1
>  
>              buffers = req.buffers
Tomi Valkeinen Aug. 26, 2022, 12:37 p.m. UTC | #3
On 19/08/2022 00:03, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Fri, Jul 01, 2022 at 11:45:18AM +0300, Tomi Valkeinen wrote:
> 
> A commit message would be nice here too.
> 
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
>> ---
>>   src/py/examples/simple-capture.py | 10 +++++++---
>>   1 file changed, 7 insertions(+), 3 deletions(-)
>>
>> diff --git a/src/py/examples/simple-capture.py b/src/py/examples/simple-capture.py
>> index 4b85408f..c26e638b 100755
>> --- a/src/py/examples/simple-capture.py
>> +++ b/src/py/examples/simple-capture.py
>> @@ -107,7 +107,7 @@ def main():
>>       sel.register(cm.event_fd, selectors.EVENT_READ)
>>   
>>       while frames_done < TOTAL_FRAMES:
>> -        # cm.get_ready_requests() does not block, so we use a Selector to wait
>> +        # cm.get_events() 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.
> 
> "Here we should almost always get a single request completion event, but
> in some cases there could be multiple ones, other events, or no events
> at all."

Thanks, that is indeed a bit clearer.

  Tomi

Patch
diff mbox series

diff --git a/src/py/examples/simple-capture.py b/src/py/examples/simple-capture.py
index 4b85408f..c26e638b 100755
--- a/src/py/examples/simple-capture.py
+++ b/src/py/examples/simple-capture.py
@@ -107,7 +107,7 @@  def main():
     sel.register(cm.event_fd, selectors.EVENT_READ)
 
     while frames_done < TOTAL_FRAMES:
-        # cm.get_ready_requests() does not block, so we use a Selector to wait
+        # cm.get_events() 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.
 
@@ -115,9 +115,13 @@  def main():
         if not events:
             continue
 
-        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
+
+            req = ev.request
 
-        for req in reqs:
             frames_done += 1
 
             buffers = req.buffers