[libcamera-devel,0/8] libcamera: Add DRM/KMS viewfinder display to cam
mbox series

Message ID 20200519032505.17307-1-laurent.pinchart@ideasonboard.com
Headers show
Series
  • libcamera: Add DRM/KMS viewfinder display to cam
Related show

Message

Laurent Pinchart May 19, 2020, 3:24 a.m. UTC
Hello,

This patch series extends the cam application to implement live
viewfinder display using a DRM/KMS device. Supported display features
are currently fairly limited (scaling and overlays are not supported for
instance), but should nonetheless be a good first step.

Patches 1/8 to 4/8 refactor the cam application and the BufferWriter
class to introduce an abstract FrameSink class. Patch 5/8 adds a set of
classes to wrap the DRM/KMS API (using libdrm). Patches 6/8 and 7/8 add
a DRM/KMS frame sink implementation, and patch 8/8 wires it up in the
cam application.

I've kept patch 7/8 separate from 6/8 from now as I'm not entirely sure
what the best course of action is. Enabling the display is a costly
operation, so doing it at start() time would be best. However, we would
need a frame buffer to be displayed at that point, and none is available
yet from the camera. Patch 7/8 thus delays enabling the display to the
first frame. The operation isn't too costly from a userspace point of
view as the atomic request is committed asynchronously (although it
still requires two ioctl calls, one to create the mode blob - but this
could be moved to start() - and one to commit the request). Another
option would be to allocate an extra dumb buffer and fill it with static
data for the first frame. I'm also toying with the idea to move the sink
handling from the request completion handler (running in the camera
manager thread) to the main application thread.

I've tested this with the simple pipeline handler on an i.MX7, running

cam -c 1 -s pixelformat=0x34325241,width=480,height=800 -C -D DPI-1

The size of the stream has to match the size of the display, as scaling
isn't supported yet (which wouldn't help on the i.MX7 anyway, as the
display controller doesn't support scaling).

Laurent Pinchart (8):
  cam: Pass stream roles to Capture class
  cam: Add FrameSink base class
  cam: Turn BufferWriter into a FrameSink
  cam: Rename BufferWriter to FileSink
  cam: Add DRM helper classes
  cam: Add KMS sink class
  cam: kms_sink: Enable display on first frame
  cam: Add support for viewfinder through DRM/KMS

 src/cam/buffer_writer.h                      |  31 -
 src/cam/capture.cpp                          | 100 ++-
 src/cam/capture.h                            |  10 +-
 src/cam/drm.cpp                              | 661 +++++++++++++++++++
 src/cam/drm.h                                | 334 ++++++++++
 src/cam/{buffer_writer.cpp => file_sink.cpp} |  35 +-
 src/cam/file_sink.h                          |  36 +
 src/cam/frame_sink.cpp                       |  31 +
 src/cam/frame_sink.h                         |  35 +
 src/cam/kms_sink.cpp                         | 288 ++++++++
 src/cam/kms_sink.h                           |  74 +++
 src/cam/main.cpp                             |  20 +-
 src/cam/main.h                               |   1 +
 src/cam/meson.build                          |  18 +-
 14 files changed, 1611 insertions(+), 63 deletions(-)
 delete mode 100644 src/cam/buffer_writer.h
 create mode 100644 src/cam/drm.cpp
 create mode 100644 src/cam/drm.h
 rename src/cam/{buffer_writer.cpp => file_sink.cpp} (69%)
 create mode 100644 src/cam/file_sink.h
 create mode 100644 src/cam/frame_sink.cpp
 create mode 100644 src/cam/frame_sink.h
 create mode 100644 src/cam/kms_sink.cpp
 create mode 100644 src/cam/kms_sink.h