add singleo_service_add_input API series support
authorInki Dae <inki.dae@samsung.com>
Mon, 25 Mar 2024 07:13:16 +0000 (16:13 +0900)
committerInki Dae <inki.dae@samsung.com>
Tue, 26 Mar 2024 03:54:23 +0000 (12:54 +0900)
Add singleo_service_add_input_{image_file,rgb_data,raw_data} API support.

Singleo service API has to allow one more input data so add this API series
to add various types of data as input data. In addition, this patch
drops ISingleoCommon, SingleoImageData and SingleoRawData classes and,
introduces a new input manager, SingleoInputManager class which manages
input data queue.

Signed-off-by: Inki Dae <inki.dae@samsung.com>
43 files changed:
capi/singleo_native_capi.h
common/include/ISingleoCommonData.h [deleted file]
common/include/SingleoCommonTypes.h
common/include/SingleoImageData.h [deleted file]
common/include/SingleoInputManager.h [new file with mode: 0644]
common/include/SingleoRawData.h [deleted file]
common/src/SingleoImageData.cpp [deleted file]
common/src/SingleoInputManager.cpp [new file with mode: 0644]
common/src/SingleoRawData.cpp [deleted file]
inference/backends/mediavision/include/MvFaceDetection.h
inference/backends/mediavision/include/MvObjectDetection.h
inference/backends/mediavision/src/MvFaceDetection.cpp
inference/backends/mediavision/src/MvObjectDetection.cpp
inference/include/IInferenceServiceInterface.h
inference/include/IInferenceTaskInterface.h
inference/include/InferenceServiceDefault.h
inference/include/InferenceServiceExternal.h
inference/src/InferenceServiceDefault.cpp
inference/src/InferenceServiceExternal.cpp
input/backends/include/ICameraBackend.h
input/backends/opencv/include/OpencvBackend.h
input/backends/opencv/src/OpencvBackend.cpp
input/include/CameraServiceDefault.h
input/include/CameraServiceExternal.h
input/include/ICameraService.h
input/include/IInputService.h
input/include/InputCamera.h
input/include/InputTypes.h
input/src/CameraServiceDefault.cpp
input/src/CameraServiceExternal.cpp
input/src/InputCamera.cpp
services/auto_zoom/include/AutoZoom.h
services/auto_zoom/src/AutoZoom.cpp
services/common/include/IPreprocessor.h
services/common/include/IService.h
services/common/include/ImagePreprocessor.h
services/common/include/ServiceConfigParser.h
services/common/src/ImagePreprocessor.cpp
services/singleo_native_capi.cpp
test/CMakeLists.txt
test/services/test_autozoom.cpp
visualizer/include/singleo_util_visualizer_2d.h
visualizer/src/singleo_util_visualizer_2d.cpp

index 8c93cd4c83e6df305a981ffa31310efa8845c067..c553de46f5b40094fd09e40b3cd7d6f16b04ad5e 100644 (file)
@@ -94,10 +94,10 @@ int singleo_service_perform(singleo_service_h handle);
 
 /**
  * @internal
- * @brief Performs the service with a given file name.
+ * @brief Adds a given image file name to the service as a input
  *
  * @since_tizen 9.0
- * @remarks With this function, the service will be performed with input source given by user as a file name.
+ * @remarks With this function, user can add input image file to the the service before invoking the service.
  *
  * @param[in] handle     The handle to the service.
  * @param[in] file_name  A file name to be used as input data. It can become one of image files supported by OpenCV.
@@ -109,14 +109,14 @@ int singleo_service_perform(singleo_service_h handle);
  *
  * @pre Create a source handle by calling singleo_service_create()
  */
-int singleo_service_perform_with_file(singleo_service_h handle, const char *file_name);
+int singleo_service_add_input_image_file(singleo_service_h handle, const char *file_name);
 
 /**
  * @internal
- * @brief Performs the service with image data information.
+ * @brief Adds a given image data to the service as a input
  *
  * @since_tizen 9.0
- * @remarks With this function, the service will be performed with raw image data information given by user.
+ * @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] buffer           A buffer pointer pointing to raw image data.
@@ -131,15 +131,15 @@ int singleo_service_perform_with_file(singleo_service_h handle, const char *file
  *
  * @pre Create a source handle by calling singleo_service_create()
  */
-int singleo_service_perform_with_image_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 unsigned char *buffer, unsigned int width,
+                                                                                unsigned int height, unsigned long byte_per_pixel);
 
 /**
  * @internal
- * @brief Performs the service with raw data information.
+ * @brief Adds a given raw data to the service as a input
  *
  * @since_tizen 9.0
- * @remarks With this function, the service will be performed with raw data information given by user.
+ * @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] buffer                 A buffer pointer pointing to raw data.
@@ -152,8 +152,8 @@ int singleo_service_perform_with_image_data(singleo_service_h handle, const unsi
  *
  * @pre Create a source handle by calling singleo_service_create()
  */
