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")
This commit is contained in:
Robert Mader 2024-03-31 13:21:19 +02:00
parent e2e8cf7944
commit bd5cc52c5c
2 changed files with 24 additions and 0 deletions

View file

@ -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 */

View file

@ -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());