[2/2] libcamera: gstreamer: Report mounting-rotation of camera sensor
diff mbox series

Message ID 20250627074208.49872-3-uajain@igalia.com
State New
Headers show
Series
  • gstreamer: Report mounting-rotation of camera sensor
Related show

Commit Message

Umang Jain June 27, 2025, 7:42 a.m. UTC
Report mounting-rotation of the camera sensor by reading the
property::Rotation property from libcamera. This is reported
in GstDevice properties for libcamerasrc element.

Signed-off-by: Umang Jain <uajain@igalia.com>
---
 src/gstreamer/gstlibcameraprovider.cpp | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Kieran Bingham June 27, 2025, 7:57 a.m. UTC | #1
Quoting Umang Jain (2025-06-27 08:42:08)
> Report mounting-rotation of the camera sensor by reading the
> property::Rotation property from libcamera. This is reported
> in GstDevice properties for libcamerasrc element.
> 
> Signed-off-by: Umang Jain <uajain@igalia.com>
> ---
>  src/gstreamer/gstlibcameraprovider.cpp | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp
> index 5da96ea3..806a149a 100644
> --- a/src/gstreamer/gstlibcameraprovider.cpp
> +++ b/src/gstreamer/gstlibcameraprovider.cpp
> @@ -12,6 +12,7 @@
>  
>  #include <libcamera/camera.h>
>  #include <libcamera/camera_manager.h>
> +#include <libcamera/property_ids.h>
>  
>  #include "gstlibcamerasrc.h"
>  #include "gstlibcamera-utils.h"
> @@ -131,6 +132,8 @@ gst_libcamera_device_new(const std::shared_ptr<Camera> &camera)
>         static const std::array roles{ StreamRole::VideoRecording };
>         g_autoptr(GstCaps) caps = gst_caps_new_empty();
>         const gchar *name = camera->id().c_str();
> +       std::string rotation_str;
> +       bool success;
>  
>         std::unique_ptr<CameraConfiguration> config = camera->generateConfiguration(roles);
>         if (!config || config->size() != roles.size()) {
> @@ -144,12 +147,23 @@ gst_libcamera_device_new(const std::shared_ptr<Camera> &camera)
>                         gst_caps_append(caps, sub_caps);
>         }
>  
> +       const int32_t rotation = camera->properties().get(properties::Rotation).value_or(0);
> +       Orientation mountingOrientation = orientationFromRotation(rotation, &success);
> +       rotation_str = success ? orientationToString(mountingOrientation)
> +                              : std::to_string(rotation);

This puts a 'libcamera style' string "Rotate0" into the results/output
of the gstlibcamerasrc ... is there any equivalent for how other
components report the rotation? Is it just a numerical value or is this
a unique property to libcamera elements?

--
Kieran