-int singleo_service_perform_with_raw_data(singleo_service_h handle, const unsigned char *buffer,
-                                                                                 unsigned long buffer_size_in_bytes);
+int singleo_service_add_input_raw_data(singleo_service_h handle, const unsigned char *buffer,
+                                                                          unsigned long buffer_size_in_bytes);
 
 /**
  * @internal
diff --git a/common/include/ISingleoCommonData.h b/common/include/ISingleoCommonData.h
deleted file mode 100644 (file)
index c3ccf30..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __ISINGLEO_COMMON_DATA_H__
-#define __ISINGLEO_COMMON_DATA_H__
-
-#include "SingleoCommonTypes.h"
-
-namespace singleo
-{
-class ISingleoCommonData
-{
-public:
-       virtual ~ISingleoCommonData() {};
-
-       virtual void setData(BaseDataType &input_data) = 0;
-       virtual BaseDataType &getData() = 0;
-};
-
-} // singleo
-
-#endif
\ No newline at end of file
index 24835c4a66e1a88edb51a8c0546b4518431ec209..a125c986af42482d30a193a40923297a07081e3f 100644 (file)
@@ -18,9 +18,6 @@
 #define __SINGLEO_COMMON_TYPES_H__
 
 #include <vector>
-#include <string>
-#include <memory>
-#include <map>
 
 namespace singleo
 {
diff --git a/common/include/SingleoImageData.h b/common/include/SingleoImageData.h
deleted file mode 100644 (file)
index 6465a3e..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __SINGLEO_IMAGE_DATA_H__
-#define __SINGLEO_IMAGE_DATA_H__
-
-#include "ISingleoCommonData.h"
-
-namespace singleo
-{
-class SingleoImageData : public ISingleoCommonData
-{
-private:
-       ImageDataType _data;
-
-public:
-       SingleoImageData() = default;
-       virtual ~SingleoImageData() = default;
-
-       void setData(BaseDataType &input_data) override;
-       BaseDataType &getData() override;
-};
-
-} // singleo
-
-#endif
diff --git a/common/include/SingleoInputManager.h b/common/include/SingleoInputManager.h
new file mode 100644 (file)
index 0000000..663dd49
--- /dev/null
@@ -0,0 +1,45 @@
+/**
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __SINGLEO_INPUT_MANAGER_H__
+#define __SINGLEO_INPUT_MANAGER_H__
+
+#include <queue>
+#include <mutex>
+#include <memory>
+
+#include "SingleoCommonTypes.h"
+
+namespace singleo
+{
+class SingleoInputManager
+{
+private:
+       std::queue<std::shared_ptr<BaseDataType> > _queue;
+       std::mutex _queue_mutex;
+
+public:
+       SingleoInputManager() = default;
+       virtual ~SingleoInputManager() = default;
+
+       void enqueue(std::shared_ptr<BaseDataType> input_data);
+       std::shared_ptr<BaseDataType> dequeue();
+       unsigned int size();
+};
+
+} // singleo
+
+#endif
diff --git a/common/include/SingleoRawData.h b/common/include/SingleoRawData.h
deleted file mode 100644 (file)
index 4d6deb3..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __SINGLEO_RAW_DATA_H__
-#define __SINGLEO_RAW_DATA_H__
-
-#include "ISingleoCommonData.h"
-
-namespace singleo
-{
-class SingleoRawData : public ISingleoCommonData
-{
-private:
-       RawDataType _data {};
-
-public:
-       SingleoRawData() = default;
-       virtual ~SingleoRawData() = default;
-
-       void setData(BaseDataType &input_data) override;
-       BaseDataType &getData() override;
-};
-
-} // singleo
-
-#endif
diff --git a/common/src/SingleoImageData.cpp b/common/src/SingleoImageData.cpp
deleted file mode 100644 (file)
index f883ed8..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "SingleoImageData.h"
-
-using namespace std;
-
-namespace singleo
-{
-void SingleoImageData::setData(BaseDataType &input_data)
-{
-       auto image_data = dynamic_cast<ImageDataType &>(input_data);
-       _data = image_data;
-}
-
-BaseDataType &SingleoImageData::getData()
-{
-       return _data;
-}
-
-}
diff --git a/common/src/SingleoInputManager.cpp b/common/src/SingleoInputManager.cpp
new file mode 100644 (file)
index 0000000..2bf4cab
--- /dev/null
@@ -0,0 +1,44 @@
+/**
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "SingleoInputManager.h"
+
+using namespace std;
+
+namespace singleo
+{
+void SingleoInputManager::enqueue(shared_ptr<BaseDataType> input_data)
+{
+       std::lock_guard<std::mutex> lock(_queue_mutex);
+       _queue.push(input_data);
+}
+
+shared_ptr<BaseDataType> SingleoInputManager::dequeue()
+{
+       std::lock_guard<std::mutex> lock(_queue_mutex);
+       shared_ptr<BaseDataType> data = _queue.front();
+
+       _queue.pop();
+
+       return data;
+}
+
+unsigned int SingleoInputManager::size()
+{
+       return _queue.size();
+}
+
+}
diff --git a/common/src/SingleoRawData.cpp b/common/src/SingleoRawData.cpp
deleted file mode 100644 (file)
index 7711e48..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "SingleoRawData.h"
-
-using namespace std;
-
-namespace singleo
-{
-void SingleoRawData::setData(BaseDataType &input_data)
-{
-       auto raw_data = dynamic_cast<RawDataType &>(input_data);
-       _data = raw_data;
-}
-
-BaseDataType &SingleoRawData::getData()
-{
-       return _data;
-}
-
-}
index 7bc9bd259ce7b3e079a1c14867c5939c00e9f5fb..21375629539279ed9a8b5312480a243dc0d81e67 100644 (file)
@@ -39,7 +39,7 @@ public:
 
        void configure() override;
        void prepare() override;
-       void invoke(ISingleoCommonData &input, bool async) override;
+       void invoke(BaseDataType &input, bool async) override;
        const SingleoOutputData &result() override;
 };
 
index 9e9b35fb1c2ad71e2c14114c85b86e00769140db..33d754829e272a7ef8a8912b8c12a5f1d7b69b5e 100644 (file)
@@ -39,7 +39,7 @@ public:
 
        void configure() override;
        void prepare() override;
-       void invoke(ISingleoCommonData &input, bool async) override;
+       void invoke(BaseDataType &input, bool async) override;
        const SingleoOutputData &result() override;
 };
 
index 9a55efeda66b0d29a2df5f366cc8eb523a69dee5..362921f9a34a46b426007d3fe6fd2ba1d52ebffc 100644 (file)
@@ -15,7 +15,7 @@
  */
 
 #include <stdexcept>
