hongquan / CoBang

A QR code scanner desktop app for Linux
GNU General Public License v3.0
240 stars 27 forks source link

TypeError: object of type `GstLibcameraDevice' does not have property `device_path' #94

Closed dgudim closed 1 month ago

dgudim commented 1 month ago

Does not open with an error:

[2:12:58.955423555] [38827] ERROR IPAModule ipa_module.cpp:172 Symbol ipaModuleInfo not found
[2:12:58.955444741] [38827] ERROR IPAModule ipa_module.cpp:292 v4l2-compat.so: IPA module has no valid info
[2:12:58.955480107] [38827]  INFO Camera camera_manager.cpp:313 libcamera v0.3.0
Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/cobang/app.py", line 220, in do_activate
    self.discover_webcam()
  File "/usr/lib/python3.12/site-packages/cobang/app.py", line 208, in discover_webcam
    cam_path, src_type = get_device_path(d)
                         ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/cobang/prep.py", line 44, in get_device_path
    return device.get_property('device_path'), 'v4l2src'

TypeError: object of type `GstLibcameraDevice' does not have property `device_path'
dgudim commented 1 month ago

Modifying get_device_path to just skip unsupported device types unsurprisingly works. I can open a PR if this is the solution you want to go with

In prep.py

def get_device_path(device: Gst.Device) -> Tuple[str, str]:
    type_name = device.__class__.__name__
    # GstPipeWireDevice doesn't have dedicated GIR binding yet,
    # so we have to access its "device.path" in general GStreamer way
    if type_name == 'GstPipeWireDevice':
        properties = device.get_properties()
        path = properties['device.path']
        if not path:
            path = properties['api.v4l2.path']
        return path, 'pipewiresrc'
    if type_name != 'GstV4l2Device':
        return '', ''
    return device.get_property('device_path'), 'v4l2src'

In app.py (~line 207)

...
...
            cam_name = d.get_display_name()
            cam_path, src_type = get_device_path(d)
            if not cam_name or len(cam_path) == 0:
                logger.error('Not recognize this device.')
                continue
...
...
hongquan commented 1 month ago

Thank you. I haven't seen GstLibcameraDevice before. Please create PR.

dgudim commented 1 month ago

Nice! Done :)

hongquan commented 1 month ago

Thank you.