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 paramters. 22 * 23 * @since 2.2 24 * @version 1.0 25 */ 26 27 /** 28 * @file slide_window_processor.h 29 * 30 * @brief Defines SlideWindowProcessor that implements sliding window for streaming data. 31 * 32 * @since 2.2 33 * @version 1.0 34 */ 35 36 #ifndef PREPROCESS_SLIDE_WINDOW_PROCESSOR_H 37 #define PREPROCESS_SLIDE_WINDOW_PROCESSOR_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 SlideWindowProcessor configuration. 48 * 49 * @since 2.2 50 * @version 1.0 51 */ 52 struct SlideWindowProcessorConfig : FeatureProcessorConfig { 53 /** Buffer multiplier for SlideWindowProcessor acceleration. 54 * The value must be greater than <b>0</b>. The default is <b>4</b>. */ 55 uint8_t bufferMultiplier = 4; 56 /** Input step size. Ensure that the maximum value is not greater than <b>windowSize</b>. */ 57 size_t stepSize; 58 /** Size of the output window. Ensure that the maximum value is not greater than {@link MAX_SAMPLE_SIZE}. */ 59 size_t windowSize; 60 }; 61 62 /** 63 * @brief Defines the functions for SlideWindowProcessor. 64 * 65 * @since 2.2 66 * @version 1.0 67 */ 68 class SlideWindowProcessor : public FeatureProcessor { 69 public: 70 /** 71 * @brief Defines the constructor for SlideWindowProcessor. 72 * 73 * @since 2.2 74 * @version 1.0 75 */ 76 SlideWindowProcessor(); 77 78 /** 79 * @brief Defines the destructor for SlideWindowProcessor. 80 * 81 * @since 2.2 82 * @version 1.0 83 */ 84 virtual ~SlideWindowProcessor(); 85 86 /** 87 * @brief Initializes SlideWindowProcessor. 88 * 89 * @param config Indicates the pointer to the basic configuration of FeatureProcessor. 90 * The caller needs to pass in a pointer address defined by {@link SlideWindowProcessorConfig} and 91 * release the pointer after using it. 92 * @return Returns {@link RETCODE_SUCCESS} if the operation is successful; 93 * returns {@link RETCODE_FAILURE} otherwise. 94 * 95 * @since 2.2 96 * @version 1.0 97 */ 98 int32_t Init(const FeatureProcessorConfig *config) override; 99 100 /** 101 * @brief Performs feature processing. 102 * 103 * @param input Indicates the input data for FeatureProcessor. 104 * The caller can input FeatureData of any data type defined by {@link DataType} except UNKNOWN. 105 * However, the address and data length must meet the configuration requirements of {@link Init}. 106 * @param output Indicates the output data for FeatureProcessor. 107 * The caller must pass in FeatureData that is consistent with the input data defined by {@link DataType}. 108 * If and only if its address is empty and the data length is <b>0</b>, 109 * data will be filled by the FeatureProcessor. 110 * @return Returns {@link RETCODE_SUCCESS} if the operation is successful; 111 * returns {@link RETCODE_FAILURE} otherwise. 112 * 113 * @since 2.2 114 * @version 1.0 115 */ 116 int32_t Process(const FeatureData &input, FeatureData &output) override; 117 118 /** 119 * @brief Releases resources. 120 * 121 * @since 2.2 122 * @version 1.0 123 */ 124 void Release() override; 125 126 private: 127 bool isInitialized_; 128 char *workBuffer_; 129 char *inputFeature_; 130 DataType inType_; 131 uint8_t typeSize_; 132 uint32_t startIndex_; 133 uint32_t initIndex_; 134 uint32_t bufferSize_; 135 size_t windowSize_; 136 size_t stepSize_; 137 }; 138 } // namespace Feature 139 } // namespace AI 140 } // namespace OHOS 141 #endif // PREPROCESS_SLIDE_WINDOW_PROCESSOR_H 142 /** @} */