[libcamera-devel] [PATCH v2 06/19] py: Add CameraManager.read_event()

Tomi Valkeinen tomi.valkeinen at ideasonboard.com
Fri May 27 08:00:44 CEST 2022


On 26/05/2022 18:27, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Tue, May 24, 2022 at 02:45:57PM +0300, Tomi Valkeinen wrote:
>> Add CameraManager.read_event() so that the user does not need to call
>> os.read().
>>
>> We use eventfd, and we must always read 8 bytes. Hiding that inside
>> read_event() makes sense.
>>
>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen at ideasonboard.com>
>> ---
>>   src/py/cam/cam.py            | 3 +--
>>   src/py/libcamera/py_main.cpp | 8 ++++++++
>>   test/py/unittests.py         | 3 +--
>>   3 files changed, 10 insertions(+), 4 deletions(-)
>>
>> diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py
>> index e2bc78da..66df18bf 100755
>> --- a/src/py/cam/cam.py
>> +++ b/src/py/cam/cam.py
>> @@ -9,7 +9,6 @@
>>   import argparse
>>   import binascii
>>   import libcamera as libcam
>> -import os
>>   import sys
>>   import traceback
>>   
>> @@ -294,7 +293,7 @@ def event_handler(state):
>>           cm = state['cm']
>>           contexts = state['contexts']
>>   
>> -        os.read(cm.efd, 8)
>> +        cm.read_event()
>>   
>>           reqs = cm.get_ready_requests()
> 
> Would it make sense to read the event within get_ready_requests() ?

I thought about these two functions, but this seemed the safest to me. 
If get_ready_requests() would do read_event(), then you could not call 
get_ready_requests() unless you knew there is an event waiting, or it 
would block. Or we could make the fd non-blocking, but I think that's 
usually the choice of the user, not the library.

  Tomi


More information about the libcamera-devel mailing list