bitsy-ai / printnanny-os

Image repository, change logs, and issue tracking for PrintNanny OS
GNU Affero General Public License v3.0
23 stars 2 forks source link

Camera module is not always detected correctly #316

Closed leigh-johnson closed 1 year ago

leigh-johnson commented 1 year ago

Describe the bug

I'm seeing crash reports where the IMX219 sensor is being used in gstreamer pipeline definitions, even though no IMX219 is plugged in.

In this case, only a Logitech Brio (USB) was plugged in:

May 25 10:30:29 [REDACTED] printnanny-vision[634]: [2023-05-25T14:30:29Z INFO  printnanny_gst_pipelines::factory] Creating camera pipeline with description: libcamerasrc camera-name=/base/soc/i2c0mux/i2c@1/imx219@10 ! capsfilter caps=video/x-raw,width=640,height=480,framerate=16/1,format=YUY2,interlace-mode=progressive,colorimetry=bt709 ! v4l2convert ! interpipesink name=camera_sink sync=true async=false

To Reproduce

TBD

Expected behavior

gstreamer pipeline definitions contain the correct device/sensor

Issue.txt

-----------------------
Build Info:  |
-----------------------
IMAGE_NAME = printnanny-release-image-raspberrypi4-64-20230521213151
DISTRO_PRETTY = PrintNanny Linux 0.7.1 (Garnet)
VARIANT_NAME = PrintNanny OS Core
VARIANT_ID = core
DISTRO = printnanny
DISTRO_NAME = PrintNanny Linux
DISTRO_VERSION = 0.7.1
DISTRO_CODENAME = Garnet
ID_LIKE = BitsyLinux
HOME_URL = https://printnanny.ai
BUG_REPORT_URL = https://github.com/bitsy-ai/printnanny-os/issues
YOCTO_VERSION = 4.1.2
YOCTO_CODENAME = Langdale
MACHINE = raspberrypi4-64
TUNE_PKGARCH = cortexa72
-----------------------
Layer Revisions:      |
-----------------------
meta              = mickledore:ddb298ce894482467d82699d223c5555baad6591
meta-poky         = mickledore:ddb298ce894482467d82699d223c5555baad6591
meta-yocto-bsp    = mickledore:ddb298ce894482467d82699d223c5555baad6591
meta-oe           = mickledore-polkit-src:4321a5fd17fa2c307ca579ae76b921fb4c560bfa
meta-networking   = mickledore-polkit-src:4321a5fd17fa2c307ca579ae76b921fb4c560bfa
meta-python       = mickledore-polkit-src:4321a5fd17fa2c307ca579ae76b921fb4c560bfa
meta-webserver    = mickledore-polkit-src:4321a5fd17fa2c307ca579ae76b921fb4c560bfa
meta-initramfs    = mickledore-polkit-src:4321a5fd17fa2c307ca579ae76b921fb4c560bfa
meta-bitsy        = libcamera-v0.5.0:9960050f52ba8ef0700673d818a6f625e7ab0096
meta-microcontroller = mickledore:a848733698649628d0c3e34ae04ced0ee6ce3aee
meta-neural-network = mickledore:39f06bfa582eedc8621df677bb5cf044e9481309
meta-raspberrypi  = issue-1167-raspberrypi-hq-camera:26a25492a639310bb94afd4b2b066895c9217bad
meta-swupdate     = master:19007b03a1d96eca38e12f3bbd7bb296aea50bab
meta-printnanny   = libcamera-v0.5.0:9960050f52ba8ef0700673d818a6f625e7ab0096
meta-multimedia   = mickledore-polkit-src:4321a5fd17fa2c307ca579ae76b921fb4c560bfa
leigh-johnson commented 1 year ago

So, I think what's happening is that we DO correctly detect a discrepancy between saved settings (IMX219) and currently plugged-in device:

May 25 10:37:03 [REDACTED] printnanny-vision[1191]: [2023-05-25T14:37:03Z WARN  printnanny_gst_pipelines::factory] start_pipelines detected a hotplug change in camera settings. Saving detected configuration
May 25 10:37:03 [REDACTED] printnanny-edge-nats[632]: [2023-05-25T14:37:03Z WARN  printnanny_nats_apps::request_reply] handle_cameras_load detected a hotplug change in camera settings. Saving detected configuration
May 25 10:37:03 [REDACTED] printnanny-vision[1191]: [2023-05-25T14:37:03Z INFO  printnanny_gst_pipelines::factory] Creating camera pipeline with description: libcamerasrc camera-name=/base/scb/pcie@7d500000/pci@0,0/usb@0,0-1.3:1.0-1e4e:0109 ! capsfilter caps=video/x-raw,width=640,height=480,framerate=16/1,format=YUY2,interlace-mode=progressive ! v4l2convert ! interpipesink name=camera_sink sync=true async=false
May 25 10:37:04 [REDACTED] printnanny-vision[1191]: [2023-05-25T14:37:04Z ERROR printnanny_gst_pipelines::factory] Error creating pipeline name=camera error=API responded with status=409 Conflict error=Some(
May 25 10:37:04 [REDACTED]  printnanny-vision[1191]:         "{\n  \"code\" : 8,\n  \"description\" : \"Resource already exists\",\n  \"response\" : null\n}",
May 25 10:37:04 [REDACTED]  printnanny-vision[1191]:     )

But per the last line, we're not correctly tearing out old pipelines when VideoStreamSettings.hotplug() returns a drift in settings:

May 25 10:37:04 [REDACTED] printnanny-vision[1191]: [2023-05-25T14:37:04Z ERROR printnanny_gst_pipelines::factory] Error creating pipeline name=camera error=API responded with status=409 Conflict error=Some(
May 25 10:37:04 [REDACTED]  printnanny-vision[1191]:         "{\n  \"code\" : 8,\n  \"description\" : \"Resource already exists\",\n  \"response\" : null\n}",
May 25 10:37:04 [REDACTED]  printnanny-vision[1191]:     )
leigh-johnson commented 1 year ago

While digging into this, I noticed gstreamer pipelines aren't stopped/deleted/re-created when new camera settings are applied. Fixed here: https://github.com/bitsy-ai/printnanny-rs/pull/589

We're also stopping pipelines as part of the start_pipelines routine here: https://github.com/bitsy-ai/printnanny-rs/commit/d2ef16f1a5013457a75d6893bbd73dd950fbdbab

leigh-johnson commented 1 year ago

I reproduced the original issue + verified a fix using a Logitech brio. =) Cutting a release shortly

Screenshot from 2023-05-28 13-57-42 Screenshot from 2023-05-28 13-57-57