Message ID | 20210628163237.3194582-3-hiroh@chromium.org |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi Hiro, Thank you for the patch. On Tue, Jun 29, 2021 at 01:32:37AM +0900, Hirokazu Honda wrote: > Provides a function to set the camera sensor a test pattern mode. > > Signed-off-by: Hirokazu Honda <hiroh@chromium.org> > --- > include/libcamera/internal/camera_sensor.h | 2 ++ > src/libcamera/camera_sensor.cpp | 35 ++++++++++++++++++++-- > 2 files changed, 35 insertions(+), 2 deletions(-) > > diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h > index db12b07e..4ecce6c9 100644 > --- a/include/libcamera/internal/camera_sensor.h > +++ b/include/libcamera/internal/camera_sensor.h > @@ -44,6 +44,7 @@ public: > { > return testPatternModes_; > } > + int setTestPatternMode(int32_t testPatternMode); > > V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes, > const Size &size) const; > @@ -85,6 +86,7 @@ private: > std::vector<unsigned int> mbusCodes_; > std::vector<Size> sizes_; > std::vector<int32_t> testPatternModes_; > + int32_t testPatternMode_; > > Size pixelArraySize_; > Rectangle activeArea_; > diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp > index ee53adf3..be2d32e3 100644 > --- a/src/libcamera/camera_sensor.cpp > +++ b/src/libcamera/camera_sensor.cpp > @@ -54,8 +54,8 @@ LOG_DEFINE_CATEGORY(CameraSensor) > * Once constructed the instance must be initialized with init(). > */ > CameraSensor::CameraSensor(const MediaEntity *entity) > - : entity_(entity), pad_(UINT_MAX), bayerFormat_(nullptr), > - properties_(properties::properties) > + : entity_(entity), pad_(UINT_MAX), testPatternMode_(-1), > + bayerFormat_(nullptr), properties_(properties::properties) > { > } > > @@ -515,6 +515,37 @@ Size CameraSensor::resolution() const > * \return The list of test pattern modes > */ > > +/** > + * \brief Set the camera sensor a specified controls::TestPatternMode > + * \param[in] testPatternMode test pattern mode control value to set the camera > + * sensor > + * > + * \return 0 on success or a negative error code otherwise > + */ > +int CameraSensor::setTestPatternMode(int32_t testPatternMode) > +{ > + if (testPatternMode_ == testPatternMode) > + return 0; > + > + const CameraSensorProperties *props = CameraSensorProperties::get(model_); > + if (!props) > + return -EINVAL; I think I've commented on that in the previous version, could we cache the CameraSensorProperties pointer in CameraSensor at init time instead of looking it up every time ? > + > + auto it = props->testPatternModes.find(testPatternMode); > + ASSERT(it != props->testPatternModes.end()); If an application set the test pattern control to an invalid value, we shouldn't crash but return an error. Is that handled in a layer above ? > + > + ControlList ctrls{ controls() }; > + ctrls.set(V4L2_CID_TEST_PATTERN, it->second); > + > + int ret = setControls(&ctrls); > + if (ret) > + return ret; > + > + testPatternMode_ = testPatternMode; > + > + return 0; > +} > + > /** > * \brief Retrieve the best sensor format for a desired output > * \param[in] mbusCodes The list of acceptable media bus codes
diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index db12b07e..4ecce6c9 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -44,6 +44,7 @@ public: { return testPatternModes_; } + int setTestPatternMode(int32_t testPatternMode); V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes, const Size &size) const; @@ -85,6 +86,7 @@ private: std::vector<unsigned int> mbusCodes_; std::vector<Size> sizes_; std::vector<int32_t> testPatternModes_; + int32_t testPatternMode_; Size pixelArraySize_; Rectangle activeArea_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index ee53adf3..be2d32e3 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -54,8 +54,8 @@ LOG_DEFINE_CATEGORY(CameraSensor) * Once constructed the instance must be initialized with init(). */ CameraSensor::CameraSensor(const MediaEntity *entity) - : entity_(entity), pad_(UINT_MAX), bayerFormat_(nullptr), - properties_(properties::properties) + : entity_(entity), pad_(UINT_MAX), testPatternMode_(-1), + bayerFormat_(nullptr), properties_(properties::properties) { } @@ -515,6 +515,37 @@ Size CameraSensor::resolution() const * \return The list of test pattern modes */ +/** + * \brief Set the camera sensor a specified controls::TestPatternMode + * \param[in] testPatternMode test pattern mode control value to set the camera + * sensor + * + * \return 0 on success or a negative error code otherwise + */ +int CameraSensor::setTestPatternMode(int32_t testPatternMode) +{ + if (testPatternMode_ == testPatternMode) + return 0; + + const CameraSensorProperties *props = CameraSensorProperties::get(model_); + if (!props) + return -EINVAL; + + auto it = props->testPatternModes.find(testPatternMode); + ASSERT(it != props->testPatternModes.end()); + + ControlList ctrls{ controls() }; + ctrls.set(V4L2_CID_TEST_PATTERN, it->second); + + int ret = setControls(&ctrls); + if (ret) + return ret; + + testPatternMode_ = testPatternMode; + + return 0; +} + /** * \brief Retrieve the best sensor format for a desired output * \param[in] mbusCodes The list of acceptable media bus codes
Provides a function to set the camera sensor a test pattern mode. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> --- include/libcamera/internal/camera_sensor.h | 2 ++ src/libcamera/camera_sensor.cpp | 35 ++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-)