update singleo_native_capi.h header file
authorInki Dae <inki.dae@samsung.com>
Fri, 12 Apr 2024 02:20:25 +0000 (11:20 +0900)
committerInki Dae <inki.dae@samsung.com>
Fri, 12 Apr 2024 02:24:16 +0000 (11:24 +0900)
Update singleo_native_capi.h header file by
- correct wrong descriptions
- update singleo_service_add_input_image_data and
  singleo_service_add_input_raw_data API by adding a option string which can
  describe speicific format type to user-given input data.

Signed-off-by: Inki Dae <inki.dae@samsung.com>
capi/singleo_native_capi.h
common/include/SingleoCommonTypes.h
services/common/include/ServiceConfigParser.h
services/common/src/ServiceConfigParser.cpp
services/singleo_native_capi.cpp

index 43224596312a761d33e0940d8355383989d01f73..e740dd1f60ff1492a9868b28b1f83937c8d65ccf 100644 (file)
@@ -28,20 +28,19 @@ typedef void *singleo_service_h;
  * @brief Creates a handle for a given service.
  * @details Use this function to create a new singleo service with given option.
  *          Options include:
- *                - "service:": specifies one service name among below list
+ *                - "service": specifies one service name among below list
  *                              "auto_zoom"
- *                - "input:": specifies one input feeding type among below list
+ *                - "input": specifies one input feeding type among below list
  *                            "camera" : Image data captured by camera device though a given camera backend will be used as input image.
  *                            "screen_capture" : Image data captured by screen capture module through a given screen capture backend will be used as input image.
- *                - "camera_backend:": specifies one backend type among below list. This key is valid only input=camera case.
- *                              "camera-api" : Tizen camera API will be used as a backend.
- *                              "vision-source" : Vision source for Mediavision framework will be used as a backend.
- *                - "fps:": specifies frame per second to capture image from the given input backend. This key is valid only input=camera or input=screen_capture
- *                - "async:": specifies whether service request should be performed in async way or sync one.
+ *                - "camera_id": specifies camera id which indicates what camera device you want to use. This key is valid only input=camera case.
+ *                                To be updated.
+ *                - "fps": specifies frame per second to capture image from the given input backend. This key is valid only input=camera or input=screen_capture
+ *                - "async": specifies whether service request should be performed in async way or sync one.
  *                            "0": service request will be performed in sync way. It means that user can get the result as soon as the request is completed.
  *                            "1": service request will be performed in async way. It mean that user is needed to create a new thread to get the result
  *                                 because it will be returned as soon as the service request is done so user has to wait for the result within its own thread context.
- *                Examples: singleo_service_create("service=auto_zoom, input=camera, camera_backend=camera-api, fbs=30, async=0")
+ *                Examples: singleo_service_create("service=auto_zoom, input=camera, camera_id=0, fbs=30, async=0")
  *
  * @since_tizen 9.0
  *
@@ -119,6 +118,11 @@ int singleo_service_add_input_image_file(singleo_service_h handle, const char *f
  * @remarks With this function, user can add input image data to the the service before invoking the service.
  *
  * @param[in] handle           The handle to the service.
+ * @param[in] option           The option string which speicifies pixel format type to a given image data.
+ *                             The option includes:
+ *                             - "format": one of below lists can be set
+ *                                          "YUV420" : Y(1byte), Cb(1/4 byte), Cr(1/4 byte)
+ *                                          "RGB888" : R(1byte), G(1byte), B(1byte))
  * @param[in] buffer           A buffer pointer pointing to raw image data.
  * @param[in] width            A number of horizontal pixels in the image.
  * @param[in] height           A number of vertical pixels in the image.
