[0/9] libcamera: Support for multi-context operations
mbox series

Message ID 20250725-multicontext-v1-0-ea558291e101@ideasonboard.com
Headers show
Series
  • libcamera: Support for multi-context operations
Related show

Message

Jacopo Mondi July 25, 2025, 10:33 a.m. UTC
Support for multi-context operations has been introduced in the Linux
kernel by patch series
https://patchwork.linuxtv.org/project/linux-media/list/?series=17092

This series adds support in libcamera for operating a media device
using multi-context support.

The key design point is around the unique ownership of a media device.
Currently the MediaDevice class allows a single user to "acquire" and
"lock" it for exclusive use, to avoid concurrently running instances of
libcamera to operate the same media graph.

With multi-context support this constraint is not valid anymore, and a
media device that supports multi-context operations can be operated as
many times as the kernel driver allows to.

To represent this, introduce a SharedMediaDevice class that derives from
MediaDevice and that implements the "acquire" and "lock" operations as
nop.

Also introduce a MediaContext class that can be created both from a
MediaDevice and from a SharedMediaDevice and that allows to bind
devices together.

MediaContext created from MediaDevice implements binding as a nop. This
is not an issue as a single instance of a MediaDevice can be created and
hence bindings is effectively only called once.

A MediaContext created from a SharedMediaDevice allows instead to
perform proper binding of devices and create an isolated execution
context.

Tested on Pi5 both with the multi-context kernel support series applied
and without to validate that the series doesn't break existing users and
can be used on both multi-context aware systems and context unaware
ones.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
Jacopo Mondi (9):
      include: linux: Update media.h with media flags
      include: linux: videodev2: Add BIND_CONTEXT
      include: linux: v4l2-subdev: Add SUBDEV_BIND_CONTEXT
      libcamera: v4l2_videodevice: Add bind context
      libcamera: v4l2_subdevice: Add bind context
      libcamera: media-device: Introduce SharedMediaDevice
      libcamera: media-device: Introduce MediaContext
      [DNI] libcamera: rpi/pisp: Bind devices in a context
      [DNI]: rpi/pisp: Set format and bind ISP subdev

 include/libcamera/internal/media_device.h     |  62 +++++-
 include/libcamera/internal/v4l2_subdevice.h   |   2 +
 include/libcamera/internal/v4l2_videodevice.h |   2 +
 include/linux/media.h                         |   6 +-
 include/linux/v4l2-subdev.h                   |  11 ++
 include/linux/videodev2.h                     |  10 +
 src/libcamera/device_enumerator.cpp           |   8 +-
 src/libcamera/media_device.cpp                | 274 ++++++++++++++++++++++++++
 src/libcamera/pipeline/rpi/pisp/pisp.cpp      |  72 ++++++-
 src/libcamera/v4l2_subdevice.cpp              |  18 ++
 src/libcamera/v4l2_videodevice.cpp            |  18 ++
 11 files changed, 472 insertions(+), 11 deletions(-)
---
base-commit: b65df7e7554b45e2d3d7fdb5b37c2ab7df3db4fe
change-id: 20250724-multicontext-d7f84562bfb7

Best regards,