> +
> +       g_autoptr(GstStructure) props =
> +               gst_structure_new("camera-properties",
> +                                 "mounting-rotation", G_TYPE_STRING, rotation_str.c_str(),
> +                                 nullptr);
> +
>         return GST_DEVICE(g_object_new(GST_TYPE_LIBCAMERA_DEVICE,
>                                        /* \todo Use a unique identifier instead of camera name. */
>                                        "name", name,
>                                        "display-name", name,
>                                        "caps", caps,
>                                        "device-class", "Source/Video",
> +                                      "properties", props,
>                                        nullptr));
>  }
>  
> -- 
> 2.50.0
>
Kieran Bingham June 27, 2025, 8:05 a.m. UTC | #2
Quoting Kieran Bingham (2025-06-27 08:57:57)
> Quoting Umang Jain (2025-06-27 08:42:08)
> > Report mounting-rotation of the camera sensor by reading the
> > property::Rotation property from libcamera. This is reported
> > in GstDevice properties for libcamerasrc element.
> > 
> > Signed-off-by: Umang Jain <uajain@igalia.com>
> > ---
> >  src/gstreamer/gstlibcameraprovider.cpp | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> > 
> > diff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp
> > index 5da96ea3..806a149a 100644
> > --- a/src/gstreamer/gstlibcameraprovider.cpp
> > +++ b/src/gstreamer/gstlibcameraprovider.cpp
> > @@ -12,6 +12,7 @@
> >  
> >  #include <libcamera/camera.h>
> >  #include <libcamera/camera_manager.h>
> > +#include <libcamera/property_ids.h>
> >  
> >  #include "gstlibcamerasrc.h"
> >  #include "gstlibcamera-utils.h"
> > @@ -131,6 +132,8 @@ gst_libcamera_device_new(const std::shared_ptr<Camera> &camera)
> >         static const std::array roles{ StreamRole::VideoRecording };
> >         g_autoptr(GstCaps) caps = gst_caps_new_empty();
> >         const gchar *name = camera->id().c_str();
> > +       std::string rotation_str;
> > +       bool success;
> >  
> >         std::unique_ptr<CameraConfiguration> config = camera->generateConfiguration(roles);
> >         if (!config || config->size() != roles.size()) {
> > @@ -144,12 +147,23 @@ gst_libcamera_device_new(const std::shared_ptr<Camera> &camera)
> >                         gst_caps_append(caps, sub_caps);
> >         }
> >  
> > +       const int32_t rotation = camera->properties().get(properties::Rotation).value_or(0);
> > +       Orientation mountingOrientation = orientationFromRotation(rotation, &success);
> > +       rotation_str = success ? orientationToString(mountingOrientation)
> > +                              : std::to_string(rotation);
> 
> This puts a 'libcamera style' string "Rotate0" into the results/output
> of the gstlibcamerasrc ... is there any equivalent for how other
> components report the rotation? Is it just a numerical value or is this
> a unique property to libcamera elements?

Digging deeper in here - orientationFromRotation will return only 0, 90,
180, or 270... giving Rotate0, Rotate90, Rotate180, Rotate270, or
otherwise if that fails it will perfrom a std::string on the integer
value.

Perhaps we should just use the string representation of the integer
value always - the property is caleld "mounting-rotation" - so a
numerical value seems correct already.

--
Kieran



> 
> --
> Kieran
> 
> > +
> > +       g_autoptr(GstStructure) props =
> > +               gst_structure_new("camera-properties",
> > +                                 "mounting-rotation", G_TYPE_STRING, rotation_str.c_str(),
> > +                                 nullptr);
> > +
> >         return GST_DEVICE(g_object_new(GST_TYPE_LIBCAMERA_DEVICE,
> >                                        /* \todo Use a unique identifier instead of camera name. */
> >                                        "name", name,
> >                                        "display-name", name,
> >                                        "caps", caps,
> >                                        "device-class", "Source/Video",
> > +                                      "properties", props,
> >                                        nullptr));
> >  }
> >  
> > -- 
> > 2.50.0
> >
Umang Jain June 27, 2025, 8:10 a.m. UTC | #3
On 6/27/25 1:27 PM, Kieran Bingham wrote:
> Quoting Umang Jain (2025-06-27 08:42:08)
>> Report mounting-rotation of the camera sensor by reading the
>> property::Rotation property from libcamera. This is reported
>> in GstDevice properties for libcamerasrc element.
>>
>> Signed-off-by: Umang Jain <uajain@igalia.com>
>> ---
>>   src/gstreamer/gstlibcameraprovider.cpp | 14 ++++++++++++++
>>   1 file changed, 14 insertions(+)
>>
>> diff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp
>> index 5da96ea3..806a149a 100644
>> --- a/src/gstreamer/gstlibcameraprovider.cpp
>> +++ b/src/gstreamer/gstlibcameraprovider.cpp
>> @@ -12,6 +12,7 @@
>>   
>>   #include <libcamera/camera.h>
>>   #include <libcamera/camera_manager.h>
>> +#include <libcamera/property_ids.h>
>>   
>>   #include "gstlibcamerasrc.h"
>>   #include "gstlibcamera-utils.h"
>> @@ -131,6 +132,8 @@ gst_libcamera_device_new(const std::shared_ptr<Camera> &camera)
>>          static const std::array roles{ StreamRole::VideoRecording };
>>          g_autoptr(GstCaps) caps = gst_caps_new_empty();
>>          const gchar *name = camera->id().c_str();
>> +       std::string rotation_str;
>> +       bool success;
>>   
>>          std::unique_ptr<CameraConfiguration> config = camera->generateConfiguration(roles);
>>          if (!config || config->size() != roles.size()) {
>> @@ -144,12 +147,23 @@ gst_libcamera_device_new(const std::shared_ptr<Camera> &camera)
>>                          gst_caps_append(caps, sub_caps);
>>          }
>>   
>> +       const int32_t rotation = camera->properties().get(properties::Rotation).value_or(0);
>> +       Orientation mountingOrientation = orientationFromRotation(rotation, &success);
>> +       rotation_str = success ? orientationToString(mountingOrientation)
>> +                              : std::to_string(rotation);
> This puts a 'libcamera style' string "Rotate0" into the results/output
> of the gstlibcamerasrc ... is there any equivalent for how other
> components report the rotation? Is it just a numerical value or is this
> a unique property to libcamera elements?


