Message ID | 20190630181049.9548-2-jacopo@jmondi.org |
---|---|
State | Accepted |
Headers | show |
Series |
|
Related | show |
Hi Jacopo, Thank you for the patch. On Sun, Jun 30, 2019 at 08:10:42PM +0200, Jacopo Mondi wrote: > Group together operations to enumerate formats and operations to handle > memory handling, alternating public and private operations but > respecting the ordering within each group. Cosmetic change to prepare > for a re-work of the memory handling operations. > > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > src/libcamera/include/v4l2_videodevice.h | 6 +- > src/libcamera/v4l2_videodevice.cpp | 170 +++++++++++------------ > 2 files changed, 88 insertions(+), 88 deletions(-) > > diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h > index 734b34f1dc53..b92df882568f 100644 > --- a/src/libcamera/include/v4l2_videodevice.h > +++ b/src/libcamera/include/v4l2_videodevice.h > @@ -160,13 +160,13 @@ private: > int getFormatSingleplane(V4L2DeviceFormat *format); > int setFormatSingleplane(V4L2DeviceFormat *format); > > + std::vector<unsigned int> enumPixelformats(); > + std::vector<SizeRange> enumSizes(unsigned int pixelFormat); > + > int requestBuffers(unsigned int count); > int createPlane(Buffer *buffer, unsigned int plane, > unsigned int length); > > - std::vector<unsigned int> enumPixelformats(); > - std::vector<SizeRange> enumSizes(unsigned int pixelFormat); > - > Buffer *dequeueBuffer(); > void bufferAvailable(EventNotifier *notifier); > > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp > index 12af3bd0639b..2d1e87a76c6f 100644 > --- a/src/libcamera/v4l2_videodevice.cpp > +++ b/src/libcamera/v4l2_videodevice.cpp > @@ -627,6 +627,91 @@ ImageFormats V4L2VideoDevice::formats() > return formats; > } > > +std::vector<unsigned int> V4L2VideoDevice::enumPixelformats() > +{ > + std::vector<unsigned int> formats; > + int ret; > + > + for (unsigned int index = 0; ; index++) { > + struct v4l2_fmtdesc pixelformatEnum = {}; > + pixelformatEnum.index = index; > + pixelformatEnum.type = bufferType_; > + > + ret = ioctl(VIDIOC_ENUM_FMT, &pixelformatEnum); > + if (ret) > + break; > + > + formats.push_back(pixelformatEnum.pixelformat); > + } > + > + if (ret && ret != -EINVAL) { > + LOG(V4L2, Error) > + << "Unable to enumerate pixel formats: " > + << strerror(-ret); > + return {}; > + } > + > + return formats; > +} > + > +std::vector<SizeRange> V4L2VideoDevice::enumSizes(unsigned int pixelFormat) > +{ > + std::vector<SizeRange> sizes; > + int ret; > + > + for (unsigned int index = 0;; index++) { > + struct v4l2_frmsizeenum frameSize = {}; > + frameSize.index = index; > + frameSize.pixel_format = pixelFormat; > + > + ret = ioctl(VIDIOC_ENUM_FRAMESIZES, &frameSize); > + if (ret) > + break; > + > + if (index != 0 && > + frameSize.type != V4L2_FRMSIZE_TYPE_DISCRETE) { > + LOG(V4L2, Error) > + << "Non-zero index for non discrete type"; > + return {}; > + } > + > + switch (frameSize.type) { > + case V4L2_FRMSIZE_TYPE_DISCRETE: > + sizes.emplace_back(frameSize.discrete.width, > + frameSize.discrete.height); > + break; > + case V4L2_FRMSIZE_TYPE_CONTINUOUS: > + sizes.emplace_back(frameSize.stepwise.min_width, > + frameSize.stepwise.min_height, > + frameSize.stepwise.max_width, > + frameSize.stepwise.max_height); > + break; > + case V4L2_FRMSIZE_TYPE_STEPWISE: > + sizes.emplace_back(frameSize.stepwise.min_width, > + frameSize.stepwise.min_height, > + frameSize.stepwise.max_width, > + frameSize.stepwise.max_height, > + frameSize.stepwise.step_width, > + frameSize.stepwise.step_height); > + break; > + default: > + LOG(V4L2, Error) > + << "Unknown VIDIOC_ENUM_FRAMESIZES type " > + << frameSize.type; > + return {}; > + } > + } > + > + if (ret && ret != -EINVAL) { > + LOG(V4L2, Error) > + << "Unable to enumerate frame sizes: " > + << strerror(-ret); > + return {}; > + } > + > + return sizes; > +} > + > int V4L2VideoDevice::requestBuffers(unsigned int count) > { > struct v4l2_requestbuffers rb = {}; > @@ -754,91 +839,6 @@ int V4L2VideoDevice::createPlane(Buffer *buffer, unsigned int planeIndex, > return 0; > } > > -std::vector<unsigned int> V4L2VideoDevice::enumPixelformats() > -{ > - std::vector<unsigned int> formats; > - int ret; > - > - for (unsigned int index = 0; ; index++) { > - struct v4l2_fmtdesc pixelformatEnum = {}; > - pixelformatEnum.index = index; > - pixelformatEnum.type = bufferType_; > - > - ret = ioctl(VIDIOC_ENUM_FMT, &pixelformatEnum); > - if (ret) > - break; > - > - formats.push_back(pixelformatEnum.pixelformat); > - } > - > - if (ret && ret != -EINVAL) { > - LOG(V4L2, Error) > - << "Unable to enumerate pixel formats: " > - << strerror(-ret); > - return {}; > - } > - > - return formats; > -} > - > -std::vector<SizeRange> V4L2VideoDevice::enumSizes(unsigned int pixelFormat) > -{ > - std::vector<SizeRange> sizes; > - int ret; > - > - for (unsigned int index = 0;; index++) { > - struct v4l2_frmsizeenum frameSize = {}; > - frameSize.index = index; > - frameSize.pixel_format = pixelFormat; > - > - ret = ioctl(VIDIOC_ENUM_FRAMESIZES, &frameSize); > - if (ret) > - break; > - > - if (index != 0 && > - frameSize.type != V4L2_FRMSIZE_TYPE_DISCRETE) { > - LOG(V4L2, Error) > - << "Non-zero index for non discrete type"; > - return {}; > - } > - > - switch (frameSize.type) { > - case V4L2_FRMSIZE_TYPE_DISCRETE: > - sizes.emplace_back(frameSize.discrete.width, > - frameSize.discrete.height); > - break; > - case V4L2_FRMSIZE_TYPE_CONTINUOUS: > - sizes.emplace_back(frameSize.stepwise.min_width, > - frameSize.stepwise.min_height, > - frameSize.stepwise.max_width, > - frameSize.stepwise.max_height); > - break; > - case V4L2_FRMSIZE_TYPE_STEPWISE: > - sizes.emplace_back(frameSize.stepwise.min_width, > - frameSize.stepwise.min_height, > - frameSize.stepwise.max_width, > - frameSize.stepwise.max_height, > - frameSize.stepwise.step_width, > - frameSize.stepwise.step_height); > - break; > - default: > - LOG(V4L2, Error) > - << "Unknown VIDIOC_ENUM_FRAMESIZES type " > - << frameSize.type; > - return {}; > - } > - } > - > - if (ret && ret != -EINVAL) { > - LOG(V4L2, Error) > - << "Unable to enumerate frame sizes: " > - << strerror(-ret); > - return {}; > - } > - > - return sizes; > -} > - > /** > * \brief Import the externally allocated \a pool of buffers > * \param[in] pool BufferPool of buffers to import > -- > 2.21.0 > > _______________________________________________ > libcamera-devel mailing list > libcamera-devel@lists.libcamera.org > https://lists.libcamera.org/listinfo/libcamera-devel
Hi Jacopo, Thanks for your work. On 2019-06-30 20:10:42 +0200, Jacopo Mondi wrote: > Group together operations to enumerate formats and operations to handle > memory handling, alternating public and private operations but > respecting the ordering within each group. Cosmetic change to prepare > for a re-work of the memory handling operations. > > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> > --- > src/libcamera/include/v4l2_videodevice.h | 6 +- > src/libcamera/v4l2_videodevice.cpp | 170 +++++++++++------------ > 2 files changed, 88 insertions(+), 88 deletions(-) > > diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h > index 734b34f1dc53..b92df882568f 100644 > --- a/src/libcamera/include/v4l2_videodevice.h > +++ b/src/libcamera/include/v4l2_videodevice.h > @@ -160,13 +160,13 @@ private: > int getFormatSingleplane(V4L2DeviceFormat *format); > int setFormatSingleplane(V4L2DeviceFormat *format); > > + std::vector<unsigned int> enumPixelformats(); > + std::vector<SizeRange> enumSizes(unsigned int pixelFormat); > + > int requestBuffers(unsigned int count); > int createPlane(Buffer *buffer, unsigned int plane, > unsigned int length); > > - std::vector<unsigned int> enumPixelformats(); > - std::vector<SizeRange> enumSizes(unsigned int pixelFormat); > - > Buffer *dequeueBuffer(); > void bufferAvailable(EventNotifier *notifier); > > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp > index 12af3bd0639b..2d1e87a76c6f 100644 > --- a/src/libcamera/v4l2_videodevice.cpp > +++ b/src/libcamera/v4l2_videodevice.cpp > @@ -627,6 +627,91 @@ ImageFormats V4L2VideoDevice::formats() > return formats; > } > > +std::vector<unsigned int> V4L2VideoDevice::enumPixelformats() > +{ > + std::vector<unsigned int> formats; > + int ret; > + > + for (unsigned int index = 0; ; index++) { > + struct v4l2_fmtdesc pixelformatEnum = {}; > + pixelformatEnum.index = index; > + pixelformatEnum.type = bufferType_; > + > + ret = ioctl(VIDIOC_ENUM_FMT, &pixelformatEnum); > + if (ret) > + break; > + > + formats.push_back(pixelformatEnum.pixelformat); > + } > + > + if (ret && ret != -EINVAL) { > + LOG(V4L2, Error) > + << "Unable to enumerate pixel formats: " > + << strerror(-ret); > + return {}; > + } > + > + return formats; > +} > + > +std::vector<SizeRange> V4L2VideoDevice::enumSizes(unsigned int pixelFormat) > +{ > + std::vector<SizeRange> sizes; > + int ret; > + > + for (unsigned int index = 0;; index++) { > + struct v4l2_frmsizeenum frameSize = {}; > + frameSize.index = index; > + frameSize.pixel_format = pixelFormat; > + > + ret = ioctl(VIDIOC_ENUM_FRAMESIZES, &frameSize); > + if (ret) > + break; > + > + if (index != 0 && > + frameSize.type != V4L2_FRMSIZE_TYPE_DISCRETE) { > + LOG(V4L2, Error) > + << "Non-zero index for non discrete type"; > + return {}; > + } > + > + switch (frameSize.type) { > + case V4L2_FRMSIZE_TYPE_DISCRETE: > + sizes.emplace_back(frameSize.discrete.width, > + frameSize.discrete.height); > + break; > + case V4L2_FRMSIZE_TYPE_CONTINUOUS: > + sizes.emplace_back(frameSize.stepwise.min_width, > + frameSize.stepwise.min_height, > + frameSize.stepwise.max_width, > + frameSize.stepwise.max_height); > + break; > + case V4L2_FRMSIZE_TYPE_STEPWISE: > + sizes.emplace_back(frameSize.stepwise.min_width, > + frameSize.stepwise.min_height, > + frameSize.stepwise.max_width, > + frameSize.stepwise.max_height, > + frameSize.stepwise.step_width, > + frameSize.stepwise.step_height); > + break; > + default: > + LOG(V4L2, Error) > + << "Unknown VIDIOC_ENUM_FRAMESIZES type " > + << frameSize.type; > + return {}; > + } > + } > + > + if (ret && ret != -EINVAL) { > + LOG(V4L2, Error) > + << "Unable to enumerate frame sizes: " > + << strerror(-ret); > + return {}; > + } > + > + return sizes; > +} > + > int V4L2VideoDevice::requestBuffers(unsigned int count) > { > struct v4l2_requestbuffers rb = {}; > @@ -754,91 +839,6 @@ int V4L2VideoDevice::createPlane(Buffer *buffer, unsigned int planeIndex, > return 0; > } > > -std::vector<unsigned int> V4L2VideoDevice::enumPixelformats() > -{ > - std::vector<unsigned int> formats; > - int ret; > - > - for (unsigned int index = 0; ; index++) { > - struct v4l2_fmtdesc pixelformatEnum = {}; > - pixelformatEnum.index = index; > - pixelformatEnum.type = bufferType_; > - > - ret = ioctl(VIDIOC_ENUM_FMT, &pixelformatEnum); > - if (ret) > - break; > - > - formats.push_back(pixelformatEnum.pixelformat); > - } > - > - if (ret && ret != -EINVAL) { > - LOG(V4L2, Error) > - << "Unable to enumerate pixel formats: " > - << strerror(-ret); > - return {}; > - } > - > - return formats; > -} > - > -std::vector<SizeRange> V4L2VideoDevice::enumSizes(unsigned int pixelFormat) > -{ > - std::vector<SizeRange> sizes; > - int ret; > - > - for (unsigned int index = 0;; index++) { > - struct v4l2_frmsizeenum frameSize = {}; > - frameSize.index = index; > - frameSize.pixel_format = pixelFormat; > - > - ret = ioctl(VIDIOC_ENUM_FRAMESIZES, &frameSize); > - if (ret) > - break; > - > - if (index != 0 && > - frameSize.type != V4L2_FRMSIZE_TYPE_DISCRETE) { > - LOG(V4L2, Error) > - << "Non-zero index for non discrete type"; > - return {}; > - } > - > - switch (frameSize.type) { > - case V4L2_FRMSIZE_TYPE_DISCRETE: > - sizes.emplace_back(frameSize.discrete.width, > - frameSize.discrete.height); > - break; > - case V4L2_FRMSIZE_TYPE_CONTINUOUS: > - sizes.emplace_back(frameSize.stepwise.min_width, > - frameSize.stepwise.min_height, > - frameSize.stepwise.max_width, > - frameSize.stepwise.max_height); > - break; > - case V4L2_FRMSIZE_TYPE_STEPWISE: > - sizes.emplace_back(frameSize.stepwise.min_width, > - frameSize.stepwise.min_height, > - frameSize.stepwise.max_width, > - frameSize.stepwise.max_height, > - frameSize.stepwise.step_width, > - frameSize.stepwise.step_height); > - break; > - default: > - LOG(V4L2, Error) > - << "Unknown VIDIOC_ENUM_FRAMESIZES type " > - << frameSize.type; > - return {}; > - } > - } > - > - if (ret && ret != -EINVAL) { > - LOG(V4L2, Error) > - << "Unable to enumerate frame sizes: " > - << strerror(-ret); > - return {}; > - } > - > - return sizes; > -} > - > /** > * \brief Import the externally allocated \a pool of buffers > * \param[in] pool BufferPool of buffers to import > -- > 2.21.0 > > _______________________________________________ > libcamera-devel mailing list > libcamera-devel@lists.libcamera.org > https://lists.libcamera.org/listinfo/libcamera-devel
Hello, On Tue, Jul 02, 2019 at 12:28:34AM +0200, Niklas Söderlund wrote: > Hi Jacopo, > > Thanks for your work. > > On 2019-06-30 20:10:42 +0200, Jacopo Mondi wrote: > > Group together operations to enumerate formats and operations to handle > > memory handling, alternating public and private operations but > > respecting the ordering within each group. Cosmetic change to prepare > > for a re-work of the memory handling operations. > > > > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> > > Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> > With Niklas' and Laurent's tags, I'm now pushing this to reduce the backlog of this series. Thanks j > > --- > > src/libcamera/include/v4l2_videodevice.h | 6 +- > > src/libcamera/v4l2_videodevice.cpp | 170 +++++++++++------------ > > 2 files changed, 88 insertions(+), 88 deletions(-) > > > > diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h > > index 734b34f1dc53..b92df882568f 100644 > > --- a/src/libcamera/include/v4l2_videodevice.h > > +++ b/src/libcamera/include/v4l2_videodevice.h > > @@ -160,13 +160,13 @@ private: > > int getFormatSingleplane(V4L2DeviceFormat *format); > > int setFormatSingleplane(V4L2DeviceFormat *format); > > > > + std::vector<unsigned int> enumPixelformats(); > > + std::vector<SizeRange> enumSizes(unsigned int pixelFormat); > > + > > int requestBuffers(unsigned int count); > > int createPlane(Buffer *buffer, unsigned int plane, > > unsigned int length); > > > > - std::vector<unsigned int> enumPixelformats(); > > - std::vector<SizeRange> enumSizes(unsigned int pixelFormat); > > - > > Buffer *dequeueBuffer(); > > void bufferAvailable(EventNotifier *notifier); > > > > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp > > index 12af3bd0639b..2d1e87a76c6f 100644 > > --- a/src/libcamera/v4l2_videodevice.cpp > > +++ b/src/libcamera/v4l2_videodevice.cpp > > @@ -627,6 +627,91 @@ ImageFormats V4L2VideoDevice::formats() > > return formats; > > } > > > > +std::vector<unsigned int> V4L2VideoDevice::enumPixelformats() > > +{ > > + std::vector<unsigned int> formats; > > + int ret; > > + > > + for (unsigned int index = 0; ; index++) { > > + struct v4l2_fmtdesc pixelformatEnum = {}; > > + pixelformatEnum.index = index; > > + pixelformatEnum.type = bufferType_; > > + > > + ret = ioctl(VIDIOC_ENUM_FMT, &pixelformatEnum); > > + if (ret) > > + break; > > + > > + formats.push_back(pixelformatEnum.pixelformat); > > + } > > + > > + if (ret && ret != -EINVAL) { > > + LOG(V4L2, Error) > > + << "Unable to enumerate pixel formats: " > > + << strerror(-ret); > > + return {}; > > + } > > + > > + return formats; > > +} > > + > > +std::vector<SizeRange> V4L2VideoDevice::enumSizes(unsigned int pixelFormat) > > +{ > > + std::vector<SizeRange> sizes; > > + int ret; > > + > > + for (unsigned int index = 0;; index++) { > > + struct v4l2_frmsizeenum frameSize = {}; > > + frameSize.index = index; > > + frameSize.pixel_format = pixelFormat; > > + > > + ret = ioctl(VIDIOC_ENUM_FRAMESIZES, &frameSize); > > + if (ret) > > + break; > > + > > + if (index != 0 && > > + frameSize.type != V4L2_FRMSIZE_TYPE_DISCRETE) { > > + LOG(V4L2, Error) > > + << "Non-zero index for non discrete type"; > > + return {}; > > + } > > + > > + switch (frameSize.type) { > > + case V4L2_FRMSIZE_TYPE_DISCRETE: > > + sizes.emplace_back(frameSize.discrete.width, > > + frameSize.discrete.height); > > + break; > > + case V4L2_FRMSIZE_TYPE_CONTINUOUS: > > + sizes.emplace_back(frameSize.stepwise.min_width, > > + frameSize.stepwise.min_height, > > + frameSize.stepwise.max_width, > > + frameSize.stepwise.max_height); > > + break; > > + case V4L2_FRMSIZE_TYPE_STEPWISE: > > + sizes.emplace_back(frameSize.stepwise.min_width, > > + frameSize.stepwise.min_height, > > + frameSize.stepwise.max_width, > > + frameSize.stepwise.max_height, > > + frameSize.stepwise.step_width, > > + frameSize.stepwise.step_height); > > + break; > > + default: > > + LOG(V4L2, Error) > > + << "Unknown VIDIOC_ENUM_FRAMESIZES type " > > + << frameSize.type; > > + return {}; > > + } > > + } > > + > > + if (ret && ret != -EINVAL) { > > + LOG(V4L2, Error) > > + << "Unable to enumerate frame sizes: " > > + << strerror(-ret); > > + return {}; > > + } > > + > > + return sizes; > > +} > > + > > int V4L2VideoDevice::requestBuffers(unsigned int count) > > { > > struct v4l2_requestbuffers rb = {}; > > @@ -754,91 +839,6 @@ int V4L2VideoDevice::createPlane(Buffer *buffer, unsigned int planeIndex, > > return 0; > > } > > > > -std::vector<unsigned int> V4L2VideoDevice::enumPixelformats() > > -{ > > - std::vector<unsigned int> formats; > > - int ret; > > - > > - for (unsigned int index = 0; ; index++) { > > - struct v4l2_fmtdesc pixelformatEnum = {}; > > - pixelformatEnum.index = index; > > - pixelformatEnum.type = bufferType_; > > - > > - ret = ioctl(VIDIOC_ENUM_FMT, &pixelformatEnum); > > - if (ret) > > - break; > > - > > - formats.push_back(pixelformatEnum.pixelformat); > > - } > > - > > - if (ret && ret != -EINVAL) { > > - LOG(V4L2, Error) > > - << "Unable to enumerate pixel formats: " > > - << strerror(-ret); > > - return {}; > > - } > > - > > - return formats; > > -} > > - > > -std::vector<SizeRange> V4L2VideoDevice::enumSizes(unsigned int pixelFormat) > > -{ > > - std::vector<SizeRange> sizes; > > - int ret; > > - > > - for (unsigned int index = 0;; index++) { > > - struct v4l2_frmsizeenum frameSize = {}; > > - frameSize.index = index; > > - frameSize.pixel_format = pixelFormat; > > - > > - ret = ioctl(VIDIOC_ENUM_FRAMESIZES, &frameSize); > > - if (ret) > > - break; > > - > > - if (index != 0 && > > - frameSize.type != V4L2_FRMSIZE_TYPE_DISCRETE) { > > - LOG(V4L2, Error) > > - << "Non-zero index for non discrete type"; > > - return {}; > > - } > > - > > - switch (frameSize.type) { > > - case V4L2_FRMSIZE_TYPE_DISCRETE: > > - sizes.emplace_back(frameSize.discrete.width, > > - frameSize.discrete.height); > > - break; > > - case V4L2_FRMSIZE_TYPE_CONTINUOUS: > > - sizes.emplace_back(frameSize.stepwise.min_width, > > - frameSize.stepwise.min_height, > > - frameSize.stepwise.max_width, > > - frameSize.stepwise.max_height); > > - break; > > - case V4L2_FRMSIZE_TYPE_STEPWISE: > > - sizes.emplace_back(frameSize.stepwise.min_width, > > - frameSize.stepwise.min_height, > > - frameSize.stepwise.max_width, > > - frameSize.stepwise.max_height, > > - frameSize.stepwise.step_width, > > - frameSize.stepwise.step_height); > > - break; > > - default: > > - LOG(V4L2, Error) > > - << "Unknown VIDIOC_ENUM_FRAMESIZES type " > > - << frameSize.type; > > - return {}; > > - } > > - } > > - > > - if (ret && ret != -EINVAL) { > > - LOG(V4L2, Error) > > - << "Unable to enumerate frame sizes: " > > - << strerror(-ret); > > - return {}; > > - } > > - > > - return sizes; > > -} > > - > > /** > > * \brief Import the externally allocated \a pool of buffers > > * \param[in] pool BufferPool of buffers to import > > -- > > 2.21.0 > > > > _______________________________________________ > > libcamera-devel mailing list > > libcamera-devel@lists.libcamera.org > > https://lists.libcamera.org/listinfo/libcamera-devel > > -- > Regards, > Niklas Söderlund
diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h index 734b34f1dc53..b92df882568f 100644 --- a/src/libcamera/include/v4l2_videodevice.h +++ b/src/libcamera/include/v4l2_videodevice.h @@ -160,13 +160,13 @@ private: int getFormatSingleplane(V4L2DeviceFormat *format); int setFormatSingleplane(V4L2DeviceFormat *format); + std::vector<unsigned int> enumPixelformats(); + std::vector<SizeRange> enumSizes(unsigned int pixelFormat); + int requestBuffers(unsigned int count); int createPlane(Buffer *buffer, unsigned int plane, unsigned int length); - std::vector<unsigned int> enumPixelformats(); - std::vector<SizeRange> enumSizes(unsigned int pixelFormat); - Buffer *dequeueBuffer(); void bufferAvailable(EventNotifier *notifier); diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 12af3bd0639b..2d1e87a76c6f 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -627,6 +627,91 @@ ImageFormats V4L2VideoDevice::formats() return formats; } +std::vector<unsigned int> V4L2VideoDevice::enumPixelformats() +{ + std::vector<unsigned int> formats; + int ret; + + for (unsigned int index = 0; ; index++) { + struct v4l2_fmtdesc pixelformatEnum = {}; + pixelformatEnum.index = index; + pixelformatEnum.type = bufferType_; + + ret = ioctl(VIDIOC_ENUM_FMT, &pixelformatEnum); + if (ret) + break; + + formats.push_back(pixelformatEnum.pixelformat); + } + + if (ret && ret != -EINVAL) { + LOG(V4L2, Error) + << "Unable to enumerate pixel formats: " + << strerror(-ret); + return {}; + } + + return formats; +} + +std::vector<SizeRange> V4L2VideoDevice::enumSizes(unsigned int pixelFormat) +{ + std::vector<SizeRange> sizes; + int ret; + + for (unsigned int index = 0;; index++) { + struct v4l2_frmsizeenum frameSize = {}; + frameSize.index = index; + frameSize.pixel_format = pixelFormat; + + ret = ioctl(VIDIOC_ENUM_FRAMESIZES, &frameSize); + if (ret) + break; + + if (index != 0 && + frameSize.type != V4L2_FRMSIZE_TYPE_DISCRETE) { + LOG(V4L2, Error) + << "Non-zero index for non discrete type"; + return {}; + } + + switch (frameSize.type) { + case V4L2_FRMSIZE_TYPE_DISCRETE: + sizes.emplace_back(frameSize.discrete.width, + frameSize.discrete.height); + break; + case V4L2_FRMSIZE_TYPE_CONTINUOUS: + sizes.emplace_back(frameSize.stepwise.min_width, + frameSize.stepwise.min_height, + frameSize.stepwise.max_width, + frameSize.stepwise.max_height); + break; + case V4L2_FRMSIZE_TYPE_STEPWISE: + sizes.emplace_back(frameSize.stepwise.min_width, + frameSize.stepwise.min_height, + frameSize.stepwise.max_width, + frameSize.stepwise.max_height, + frameSize.stepwise.step_width, + frameSize.stepwise.step_height); + break; + default: + LOG(V4L2, Error) + << "Unknown VIDIOC_ENUM_FRAMESIZES type " + << frameSize.type; + return {}; + } + } + + if (ret && ret != -EINVAL) { + LOG(V4L2, Error) + << "Unable to enumerate frame sizes: " + << strerror(-ret); + return {}; + } + + return sizes; +} + int V4L2VideoDevice::requestBuffers(unsigned int count) { struct v4l2_requestbuffers rb = {}; @@ -754,91 +839,6 @@ int V4L2VideoDevice::createPlane(Buffer *buffer, unsigned int planeIndex, return 0; } -std::vector<unsigned int> V4L2VideoDevice::enumPixelformats() -{ - std::vector<unsigned int> formats; - int ret; - - for (unsigned int index = 0; ; index++) { - struct v4l2_fmtdesc pixelformatEnum = {}; - pixelformatEnum.index = index; - pixelformatEnum.type = bufferType_; - - ret = ioctl(VIDIOC_ENUM_FMT, &pixelformatEnum); - if (ret) - break; - - formats.push_back(pixelformatEnum.pixelformat); - } - - if (ret && ret != -EINVAL) { - LOG(V4L2, Error) - << "Unable to enumerate pixel formats: " - << strerror(-ret); - return {}; - } - - return formats; -} - -std::vector<SizeRange> V4L2VideoDevice::enumSizes(unsigned int pixelFormat) -{ - std::vector<SizeRange> sizes; - int ret; - - for (unsigned int index = 0;; index++) { - struct v4l2_frmsizeenum frameSize = {}; - frameSize.index = index; - frameSize.pixel_format = pixelFormat; - - ret = ioctl(VIDIOC_ENUM_FRAMESIZES, &frameSize); - if (ret) - break; - - if (index != 0 && - frameSize.type != V4L2_FRMSIZE_TYPE_DISCRETE) { - LOG(V4L2, Error) - << "Non-zero index for non discrete type"; - return {}; - } - - switch (frameSize.type) { - case V4L2_FRMSIZE_TYPE_DISCRETE: - sizes.emplace_back(frameSize.discrete.width, - frameSize.discrete.height); - break; - case V4L2_FRMSIZE_TYPE_CONTINUOUS: - sizes.emplace_back(frameSize.stepwise.min_width, - frameSize.stepwise.min_height, - frameSize.stepwise.max_width, - frameSize.stepwise.max_height); - break; - case V4L2_FRMSIZE_TYPE_STEPWISE: - sizes.emplace_back(frameSize.stepwise.min_width, - frameSize.stepwise.min_height, - frameSize.stepwise.max_width, - frameSize.stepwise.max_height, - frameSize.stepwise.step_width, - frameSize.stepwise.step_height); - break; - default: - LOG(V4L2, Error) - << "Unknown VIDIOC_ENUM_FRAMESIZES type " - << frameSize.type; - return {}; - } - } - - if (ret && ret != -EINVAL) { - LOG(V4L2, Error) - << "Unable to enumerate frame sizes: " - << strerror(-ret); - return {}; - } - - return sizes; -} - /** * \brief Import the externally allocated \a pool of buffers * \param[in] pool BufferPool of buffers to import
Group together operations to enumerate formats and operations to handle memory handling, alternating public and private operations but respecting the ordering within each group. Cosmetic change to prepare for a re-work of the memory handling operations. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> --- src/libcamera/include/v4l2_videodevice.h | 6 +- src/libcamera/v4l2_videodevice.cpp | 170 +++++++++++------------ 2 files changed, 88 insertions(+), 88 deletions(-)