diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 90 |
1 files changed, 71 insertions, 19 deletions
diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index 7470b562..3a2a64cf 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -6,10 +6,12 @@ */ #include <algorithm> +#include <bitset> #include <cmath> #include <fstream> #include <map> #include <memory> +#include <optional> #include <set> #include <string> #include <vector> @@ -56,6 +58,9 @@ public: Stream stream_; std::map<PixelFormat, std::vector<SizeRange>> formats_; + std::optional<v4l2_exposure_auto_type> autoExposureMode_; + std::optional<v4l2_exposure_auto_type> manualExposureMode_; + private: bool generateId(); @@ -106,6 +111,26 @@ private: } }; +namespace { + +std::optional<controls::ExposureTimeModeEnum> v4l2ToExposureMode(int32_t x) +{ + using namespace controls; + + switch (x) { + case V4L2_EXPOSURE_AUTO: + case V4L2_EXPOSURE_APERTURE_PRIORITY: + return ExposureTimeModeAuto; + case V4L2_EXPOSURE_MANUAL: + case V4L2_EXPOSURE_SHUTTER_PRIORITY: + return ExposureTimeModeManual; + default: + return {}; + } +} + +} /* namespace */ + UVCCameraConfiguration::UVCCameraConfiguration(UVCCameraData *data) : CameraConfiguration(), data_(data) { @@ -723,25 +748,52 @@ void UVCCameraData::addControl(uint32_t cid, const ControlInfo &v4l2Info, * ExposureTimeModeManual = { V4L2_EXPOSURE_MANUAL, * V4L2_EXPOSURE_SHUTTER_PRIORITY } */ - std::array<int32_t, 2> values{}; - - auto it = std::find_if(v4l2Values.begin(), v4l2Values.end(), - [&](const ControlValue &val) { - return (val.get<int32_t>() == V4L2_EXPOSURE_APERTURE_PRIORITY || - val.get<int32_t>() == V4L2_EXPOSURE_AUTO) ? true : false; - }); - if (it != v4l2Values.end()) - values.back() = static_cast<int32_t>(controls::ExposureTimeModeAuto); - - it = std::find_if(v4l2Values.begin(), v4l2Values.end(), - [&](const ControlValue &val) { - return (val.get<int32_t>() == V4L2_EXPOSURE_SHUTTER_PRIORITY || - val.get<int32_t>() == V4L2_EXPOSURE_MANUAL) ? true : false; - }); - if (it != v4l2Values.end()) - values.back() = static_cast<int32_t>(controls::ExposureTimeModeManual); - - info = ControlInfo{Span<int32_t>{values}, values[0]}; + + std::bitset< + std::max(V4L2_EXPOSURE_AUTO, + std::max(V4L2_EXPOSURE_APERTURE_PRIORITY, + std::max(V4L2_EXPOSURE_MANUAL, + V4L2_EXPOSURE_SHUTTER_PRIORITY))) + 1 + > exposureModes; + std::optional<controls::ExposureTimeModeEnum> lcDef; + + for (const ControlValue &value : v4l2Values) { + const auto x = value.get<int32_t>(); + + if (0 <= x && static_cast<std::size_t>(x) < exposureModes.size()) { + exposureModes[x] = true; + + if (x == def) + lcDef = v4l2ToExposureMode(x); + } + } + + if (exposureModes[V4L2_EXPOSURE_AUTO]) + autoExposureMode_ = V4L2_EXPOSURE_AUTO; + else if (exposureModes[V4L2_EXPOSURE_APERTURE_PRIORITY]) + autoExposureMode_ = V4L2_EXPOSURE_APERTURE_PRIORITY; + + if (exposureModes[V4L2_EXPOSURE_SHUTTER_PRIORITY]) + manualExposureMode_ = V4L2_EXPOSURE_SHUTTER_PRIORITY; + else if (exposureModes[V4L2_EXPOSURE_MANUAL]) + manualExposureMode_ = V4L2_EXPOSURE_MANUAL; + + std::array<ControlValue, 2> values; + std::size_t count = 0; + + if (autoExposureMode_) + values[count++] = controls::ExposureTimeModeAuto; + + if (manualExposureMode_) + values[count++] = controls::ExposureTimeModeManual; + + if (count == 0) + return; + + info = ControlInfo{ + Span<const ControlValue>{ values.data(), count }, + !lcDef ? values.front() : *lcDef, + }; break; } case V4L2_CID_EXPOSURE_ABSOLUTE: |