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

Nicolas Dufresne nicolas at ndufresne.ca
Fri Dec 23 16:43:40 CET 2022


Le mercredi 21 décembre 2022 à 12:53 +0000, Kieran Bingham a écrit :
> Quoting Pavel Machek via libcamera-devel (2022-12-20 22:13:26)
> > 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?
> 
> If you can get it working and tested - yes please?!
> 
> > 
> > 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 },
> > +
> > +
> >         /* \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";
> 
> I expect this string needs to mention that it's 8 bit. There could be
> 10bit, 12bit, 14bit, 16bit variations of this ...

For historical reason, no depth means 8bit. These formats have been in GStreamer
for 15 years. No one added 10/12/14/16 bits yet, but some partial patches are
floating. Its all about naming, there is nothing complex there. Ideally, a
design doc to document that bayers formats shall be added.

> 
> 
> > +       }
> > +       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");
> > +
> >         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")
> 
> If this is a prioritised list, I expect x-bayer should be after jpeg?
> But I'm not sure if it is...
> 
> And I wonder if the caps should be determined from the camera device anyway?
> 
> >  
> >  /* For the simple case, we have a src pad that is always present. */
> >  GstStaticPadTemplate src_template = {
> > 
> > -- 
> > People of Russia, stop Putin before his war on Ukraine escalates.



More information about the libcamera-devel mailing list