• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef HDI_DEVICE_INTELL_VOICE_ADAPTER_SERVICE_H
17 #define HDI_DEVICE_INTELL_VOICE_ADAPTER_SERVICE_H
18 
19 #include <memory>
20 #include <fstream>
21 #include <map>
22 
23 #include "v1_0/iintell_voice_engine_adapter.h"
24 #include "i_engine.h"
25 
26 namespace OHOS {
27 namespace IntelligentVoice {
28 namespace Engine {
29 using OHOS::HDI::IntelligentVoice::Engine::V1_0::IIntellVoiceEngineCallback;
30 using OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent;
31 
32 using OHOS::HDI::IntelligentVoice::Engine::V1_0::IIntellVoiceEngineAdapter;
33 using OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineAdapterInfo;
34 using OHOS::HDI::IntelligentVoice::Engine::V1_0::StartInfo;
35 using OHOS::HDI::IntelligentVoice::Engine::V1_0::ContentType;
36 
37 class EngineListener : public IEngineCallback {
38 public:
39     explicit EngineListener(const sptr<IIntellVoiceEngineCallback> &cb);
40     ~EngineListener();
41     void OnIntellVoiceEvent(const IntellVoiceEngineCallBackEvent &event) override;
42 private:
43     sptr<IIntellVoiceEngineCallback> cb_;
44 };
45 
46 class IntellVoiceEngineAdapterImpl : public IIntellVoiceEngineAdapter {
47 public:
48     explicit IntellVoiceEngineAdapterImpl(std::unique_ptr<IEngine> engine);
49     ~IntellVoiceEngineAdapterImpl();
50 
51     int32_t SetCallback(const sptr<IIntellVoiceEngineCallback>& engineCallback) override;
52     int32_t Attach(const IntellVoiceEngineAdapterInfo& info) override;
53     int32_t Detach() override;
54     int32_t SetParameter(const std::string& keyValueList) override;
55     int32_t GetParameter(const std::string& keyList, std::string& valueList) override;
56     int32_t Start(const StartInfo &info) override;
57     int32_t Stop() override;
58     int32_t WriteAudio(const std::vector<uint8_t>& buffer) override;
59     int32_t Read(ContentType type, sptr<Ashmem>& buffer) override;
60 
61 private:
62     int32_t ReadFileDataInner(ContentType type, uint8_t *&buffer, uint32_t &size);
63 
64 private:
65     std::unique_ptr<IEngine> engine_ = nullptr;
66 };
67 }
68 }
69 }
70 #endif