Message ID | 20200203114254.27424-1-naush@raspberrypi.com |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi Naushir thanks for the patch I only have typographical comments, so please bear with me being a bit picky On Mon, Feb 03, 2020 at 11:42:54AM +0000, Naushir Patuck wrote: > Add control for cropping/selection on a V4L2 video device through > the VIDIOC_S_SELECTION ioctl. This is similar to the exising cropping ^ double space s/exising/existing > control available on V4L2 sub-devices. > > Signed-off-by: Naushir Patuck <naush@raspberrypi.com> > --- > src/libcamera/include/v4l2_videodevice.h | 5 +++ > src/libcamera/v4l2_videodevice.cpp | 50 ++++++++++++++++++++++++ > 2 files changed, 55 insertions(+) > > diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h > index e4d35ab..5de4c65 100644 > --- a/src/libcamera/include/v4l2_videodevice.h > +++ b/src/libcamera/include/v4l2_videodevice.h > @@ -200,6 +200,9 @@ public: > uint32_t toV4L2Fourcc(PixelFormat pixelFormat); > static uint32_t toV4L2Fourcc(PixelFormat pixelFormat, bool multiplanar); > > + int setCrop(Rectangle *rect); > + int setCompose(Rectangle *rect); > + I would actually move these up, before or after the format handling functions. > protected: > std::string logPrefix() const; > > @@ -213,6 +216,8 @@ private: > int getFormatSingleplane(V4L2DeviceFormat *format); > int setFormatSingleplane(V4L2DeviceFormat *format); > > + int setSelection(unsigned int target, Rectangle *rect); > + > std::vector<unsigned int> enumPixelformats(); > std::vector<SizeRange> enumSizes(unsigned int pixelFormat); > > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp > index 8226773..7914434 100644 > --- a/src/libcamera/v4l2_videodevice.cpp > +++ b/src/libcamera/v4l2_videodevice.cpp > @@ -1499,6 +1499,56 @@ uint32_t V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat, bool multiplanar > return 0; > } > > +/** > + * \brief Set a crop rectangle on the V4L2 video device node > + * \param[inout] rect The rectangle describing the compose target area "the crop target area" ? > + * \return 0 on success or a negative error code otherwise > + */ > +int V4L2VideoDevice::setCrop( Rectangle *rect) ^ ups > +{ > + return setSelection(V4L2_SEL_TGT_CROP, rect); > +} > + > +/** > + * \brief Set a compose rectangle on the V4L2 video device node > + * \param[inout] rect The rectangle describing the compose target area > + * \return 0 on success or a negative error code otherwise > + */ > +int V4L2VideoDevice::setCompose(Rectangle *rect) > +{ > + return setSelection(V4L2_SEL_TGT_COMPOSE, rect); > +} > + > +int V4L2VideoDevice::setSelection(unsigned int target, > + Rectangle *rect) ^ please align to the open ( Running ./utils/checkstyle.py helps you catch trivial syntax mistakes. You might want to setup a commit hook for that: $ cat .git/hooks/post-commit exec ./utils/checkstyle.py > +{ > + struct v4l2_selection sel = {}; > + > + sel.type = bufferType_; > + sel.target = target; > + sel.flags = 0; > + > + sel.r.left = rect->x; > + sel.r.top = rect->y; > + sel.r.width = rect->w; > + sel.r.height = rect->h; > + > + int ret = ioctl(VIDIOC_S_SELECTION, &sel); > + if (ret < 0) { > + LOG(V4L2, Error) > + << "Unable to set rectangle " << target This would fit on a single line, but I'll let you decide what looks nicer :) > + << ": " << strerror(-ret); > + return ret; > + } > + > + rect->x = sel.r.left; > + rect->y = sel.r.top; > + rect->w = sel.r.width; > + rect->h = sel.r.height; > + > + return 0; > +} > + With the above minors addressed: Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Thanks j > /** > * \class V4L2M2MDevice > * \brief Memory-to-Memory video device > -- > 2.17.1 > > _______________________________________________ > libcamera-devel mailing list > libcamera-devel@lists.libcamera.org > https://lists.libcamera.org/listinfo/libcamera-devel
diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h index e4d35ab..5de4c65 100644 --- a/src/libcamera/include/v4l2_videodevice.h +++ b/src/libcamera/include/v4l2_videodevice.h @@ -200,6 +200,9 @@ public: uint32_t toV4L2Fourcc(PixelFormat pixelFormat); static uint32_t toV4L2Fourcc(PixelFormat pixelFormat, bool multiplanar); + int setCrop(Rectangle *rect); + int setCompose(Rectangle *rect); + protected: std::string logPrefix() const; @@ -213,6 +216,8 @@ private: int getFormatSingleplane(V4L2DeviceFormat *format); int setFormatSingleplane(V4L2DeviceFormat *format); + int setSelection(unsigned int target, Rectangle *rect); + std::vector<unsigned int> enumPixelformats(); std::vector<SizeRange> enumSizes(unsigned int pixelFormat); diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 8226773..7914434 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1499,6 +1499,56 @@ uint32_t V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat, bool multiplanar return 0; } +/** + * \brief Set a crop rectangle on the V4L2 video device node + * \param[inout] rect The rectangle describing the compose target area + * \return 0 on success or a negative error code otherwise + */ +int V4L2VideoDevice::setCrop( Rectangle *rect) +{ + return setSelection(V4L2_SEL_TGT_CROP, rect); +} + +/** + * \brief Set a compose rectangle on the V4L2 video device node + * \param[inout] rect The rectangle describing the compose target area + * \return 0 on success or a negative error code otherwise + */ +int V4L2VideoDevice::setCompose(Rectangle *rect) +{ + return setSelection(V4L2_SEL_TGT_COMPOSE, rect); +} + +int V4L2VideoDevice::setSelection(unsigned int target, + Rectangle *rect) +{ + struct v4l2_selection sel = {}; + + sel.type = bufferType_; + sel.target = target; + sel.flags = 0; + + sel.r.left = rect->x; + sel.r.top = rect->y; + sel.r.width = rect->w; + sel.r.height = rect->h; + + int ret = ioctl(VIDIOC_S_SELECTION, &sel); + if (ret < 0) { + LOG(V4L2, Error) + << "Unable to set rectangle " << target + << ": " << strerror(-ret); + return ret; + } + + rect->x = sel.r.left; + rect->y = sel.r.top; + rect->w = sel.r.width; + rect->h = sel.r.height; + + return 0; +} + /** * \class V4L2M2MDevice * \brief Memory-to-Memory video device
Add control for cropping/selection on a V4L2 video device through the VIDIOC_S_SELECTION ioctl. This is similar to the exising cropping control available on V4L2 sub-devices. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> --- src/libcamera/include/v4l2_videodevice.h | 5 +++ src/libcamera/v4l2_videodevice.cpp | 50 ++++++++++++++++++++++++ 2 files changed, 55 insertions(+)