drop SingleoInputManager 07/311907/2
authorInki Dae <inki.dae@samsung.com>
Thu, 30 May 2024 06:16:52 +0000 (15:16 +0900)
committerInki Dae <inki.dae@samsung.com>
Thu, 30 May 2024 09:20:50 +0000 (18:20 +0900)
Drop SingleoInputManager and use internal queue of AutoZoom instead.

As for SingleoInputManager, I will introduce a reference counting based
generic buffer manager later, which can be used commonly by other sub modules.
As for now, the use of SingleoInputManager in AutoZoom is over-engineering.

Change-Id: I1c281e5dcbd97d5714b19f74906a0222b9c0b002
Signed-off-by: Inki Dae <inki.dae@samsung.com>
12 files changed:
common/include/SingleoInputManager.h [deleted file]
common/src/SingleoInputManager.cpp [deleted file]
inference/backends/mediavision/src/MvFaceDetection.cpp
inference/backends/mediavision/src/MvFaceLandmark.cpp
inference/backends/mediavision/src/MvObjectDetection.cpp
input/backends/camera_api/include/CameraApiBackend.h
input/backends/include/ICameraBackend.h
input/backends/opencv/include/OpencvBackend.h
input/src/InputCamera.cpp
services/CMakeLists.txt
services/auto_zoom/include/AutoZoom.h
services/auto_zoom/src/AutoZoom.cpp

diff --git a/common/include/SingleoInputManager.h b/common/include/SingleoInputManager.h
deleted file mode 100644 (file)
index 663dd49..0000000
+++ /dev/null
@@ -1,45 +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_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/src/SingleoInputManager.cpp b/common/src/SingleoInputManager.cpp
deleted file mode 100644 (file)
index 2bf4cab..0000000
+++ /dev/null
@@ -1,44 +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 "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();
-}
-
-}
index ac2c61a87ac63626c8b33941bef71ed54db7bfef..9e7ab0c8a355b1b4feed3ba36f1f1f51cdc695b8 100644 (file)
@@ -15,7 +15,6 @@
  */
 
 #include <stdexcept>
-#include "SingleoInputManager.h"
 #include "MvFaceDetection.h"
 #include "SingleoLog.h"
 
index 99e73d42dfcfc07967123020c5e8694a29df015b..a624c8d0ad1e3076474b3b3621087f00bc2d8d7d 100644 (file)
@@ -15,7 +15,6 @@
  */
 
 #include <stdexcept>
-#include "SingleoInputManager.h"
 #include "MvFaceLandmark.h"
 #include "SingleoLog.h"
 
index 4a7c279a30aeb3d055e0d553b8df97402adadf80..1a6e6892bcbd629eed6b4da35e3a28351de3d4ce 100644 (file)
@@ -15,7 +15,6 @@
  */
 
 #include <stdexcept>
-#include "SingleoInputManager.h"
 #include "MvObjectDetection.h"
 #include "SingleoLog.h"
 
index 017e34f372485fe65dba356307e076f3c65277fd..3f3fbb2dd61019c5ab446f43d4fd3bc29d317869 100644 (file)
@@ -27,7 +27,6 @@
 
 #include "IInputObserver.h"
 #include "ICameraBackend.h"
-#include "SingleoInputManager.h"
 #include "InputTypes.h"
 
 namespace singleo
index 6dbc1908254c6d6cde145ad93b7c52cb53b5b3b4..028b3d8ee2d6ca817aafb7e702c3862d68f287f6 100644 (file)
@@ -20,7 +20,6 @@
 #include "IService.h"
 #include "InputTypes.h"
 #include "IInputObserver.h"