I think it's upto the element on how it wants to form the human readable 
string.

If you expect, that some computations/transformations needs to be done 
and have
valid use case, you can append the GstStructure to contain additional
"mounting-rotation-angle" property to report it numerically.


>
> --
> Kieran
>
>> +
>> +       g_autoptr(GstStructure) props =
>> +               gst_structure_new("camera-properties",
>> +                                 "mounting-rotation", G_TYPE_STRING, rotation_str.c_str(),
>> +                                 nullptr);
>> +
>>          return GST_DEVICE(g_object_new(GST_TYPE_LIBCAMERA_DEVICE,
>>                                         /* \todo Use a unique identifier instead of camera name. */
>>                                         "name", name,
>>                                         "display-name", name,
>>                                         "caps", caps,
>>                                         "device-class", "Source/Video",
>> +                                      "properties", props,
>>                                         nullptr));
>>   }
>>   
>> -- 
>> 2.50.0
>>
Nicolas Dufresne June 27, 2025, 2:54 p.m. UTC | #4
Le vendredi 27 juin 2025 à 08:57 +0100, Kieran Bingham a écrit :
> Quoting Umang Jain (2025-06-27 08:42:08)
> > Report mounting-rotation of the camera sensor by reading the
> > property::Rotation property from libcamera. This is reported
> > in GstDevice properties for libcamerasrc element.
> > 
> > Signed-off-by: Umang Jain <uajain@igalia.com>
> > ---
> >  src/gstreamer/gstlibcameraprovider.cpp | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> > 
> > diff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp
> > index 5da96ea3..806a149a 100644
> > --- a/src/gstreamer/gstlibcameraprovider.cpp
> > +++ b/src/gstreamer/gstlibcameraprovider.cpp
> > @@ -12,6 +12,7 @@
> >  
> >  #include <libcamera/camera.h>
> >  #include <libcamera/camera_manager.h>
> > +#include <libcamera/property_ids.h>
> >  
> >  #include "gstlibcamerasrc.h"
> >  #include "gstlibcamera-utils.h"
> > @@ -131,6 +132,8 @@ gst_libcamera_device_new(const std::shared_ptr<Camera> &camera)
> >         static const std::array roles{ StreamRole::VideoRecording };
> >         g_autoptr(GstCaps) caps = gst_caps_new_empty();
> >         const gchar *name = camera->id().c_str();
> > +       std::string rotation_str;
> > +       bool success;
> >  
> >         std::unique_ptr<CameraConfiguration> config = camera->generateConfiguration(roles);
> >         if (!config || config->size() != roles.size()) {
> > @@ -144,12 +147,23 @@ gst_libcamera_device_new(const std::shared_ptr<Camera> &camera)
> >                         gst_caps_append(caps, sub_caps);
> >         }
> >  
> > +       const int32_t rotation = camera->properties().get(properties::Rotation).value_or(0);
> > +       Orientation mountingOrientation = orientationFromRotation(rotation, &success);
> > +       rotation_str = success ? orientationToString(mountingOrientation)
> > +                              : std::to_string(rotation);
> 
> This puts a 'libcamera style' string "Rotate0" into the results/output
> of the gstlibcamerasrc ... is there any equivalent for how other
> components report the rotation? Is it just a numerical value or is this
> a unique property to libcamera elements?