-#include "SingleoImageData.h"
+#include "SingleoInputManager.h"
 #include "MvFaceDetection.h"
 #include "SingleoLog.h"
 
@@ -53,9 +53,9 @@ void MvFaceDetection::prepare()
                throw runtime_error("Fail to prepare face detection.");
 }
 
-void MvFaceDetection::invoke(ISingleoCommonData &input, bool async)
+void MvFaceDetection::invoke(BaseDataType &input, bool async)
 {
-       ImageDataType &data = dynamic_cast<ImageDataType &>(input.getData());
+       ImageDataType &data = dynamic_cast<ImageDataType &>(input);
 
        if (data._data_type != DataType::IMAGE) {
                SINGLEO_LOGE("Invalid input type.");
index 44af54e6b71f67becde603575cce7aecfab16b02..cf40df9e955eba29ef7a0c14cb4130f792338cf9 100644 (file)
@@ -15,7 +15,7 @@
  */
 
 #include <stdexcept>
-#include "SingleoImageData.h"
+#include "SingleoInputManager.h"
 #include "MvObjectDetection.h"
 #include "SingleoLog.h"
 
@@ -53,9 +53,9 @@ void MvObjectDetection::prepare()
                throw runtime_error("Fail to prepare object detection.");
 }
 
-void MvObjectDetection::invoke(ISingleoCommonData &input, bool async)
+void MvObjectDetection::invoke(BaseDataType &input, bool async)
 {
-       ImageDataType &data = dynamic_cast<ImageDataType &>(input.getData());
+       ImageDataType &data = dynamic_cast<ImageDataType &>(input);
 
        if (data._data_type != DataType::IMAGE) {
                SINGLEO_LOGE("Invalid input type.");
index a093d4335cb1d49b2069a64fd3446947eaf57c23..ba9442ddcb645c4cce37db224ff5be1ff258ba84 100644 (file)
@@ -17,7 +17,6 @@
 #ifndef __IINFERENCE_SERVICE_INTERFACE_H__
 #define __IINFERENCE_SERVICE_INTERFACE_H__
 
-#include "ISingleoCommonData.h"
 #include "IInferenceTaskInterface.h"
 
 namespace singleo
@@ -31,7 +30,7 @@ public:
 
        virtual void configure() = 0;
        virtual void prepare() = 0;
-       virtual void invoke(ISingleoCommonData &input, bool async = false) = 0;
+       virtual void invoke(BaseDataType &input, bool async = false) = 0;
        virtual const SingleoOutputData &result() = 0;
 };
 
index 651dd2c46d23e0ef9a2a4267d1f6bf83e88e2a8d..7d21f506622ddd835b9a08d1cfd63049598471ec 100644 (file)
@@ -17,7 +17,6 @@
 #ifndef __IINFERENCE_TASK_INTERFACE_H__
 #define __IINFERENCE_TASK_INTERFACE_H__
 
-#include "ISingleoCommonData.h"
 #include "SingleoOutputData.h"
 
 namespace singleo
@@ -31,7 +30,7 @@ public:
 
        virtual void configure() = 0;
        virtual void prepare() = 0;
-       virtual void invoke(ISingleoCommonData &input, bool async = false) = 0;
+       virtual void invoke(BaseDataType &input, bool async = false) = 0;
        virtual const SingleoOutputData &result() = 0;
 };
 
index c229aed88fc4629b30dfba8fba78cb628381aa07..92faa7c337404035a56c0250a3bdfc1fba7bc980 100644 (file)
@@ -37,7 +37,7 @@ public:
 
        void configure() override;
        void prepare() override;
-       void invoke(ISingleoCommonData &input, bool async = false) override;
+       void invoke(BaseDataType &input, bool async = false) override;
        const SingleoOutputData &result() override;
 };
 
index 4fa101280d5c24c5310db50f71fc3242f45ec6cb..57140c8be3ccf3f620b2b13552b2dda6bb7d3036 100644 (file)
@@ -33,7 +33,7 @@ public:
 
        void configure() override;
        void prepare() override;
-       void invoke(ISingleoCommonData &input, bool async = false) override;
+       void invoke(BaseDataType &input, bool async = false) override;
        const SingleoOutputData &result() override;
 };
 
index 02ba4f40f31987cc8ae99f424132f066b31fb6d3..aaef257fc07faa429dd6c804d3d6edbd9459ec5e 100644 (file)
@@ -54,7 +54,7 @@ void InferenceServiceDefault::prepare()
        _task->prepare();
 }
 
-void InferenceServiceDefault::invoke(ISingleoCommonData &input, bool async)
+void InferenceServiceDefault::invoke(BaseDataType &input, bool async)
 {
        _task->invoke(input, async);
 }
index 0a9089aa2753d6442a2e76e2f7b7e78ed8ce07bc..a23860d85daa08959e0e5636e4dc5bdba1129862 100644 (file)
@@ -38,7 +38,7 @@ void InferenceServiceExternal::prepare()
        throw runtime_error("Not support yet.");
 }
 
-void InferenceServiceExternal::invoke(ISingleoCommonData &input, bool async)
+void InferenceServiceExternal::invoke(BaseDataType &input, bool async)
 {
        throw runtime_error("Not support yet.");
 }
index 4ebefa9751e8d252ae20f9d9390cb1b4ef1faa57..445d8d9d4b684c538b5c2ee4b191fb647a32e676 100644 (file)
@@ -18,7 +18,7 @@
 #define __ICAMERA_BACKEND_H__
 
 #include <functional>
-#include "SingleoImageData.h"
+#include "SingleoInputManager.h"
 
 namespace singleo
 {
@@ -29,10 +29,9 @@ class ICameraBackend
 public:
        virtual ~ICameraBackend() {};
 
-       virtual void setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
-                                                  void *user_data) = 0;
+       virtual void setUserCb(const std::function<void(BaseDataType &data, void *user_data)> &userCb, void *user_data) = 0;
        virtual void configure() = 0;
-       virtual void capture(SingleoImageData &out_data) = 0;
+       virtual void capture(BaseDataType &out_data) = 0;
        virtual void streamOn() = 0;
        virtual void streamOff() = 0;
 };
index 10d8520bb6e494c484c2ae2cf46070e5504849f9..2771c5611a02c6d8306a6958b62a6b17c62ac153 100644 (file)
@@ -23,7 +23,7 @@
 #include <opencv2/opencv.hpp>
 
 #include "ICameraBackend.h"
-#include "SingleoImageData.h"
+#include "SingleoInputManager.h"
 #include "InputTypes.h"
 
 namespace singleo
@@ -52,7 +52,7 @@ public:
 
        void setUserCb(const InputServiceCallbackType &userCb, void *user_data) override;
        void configure() override;
-       void capture(SingleoImageData &out_data) override;
+       void capture(BaseDataType &out_data) override;
        void streamOn() override;
        void streamOff() override;
 };
index bdc4687c518945c41fcf1dc30fa5414fef15a637..2b9e4c2a807507ad2712243b86d95780575e2846 100644 (file)
@@ -52,8 +52,7 @@ void OpencvBackend::updateAvailableCameraDevices()
        }
 }
 
-void OpencvBackend::setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
-                                                         void *user_data)
+void OpencvBackend::setUserCb(const std::function<void(BaseDataType &data, void *user_data)> &userCb, void *user_data)
 {
        _userCb = userCb;
        _userData = user_data;
@@ -80,8 +79,11 @@ void OpencvBackend::configure()
        }
 }
 
-void OpencvBackend::capture(SingleoImageData &out_data)
+void OpencvBackend::capture(BaseDataType &out_data)
 {
+       if (out_data._data_type != DataType::IMAGE)
+               throw InvalidParameter("Invalid data type.");
+
        *_video_capture >> _captured_image;
        if (_captured_image.empty()) {
                SINGLEO_LOGE("Captured frame is empty.");
@@ -94,21 +96,19 @@ void OpencvBackend::capture(SingleoImageData &out_data)
                throw InvalidOperation("Invalid image format.");
        }
 
-       ImageDataType image_data;
+       ImageDataType &image_data = dynamic_cast<ImageDataType &>(out_data);
 
        image_data.width = _captured_image.cols;
        image_data.height = _captured_image.rows;
        image_data.byte_per_pixel = _captured_image.channels();
        image_data.ptr = _captured_image.data;
-
-       out_data.setData(image_data);
 }
 
 void OpencvBackend::threadLoop()
 {
        SINGLEO_LOGD("OpencvBackend: stream off.");
 
-       SingleoImageData data;
+       ImageDataType data;
 
        while (!_exit_thread) {
                capture(data);
index c120ec2d41bb966c988e9a7c081ca9e3ce3251e1..80b826fa27d1247c0a044b3c65acdfe1981dea66 100644 (file)
@@ -37,7 +37,7 @@ public:
 
        void setUserCb(const InputServiceCallbackType &userCb, void *user_data) override;
        void configure() override;
-       void capture(ISingleoCommonData &data) override;
+       void capture(BaseDataType &data) override;
        void streamOn() override;
        void streamOff() override;
 };
index dca12e905693c31fe69b5b7832097cbca38745de..e0e0a82ebcf008ff047e307cb99f15709b673d3d 100644 (file)
@@ -33,7 +33,7 @@ public:
 
        void setUserCb(const InputServiceCallbackType &userCb, void *user_data) override;
        void configure() override;
-       void capture(ISingleoCommonData &data) override;
+       void capture(BaseDataType &data) override;
        void streamOn() override;
        void streamOff() override;
 };