@@ -131,8 +135,8 @@ int singleo_service_add_input_image_file(singleo_service_h handle, const char *f
  *
  * @pre Create a source handle by calling singleo_service_create()
  */
-int singleo_service_add_input_rgb_data(singleo_service_h handle, const unsigned char *buffer, unsigned int width,
-                                                                          unsigned int height, unsigned long byte_per_pixel);
+int singleo_service_add_input_image_data(singleo_service_h handle, const char *option, const unsigned char *buffer,
+                                                                                unsigned int width, unsigned int height, unsigned long bytes_per_pixel);
 
 /**
  * @internal
@@ -142,6 +146,9 @@ int singleo_service_add_input_rgb_data(singleo_service_h handle, const unsigned
  * @remarks With this function, user can add input raw data to the the service before invoking the service.
  *
  * @param[in] handle                 The handle to the service.
+ * @param[in] option                 The option string which speicifies data type to a raw data.
+ *                                   The option includes:
+ *                                   - To be updated.
  * @param[in] buffer                 A buffer pointer pointing to raw data.
  * @param[in] buffer_size_in_bytes   Buffer size to a given buffer in bytes.
  *
@@ -152,7 +159,7 @@ int singleo_service_add_input_rgb_data(singleo_service_h handle, const unsigned
  *
  * @pre Create a source handle by calling singleo_service_create()
  */
-int singleo_service_add_input_raw_data(singleo_service_h handle, const unsigned char *buffer,
+int singleo_service_add_input_raw_data(singleo_service_h handle, const char *option, const unsigned char *buffer,
                                                                           unsigned long buffer_size_in_bytes);
 
 /**
index cd572ebad788db96abf767198225499be60cbc34..d048ba4b3be7bd22485cf2fd9596b680ddb80c07 100644 (file)
@@ -32,6 +32,8 @@ using VecRect = std::vector<Rect>;
 
 enum class DataType { NONE, FILE, IMAGE, RAW };
 
+enum class ImagePixelFormat { NONE, YUV420, RGB888 };
+
 struct BaseDataType {
        DataType _data_type { DataType::NONE };
        BaseDataType(DataType data_type) : _data_type(data_type)
@@ -53,6 +55,7 @@ struct ImageDataType : public BaseDataType {
        unsigned int width {};
        unsigned int height {};
        unsigned int byte_per_pixel {};
+       ImagePixelFormat pixel_format { ImagePixelFormat::NONE };
 };
 
 struct RawDataType : public BaseDataType {
index bfb9f9ada25a838e8c2497cb1848cc275219e2d1..de2ecb574cb164aee086cf5bec8688a98442c250 100644 (file)
@@ -32,6 +32,7 @@ private:
        std::map<std::string, std::string> _params;
        ServiceType _service_type { ServiceType::NONE };
        InputFeedType _input_feed_type { InputFeedType::NONE };
+       ImagePixelFormat _image_pixel_format { ImagePixelFormat::NONE };
        unsigned int _fps {};
        bool _async_mode {};
        input::InputConfigBase _default_config;
@@ -41,21 +42,24 @@ private:
        bool isValidPair(const std::string &key, const std::string &value);
        void trim(std::string &str);
        bool isKeyValid(std::map<std::string, bool> &valid_keys, const std::string &key);
+       void parse(std::map<std::string, bool> &valid_keys, std::string option);
        void update();
        void setServiceType(std::string key);
        void setInputFeedType(std::string key);
        void setCameraDeviceId(std::string key);
        void setFps(std::string key);
        void setAsyncMode(std::string key);
+       void setInputFormat(std::string key);
 
 public:
-       explicit ServiceConfigParser() = default;
-       ServiceConfigParser(std::string option);
+       ServiceConfigParser() = default;
        virtual ~ServiceConfigParser() = default;
 
-       void parse(std::string option);
+       void parseService(std::string option);
+       void parseInput(std::string option);
        ServiceType getServiceType();
        InputFeedType getInputFeedType();
+       ImagePixelFormat getImagePixelFormat();
        CameraBackendType getCameraBackendType();
        unsigned int getFps();
        bool getAsyncMode();
index 2f37be8c4a39a26fc43a66027577b17a6286498b..d23bdaadc749e5e340d776d5937be070c8474c66 100644 (file)
@@ -28,10 +28,6 @@ namespace singleo
 {
 namespace services
 {
-ServiceConfigParser::ServiceConfigParser(string option)
-{
-       parse(option);
-}
 
 bool ServiceConfigParser::isValidPair(const string &key, const string &value)
 {
@@ -105,6 +101,20 @@ void ServiceConfigParser::setAsyncMode(std::string key)
        _async_mode = async_mode;
 }
 
+void ServiceConfigParser::setInputFormat(string key)
+{
+       static map<string, ImagePixelFormat> valid_services = {
+               { "YUV420", ImagePixelFormat::YUV420 },
+               { "RGB888", ImagePixelFormat::RGB888 }
+       };
+
+       auto it = valid_services.find(key);
+       if (it == valid_services.end())
+               throw InvalidParameter("Invalid image pixel format.");
+
+       _image_pixel_format = it->second;
+}
+
 ServiceType ServiceConfigParser::getServiceType()
 {
        return _service_type;
@@ -115,6 +125,11 @@ InputFeedType ServiceConfigParser::getInputFeedType()
        return _input_feed_type;
 }
 
+ImagePixelFormat ServiceConfigParser::getImagePixelFormat()
+{
+       return _image_pixel_format;
+}
+
 bool ServiceConfigParser::getAsyncMode()
 {
        return _async_mode;
@@ -126,11 +141,8 @@ void ServiceConfigParser::trim(string &str)
        str.erase(str.find_last_not_of(" \n\r\t") + 1);
 }
 
-void ServiceConfigParser::parse(string option)
+void ServiceConfigParser::parse(map<string, bool> &valid_keys, string option)
 {
-       map<string, bool> valid_keys = {
-               { "SERVICE", false }, { "INPUT_FEED", false }, { "CAMERA_ID", false }, { "FPS", false }, { "ASYNC", false }
-       };
        istringstream iss(option);
        string token;
 
@@ -160,6 +172,24 @@ void ServiceConfigParser::parse(string option)
        update();
 }
 
+void ServiceConfigParser::parseService(string option)
+{
+       map<string, bool> valid_keys = {
+               { "SERVICE", false }, { "INPUT_FEED", false }, { "CAMERA_ID", false }, { "FPS", false }, { "ASYNC", false }
+       };
+
+       parse(valid_keys, option);
+}
+
+void ServiceConfigParser::parseInput(std::string option)
+{
+       map<string, bool> valid_keys = {
+               { "FORMAT", false }
+       };
+
+       parse(valid_keys, option);
+}
+
 void ServiceConfigParser::update()
 {
        using setParamCallback = void (ServiceConfigParser::*)(std::string);
@@ -183,6 +213,7 @@ void ServiceConfigParser::update()
        setParam("CAMERA_ID", &ServiceConfigParser::setCameraDeviceId);
        setParam("FPS", &ServiceConfigParser::setFps);
        setParam("ASYNC", &ServiceConfigParser::setAsyncMode);
+       setParam("FORMAT", &ServiceConfigParser::setInputFormat);
 }
 
 InputConfigBase &ServiceConfigParser::getConfig(InputFeedType input_feed_type)
index 1595d9324bfcf9482f450d41f09fca3c10fff5ae..f6ae56add0723fb1d6d0576069899d026c942d43 100644 (file)
@@ -22,8 +22,9 @@ int singleo_service_create(const char *option, singleo_service_h *handle)
        Context *context = NULL;
 
        try {
-               ServiceConfigParser parser(option);
+               ServiceConfigParser parser;
 
+               parser.parseService(option);
                async_mode = parser.getAsyncMode();
 
                if (ServiceType::AUTO_ZOOM == parser.getServiceType()) {
@@ -82,13 +83,18 @@ int singleo_service_add_input_image_file(singleo_service_h handle, const char *f
        return SINGLEO_ERROR_NONE;
 }
 
-int singleo_service_add_input_rgb_data(singleo_service_h handle, const unsigned char *buffer, unsigned int width,
+int singleo_service_add_input_image_data(singleo_service_h handle, const char *option, const unsigned char *buffer, unsigned int width,
                                                                           unsigned int height, unsigned long byte_per_pixel)
 {
        try {
                auto context = static_cast<Context *>(handle);
+               ServiceConfigParser parser;
+
+               parser.parseInput(option);
+
                ImageDataType input_data;
 
+               input_data.pixel_format = parser.getImagePixelFormat();
                input_data.ptr = const_cast<unsigned char *>(buffer);
                input_data.width = width;
                input_data.height = height;
@@ -101,7 +107,7 @@ int singleo_service_add_input_rgb_data(singleo_service_h handle, const unsigned
        return SINGLEO_ERROR_NONE;
 }
 
-int singleo_service_add_input_raw_data(singleo_service_h handle, const unsigned char *buffer,
+int singleo_service_add_input_raw_data(singleo_service_h handle, const char *option, const unsigned char *buffer,
                                                                           unsigned long buffer_size_in_bytes)
 {
        try {