-#include "SingleoInputManager.h"
 
 namespace singleo
 {
index 855149e73f8ae27b5c9d72fa722bb6588688f9a5..d0df1ec96f012d0adb7694c285c28f71307a5289 100644 (file)
@@ -23,7 +23,6 @@
 #include <opencv2/opencv.hpp>
 
 #include "ICameraBackend.h"
-#include "SingleoInputManager.h"
 #include "InputTypes.h"
 
 namespace singleo
index 0b556ef2284f3dc09a6fd3d72247977ab8926d3b..22fb420d3b48c44a149c74a32c8938d074940485 100644 (file)
@@ -17,7 +17,6 @@
 #include "SingleoException.h"
 #include "InputCamera.h"
 #include "CameraBackendFactory.h"
-#include "SingleoInputManager.h"
 #include "SingleoLog.h"
 
 using namespace std;
index e319e6ef49221abea8b5601868ea2d60704f6a47..189479c9269969c6ece0d5dd3f1b4c51f4dc6cf6 100644 (file)
@@ -3,8 +3,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.13)
 
 FILE(GLOB SINGLEO_SERVICE_SOURCE_FILES "${PROJECT_SOURCE_DIR}/*.cpp"
                                        "${PROJECT_SOURCE_DIR}/src/*.cpp"
-                                       "${PROJECT_SOURCE_DIR}/common/src/*.cpp"
-                                       "${PROJECT_SOURCE_DIR}/../common/src/*.cpp")
+                                       "${PROJECT_SOURCE_DIR}/common/src/*.cpp")
 
 INCLUDE(${ROOT_DIRECTORY}/input/CMakeLists.txt)
 INCLUDE(${ROOT_DIRECTORY}/inference/CMakeLists.txt)
index d0e5901ebc5b173d1552e2149e947747cbc76aa2..ccf8b25fd8efc2f89f1b01176a6b545c1f336007 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "IService.h"
 #include "SingleoCommonTypes.h"
-#include "SingleoInputManager.h"
 #include "IInputService.h"
 #include "SingleoInferenceTypes.h"
 #include "InputTypes.h"
@@ -42,7 +41,8 @@ private:
        std::unique_ptr<TaskManager> _taskManager;
        std::unique_ptr<singleo::input::IInputService> _input_service;
        std::unique_ptr<IPostprocessor> _postprocessor;
-       SingleoInputManager _input_image_data;
+       std::queue<std::shared_ptr<BaseDataType> > _inputQ;
+       std::mutex _inputMutex;
        AutoZoomResult _result {};
        std::map<std::string, AutoZoomResultType> _result_keys = { { "X", AutoZoomResultType::X },
                                                                                                                           { "Y", AutoZoomResultType::Y },
index 8cfe2ef2d15b6ced5b8dc53fa7b90b3ebfccfe82..4657ee3c5ecc212103f0cd077abe3df70c4399ee 100644 (file)
@@ -121,10 +121,9 @@ bool AutoZoom::isKeyValid(std::string key)
 
 void AutoZoom::add_input(BaseDataType &input_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;
+       if (_inputQ.size() > 0) {
+               SINGLEO_LOGE("Only one input data is allowed.");
+               throw InvalidOperation("Only one input data is allowed.");
        }
 
        if (input_data._data_type != DataType::IMAGE && input_data._data_type != DataType::FILE) {
@@ -132,7 +131,9 @@ void AutoZoom::add_input(BaseDataType &input_data)
                throw InvalidOperation("Only IMAGE and FILE types are allowed.");
        }
 
-       _input_image_data.enqueue(input_data.clone());
+       std::lock_guard<std::mutex> lock(_inputMutex);
+
+       _inputQ.push(input_data.clone());
 }
 
 void AutoZoom::runTaskManager(BaseDataType &input_data)
@@ -148,12 +149,12 @@ void AutoZoom::perform()
        ImagePreprocessor preprocessor;
 
        // If input service is not set, input data comes from user.
-       // In this case, get input data from queue, _input_image_data.
+       // In this case, get input data from _inputs.
        if (!_input_service) {
-               shared_ptr<BaseDataType> result = _input_image_data.dequeue();
-               auto data = dynamic_pointer_cast<FileDataType>(result);
+               std::lock_guard<std::mutex> lock(_inputMutex);
 
-               preprocessor.update(*data);
+               preprocessor.update(*_inputQ.front());
+               _inputQ.pop();
        } else {
                ImageDataType input_data;