Message ID | 20200317035239.2697679-6-niklas.soderlund@ragnatech.se |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi Niklas, Thank you for the patch. On Tue, Mar 17, 2020 at 04:52:36AM +0100, Niklas Söderlund wrote: > The ImageFormats class is not very nice as it forces the pixel format to > be an unsigned integer. Replace it with a map of unsigned int to vector > of sizes. s/sizes/size ranges/ The commit message probably needs some improvement. I understand what you're doing here, but replacing a class that forces usage of an integer with a map that uses an integer key still forces usage of an integer :-) You should explain the rationale behind this. > > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> > --- > src/libcamera/include/v4l2_videodevice.h | 2 +- > src/libcamera/pipeline/uvcvideo.cpp | 3 +-- > src/libcamera/v4l2_videodevice.cpp | 11 +++-------- > 3 files changed, 5 insertions(+), 11 deletions(-) > > diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h > index 2507daf23efac66f..62e6a657fc7eedb0 100644 > --- a/src/libcamera/include/v4l2_videodevice.h > +++ b/src/libcamera/include/v4l2_videodevice.h > @@ -184,7 +184,7 @@ public: > > int getFormat(V4L2DeviceFormat *format); > int setFormat(V4L2DeviceFormat *format); > - ImageFormats formats(); > + std::map<unsigned int, std::vector<SizeRange>> formats(); A shorter alias for the map would be nice, but I think it can go on top, once we figure out what we need exactly. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > int setCrop(Rectangle *rect); > int setCompose(Rectangle *rect); > diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp > index 14f7ddb18a765834..5ebd83f3c2099ffe 100644 > --- a/src/libcamera/pipeline/uvcvideo.cpp > +++ b/src/libcamera/pipeline/uvcvideo.cpp > @@ -153,9 +153,8 @@ CameraConfiguration *PipelineHandlerUVC::generateConfiguration(Camera *camera, > if (roles.empty()) > return config; > > - ImageFormats v4l2formats = data->video_->formats(); > std::map<PixelFormat, std::vector<SizeRange>> deviceformats; > - for (const auto &it : v4l2formats.data()) { > + for (const auto &it : data->video_->formats()) { > PixelFormat pixelformat = V4L2VideoDevice::toPixelFormat(it.first); > const std::vector<SizeRange> &ranges = it.second; > deviceformats[pixelformat] = ranges; > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp > index 858310c3b810350a..280cf1877c8936d7 100644 > --- a/src/libcamera/v4l2_videodevice.cpp > +++ b/src/libcamera/v4l2_videodevice.cpp > @@ -901,21 +901,16 @@ int V4L2VideoDevice::setFormatSingleplane(V4L2DeviceFormat *format) > * > * \return A list of the supported video device formats > */ > -ImageFormats V4L2VideoDevice::formats() > +std::map<unsigned int, std::vector<SizeRange>> V4L2VideoDevice::formats() > { > - ImageFormats formats; > + std::map<unsigned int, std::vector<SizeRange>> formats; > > for (unsigned int pixelformat : enumPixelformats()) { > std::vector<SizeRange> sizes = enumSizes(pixelformat); > if (sizes.empty()) > return {}; > > - if (formats.addFormat(pixelformat, sizes)) { > - LOG(V4L2, Error) > - << "Could not add sizes for pixel format " > - << pixelformat; > - return {}; > - } > + formats[pixelformat] = sizes; > } > > return formats;
diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h index 2507daf23efac66f..62e6a657fc7eedb0 100644 --- a/src/libcamera/include/v4l2_videodevice.h +++ b/src/libcamera/include/v4l2_videodevice.h @@ -184,7 +184,7 @@ public: int getFormat(V4L2DeviceFormat *format); int setFormat(V4L2DeviceFormat *format); - ImageFormats formats(); + std::map<unsigned int, std::vector<SizeRange>> formats(); int setCrop(Rectangle *rect); int setCompose(Rectangle *rect); diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index 14f7ddb18a765834..5ebd83f3c2099ffe 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -153,9 +153,8 @@ CameraConfiguration *PipelineHandlerUVC::generateConfiguration(Camera *camera, if (roles.empty()) return config; - ImageFormats v4l2formats = data->video_->formats(); std::map<PixelFormat, std::vector<SizeRange>> deviceformats; - for (const auto &it : v4l2formats.data()) { + for (const auto &it : data->video_->formats()) { PixelFormat pixelformat = V4L2VideoDevice::toPixelFormat(it.first); const std::vector<SizeRange> &ranges = it.second; deviceformats[pixelformat] = ranges; diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 858310c3b810350a..280cf1877c8936d7 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -901,21 +901,16 @@ int V4L2VideoDevice::setFormatSingleplane(V4L2DeviceFormat *format) * * \return A list of the supported video device formats */ -ImageFormats V4L2VideoDevice::formats() +std::map<unsigned int, std::vector<SizeRange>> V4L2VideoDevice::formats() { - ImageFormats formats; + std::map<unsigned int, std::vector<SizeRange>> formats; for (unsigned int pixelformat : enumPixelformats()) { std::vector<SizeRange> sizes = enumSizes(pixelformat); if (sizes.empty()) return {}; - if (formats.addFormat(pixelformat, sizes)) { - LOG(V4L2, Error) - << "Could not add sizes for pixel format " - << pixelformat; - return {}; - } + formats[pixelformat] = sizes; } return formats;
The ImageFormats class is not very nice as it forces the pixel format to be an unsigned integer. Replace it with a map of unsigned int to vector of sizes. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> --- src/libcamera/include/v4l2_videodevice.h | 2 +- src/libcamera/pipeline/uvcvideo.cpp | 3 +-- src/libcamera/v4l2_videodevice.cpp | 11 +++-------- 3 files changed, 5 insertions(+), 11 deletions(-)