1 /* 2 * Copyright (c) 2023 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 #ifndef ENGINE_BASE_H 16 #define ENGINE_BASE_H 17 #include <memory> 18 #include <mutex> 19 #include <string> 20 #include <map> 21 #include "intell_voice_engine_stub.h" 22 #include "v1_0/iintell_voice_engine_adapter.h" 23 24 namespace OHOS { 25 namespace IntellVoiceEngine { 26 enum EngineRelationType { 27 CONCURRENCY_TYPE, 28 PREEMPTION_TYPE, 29 REPLACEMENT_TYPE, 30 }; 31 32 class EngineBase : public IntellVoiceEngineStub { 33 public: 34 ~EngineBase() = default; 35 virtual bool Init() = 0; 36 int32_t SetParameter(const std::string &keyValueList) override; 37 std::string GetParameter(const std::string &key) override; 38 int32_t WriteAudio(const uint8_t *buffer, uint32_t size) override; 39 int32_t Stop() override; OnDetected()40 virtual void OnDetected() {}; IsRunning()41 bool IsRunning() 42 { 43 return isRunning_; 44 } GetEngineRelationType()45 EngineRelationType GetEngineRelationType() 46 { 47 return type_; 48 } GetPriority()49 int32_t GetPriority() 50 { 51 return priority_; 52 } 53 54 protected: 55 EngineBase(); 56 void SplitStringToKVPair(const std::string &inputStr, std::map<std::string, std::string> &kvpairs); 57 std::mutex mutex_; 58 sptr<OHOS::HDI::IntelligentVoice::Engine::V1_0::IIntellVoiceEngineAdapter> adapter_ = nullptr; 59 OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineAdapterDescriptor desc_; 60 61 bool isRunning_ = false; 62 EngineRelationType type_ = CONCURRENCY_TYPE; 63 int32_t priority_ = 0; 64 }; 65 } 66 } 67 #endif