From: Inki Dae Date: Fri, 12 Apr 2024 02:20:25 +0000 (+0900) Subject: update singleo_native_capi.h header file X-Git-Tag: accepted/tizen/unified/20240903.110722~74^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=93b91b2a5391f715e2e4a6b9cbfcbd94a3d6ada8;p=platform%2Fcore%2Fapi%2Fsingleo.git update singleo_native_capi.h header file 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 --- diff --git a/capi/singleo_native_capi.h b/capi/singleo_native_capi.h index 4322459..e740dd1 100644 --- a/capi/singleo_native_capi.h +++ b/capi/singleo_native_capi.h @@ -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); /** diff --git a/common/include/SingleoCommonTypes.h b/common/include/SingleoCommonTypes.h index cd572eb..d048ba4 100644 --- a/common/include/SingleoCommonTypes.h +++ b/common/include/SingleoCommonTypes.h @@ -32,6 +32,8 @@ using VecRect = std::vector; 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 { diff --git a/services/common/include/ServiceConfigParser.h b/services/common/include/ServiceConfigParser.h index bfb9f9a..de2ecb5 100644 --- a/services/common/include/ServiceConfigParser.h +++ b/services/common/include/ServiceConfigParser.h @@ -32,6 +32,7 @@ private: std::map _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 &valid_keys, const std::string &key); + void parse(std::map &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(); diff --git a/services/common/src/ServiceConfigParser.cpp b/services/common/src/ServiceConfigParser.cpp index 2f37be8..d23bdaa 100644 --- a/services/common/src/ServiceConfigParser.cpp +++ b/services/common/src/ServiceConfigParser.cpp @@ -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 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 &valid_keys, string option) { - map 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 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 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) diff --git a/services/singleo_native_capi.cpp b/services/singleo_native_capi.cpp index 1595d93..f6ae56a 100644 --- a/services/singleo_native_capi.cpp +++ b/services/singleo_native_capi.cpp @@ -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(handle); + ServiceConfigParser parser; + + parser.parseInput(option); + ImageDataType input_data; + input_data.pixel_format = parser.getImagePixelFormat(); input_data.ptr = const_cast(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 {