summaryrefslogtreecommitdiff
path: root/src/libcamera/pipeline/uvcvideo
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-05-26 16:26:44 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-05-27 16:06:25 +0300
commitb50718928dcfdd1e6fb890a0230614eb9aa38111 (patch)
tree945131b41fd3e69525ad27e8ad7605167ade1d31 /src/libcamera/pipeline/uvcvideo
parent7d1f03e5baaa783eeb0587bbbf319eacc1383ab7 (diff)
libcamera: pipeline: uvcvideo: Infer camera location from removable attribute
Use the removable attribute exposed by the USB device in sysfs to infer if the camera is an external (when removable) or front (when non-removable) camera. This is likely not perfect as the removable attribute is derived from ACPI data which may not always be accurate, and non-ACPI platforms likely report all devices as removable. Still, this is a first step upon which a better method could be built. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Diffstat (limited to 'src/libcamera/pipeline/uvcvideo')
-rw-r--r--src/libcamera/pipeline/uvcvideo/uvcvideo.cpp31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
index 2ebf2788..53b2f23a 100644
--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
@@ -501,12 +501,35 @@ int UVCCameraData::init(MediaDevice *media)
video_->bufferReady.connect(this, &UVCCameraData::bufferReady);
+ properties_.set(properties::Model, utils::toAscii(media->model()));
+
/*
- * \todo Find a way to tell internal and external UVC cameras apart.
- * Until then, treat all UVC cameras as external.
+ * Derive the location from the device removable attribute in sysfs.
+ * Non-removable devices are assumed to be front as we lack detailed
+ * location information, and removable device are considered external.
+ *
+ * The sysfs removable attribute is derived from the ACPI _UPC attribute
+ * if available, or from the USB hub descriptors otherwise. ACPI data
+ * may not be very reliable, and the USB hub descriptors may not be
+ * accurate on DT-based platforms. A heuristic may need to be
+ * implemented later if too many devices end up being miscategorized.
+ *
+ * \todo Find a way to tell front and back devices apart. This could
+ * come from the ACPI _PLD, but that may be even more unreliable than
+ * the _UPC.
*/
- properties_.set(properties::Location, properties::CameraLocationExternal);
- properties_.set(properties::Model, utils::toAscii(media->model()));
+ properties::LocationEnum location = properties::CameraLocationExternal;
+ std::ifstream file(video_->devicePath() + "/../removable");
+ if (file.is_open()) {
+ std::string value;
+ std::getline(file, value);
+ file.close();
+
+ if (value == "fixed")
+ location = properties::CameraLocationFront;
+ }
+
+ properties_.set(properties::Location, location);
/*
* Get the current format in order to initialize the sensor array