1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup feature_processor
18  * @{
19  *
20  * @brief Defines the basic functions for FeatureProcessor, including the supported data types
21  * and other related configuration parameters.
22  *
23  * @since 2.2
24  * @version 1.0
25  */
26 
27 /**
28  * @file type_converter.h
29  *
30  * @brief Defines TypeConverter with specified input and output types.
31  *
32  * @since 2.2
33  * @version 1.0
34  */
35 
36 #ifndef PREPROCESS_TYPE_CONVERTER_H
37 #define PREPROCESS_TYPE_CONVERTER_H
38 
39 #include <cstdint>
40 
41 #include "feature_processor.h"
42 
43 namespace OHOS {
44 namespace AI {
45 namespace Feature {
46 /**
47  * @brief Specifies the structure for the TypeConverter configuration.
48  *
49  * @since 2.2
50  * @version 1.0
51  */
52 struct TypeConverterConfig : FeatureProcessorConfig {
53     /** Number of data records supported by a single conversion. The maximum is {@link MAX_SAMPLE_SIZE}. */
54     size_t size;
55     TypeConverterConfig() = default;
TypeConverterConfigTypeConverterConfig56     TypeConverterConfig(DataType dt, size_t sz)
57     {
58         dataType = dt;
59         size = sz;
60     }
61 };
62 
63 /**
64  * @brief Defines the functions for TypeConverter.
65  *
66  * @since 2.2
67  * @version 1.0
68  */
69 class TypeConverter : public FeatureProcessor {
70 public:
71     /**
72      * @brief Defines the constructor for TypeConverter.
73      *
74      * @since 2.2
75      * @version 1.0
76      */
77     TypeConverter();
78 
79     /**
80      * @brief Defines the destructor for TypeConverter.
81      *
82      * @since 2.2
83      * @version 1.0
84      */
85     virtual ~TypeConverter();
86 
87     /**
88      * @brief Initializes TypeConverter.
89      *
90      * @param config Indicates the pointer to the basic configuration of FeatureProcessor.
91      * The caller needs to pass in a pointer address defined by {@link TypeConverterConfig} and
92      * release the pointer after using it.
93      * @return Returns {@link RETCODE_SUCCESS} if the operation is successful;
94      * returns {@link RETCODE_FAILURE} otherwise.
95      *
96      * @since 2.2
97      * @version 1.0
98      */
99     int32_t Init(const FeatureProcessorConfig *config) override;
100 
101     /**
102      * @brief Performs feature processing.
103      *
104      * @param input Indicates the input data for FeatureProcessor.
105      * The caller can input FeatureData of any data type defined by {@link DataType} except UNKNOWN.
106      * However, the address and data length must meet the configuration requirements of {@link Init}.
107      * @param output Indicates the output data for FeatureProcessor.
108      * The caller can input FeatureData of any data type defind by {@link DataType} except UNKNOWN.
109      * If and only if its address is empty and the data length is <b>0</b>,
110      * data will be filled by the FeatureProcessor.
111      * @return Returns {@link RETCODE_SUCCESS} if the operation is successful;
112      * returns {@link RETCODE_FAILURE} otherwise.
113      *
114      * @since 2.2
115      * @version 1.0
116      */
117     int32_t Process(const FeatureData &input, FeatureData &output) override;
118 
119     /**
120      * @brief Releases resources.
121      *
122      * @since 2.2
123      * @version 1.0
124      */
125     void Release() override;
126 
127 private:
128     int32_t InnerProcess(const FeatureData &input);
129 
130 private:
131     bool isInitialized_;
132     FeatureData workBuffer_;
133 };
134 } // namespace Feature
135 } // namespace AI
136 } // namespace OHOS
137 #endif // PREPROCESS_TYPE_CONVERTER_H
138 /** @} */