I was looking around, and actually we have more options. The general style that
has been used on linux is udev style. Typically, udev have generic namespaces
such as object.id = 87 / object.serial = 3264, and then API specific looks like
alsa.long_card_name = LENOVO-21KCCTO1WW-ThinkPadX1CarbonGen12 (but also
api.alsa.card.longname, I bet one of the two is deprecated),
api.v4l2.cap.bus_info is what the V4L2 udev plugin do.

So with that in mind, we could go really simple and use libcamera.mounting-
rotation = number, or api.libcamera.. if we figure-out what is the new standard.

In short, we have a way to place API specific stuff there in a way that if there
is another standard later they can coexist. Would you prefer this simple
approach ?

Nicolas

> 
> --
> Kieran
> 
> > +
> > +       g_autoptr(GstStructure) props =
> > +               gst_structure_new("camera-properties",
> > +                                 "mounting-rotation", G_TYPE_STRING, rotation_str.c_str(),
> > +                                 nullptr);
> > +
> >         return GST_DEVICE(g_object_new(GST_TYPE_LIBCAMERA_DEVICE,
> >                                        /* \todo Use a unique identifier instead of camera name. */
> >                                        "name", name,
> >                                        "display-name", name,
> >                                        "caps", caps,
> >                                        "device-class", "Source/Video",
> > +                                      "properties", props,
> >                                        nullptr));
> >  }
> >  
> > -- 
> > 2.50.0
> >

Patch
diff mbox series

diff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp
index 5da96ea3..806a149a 100644
--- a/src/gstreamer/gstlibcameraprovider.cpp
+++ b/src/gstreamer/gstlibcameraprovider.cpp
@@ -12,6 +12,7 @@ 
 
 #include <libcamera/camera.h>
 #include <libcamera/camera_manager.h>
+#include <libcamera/property_ids.h>
 
 #include "gstlibcamerasrc.h"
 #include "gstlibcamera-utils.h"
@@ -131,6 +132,8 @@  gst_libcamera_device_new(const std::shared_ptr<Camera> &camera)
 	static const std::array roles{ StreamRole::VideoRecording };
 	g_autoptr(GstCaps) caps = gst_caps_new_empty();
 	const gchar *name = camera->id().c_str();
+	std::string rotation_str;
+	bool success;
 
 	std::unique_ptr<CameraConfiguration> config = camera->generateConfiguration(roles);
 	if (!config || config->size() != roles.size()) {
@@ -144,12 +147,23 @@  gst_libcamera_device_new(const std::shared_ptr<Camera> &camera)
 			gst_caps_append(caps, sub_caps);
 	}
 
+	const int32_t rotation = camera->properties().get(properties::Rotation).value_or(0);
+	Orientation mountingOrientation = orientationFromRotation(rotation, &success);
+	rotation_str = success ? orientationToString(mountingOrientation)
+			       : std::to_string(rotation);
+
+	g_autoptr(GstStructure) props =
+		gst_structure_new("camera-properties",
+				  "mounting-rotation", G_TYPE_STRING, rotation_str.c_str(),
+				  nullptr);
+
 	return GST_DEVICE(g_object_new(GST_TYPE_LIBCAMERA_DEVICE,
 				       /* \todo Use a unique identifier instead of camera name. */
 				       "name", name,
 				       "display-name", name,
 				       "caps", caps,
 				       "device-class", "Source/Video",
+				       "properties", props,
 				       nullptr));
 }