Rishikesh Donadkar

Hello, I am Rishikesh applying as a GSoC student this year in the organization libcamera.I am writing this blog when the GSoC student application period is about to begin. This blog will cover the journey of applying for the libcamera organization and the challenges I faced during it and how I tackled them.

Introduction

what is libcamera?

libcamera is an open source camera stack for many platforms with a core userspace library, and support from the Linux kernel APIs and drivers already in place. It aims to control the complexity of embedded camera hardware by providing an intuitive API and method of separating untrusted vendor code from the open source core.

Project-idea: Improve GStreamer element to add support for properties

Project idea introduction.

GStreamer element is used to use libcamera as a video source in the gstreamer pipeline. Libcamera can be used to stream video using gstreamer. The aim of this project is add more control over the aspects of the stream by adding support for properties in the GStreamer element.

Warmup Task

For the new open-source contributors who want to contribute in this project some warmup tasks were provided to make the new contributors familiar with the source code and how libcamera works behind the hood. All the project ideas have separate warm up tasks as I was interested in the project idea ‘Improve GStreamer element to add support for properties’ . I began with those tasks.

1.Build libcamera with the GStreamer element enabled

Followed the instruction of getting started page to clone and build libcamera. Faced many problems in building libcamera but was successfully able to build the project on Raspberry Pi 3 model B (1 GB ram).

2.Stream using GStreamer from the libcamera element

Used the command of the getting started page to stream using the libcamera element as source in the gstreamer pipeline. To capture and encode as a JPEG stream(from the Raspberry pi 5 MP camera) and receive on another device(laptop) use the following commands from the getting started page.

  gst-launch-1.0 libcamerasrc ! \
     video/x-raw,colorimetry=bt709,format=NV12,width=1280,height=720,framerate=30/1 ! \
     jpegenc ! multipartmux ! \
     tcpserversink host=0.0.0.0 port=5000
  gst-launch-1.0 tcpclientsrc host=$DEVICE_IP port=5000 ! \
      multipartdemux ! jpegdec ! autovideosink

test_img_two

3.Explore how controls work in libcamera. Building a test application that uses libcamera (or extend cam) that can set controls might help.

For reference I went through simple-cam and built a test application that can set controls. The code for the test application can be found here. Next, I was asked by Vedant to go through GStreamer tutorials and build a gstreamer application using libcamerasrc element. I build a gstreamer application which useases libcamera as source and glimagesink as sink. A filter is added in between which flips the video stream clockwise by 90 degrees. The code for GStreamer application can be found here.

4.Explore GStreamer properties

Read about the GStreamer properties from the GStreamer tutorials. First I read about GLib, GObject instantiation and GObject properties. Next, I went through the code in libcamera/src/gstreamer and understood how the camera-name property is defined in the gst_libcamera_src_class_init() function and how the gst_libcamera_src_set_property() and gst_libcamera_src_get_property()S functions manage the property.

5.How would you connect GStreamer properties to libcamera controls? This will form the design of your project.

Now, I was clear about the gstreamer properties and libcamera controls. I asked for help on IRC on how to connect them to each other. To connect them we need to map the property form gstreamer to the appropriate control in libcamera. I understood how the mapping can be done by backtracking the function gst_libcamera_stream_configuration_to_caps(), for now the gstreamer GstVideoFormat is mapped to libcamera PixelFormat, this function can be further extended to map libcamera colorspace ot gstreamer colorimetry. Similarly, gst_libcamera_stream_formats_to_caps() could be extended to map the framerate form gstreamer and the FrameDuration (or FrameDurationLimits) from libcamera, and probably set it to be configured when the camera is started.

Contributions

As a part of my contribution in libcamera I submitted this patch. The patch was trivial but I was happy about my first contribution in open source. I will be glad to contribute more in the libcamera codebase.