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 ENROLL_ENGINE_H 16 #define ENROLL_ENGINE_H 17 #include <memory> 18 #include <string> 19 #include <ashmem.h> 20 #include "engine_base.h" 21 #include "v1_0/iintell_voice_engine_callback.h" 22 #include "audio_info.h" 23 #include "audio_source.h" 24 #include "intell_voice_generic_factory.h" 25 26 namespace OHOS { 27 namespace IntellVoiceEngine { 28 class EnrollEngine : public EngineBase { 29 public: 30 ~EnrollEngine(); 31 virtual bool Init() override; 32 void SetCallback(sptr<IRemoteObject> object) override; 33 int32_t Attach(const IntellVoiceEngineInfo &info) override; 34 int32_t Detach(void) override; 35 int32_t Start(bool isLast) override; 36 int32_t Stop() override; 37 int32_t SetParameter(const std::string &keyValueList) override; 38 39 private: 40 EnrollEngine(); 41 bool SetParameterInner(const std::string &keyValueList); 42 bool StartAudioSource(); 43 void StopAudioSource(); 44 void OnEnrollEvent(int32_t msgId, int32_t result); 45 void OnEnrollComplete(); 46 void ProcDspModel(); 47 void WriteBufferFromAshmem(uint8_t *&buffer, uint32_t size, sptr<OHOS::Ashmem> ashmem); 48 49 private: 50 std::string name_ = "lp enroll engine instance"; 51 bool isPcmFromExternal_ = false; 52 int32_t enrollResult_ = -1; 53 sptr<OHOS::HDI::IntelligentVoice::Engine::V1_0::IIntellVoiceEngineCallback> callback_ = nullptr; 54 OHOS::AudioStandard::AudioCapturerOptions capturerOptions_; 55 std::unique_ptr<AudioSource> audioSource_ = nullptr; 56 friend class IntellVoiceUtils::SptrFactory<EnrollEngine>; 57 }; 58 } 59 } 60 #endif 61