Message ID | 20200316024036.2474307-3-niklas.soderlund@ragnatech.se |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi Niklas, Thank you for the patch. On Mon, Mar 16, 2020 at 03:40:34AM +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 PixelFormat 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(-) > > diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h > index 2507daf23efac66f..38dfd92544fa2c0e 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<PixelFormat, std::vector<SizeRange>> formats(); This should be a map of unsigned int to std::vector<SizeRange>, as we're dealing with V4L2 4CCs here. I would introduce a V4L2PixelFormat class to model the V4L2 4CCs, to avoid confusion. > > int setCrop(Rectangle *rect); > int setCompose(Rectangle *rect); > diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp > index 320da2685795c041..b5f98a96a14fe348 100644 > --- a/src/libcamera/pipeline/uvcvideo.cpp > +++ b/src/libcamera/pipeline/uvcvideo.cpp > @@ -153,8 +153,7 @@ CameraConfiguration *PipelineHandlerUVC::generateConfiguration(Camera *camera, > if (roles.empty()) > return config; > > - ImageFormats v4l2formats = data->video_->formats(); > - StreamFormats formats(v4l2formats.data()); > + StreamFormats formats(data->video_->formats()); > StreamConfiguration cfg(formats); > > cfg.pixelFormat = formats.pixelformats().front(); > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp > index 858310c3b810350a..f9c59d5e3fb65737 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<PixelFormat, std::vector<SizeRange>> V4L2VideoDevice::formats() > { > - ImageFormats formats; > + std::map<PixelFormat, 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..38dfd92544fa2c0e 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<PixelFormat, 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 320da2685795c041..b5f98a96a14fe348 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -153,8 +153,7 @@ CameraConfiguration *PipelineHandlerUVC::generateConfiguration(Camera *camera, if (roles.empty()) return config; - ImageFormats v4l2formats = data->video_->formats(); - StreamFormats formats(v4l2formats.data()); + StreamFormats formats(data->video_->formats()); StreamConfiguration cfg(formats); cfg.pixelFormat = formats.pixelformats().front(); diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 858310c3b810350a..f9c59d5e3fb65737 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<PixelFormat, std::vector<SizeRange>> V4L2VideoDevice::formats() { - ImageFormats formats; + std::map<PixelFormat, 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 PixelFormat 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(-)