index d294efc30652a6bd95f6ada2acf6d2ddc3cfcf12..eea9f4a041a4e53cf8350ba4aa8563c2c7c8ce05 100644 (file)
@@ -17,7 +17,6 @@
 #ifndef __ICAMERA_SERVICE_H__
 #define __ICAMERA_SERVICE_H__
 
-#include "ISingleoCommonData.h"
 #include "InputTypes.h"
 
 namespace singleo
@@ -31,7 +30,7 @@ public:
 
        virtual void setUserCb(const InputServiceCallbackType &userCb, void *user_data) = 0;
        virtual void configure() = 0;
-       virtual void capture(ISingleoCommonData &data) = 0;
+       virtual void capture(BaseDataType &data) = 0;
        virtual void streamOn() = 0;
        virtual void streamOff() = 0;
 };
index 59c8d58e6e2d59e35d87a7a83857a0422ee21096..82b893a6cfd500e4ae8bb40b8dff9c1990038015 100644 (file)
@@ -18,7 +18,6 @@
 #define __IINPUT_SERVICE_H__
 
 #include <functional>
-#include "ISingleoCommonData.h"
 #include "InputTypes.h"
 
 namespace singleo
@@ -32,7 +31,7 @@ public:
 
        virtual void setUserCb(const InputServiceCallbackType &userCb, void *user_data) = 0;
        virtual void configure() = 0;
-       virtual void capture(ISingleoCommonData &data) = 0;
+       virtual void capture(BaseDataType &data) = 0;
        virtual void streamOn() = 0;
        virtual void streamOff() = 0;
 };
index d5654007c0f99482ad044948d8d5fc5db526ce79..98701048dfb069cc7a4a57a72c6d231f0549153b 100644 (file)
@@ -37,7 +37,7 @@ public:
 
        void setUserCb(const InputServiceCallbackType &userCb, void *user_data) override;
        void configure() override;
-       void capture(ISingleoCommonData &data) override;
+       void capture(BaseDataType &data) override;
        void streamOn() override;
        void streamOff() override;
 };
index db42f692bb2474dc6732048c16210c26d5dca579..43c4603e04a7ef6ef95da22aa5ea6f703ba9ddba 100644 (file)
@@ -19,7 +19,6 @@
 
 #include <functional>
 #include "SingleoCommonTypes.h"
-#include "ISingleoCommonData.h"
 
 namespace singleo
 {
@@ -55,7 +54,7 @@ struct ScreenCaptureConfig : public InputConfigBase {
        unsigned int y_resolution {};
 };
 
-using InputServiceCallbackType = std::function<void(ISingleoCommonData &data, void *user_data)>;
+using InputServiceCallbackType = std::function<void(BaseDataType &data, void *user_data)>;
 
 } // input
 } // singleo
index ccd107a456a5f5639d34f0813deda212422865cc..157540534a058b67659abe21320132abc7c8ee7d 100644 (file)
@@ -39,7 +39,7 @@ CameraServiceDefault::CameraServiceDefault(CameraConfig &config)
 CameraServiceDefault::~CameraServiceDefault()
 {}
 
-void CameraServiceDefault::setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
+void CameraServiceDefault::setUserCb(const std::function<void(BaseDataType &data, void *user_data)> &userCb,
                                                                         void *user_data)
 {
        _camera->setUserCb(userCb, user_data);
@@ -50,9 +50,9 @@ void CameraServiceDefault::configure()
        _camera->configure();
 }
 
-void CameraServiceDefault::capture(ISingleoCommonData &data)
+void CameraServiceDefault::capture(BaseDataType &data)
 {
-       _camera->capture(dynamic_cast<SingleoImageData &>(data));
+       _camera->capture(data);
 }
 
 void CameraServiceDefault::streamOn()
index dd27c05cbe8df61784c6651210b132386158c07d..3fbd59b24c7b1f53b3a17c09a52865c378ff3690 100644 (file)
@@ -28,14 +28,14 @@ CameraServiceExternal::CameraServiceExternal(CameraConfig &config)
 CameraServiceExternal::~CameraServiceExternal()
 {}
 
