From 0567d3ad75422c99e574a351dafb4f7a7447e0fe Mon Sep 17 00:00:00 2001 From: Phi-Bang Nguyen Date: Thu, 11 Feb 2021 16:26:37 +0100 Subject: libcamera: v4l2_subdevice: Add VIDIOC_SUBDEV_G_ROUTING ioctl Signed-off-by: Phi-Bang Nguyen --- include/libcamera/internal/v4l2_subdevice.h | 5 ++++ src/libcamera/v4l2_subdevice.cpp | 40 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index 97b89fb9..7281b4bc 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -11,6 +11,8 @@ #include #include +#include + #include #include @@ -61,6 +63,9 @@ public: int setFormat(unsigned int pad, V4L2SubdeviceFormat *format, Whence whence = ActiveFormat); + int getRouting(std::vector *routes, + Whence whence = ActiveFormat); + static std::unique_ptr fromEntityName(const MediaDevice *media, const std::string &entity); diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 023e2328..a0cc5eb4 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -442,6 +442,46 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, return 0; } +/** + * \brief Retrieve the subdevice's internal routing table + * \param[out] routes The routing table + * \param[in] whence The routing table to get, \ref V4L2Subdevice::ActiveFormat + * "ActiveFormat" or \ref V4L2Subdevice::TryFormat "TryFormat" + * + * \return 0 on success or a negative error code otherwise + */ +int V4L2Subdevice::getRouting(std::vector *routes, + Whence whence) +{ + struct v4l2_subdev_routing rt = {}; + + rt.which = whence == ActiveFormat ? V4L2_SUBDEV_FORMAT_ACTIVE + : V4L2_SUBDEV_FORMAT_TRY; + + int ret = ioctl(VIDIOC_SUBDEV_G_ROUTING, &rt); + if (ret == 0 || ret == -ENOTTY) + return ret; + + if (ret != -ENOSPC) { + LOG(V4L2, Error) + << "Failed to retrieve number of routes: " + << strerror(-ret); + return ret; + } + + routes->resize(rt.num_routes); + rt.routes = reinterpret_cast(routes->data()); + + ret = ioctl(VIDIOC_SUBDEV_G_ROUTING, &rt); + if (ret) { + LOG(V4L2, Error) + << "Failed to retrieve routes: " << strerror(-ret); + return ret; + } + + return 0; +} + /** * \brief Create a new video subdevice instance from \a entity in media device * \a media -- cgit v1.2.1