From bd5cc52c5c2d542bf992ac834871ca9a961407ea Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Sun, 31 Mar 2024 13:21:19 +0200 Subject: [PATCH] libcamera: add camera rotation property on nodes Like the location, the orientation is a static property of libcamera devices. While the rotation is already exposed as buffer transform, knowing the property can be handy for applications in various ways. See also: cd8ac5c1a ("libcamera: add camera location property on nodes") --- spa/include/spa/utils/keys.h | 2 ++ spa/plugins/libcamera/libcamera-device.cpp | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/spa/include/spa/utils/keys.h b/spa/include/spa/utils/keys.h index 2f007ade3..48b94c50a 100644 --- a/spa/include/spa/utils/keys.h +++ b/spa/include/spa/utils/keys.h @@ -78,6 +78,8 @@ extern "C" { * used in open() */ #define SPA_KEY_API_LIBCAMERA_LOCATION "api.libcamera.location" /**< location of the camera: * "front", "back" or "external" */ +#define SPA_KEY_API_LIBCAMERA_ROTATION "api.libcamera.rotation" /**< rotation of the camera: + * "0", "90", "180" or "270" */ /** info from libcamera_capability */ #define SPA_KEY_API_LIBCAMERA_CAP_DRIVER "api.libcamera.cap.driver" /**< driver from capbility */ diff --git a/spa/plugins/libcamera/libcamera-device.cpp b/spa/plugins/libcamera/libcamera-device.cpp index b25a4eb72..1692fcbea 100644 --- a/spa/plugins/libcamera/libcamera-device.cpp +++ b/spa/plugins/libcamera/libcamera-device.cpp @@ -97,6 +97,26 @@ static const char *cameraLoc(const Camera *camera) return nullptr; } +static const char *cameraRot(const Camera *camera) +{ + const ControlList &props = camera->properties(); + + if (auto rotation = props.get(properties::Rotation)) { + switch (rotation.value()) { + case 90: + return "90"; + case 180: + return "180"; + case 270: + return "270"; + default: + return "0"; + } + } + + return nullptr; +} + static int emit_info(struct impl *impl, bool full) { struct spa_dict_item items[10]; @@ -120,6 +140,8 @@ static int emit_info(struct impl *impl, bool full) if (auto location = cameraLoc(impl->camera.get())) ADD_ITEM(SPA_KEY_API_LIBCAMERA_LOCATION, location); + if (auto rotation = cameraRot(impl->camera.get())) + ADD_ITEM(SPA_KEY_API_LIBCAMERA_ROTATION, rotation); const auto model = cameraModel(impl->camera.get()); ADD_ITEM(SPA_KEY_DEVICE_PRODUCT_NAME, model.c_str());