Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPi camera index (RPICameraCamID) ignored and cameras are assigned randomly #3994

Open
marksutheran opened this issue Nov 30, 2024 · 2 comments

Comments

@marksutheran
Copy link

marksutheran commented Nov 30, 2024

Which version are you using?

v1.9.3

Which operating system are you using?

Linux arm64 standard

Describe how to replicate the issue

Every time the RPi system is rebooted the MediaMTX camera path with index RPICameraCamID=0 and the camera with index RPICameraCamID=1 have a chance of being switched.

e.g. This means that the MediaMTX camera at path camera_0 will be randomly assigned to physical camera at CSI0 or CSI1 every system boot. The camera at path camera_1 will be assigned to the other device.

 paths:
  camera_0:
    source: rpiCamera
    rpiCameraCamID: 0
    rpiCameraWidth: 1920
    [snip]
  camera_1:
    source: rpiCamera
    rpiCameraCamID: 1
    rpiCameraWidth: 1920
    [snip]

If I open a WebRTC stream for one camera path [ e.g. http://192.168.1.211:8889/camera_0/] then the video will randomly switch between cameras after a system reboot.

Restarting the MediaMTX server does not affect this behaviour, only restarting the OS changes the camera mappings.

However, when calling the libcamera cli, the results are consistent across reboots, camera '0' is always CAM0

libcamera-still --camera 0 --output test_c0_r11.jpg

[0:01:22.065130239] [1082] INFO RPI vc4.cpp:565 Sensor: /base/soc/i2c0mux/i2c@1/imx290@1a - Selected sensor format: 1920x1080-SRGGB12_1X12 - Selected unicam format: 1920x1080-pRCC

Server logs

No response

Network dump

No response

@marksutheran
Copy link
Author

marksutheran commented Nov 30, 2024

Edit: original comment was r.e. mediamtx-rpicamera / camera.cpp

Just double checked that libcamera CameraManager::cameras() order is indeed stable between system boots. Even if MediaMTX stream shows the cameras flipped, the cameras are always at the same index.

Test code:

int main()
{
    std::unique_ptr<CameraManager> cm = std::make_unique<CameraManager>();
    cm->start();


    for (int i = 0; i < 2; i++)
        std::cout << std::to_string(i) + " - " << cm->cameras()[i].get()->id() << std::endl;

    cm->stop();
    return 0;
}

[0:01:19.951268580] [1156]  INFO Camera camera_manager.cpp:297 libcamera v0.0.5+83-bde9b04f
[0:01:20.001300324] [1157]  INFO RPI vc4.cpp:437 Registered camera /base/soc/i2c0mux/i2c@0/imx290@1a to Unicam device /dev/media4 and ISP device /dev/media0
[0:01:20.017983955] [1157]  INFO RPI vc4.cpp:437 Registered camera /base/soc/i2c0mux/i2c@1/imx290@1a to Unicam device /dev/media5 and ISP device /dev/media2
0 - /base/soc/i2c0mux/i2c@0/imx290@1a
1 - /base/soc/i2c0mux/i2c@1/imx290@1a

@marksutheran
Copy link
Author

marksutheran commented Nov 30, 2024

Update: This bug was introduced in v1.9.0 and affects releases up to v1.9.3: v1.8.5 is OK

Test:

  • Run mediamtx v1.8.5
  • Open a WebRTC stream to one of the cameras
  • Stop mediamtx and start mediamtx 1.9.x with same config.yml
  • Check that the same WebRTC stream has switched to the other camera

Workaround: roll back to v1.8.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant