summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-07-01 22:05:09 +0200
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-07-23 16:31:41 +0200
commitdcda73ec14a69d303456cb8ab4869410c29bd762 (patch)
treeda39c75d2825cac7b0fa73dcbb5d1626e6585233 /src
parentd9295552b17c72c57357e901cd256bcf66528233 (diff)
libcamera: v4l2_subdevice: Replace ImageFormats with a map
Replace the V4L2Subdevice usage of the ImageFormats class with a std::map and the utils::map_keys() helper. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/camera_sensor.cpp13
-rw-r--r--src/libcamera/v4l2_subdevice.cpp12
2 files changed, 16 insertions, 9 deletions
diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
index 6e93cc51..350f49ac 100644
--- a/src/libcamera/camera_sensor.cpp
+++ b/src/libcamera/camera_sensor.cpp
@@ -18,7 +18,6 @@
#include "libcamera/internal/formats.h"
#include "libcamera/internal/utils.h"
-#include "libcamera/internal/v4l2_subdevice.h"
/**
* \file camera_sensor.h
@@ -245,15 +244,15 @@ int CameraSensor::init()
/* Enumerate, sort and cache media bus codes and sizes. */
formats_ = subdev_->formats(pad_);
- if (formats_.isEmpty()) {
+ if (formats_.empty()) {
LOG(CameraSensor, Error) << "No image format found";
return -EINVAL;
}
- mbusCodes_ = formats_.formats();
+ mbusCodes_ = utils::map_keys(formats_);
std::sort(mbusCodes_.begin(), mbusCodes_.end());
- for (const auto &format : formats_.data()) {
+ for (const auto &format : formats_) {
const std::vector<SizeRange> &ranges = format.second;
std::transform(ranges.begin(), ranges.end(), std::back_inserter(sizes_),
[](const SizeRange &range) { return range.max; });
@@ -359,9 +358,11 @@ V4L2SubdeviceFormat CameraSensor::getFormat(const std::vector<unsigned int> &mbu
uint32_t bestCode = 0;
for (unsigned int code : mbusCodes) {
- const std::vector<SizeRange> &ranges = formats_.sizes(code);
+ const auto formats = formats_.find(code);
+ if (formats == formats_.end())
+ continue;
- for (const SizeRange &range : ranges) {
+ for (const SizeRange &range : formats->second) {
const Size &sz = range.max;
if (sz.width < size.width || sz.height < size.height)
diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp
index 32c6c7ac..85d00c24 100644
--- a/src/libcamera/v4l2_subdevice.cpp
+++ b/src/libcamera/v4l2_subdevice.cpp
@@ -218,6 +218,11 @@ uint8_t V4L2SubdeviceFormat::bitsPerPixel() const
*/
/**
+ * \typedef V4L2Subdevice::Formats
+ * \brief A map of supported media bus formats to frame sizes
+ */
+
+/**
* \enum V4L2Subdevice::Whence
* \brief Specify the type of format for getFormat() and setFormat() operations
* \var V4L2Subdevice::ActiveFormat
@@ -340,9 +345,9 @@ int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,
*
* \return A list of the supported device formats
*/
-ImageFormats V4L2Subdevice::formats(unsigned int pad)
+V4L2Subdevice::Formats V4L2Subdevice::formats(unsigned int pad)
{
- ImageFormats formats;
+ Formats formats;
if (pad >= entity_->pads().size()) {
LOG(V4L2, Error) << "Invalid pad: " << pad;
@@ -354,7 +359,8 @@ ImageFormats V4L2Subdevice::formats(unsigned int pad)
if (sizes.empty())
return {};
- if (formats.addFormat(code, sizes)) {
+ const auto inserted = formats.insert({ code, sizes });
+ if (!inserted.second) {
LOG(V4L2, Error)
<< "Could not add sizes for media bus code "
<< code << " on pad " << pad;