-void CameraServiceExternal::setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
+void CameraServiceExternal::setUserCb(const std::function<void(BaseDataType &data, void *user_data)> &userCb,
                                                                          void *user_data)
 {}
 
 void CameraServiceExternal::configure()
 {}
 
-void CameraServiceExternal::capture(ISingleoCommonData &data)
+void CameraServiceExternal::capture(BaseDataType &data)
 {}
 
 void CameraServiceExternal::streamOn()
index a373e288de35ba2198979f62fff48ed4e634a593..d376b85bbdfbf1f64f70186439e0f30d23654b70 100644 (file)
@@ -16,7 +16,7 @@
 
 #include "InputCamera.h"
 #include "CameraServiceDefault.h"
-#include "SingleoImageData.h"
+#include "SingleoInputManager.h"
 #include "SingleoLog.h"
 
 using namespace std;
@@ -34,8 +34,7 @@ InputCamera::InputCamera(CameraConfig &config)
 InputCamera::~InputCamera()
 {}
 
-void InputCamera::setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
-                                                       void *user_data)
+void InputCamera::setUserCb(const std::function<void(BaseDataType &data, void *user_data)> &userCb, void *user_data)
 {
        _input->setUserCb(userCb, user_data);
 }
@@ -45,7 +44,7 @@ void InputCamera::configure()
        _input->configure();
 }
 
