[libcamera-devel] libcamerasrc on librem 5: bayer support missing

Nicolas Dufresne nicolas at ndufresne.ca
Fri Dec 23 16:41:07 CET 2022


Le mardi 20 décembre 2022 à 23:13 +0100, Pavel Machek a écrit :
> Hi!
> 
> > > This gets me going. I don't know how to pass details of bayer format,
> > > so help would be welcome there.
> > 
> > 
> >       video/x-bayer
> >                  format: { (string)bggr, (string)grbg, (string)gbrg, (string)rggb }
> > 
> > 
> > So in you case, create caps that looks like video/x-bayer, format=grbg, width=X,
> > height=Y. Stride must match the Width * 4, cause there is no custom stride
> > support yet.
> 
> Thanks for the hints. Should I add support for other bayer8 formats
> and submit it for merge?

There is two schools, you can just map them all and fix them later if something
isn't quite right (its low risk, trivial), or some folks feels more confortable
to just add the one they can test. Either way, patches are likely going in.

> 
> Best regards,
> 									Pavel
> 
> diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp
> index 36b9564c..7f45f4e7 100644
> --- a/src/gstreamer/gstlibcamera-utils.cpp
> +++ b/src/gstreamer/gstlibcamera-utils.cpp
> @@ -55,6 +55,10 @@ static struct {
>  	{ GST_VIDEO_FORMAT_YUY2, formats::YUYV },
>  	{ GST_VIDEO_FORMAT_YVYU, formats::YVYU },
>  
> +	/* Lie about bayer */
> +	{ GST_VIDEO_FORMAT_ENCODED, formats::SGRBG8 },

:-D from libgstvideo stand point, if its not video/x-raw, its encoded, just a
small  lie.

> +
> +

Only 1 empty line should be sufficient.

>  	/* \todo NV42 is used in libcamera but is not mapped in GStreamer yet. */
>  };
>  
> @@ -228,11 +232,23 @@ gst_format_to_pixel_format(GstVideoFormat gst_format)
>  	return PixelFormat{};
>  }
>  
> +static const gchar *
> +bayer_format_to_string(int format)
> +{
> +	switch (format) {
> +	case formats::SGRBG8:
> +		return "grbg";
> +	}
> +	return NULL;
> +}
> +
>  static GstStructure *
>  bare_structure_from_format(const PixelFormat &format)
>  {
>  	GstVideoFormat gst_format = pixel_format_to_gst_format(format);
>  
> +	printf("bare_structure_from_format: XXX\n");
> +

To be dropped for you final submission.

>  	if (gst_format == GST_VIDEO_FORMAT_UNKNOWN)
>  		return nullptr;
>  
> @@ -243,6 +259,9 @@ bare_structure_from_format(const PixelFormat &format)
>  	switch (format) {
>  	case formats::MJPEG:
>  		return gst_structure_new_empty("image/jpeg");
> +	case formats::SGRBG8:
> +		return gst_structure_new("video/x-bayer", "format", G_TYPE_STRING,
> +					 bayer_format_to_string(format), nullptr);
>  	default:
>  		return nullptr;
>  	}
> diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp
> index 8d97d7c2..2ceeeb99 100644
> --- a/src/gstreamer/gstlibcamerasrc.cpp
> +++ b/src/gstreamer/gstlibcamerasrc.cpp
> @@ -161,7 +161,7 @@ G_DEFINE_TYPE_WITH_CODE(GstLibcameraSrc, gst_libcamera_src, GST_TYPE_ELEMENT,
>  			GST_DEBUG_CATEGORY_INIT(source_debug, "libcamerasrc", 0,
>  						"libcamera Source"))
>  
> -#define TEMPLATE_CAPS GST_STATIC_CAPS("video/x-raw; image/jpeg")
> +#define TEMPLATE_CAPS GST_STATIC_CAPS("video/x-raw; video/x-bayer; image/jpeg")
>  
>  /* For the simple case, we have a src pad that is always present. */
>  GstStaticPadTemplate src_template = {

This seems right.

regards,
Nicolas

> 



More information about the libcamera-devel mailing list