• 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 #include "intell_voice_engine_proxy.h"
17 #include "intell_voice_log.h"
18 
19 #define LOG_TAG "IntellVoiceEngineProxy"
20 
21 namespace OHOS {
22 namespace IntellVoiceEngine {
SetCallback(sptr<IRemoteObject> object)23 void IntellVoiceEngineProxy::SetCallback(sptr<IRemoteObject> object)
24 {
25     MessageParcel data;
26     MessageParcel reply;
27     MessageOption option;
28     if (object == nullptr) {
29         INTELL_VOICE_LOG_ERROR("object is null");
30         return;
31     }
32 
33     data.WriteInterfaceToken(IIntellVoiceEngine::GetDescriptor());
34     data.WriteRemoteObject(object);
35     Remote()->SendRequest(INTELL_VOICE_ENGINE_SET_CALLBACK, data, reply, option);
36 }
37 
Attach(const IntellVoiceEngineInfo & info)38 int32_t IntellVoiceEngineProxy::Attach(const IntellVoiceEngineInfo &info)
39 {
40     MessageParcel data;
41     MessageParcel reply;
42     MessageOption option;
43 
44     data.WriteInterfaceToken(IIntellVoiceEngine::GetDescriptor());
45     data.WriteString(info.wakeupPhrase);
46     data.WriteBool(info.isPcmFromExternal);
47     data.WriteInt32(info.minBufSize);
48     data.WriteInt32(info.sampleChannels);
49     data.WriteInt32(info.bitsPerSample);
50     data.WriteInt32(info.sampleRate);
51 
52     Remote()->SendRequest(INTELL_VOICE_ENGINE_ATTACH, data, reply, option);
53 
54     INTELL_VOICE_LOG_INFO("Attach call");
55     return reply.ReadInt32();
56 }
57 
Detach(void)58 int32_t IntellVoiceEngineProxy::Detach(void)
59 {
60     MessageParcel data;
61     MessageParcel reply;
62     MessageOption option;
63 
64     data.WriteInterfaceToken(IIntellVoiceEngine::GetDescriptor());
65     Remote()->SendRequest(INTELL_VOICE_ENGINE_DETACH, data, reply, option);
66     return reply.ReadInt32();
67 }
68 
SetParameter(const std::string & keyValueList)69 int32_t IntellVoiceEngineProxy::SetParameter(const std::string &keyValueList)
70 {
71     MessageParcel data;
72     MessageParcel reply;
73     MessageOption option;
74 
75     data.WriteInterfaceToken(IIntellVoiceEngine::GetDescriptor());
76     data.WriteString(keyValueList);
77     Remote()->SendRequest(INTELL_VOICE_ENGINE_SET_PARAMETER, data, reply, option);
78     return reply.ReadInt32();
79 }
80 
GetParameter(const std::string & key)81 std::string IntellVoiceEngineProxy::GetParameter(const std::string &key)
82 {
83     MessageParcel data;
84     MessageParcel reply;
85     MessageOption option;
86 
87     data.WriteInterfaceToken(IIntellVoiceEngine::GetDescriptor());
88     data.WriteString(key);
89 
90     Remote()->SendRequest(INTELL_VOICE_ENGINE_GET_PARAMETER, data, reply, option);
91     return reply.ReadString();
92 }
93 
Start(bool isLast)94 int32_t IntellVoiceEngineProxy::Start(bool isLast)
95 {
96     MessageParcel data;
97     MessageParcel reply;
98     MessageOption option;
99 
100     data.WriteInterfaceToken(IIntellVoiceEngine::GetDescriptor());
101 
102     Remote()->SendRequest(INTELL_VOICE_ENGINE_START, data, reply, option);
103     return reply.ReadInt32();
104 }
105 
Stop(void)106 int32_t IntellVoiceEngineProxy::Stop(void)
107 {
108     MessageParcel data;
109     MessageParcel reply;
110     MessageOption option;
111 
112     data.WriteInterfaceToken(IIntellVoiceEngine::GetDescriptor());
113 
114     Remote()->SendRequest(INTELL_VOICE_ENGINE_STOP, data, reply, option);
115     return reply.ReadInt32();
116 }
117 
WriteAudio(const uint8_t * buffer,uint32_t size)118 int32_t IntellVoiceEngineProxy::WriteAudio(const uint8_t *buffer, uint32_t size)
119 {
120     MessageParcel data;
121     MessageParcel reply;
122     MessageOption option;
123 
124     data.WriteInterfaceToken(IIntellVoiceEngine::GetDescriptor());
125     data.WriteUint32(size);
126     data.WriteBuffer(buffer, size);
127 
128     Remote()->SendRequest(INTELL_VOICE_ENGINE_WRITE_AUDIO, data, reply, option);
129     return reply.ReadInt32();
130 }
131 }
132 }
133