input/camera_api: list up valid fps and use it 21/314221/4
authorInki Dae <inki.dae@samsung.com>
Tue, 9 Jul 2024 03:36:07 +0000 (12:36 +0900)
committerInki Dae <inki.dae@samsung.com>
Tue, 9 Jul 2024 09:06:07 +0000 (18:06 +0900)
List up valid fps through Camara API and use user-given config value
instead of fixed one.

Change-Id: Ied13ed85ad8482fb0e8c3927fd1c68fdee90e928
Signed-off-by: Inki Dae <inki.dae@samsung.com>
input/backends/camera_api/include/CameraApiBackend.h
input/backends/camera_api/src/CameraApiBackend.cpp
services/common/include/ServiceConfigParser.h
services/common/src/ServiceConfigParser.cpp

index 2306e96d46ed7cbefc2383b1ad8b3fcf6a2950bf..4c30632816315486f16b343a08e8466334ee25d4 100644 (file)
@@ -48,6 +48,7 @@ private:
        std::vector<camera_pixel_format_e> _validCapturePixelFormat;
        std::vector<cv::Size> _validPreviewResolution;
        std::vector<cv::Size> _validCaptureResolution;
+       std::vector<camera_attr_fps_e> _validFps;
        std::unordered_set<unsigned int> _camera_ids;
        camera_device_e _active_camera_id {};
        static bool _registered;
@@ -68,6 +69,12 @@ private:
                { CAMERA_PIXEL_FORMAT_H264, "H264" },     { CAMERA_PIXEL_FORMAT_INVZ, "INVZ" }
        };
 
+       std::map<unsigned int, camera_attr_fps_e> _fpsTypeTable = {
+               { 7, CAMERA_ATTR_FPS_7 },       { 8, CAMERA_ATTR_FPS_8 },        { 15, CAMERA_ATTR_FPS_15 }, { 20, CAMERA_ATTR_FPS_20 },
+               { 24, CAMERA_ATTR_FPS_24 }, { 25, CAMERA_ATTR_FPS_25 },  { 30, CAMERA_ATTR_FPS_30 }, { 60, CAMERA_ATTR_FPS_60 },
+               { 90, CAMERA_ATTR_FPS_90 }, { 120, CAMERA_ATTR_FPS_120 }
+       };
+
        void updateAvailableCameraDevices();
        void setActiveCameraDevice(unsigned int id);
        void threadLoop();
@@ -79,6 +86,7 @@ private:
        static bool previewResolutionCb(int width, int height, void *user_data);
        static bool captureResolutionCb(int width, int height, void *user_data);
        static void captureCompletedCb(void *user_data);
+       static bool previewFpsCb(camera_attr_fps_e fps, void *user_data);
        static bool compareSizesDescending(const cv::Size &a, const cv::Size &b);
 
 public:
index 7aaa1f3e0cee11cb51dba20093e5ff7ec0f5b8ef..6c4f44e62c088a13bc999d4ee867e1ae9b638a8e 100644 (file)
@@ -164,6 +164,17 @@ bool CameraApiBackend::captureResolutionCb(int width, int height, void *user_dat
        return true;
 }
 
+bool CameraApiBackend::previewFpsCb(camera_attr_fps_e fps, void *user_data)
+{
+       auto context = static_cast<CameraApiBackend *>(user_data);
+
+       SINGLEO_LOGD("supported fps: %d", fps);
+
+       context->_validFps.push_back(fps);
+
+       return true;
+}
+
 void CameraApiBackend::configure(const CameraConfig &config)
 {
        setActiveCameraDevice(config.device_id);
@@ -238,6 +249,43 @@ void CameraApiBackend::configure(const CameraConfig &config)
                SINGLEO_LOGE("CameraApiBackend: camera_set_capture_format failed. ret: %d", ret);
                throw InvalidOperation("CameraApiBackend: camera_set_capture_format failed.");
        }
+
+       ret = camera_attr_foreach_supported_fps(_camera, previewFpsCb, this);
+       if (ret != CAMERA_ERROR_NONE) {
+               SINGLEO_LOGE("CameraApiBackend: camera_attr_foreach_supported_fps failed. ret: %d", ret);
+               throw InvalidOperation("CameraApiBackend: camera_attr_foreach_supported_fps failed.");
+       }
+
+       camera_attr_fps_e givenFps = CAMERA_ATTR_FPS_AUTO;
+
+       try {
+               givenFps = _fpsTypeTable.at(config.fps);
+       } catch (const std::out_of_range &e) {
+               SINGLEO_LOGE("CameraApiBackend: a given fps(%d) is out_of_range.", config.fps);
+               throw InvalidOperation("CameraApiBackend: a given fps is out_of_range.");
+       }
+
+       auto fps_it = find(_validFps.begin(), _validFps.end(), givenFps);
+       if (fps_it == _validFps.end()) {
+               SINGLEO_LOGE("CameraApiBackend: fps(%d) is not supported.", config.fps);
+               throw InvalidOperation("CameraApiBackend: fps is not supported.");
+       }
+
+       ret = camera_attr_set_preview_fps(_camera, givenFps);
+       if (ret != CAMERA_ERROR_NONE) {
+               SINGLEO_LOGE("CameraApiBackend: camera_attr_set_preview_fps failed. ret: %d", ret);
+               throw InvalidOperation("CameraApiBackend: camera_attr_set_preview_fps failed.");
+       }
+
+       camera_attr_fps_e previewFps;
+
+       ret = camera_attr_get_preview_fps(_camera, &previewFps);
+       if (ret != CAMERA_ERROR_NONE) {
+               SINGLEO_LOGE("CameraApiBackend: camera_attr_get_preview_fps failed. ret: %d", ret);
+               throw InvalidOperation("CameraApiBackend: camera_attr_get_preview_fps failed.");
+       }
+
+       SINGLEO_LOGD("CameraApiBackend: previewFps: %d", previewFps);
 }
 
 void CameraApiBackend::captureCb(camera_image_data_s *image, camera_image_data_s *postview,
index 83d2cc10bd3a117d26e162aa8cf3084c8a0a0e6d..7d65323fc075cdf4afe8e4297827b965f1f6b1d5 100644 (file)
@@ -33,7 +33,6 @@ private:
        std::string _service_name;
        InputFeedType _input_feed_type { InputFeedType::NONE };
        ImagePixelFormat _image_pixel_format { ImagePixelFormat::NONE };
-       unsigned int _fps {};
        bool _async_mode {};
        input::InputConfigBase _default_config;
        input::CameraConfig _camera_config;
index 6119ef5e311b16c9ea4b15edf8e504b96c56db1b..3eacacf0e8d6bff57429fcafc46298170e7b31b7 100644 (file)
@@ -82,7 +82,7 @@ void ServiceConfigParser::setFps(const std::string &key)
        if (fps < 1 || fps > 60)
                throw InvalidParameter("Invalid fps.");
 
-       _fps = fps;
+       _camera_config.fps = fps;
 }
 
 void ServiceConfigParser::setAsyncMode(const std::string &key)