From 2d692502e41237187180eedec266e5204bea3c3b Mon Sep 17 00:00:00 2001 From: Jasem Mutlaq Date: Wed, 21 Feb 2024 20:42:57 +0300 Subject: [PATCH] iteration in V4L2 needs to be in reversed --- libs/indibase/webcam/v4l2_base.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/indibase/webcam/v4l2_base.cpp b/libs/indibase/webcam/v4l2_base.cpp index f6b3b3f452..7752102001 100644 --- a/libs/indibase/webcam/v4l2_base.cpp +++ b/libs/indibase/webcam/v4l2_base.cpp @@ -2998,7 +2998,9 @@ std::map V4L2_Base::enumerate() std::vector detectedDevices; int devCount = 0; devCount = scandir(prefix.c_str(), &namelist, video_dev_file_select, alphasort); - for (int i = 0; i < devCount; i++) + // Need to do this in reverse because some devices might have two end points + // e.g. /dev/video0 and /dev/video1 for the same device but only /dev/video0 can be used to control it. + for (int i = devCount - 1; i >= 0; i--) { std::string s(namelist[i]->d_name); s.erase(s.find_last_not_of(" \n\r\t") + 1);