-void InputCamera::capture(ISingleoCommonData &data)
+void InputCamera::capture(BaseDataType &data)
 {
        _input->capture(data);
 
index 8f8cb0cabd911b16d7428ddcf1000186cbcab43f..f062acda9e0b04ba26615592d1d48b8c78b098c8 100644 (file)
@@ -20,7 +20,7 @@
 #include "IService.h"
 #include "SingleoCommonTypes.h"
 #include "IInferenceServiceInterface.h"
-#include "SingleoImageData.h"
+#include "SingleoInputManager.h"
 #include "IInputService.h"
 #include "SingleoInferenceTypes.h"
 #include "InputTypes.h"
@@ -45,7 +45,7 @@ class AutoZoom : public IService
 private:
        std::unique_ptr<singleo::inference::IInferenceServiceInterface> _inference_service;
        std::unique_ptr<singleo::input::IInputService> _input_service;
-       std::queue<SingleoImageData> _input_data_q;
+       SingleoInputManager _input_image_data;
        AutoZoomResult _result {};
        std::map<std::string, AutoZoomResultType> _result_keys = { { "X", AutoZoomResultType::X },
                                                                                                                           { "Y", AutoZoomResultType::Y },
@@ -72,8 +72,8 @@ public:
 
        // This function will be called by specific input service internally.
        // Ps. caller has to provide captured data with concrete class object as data parameter.
-       static void inputServiceCb(ISingleoCommonData &data, void *user_data);
-       void perform_with_file(BaseDataType &input_data) override;
+       static void inputServiceCb(BaseDataType &data, void *user_data);
+       void add_input(BaseDataType &input_data) override;
        void perform() override;
        void performAsync() override;
        void getResultCnt(unsigned int *cnt) override;
index 6f683017893209ec89af48be4bdf47d66301e3fd..1a55f4c01d7e065bfe4569679dc1ebfa8a16ab9c 100644 (file)
@@ -59,10 +59,10 @@ AutoZoom::~AutoZoom()
                _input_service->streamOff();
 }
 
-void AutoZoom::inputServiceCb(ISingleoCommonData &data, void *user_data)
+void AutoZoom::inputServiceCb(BaseDataType &data, void *user_data)
 {
        auto auto_zoom = static_cast<AutoZoom *>(user_data);
-       ImagePreprocessor preprocessor(data.getData());
+       ImagePreprocessor preprocessor(data);
        ImageDataType preprocessed = dynamic_cast<ImageDataType &>(preprocessor.getData());
        ImageDataType copied = preprocessed;
        size_t buffer_size = copied.width * copied.height * copied.byte_per_pixel;
@@ -86,34 +86,46 @@ bool AutoZoom::isKeyValid(std::string key)
        return true;
 }
 
-void AutoZoom::perform_with_file(BaseDataType &input_data)
+void AutoZoom::add_input(BaseDataType &input_data)
 {
-       ImagePreprocessor preprocessor(input_data);
-       SingleoImageData image_data;
-       image_data.setData(preprocessor.getData());
-
-       _inference_service->invoke(image_data);
+       // This service allows only one input data per a service request.
+       if (_input_image_data.size() > 0) {
+               SINGLEO_LOGW("This service allows only one input data.");
+               return;
+       }
 
-       updateResult(preprocessor.getData());
+       if (input_data._data_type == DataType::FILE) {
+               FileDataType &file_data = dynamic_cast<FileDataType &>(input_data);
+               _input_image_data.enqueue(make_shared<FileDataType>(file_data));
+       } else if (input_data._data_type == DataType::IMAGE) {
+               ImageDataType &image_data = dynamic_cast<ImageDataType &>(input_data);
+               _input_image_data.enqueue(make_shared<ImageDataType>(image_data));
+       } else {
+               throw InvalidParameter("Invalid input data type.");
+       }
 }
 
 void AutoZoom::perform()
 {
-       if (!_input_service) {
-               SINGLEO_LOGE("This API is valid only the case that input feed device type is given.");
-               throw InvalidOperation("Invalid API request.");
-       }
+       ImagePreprocessor preprocessor;
 
-       SingleoImageData captured_image;
-
-       _input_service->capture(captured_image);
+       // If input service is not set, input data is from file.
+       if (!_input_service) {
+               shared_ptr<BaseDataType> result = _input_image_data.dequeue();
+               auto data = dynamic_pointer_cast<FileDataType>(result);
 
-       ImagePreprocessor preprocessor(captured_image.getData());
-       SingleoImageData preprocessed_image;
+               preprocessor.update(*data);
+               _inference_service->invoke(preprocessor.getData());
+               updateResult(preprocessor.getData());
+               return;
+       } else {
+               ImageDataType input_data;
 
-       preprocessed_image.setData(preprocessor.getData());
-       _inference_service->invoke(preprocessed_image);
+               _input_service->capture(input_data);
+               preprocessor.update(input_data);
+       }
 
+       _inference_service->invoke(preprocessor.getData());
        updateResult(preprocessor.getData());
 }
 
@@ -129,11 +141,9 @@ void AutoZoom::performAsync()
        _async_mode = true;
        _async_manager = make_unique<AsyncManager<ImageDataType, AutoZoomResult> >();
        _async_manager->registerInvokeCb(this, [this](IService *service, BaseDataType &data) {
-               SingleoImageData input_container;
                auto auto_zoom = static_cast<AutoZoom *>(service);
 
-               input_container.setData(data);
-               auto_zoom->getInferenceService()->invoke(input_container);
+               auto_zoom->getInferenceService()->invoke(data);
                auto_zoom->updateResult(data);
 
                // This buffer was allocated and copied in inputServiceCb callback.
index 472f2d60b01c8302c236ea829540e5ddfefb1ec9..fa28d7280d3cbfdd517b8a329eb53743f2541448 100644 (file)
@@ -28,7 +28,7 @@ class IPreprocessor
 public:
        virtual ~IPreprocessor() {};
 
-       virtual void setData(BaseDataType &data) = 0;
+       virtual void update(BaseDataType &input_data) = 0;
        virtual BaseDataType &getData() = 0;
 };
 
index 32dc0ce511ba20295bd743819384eb122c8d9c8f..f5bdf51e903dc96a787b2904e0217f91c8cc6bd0 100644 (file)
@@ -32,7 +32,7 @@ class IService
 public:
        virtual ~IService() {};
 
-       virtual void perform_with_file(BaseDataType &input_data) = 0;
+       virtual void add_input(BaseDataType &input_data) = 0;
        virtual void perform() = 0;
        virtual void performAsync() = 0;
        virtual void getResultCnt(unsigned int *cnt) = 0;
index 5473b70d1d3f0e741b0f241a1d9976b092016f4a..8ba3dcf2dc7f2172b5d8f002eed6df5c5fbcc78b 100644 (file)
@@ -43,7 +43,7 @@ public:
        ImagePreprocessor(BaseDataType &input_data);
        virtual ~ImagePreprocessor() = default;
 
-       void setData(BaseDataType &data) override;
+       void update(BaseDataType &input_data) override;
        BaseDataType &getData() override;
 
        void drawBox(Rect &rect, unsigned char r, unsigned char g, unsigned char b);
index f519bc08f34fcd42e1824a4e3d352ff91cb79911..bfb9f9ada25a838e8c2497cb1848cc275219e2d1 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef __SERVICE_CONFIG_PARSER_H__
 #define __SERVICE_CONFIG_PARSER_H__
 
+#include <map>
+
 #include "SingleoCommonTypes.h"
 #include "InputTypes.h"
 
index 1021c8a7ecc6bc21af1e0c4fee4101ff5eccbaa1..820c0b9bfcc61bce7b923f0d03cf814daa98ef2b 100644 (file)
@@ -27,21 +27,7 @@ namespace services
 {
 ImagePreprocessor::ImagePreprocessor(BaseDataType &input_data)
 {
-       if (input_data._data_type != DataType::FILE && input_data._data_type != DataType::IMAGE) {
-               SINGLEO_LOGE("Invalid data type.");
-               throw InvalidParameter("Invalid data type.");
-       }
-
-       if (input_data._data_type == DataType::FILE) {
-               FileDataType &file_data = dynamic_cast<FileDataType &>(input_data);
-
-               run(file_data._file_name);
-               return;
-       }
-
-       ImageDataType &image_data = dynamic_cast<ImageDataType &>(input_data);
-
-       run(image_data);
+       update(input_data);
 }
 
 void ImagePreprocessor::run(string file_name)
@@ -60,9 +46,23 @@ void ImagePreprocessor::run(ImageDataType &image_data)
        _cv_image = cv_image;
 }
 
-void ImagePreprocessor::setData(BaseDataType &data)
+void ImagePreprocessor::update(BaseDataType &input_data)
 {
-       _image_data = dynamic_cast<ImageDataType &>(data);
+       if (input_data._data_type != DataType::FILE && input_data._data_type != DataType::IMAGE) {
+               SINGLEO_LOGE("Invalid data type.");
+               throw InvalidParameter("Invalid data type.");
+       }
+
+       if (input_data._data_type == DataType::FILE) {
+               FileDataType &file_data = dynamic_cast<FileDataType &>(input_data);
+
+               run(file_data._file_name);
+               return;
+       }
+
+       ImageDataType &image_data = dynamic_cast<ImageDataType &>(input_data);
+
+       run(image_data);
 }
 
 BaseDataType &ImagePreprocessor::getData()
index e161af0e57ceb6686b31edfb3156440a3d06f407..35656a30732e6192d7e377232d51fbb9579b3782 100644 (file)
@@ -65,15 +65,52 @@ int singleo_service_destroy(singleo_service_h handle)
        return SINGLEO_ERROR_NONE;
 }
 
-int singleo_service_perform_with_file(singleo_service_h handle, const char *file_name)
+int singleo_service_add_input_image_file(singleo_service_h handle, const char *file_name)
 {
        try {
                auto context = static_cast<Context *>(handle);
                FileDataType input_data;
 
-               SINGLEO_LOGD("Inference requested with %s", file_name);
+               SINGLEO_LOGD("Add input image file(%s)", file_name);
+
                input_data._file_name = file_name;
-               context->_service_handle->perform_with_file(input_data);
+               context->_service_handle->add_input(input_data);
+       } catch (const BaseException &e) {
+               return e.getError();
+       }
+
+       return SINGLEO_ERROR_NONE;
+}
+
+int singleo_service_add_input_image_data(singleo_service_h handle, const unsigned char *buffer, unsigned int width,
+                                                                                unsigned int height, unsigned long byte_per_pixel)
+{
+       try {
+               auto context = static_cast<Context *>(handle);
+               ImageDataType input_data;
+
+               input_data.ptr = const_cast<unsigned char *>(buffer);
+               input_data.width = width;
+               input_data.height = height;
+               input_data.byte_per_pixel = byte_per_pixel;
+               context->_service_handle->add_input(input_data);
+       } catch (const BaseException &e) {
+               return e.getError();
+       }
+
+       return SINGLEO_ERROR_NONE;
+}
+
+int singleo_service_add_input_raw_data(singleo_service_h handle, const unsigned char *buffer,
+                                                                          unsigned long buffer_size_in_bytes)
+{
+       try {
+               auto context = static_cast<Context *>(handle);
+               RawDataType input_data;
+
+               input_data.ptr = const_cast<unsigned char *>(buffer);
+               input_data.size_in_bytes = buffer_size_in_bytes;
+               context->_service_handle->add_input(input_data);
        } catch (const BaseException &e) {
                return e.getError();
        }
index f5716b6750b282015d93acf5b37b5c05475f5072..d0b0140c1471e46d6d3ccf3b60570e22d52d8292 100644 (file)
@@ -1 +1 @@
-add_subdirectory(services)
+ADD_SUBDIRECTORY(services)
index af45d51c14d40496ef21af98fb82f9bd8d640fd2..1167e9b245c19fedd5344f82b5ad33847768c97f 100644 (file)
@@ -36,7 +36,10 @@ TEST(AutoZoomTest, InferenceRequestShouldBeOk)
        int ret = singleo_service_create("service=auto_zoom", &handle);
        ASSERT_EQ(ret, SINGLEO_ERROR_NONE);
 
-       ret = singleo_service_perform_with_file(handle, IMG_FACE);
+       ret = singleo_service_add_input_image_file(handle, IMG_FACE);
+       ASSERT_EQ(ret, SINGLEO_ERROR_NONE);
+
+       ret = singleo_service_perform(handle);
        ASSERT_EQ(ret, SINGLEO_ERROR_NONE);
 
        unsigned int cnt;
index ee9b4dcabf61790267bb0b7a2e0da0f2e67d763d..85e2defe9baaf47130bf965eafda6a757e226da6 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,9 +17,6 @@
 #ifndef __SINGLEO_UTIL_VISUALIZER_2D_H__
 #define __SINGLEO_UTIL_VISUALIZER_2D_H__
 
-#include <opencv2/opencv.hpp>
-#include <GLES2/gl2.h>
-
 #include "singleo_util_render_2d.h"
 
 int singleo_util_visualizer_2d(cv::Mat &source, const char *url);
index 92bc273cbd22fc37b3faa248fc081fa98c50b1bc..a9531e2126bb9fa2170432db3cf462c58caff14e 100644 (file)
@@ -20,6 +20,7 @@
 #include <opencv2/imgcodecs.hpp>
 #include <opencv2/imgproc/imgproc.hpp>
 #include <opencv2/opencv.hpp>
+#include <GLES2/gl2.h>
 
 #include "SingleoLog.h"
 #include "singleo_error.h"