• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <hdf_log.h>
16 #include "audio_proxy_common.h"
17 
18 namespace OHOS::HDI::Audio_Bluetooth {
AudioProxyRenderCtrl(int cmId,AudioHandle handle)19 int32_t AudioProxyRenderCtrl(int cmId, AudioHandle handle)
20 {
21     struct HdfSBuf *data = NULL;
22     struct HdfSBuf *reply = NULL;
23     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(handle);
24     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
25         HDF_LOGE("The hwRender parameter is null");
26         return AUDIO_HAL_ERR_INVALID_PARAM;
27     }
28     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
29         return AUDIO_HAL_ERR_INTERNAL;
30     }
31     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, cmId, data, reply);
32     AudioProxyBufReplyRecycle(data, reply);
33     return ret;
34 }
35 
AudioProxyRenderStart(AudioHandle handle)36 int32_t AudioProxyRenderStart(AudioHandle handle)
37 {
38     HDF_LOGI("%{public}s, ", __func__);
39     return AudioProxyRenderCtrl(AUDIO_HDI_RENDER_START, handle);
40 }
41 
AudioProxyRenderStop(AudioHandle handle)42 int32_t AudioProxyRenderStop(AudioHandle handle)
43 {
44     HDF_LOGI("%{public}s, ", __func__);
45     return AudioProxyRenderCtrl(AUDIO_HDI_RENDER_STOP, handle);
46 }
47 
AudioProxyRenderPause(AudioHandle handle)48 int32_t AudioProxyRenderPause(AudioHandle handle)
49 {
50     HDF_LOGI("%{public}s, ", __func__);
51     return AudioProxyRenderCtrl(AUDIO_HDI_RENDER_PAUSE, handle);
52 }
53 
AudioProxyRenderResume(AudioHandle handle)54 int32_t AudioProxyRenderResume(AudioHandle handle)
55 {
56     HDF_LOGI("%{public}s, ", __func__);
57     return AudioProxyRenderCtrl(AUDIO_HDI_RENDER_RESUME, handle);
58 }
59 
AudioProxyRenderFlush(AudioHandle handle)60 int32_t AudioProxyRenderFlush(AudioHandle handle)
61 {
62     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(handle);
63     if (hwRender == NULL) {
64         return AUDIO_HAL_ERR_INVALID_PARAM;
65     }
66     return AUDIO_HAL_ERR_NOT_SUPPORT;
67 }
68 
AudioProxyRenderGetFrameParameter(int cmId,const AudioHandle handle,uint64_t * param)69 int32_t AudioProxyRenderGetFrameParameter(int cmId, const AudioHandle handle, uint64_t *param)
70 {
71     if (param == NULL) {
72         return AUDIO_HAL_ERR_INVALID_PARAM;
73     }
74     int32_t ret;
75     struct HdfSBuf *data = NULL;
76     struct HdfSBuf *reply = NULL;
77     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(handle);
78     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
79         HDF_LOGE("invalid pointer");
80         return AUDIO_HAL_ERR_INVALID_PARAM;
81     }
82     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
83         return AUDIO_HAL_ERR_INTERNAL;
84     }
85     ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, cmId, data, reply);
86     if (ret < 0) {
87         AudioProxyBufReplyRecycle(data, reply);
88         return ret;
89     }
90     if (!HdfSbufReadUint64(reply, param)) {
91         AudioProxyBufReplyRecycle(data, reply);
92         return AUDIO_HAL_ERR_INTERNAL;
93     }
94     AudioProxyBufReplyRecycle(data, reply);
95     return AUDIO_HAL_SUCCESS;
96 }
97 
AudioProxyRenderGetFrameSize(const AudioHandle handle,uint64_t * size)98 int32_t AudioProxyRenderGetFrameSize(const AudioHandle handle, uint64_t *size)
99 {
100     return AudioProxyRenderGetFrameParameter(AUDIO_HDI_RENDER_GET_FRAME_SIZE, handle, size);
101 }
102 
AudioProxyRenderGetFrameCount(const AudioHandle handle,uint64_t * count)103 int32_t AudioProxyRenderGetFrameCount(const AudioHandle handle, uint64_t *count)
104 {
105     return AudioProxyRenderGetFrameParameter(AUDIO_HDI_RENDER_GET_FRAME_COUNT, handle, count);
106 }
107 
AudioProxyRenderSetSampleAttributes(const AudioHandle handle,const struct AudioSampleAttributes * attrs)108 int32_t AudioProxyRenderSetSampleAttributes(const AudioHandle handle, const struct AudioSampleAttributes *attrs)
109 {
110     if (handle == NULL || attrs == NULL) {
111         return AUDIO_HAL_ERR_INVALID_PARAM;
112     }
113     struct HdfSBuf *data = NULL;
114     struct HdfSBuf *reply = NULL;
115     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(handle);
116     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
117         HDF_LOGE("pointer is invalid");
118         return AUDIO_HAL_ERR_INVALID_PARAM;
119     }
120     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
121         return AUDIO_HAL_ERR_INTERNAL;
122     }
123     if (AudioProxyWriteSampleAttributes(data, attrs) < 0) {
124         AudioProxyBufReplyRecycle(data, reply);
125         return AUDIO_HAL_ERR_INTERNAL;
126     }
127     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_SET_SAMPLE_ATTR, data, reply);
128     AudioProxyBufReplyRecycle(data, reply);
129     return ret;
130 }
131 
AudioProxyRenderGetSampleAttributes(const AudioHandle handle,struct AudioSampleAttributes * attrs)132 int32_t AudioProxyRenderGetSampleAttributes(const AudioHandle handle,
133     struct AudioSampleAttributes *attrs)
134 {
135     if (attrs == NULL) {
136         return AUDIO_HAL_ERR_INVALID_PARAM;
137     }
138     struct HdfSBuf *data = NULL;
139     struct HdfSBuf *reply = NULL;
140     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(handle);
141     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
142         HDF_LOGE("The hwRender parameter is empty");
143         return AUDIO_HAL_ERR_INVALID_PARAM;
144     }
145     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
146         return AUDIO_HAL_ERR_INTERNAL;
147     }
148     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_GET_SAMPLE_ATTR, data, reply);
149     if (ret < 0) {
150         HDF_LOGE("AudioRenderGetSampleAttributes FAIL");
151         AudioProxyBufReplyRecycle(data, reply);
152         return ret;
153     }
154     if (AudioProxyReadSapmleAttrbutes(reply, attrs)) {
155         HDF_LOGE("AudioProxyReadSapmleAttrbutes FAIL");
156         AudioProxyBufReplyRecycle(data, reply);
157         return AUDIO_HAL_ERR_INTERNAL;
158     }
159     AudioProxyBufReplyRecycle(data, reply);
160     return AUDIO_HAL_SUCCESS;
161 }
162 
AudioProxyRenderGetCurrentChannelId(const AudioHandle handle,uint32_t * channelId)163 int32_t AudioProxyRenderGetCurrentChannelId(const AudioHandle handle, uint32_t *channelId)
164 {
165     if (channelId == NULL) {
166         return AUDIO_HAL_ERR_INVALID_PARAM;
167     }
168     struct HdfSBuf *data = NULL;
169     struct HdfSBuf *reply = NULL;
170     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(handle);
171     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
172         HDF_LOGE("pointer is null");
173         return AUDIO_HAL_ERR_INVALID_PARAM;
174     }
175     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
176         return AUDIO_HAL_ERR_INTERNAL;
177     }
178     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_GET_CUR_CHANNEL_ID, data, reply);
179     if (ret < 0) {
180         HDF_LOGE("AudioRenderGetCurrentChannelId FAIL");
181         AudioProxyBufReplyRecycle(data, reply);
182         return ret;
183     }
184     if (!HdfSbufReadUint32(reply, channelId)) {
185         AudioProxyBufReplyRecycle(data, reply);
186         return AUDIO_HAL_ERR_INTERNAL;
187     }
188     AudioProxyBufReplyRecycle(data, reply);
189     return AUDIO_HAL_SUCCESS;
190 }
191 
AudioProxyRenderCheckSceneCapability(const AudioHandle handle,const struct AudioSceneDescriptor * scene,bool * supported)192 int32_t AudioProxyRenderCheckSceneCapability(const AudioHandle handle,
193     const struct AudioSceneDescriptor *scene, bool *supported)
194 {
195     if (scene == NULL || supported == NULL) {
196         return AUDIO_HAL_ERR_INVALID_PARAM;
197     }
198     uint32_t tempPins;
199     struct HdfSBuf *data = NULL;
200     struct HdfSBuf *reply = NULL;
201     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(handle);
202     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
203         HDF_LOGE("The hwRender pointer is null");
204         return AUDIO_HAL_ERR_INVALID_PARAM;
205     }
206     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
207         HDF_LOGE("AudioProxyPreprocessRender FAIL");
208         return AUDIO_HAL_ERR_INTERNAL;
209     }
210     if (!HdfSbufWriteUint32(data, scene->scene.id)) {
211         HDF_LOGE("scene->scene.id Write FAIL");
212         AudioProxyBufReplyRecycle(data, reply);
213         return AUDIO_HAL_ERR_INTERNAL;
214     }
215     tempPins = (uint32_t)scene->desc.pins;
216     if (!HdfSbufWriteUint32(data, tempPins)) {
217         HDF_LOGE("tempPins Write FAIL");
218         AudioProxyBufReplyRecycle(data, reply);
219         return AUDIO_HAL_ERR_INTERNAL;
220     }
221     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle,
222         AUDIO_HDI_RENDER_CHECK_SCENE_CAPABILITY, data, reply);
223     if (ret < 0) {
224         HDF_LOGE("AudioRenderCheckSceneCapability FAIL");
225         AudioProxyBufReplyRecycle(data, reply);
226         return ret;
227     }
228     uint32_t tempSupported = 0;
229     if (!HdfSbufReadUint32(reply, &tempSupported)) {
230         AudioProxyBufReplyRecycle(data, reply);
231         return AUDIO_HAL_ERR_INTERNAL;
232     }
233     *supported = (bool)tempSupported;
234     AudioProxyBufReplyRecycle(data, reply);
235     return AUDIO_HAL_SUCCESS;
236 }
237 
AudioProxyRenderSelectScene(const AudioHandle handle,const struct AudioSceneDescriptor * scene)238 int32_t AudioProxyRenderSelectScene(const AudioHandle handle, const struct AudioSceneDescriptor *scene)
239 {
240     if (scene == NULL) {
241         return AUDIO_HAL_ERR_INVALID_PARAM;
242     }
243     struct HdfSBuf *data = NULL;
244     struct HdfSBuf *reply = NULL;
245     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(handle);
246     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
247         HDF_LOGE("parameter is null");
248         return AUDIO_HAL_ERR_INVALID_PARAM;
249     }
250     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
251         return AUDIO_HAL_ERR_INTERNAL;
252     }
253     if (!HdfSbufWriteUint32(data, scene->scene.id)) {
254         AudioProxyBufReplyRecycle(data, reply);
255         return AUDIO_HAL_ERR_INTERNAL;
256     }
257     uint32_t temporaryPins = scene->desc.pins;
258     if (!HdfSbufWriteUint32(data, temporaryPins)) {
259         AudioProxyBufReplyRecycle(data, reply);
260         return AUDIO_HAL_ERR_INTERNAL;
261     }
262     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_SELECT_SCENE, data, reply);
263     AudioProxyBufReplyRecycle(data, reply);
264     return ret;
265 }
266 
AudioProxyRenderSetMute(const AudioHandle handle,bool mute)267 int32_t AudioProxyRenderSetMute(const AudioHandle handle, bool mute)
268 {
269     (void)mute;
270     struct HdfSBuf *data = NULL;
271     struct HdfSBuf *reply = NULL;
272     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(handle);
273     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
274         HDF_LOGE("The pointer is null");
275         return AUDIO_HAL_ERR_INVALID_PARAM;
276     }
277     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
278         return AUDIO_HAL_ERR_INTERNAL;
279     }
280     uint32_t tempMute = (uint32_t)mute;
281     if (!HdfSbufWriteUint32(data, tempMute)) {
282         AudioProxyBufReplyRecycle(data, reply);
283         return AUDIO_HAL_ERR_INTERNAL;
284     }
285     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_SET_MUTE, data, reply);
286     AudioProxyBufReplyRecycle(data, reply);
287     return ret;
288 }
289 
AudioProxyRenderGetMute(const AudioHandle handle,bool * mute)290 int32_t AudioProxyRenderGetMute(const AudioHandle handle, bool *mute)
291 {
292     if (mute == NULL) {
293         return AUDIO_HAL_ERR_INVALID_PARAM;
294     }
295     struct HdfSBuf *data = NULL;
296     struct HdfSBuf *reply = NULL;
297     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(handle);
298     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
299         HDF_LOGE("The parameter is null");
300         return AUDIO_HAL_ERR_INVALID_PARAM;
301     }
302     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
303         return AUDIO_HAL_ERR_INTERNAL;
304     }
305     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_GET_MUTE, data, reply);
306     uint32_t tempMute = 0;
307     if (!HdfSbufReadUint32(reply, &tempMute)) {
308         AudioProxyBufReplyRecycle(data, reply);
309         return AUDIO_HAL_ERR_INTERNAL;
310     }
311     *mute = (bool)tempMute;
312     AudioProxyBufReplyRecycle(data, reply);
313     LOG_PARA_INFO("GetMute SUCCESS!");
314     return ret;
315 }
316 
AudioProxyRenderSetVolume(const AudioHandle handle,float volume)317 int32_t AudioProxyRenderSetVolume(const AudioHandle handle, float volume)
318 {
319     HDF_LOGI("%{public}s, ", __func__);
320     return AudioProxyCommonSetRenderCtrlParam(AUDIO_HDI_RENDER_SET_VOLUME, handle, volume);
321 }
322 
AudioProxyRenderGetVolume(const AudioHandle handle,float * volume)323 int32_t AudioProxyRenderGetVolume(const AudioHandle handle, float *volume)
324 {
325     HDF_LOGI("%{public}s, ", __func__);
326     return AudioProxyCommonGetRenderCtrlParam(AUDIO_HDI_RENDER_GET_VOLUME, handle, volume);
327 }
328 
AudioProxyRenderGetGainThreshold(const AudioHandle handle,float * min,float * max)329 int32_t AudioProxyRenderGetGainThreshold(const AudioHandle handle, float *min, float *max)
330 {
331     if (min == NULL || max == NULL) {
332         return AUDIO_HAL_ERR_INVALID_PARAM;
333     }
334     struct HdfSBuf *data = NULL;
335     struct HdfSBuf *reply = NULL;
336     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(handle);
337     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
338         HDF_LOGE("The pointer is invalid");
339         return AUDIO_HAL_ERR_INVALID_PARAM;
340     }
341     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
342         return AUDIO_HAL_ERR_INTERNAL;
343     }
344     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_GET_GAIN_THRESHOLD, data, reply);
345     if (ret < 0) {
346         HDF_LOGE("AudioRenderGetGainThreshold FAIL");
347         AudioProxyBufReplyRecycle(data, reply);
348         return ret;
349     }
350     uint32_t tempMin = 0;
351     uint32_t tempMax = 0;
352     if (!HdfSbufReadUint32(reply, &tempMin)) {
353         AudioProxyBufReplyRecycle(data, reply);
354         return AUDIO_HAL_ERR_INTERNAL;
355     }
356     if (!HdfSbufReadUint32(reply, &tempMax)) {
357         AudioProxyBufReplyRecycle(data, reply);
358         return AUDIO_HAL_ERR_INTERNAL;
359     }
360     *min = (float)tempMin;
361     *max = (float)tempMax;
362     AudioProxyBufReplyRecycle(data, reply);
363     return AUDIO_HAL_SUCCESS;
364 }
365 
AudioProxyRenderGetGain(const AudioHandle handle,float * gain)366 int32_t AudioProxyRenderGetGain(const AudioHandle handle, float *gain)
367 {
368     return AudioProxyCommonGetRenderCtrlParam(AUDIO_HDI_RENDER_GET_GAIN, handle, gain);
369 }
370 
AudioProxyRenderSetGain(const AudioHandle handle,float gain)371 int32_t AudioProxyRenderSetGain(const AudioHandle handle, float gain)
372 {
373     return AudioProxyCommonSetRenderCtrlParam(AUDIO_HDI_RENDER_SET_GAIN, handle, gain);
374 }
375 
AudioProxyRenderGetLatency(struct AudioRender * render,uint32_t * ms)376 int32_t AudioProxyRenderGetLatency(struct AudioRender *render, uint32_t *ms)
377 {
378     struct HdfSBuf *data = NULL;
379     struct HdfSBuf *reply = NULL;
380     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(render);
381     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL || ms == NULL) {
382         HDF_LOGE("The pointer is empty");
383         return AUDIO_HAL_ERR_INVALID_PARAM;
384     }
385     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
386         return AUDIO_HAL_ERR_INTERNAL;
387     }
388     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_GET_LATENCY, data, reply);
389     if (ret < 0) {
390         HDF_LOGE("AudioRenderGetLatency FAIL");
391         AudioProxyBufReplyRecycle(data, reply);
392         return ret;
393     }
394     if (!HdfSbufReadUint32(reply, ms)) {
395         AudioProxyBufReplyRecycle(data, reply);
396         return AUDIO_HAL_ERR_INTERNAL;
397     }
398     AudioProxyBufReplyRecycle(data, reply);
399     return AUDIO_HAL_SUCCESS;
400 }
401 
AudioProxyRenderRenderFrame(struct AudioRender * render,const void * frame,uint64_t requestBytes,uint64_t * replyBytes)402 int32_t AudioProxyRenderRenderFrame(struct AudioRender *render, const void *frame,
403                                     uint64_t requestBytes, uint64_t *replyBytes)
404 {
405     HDF_LOGI("%{public}s, ", __func__);
406     if (frame == NULL || replyBytes == NULL) {
407         HDF_LOGE("Render Frame Paras is NULL!");
408         return AUDIO_HAL_ERR_INVALID_PARAM;
409     }
410     struct HdfSBuf *data = NULL;
411     struct HdfSBuf *reply = NULL;
412     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(render);
413     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
414         HDF_LOGE("The hwRender parameter is null");
415         return AUDIO_HAL_ERR_INVALID_PARAM;
416     }
417     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
418         HDF_LOGE("AudioProxyPreprocessRender FAIL");
419         return AUDIO_HAL_ERR_INTERNAL;
420     }
421     if (!HdfSbufWriteBuffer(data, frame, (uint32_t)requestBytes)) {
422         AudioProxyBufReplyRecycle(data, reply);
423         HDF_LOGE("HdfSbufWriteBuffer FAIL");
424         return AUDIO_HAL_ERR_INTERNAL;
425     }
426     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_RENDER_FRAME, data, reply);
427     if (ret < 0) {
428         if (ret != AUDIO_HAL_ERR_INVALID_OBJECT) {
429             HDF_LOGE("AudioRenderRenderFrame FAIL");
430         }
431         AudioProxyBufReplyRecycle(data, reply);
432         return ret;
433     }
434     *replyBytes = requestBytes;
435     AudioProxyBufReplyRecycle(data, reply);
436     return AUDIO_HAL_SUCCESS;
437 }
438 
AudioProxyRenderGetRenderPosition(struct AudioRender * render,uint64_t * frames,struct AudioTimeStamp * time)439 int32_t AudioProxyRenderGetRenderPosition(struct AudioRender *render, uint64_t *frames, struct AudioTimeStamp *time)
440 {
441     if (frames == NULL || time == NULL) {
442         return AUDIO_HAL_ERR_INVALID_PARAM;
443     }
444     struct HdfSBuf *data = NULL;
445     struct HdfSBuf *reply = NULL;
446     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(render);
447     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
448         HDF_LOGE("hwRender or hwRender->proxyRemoteHandle invalid");
449         return AUDIO_HAL_ERR_INVALID_PARAM;
450     }
451     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
452         HDF_LOGE("AudioProxyPreprocessRender FAIL");
453         return AUDIO_HAL_ERR_INTERNAL;
454     }
455     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle,
456         AUDIO_HDI_RENDER_GET_RENDER_POSITION, data, reply);
457     if (ret < 0) {
458         HDF_LOGE("AudioRenderGetRenderPosition FAIL");
459         AudioProxyBufReplyRecycle(data, reply);
460         return ret;
461     }
462     if (AudioProxyGetMmapPositionRead(reply, frames, time) < 0) {
463         HDF_LOGE("AudioProxyGetMmapPositionRead FAIL");
464         AudioProxyBufReplyRecycle(data, reply);
465         return AUDIO_HAL_ERR_INTERNAL;
466     }
467     AudioProxyBufReplyRecycle(data, reply);
468     return AUDIO_HAL_SUCCESS;
469 }
470 
AudioProxyRenderSetRenderSpeed(struct AudioRender * render,float speed)471 int32_t AudioProxyRenderSetRenderSpeed(struct AudioRender *render, float speed)
472 {
473     (void)speed;
474     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(render);
475     if (hwRender == NULL) {
476         return AUDIO_HAL_ERR_INVALID_PARAM;
477     }
478     return AUDIO_HAL_ERR_NOT_SUPPORT;
479 }
480 
AudioProxyRenderGetRenderSpeed(struct AudioRender * render,float * speed)481 int32_t AudioProxyRenderGetRenderSpeed(struct AudioRender *render, float *speed)
482 {
483     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(render);
484     if (hwRender == NULL || speed == NULL) {
485         return AUDIO_HAL_ERR_INVALID_PARAM;
486     }
487     return AUDIO_HAL_ERR_NOT_SUPPORT;
488 }
489 
AudioProxyRenderSetChannelMode(struct AudioRender * render,AudioChannelMode mode)490 int32_t AudioProxyRenderSetChannelMode(struct AudioRender *render, AudioChannelMode mode)
491 {
492     struct HdfSBuf *data = NULL;
493     struct HdfSBuf *reply = NULL;
494     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(render);
495     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
496         HDF_LOGE("parameter is null");
497         return AUDIO_HAL_ERR_INVALID_PARAM;
498     }
499     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
500         HDF_LOGE("AudioProxyPreprocessRender FAIL");
501         return AUDIO_HAL_ERR_INTERNAL;
502     }
503     uint32_t tempMode = (uint32_t)mode;
504     if (!HdfSbufWriteUint32(data, tempMode)) {
505         AudioProxyBufReplyRecycle(data, reply);
506         return AUDIO_HAL_ERR_INTERNAL;
507     }
508     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_SET_CHANNEL_MODE, data, reply);
509     AudioProxyBufReplyRecycle(data, reply);
510     return ret;
511 }
512 
AudioProxyRenderGetChannelMode(struct AudioRender * render,AudioChannelMode * mode)513 int32_t AudioProxyRenderGetChannelMode(struct AudioRender *render, AudioChannelMode *mode)
514 {
515     if (mode == NULL || render == NULL) {
516         return AUDIO_HAL_ERR_INVALID_PARAM;
517     }
518     struct HdfSBuf *data = NULL;
519     struct HdfSBuf *reply = NULL;
520     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(render);
521     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
522         HDF_LOGE("hwRender or hwRender->proxyRemoteHandle is NULL");
523         return AUDIO_HAL_ERR_INVALID_PARAM;
524     }
525     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
526         HDF_LOGE("AudioProxyPreprocessRender FAIL");
527         return AUDIO_HAL_ERR_INTERNAL;
528     }
529     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_GET_CHANNEL_MODE, data, reply);
530     if (ret < 0) {
531         HDF_LOGE("AudioRenderGetChannelMode FAIL");
532         AudioProxyBufReplyRecycle(data, reply);
533         return ret;
534     }
535     uint32_t tempMode = 0;
536     if (!HdfSbufReadUint32(reply, &tempMode)) {
537         AudioProxyBufReplyRecycle(data, reply);
538         return AUDIO_HAL_ERR_INTERNAL;
539     }
540     *mode = (AudioChannelMode)tempMode;
541     AudioProxyBufReplyRecycle(data, reply);
542     return AUDIO_HAL_SUCCESS;
543 }
544 
AudioProxyRenderSetExtraParams(AudioHandle handle,const char * keyValueList)545 int32_t AudioProxyRenderSetExtraParams(AudioHandle handle, const char *keyValueList)
546 {
547     if (handle == NULL || keyValueList == NULL) {
548         HDF_LOGE("The parameter is empty");
549         return AUDIO_HAL_ERR_INVALID_PARAM;
550     }
551     struct HdfSBuf *data = NULL;
552     struct HdfSBuf *reply = NULL;
553     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(handle);
554     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
555         HDF_LOGE("The parameter is null");
556         return AUDIO_HAL_ERR_INVALID_PARAM;
557     }
558     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
559         return AUDIO_HAL_ERR_INTERNAL;
560     }
561     if (!HdfSbufWriteString(data, keyValueList)) {
562         AudioProxyBufReplyRecycle(data, reply);
563         return AUDIO_HAL_ERR_INTERNAL;
564     }
565     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_SET_EXTRA_PARAMS, data, reply);
566     AudioProxyBufReplyRecycle(data, reply);
567     return ret;
568 }
AudioProxyRenderGetExtraParams(AudioHandle handle,char * keyValueList,int32_t listLenth)569 int32_t AudioProxyRenderGetExtraParams(AudioHandle handle, char *keyValueList, int32_t listLenth)
570 {
571     LOG_PARA_INFO("AudioProxyRenderGetExtraParams enter!");
572     if (handle == NULL || keyValueList == NULL || listLenth <= 0) {
573         return AUDIO_HAL_ERR_INVALID_PARAM;
574     }
575     struct HdfSBuf *data = NULL;
576     struct HdfSBuf *reply = NULL;
577     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(handle);
578     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
579         HDF_LOGE("parameter is null");
580         return AUDIO_HAL_ERR_INVALID_PARAM;
581     }
582     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
583         HDF_LOGE("AudioProxyRenderGetExtraParams FAIL");
584         return AUDIO_HAL_ERR_INTERNAL;
585     }
586     if (!HdfSbufWriteInt32(data, listLenth)) {
587         AudioProxyBufReplyRecycle(data, reply);
588         return AUDIO_HAL_ERR_INTERNAL;
589     }
590     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_GET_EXTRA_PARAMS, data, reply);
591     if (ret < 0) {
592         HDF_LOGE("AudioProxyRenderGetExtraParams FAIL");
593         AudioProxyBufReplyRecycle(data, reply);
594         return ret;
595     }
596     const char *strKeyValueList = NULL;
597     if ((strKeyValueList = HdfSbufReadString(reply)) == NULL) {
598         HDF_LOGE("keyValueList Is empty");
599         AudioProxyBufReplyRecycle(data, reply);
600         return AUDIO_HAL_ERR_INTERNAL;
601     }
602     ret = strncpy_s(keyValueList, listLenth, strKeyValueList, strlen(strKeyValueList));
603     if (ret != 0) {
604         HDF_LOGE("Copy failed!");
605         AudioProxyBufReplyRecycle(data, reply);
606         return AUDIO_HAL_ERR_INTERNAL;
607     }
608     AudioProxyBufReplyRecycle(data, reply);
609     return ret;
610 }
611 
AudioProxyRenderReqMmapBuffer(AudioHandle handle,int32_t reqSize,struct AudioMmapBufferDescriptor * desc)612 int32_t AudioProxyRenderReqMmapBuffer(AudioHandle handle, int32_t reqSize, struct AudioMmapBufferDescriptor *desc)
613 {
614     if (handle == NULL || desc == NULL) {
615         return AUDIO_HAL_ERR_INVALID_PARAM;
616     }
617     struct HdfSBuf *data = NULL;
618     struct HdfSBuf *reply = NULL;
619     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(handle);
620     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
621         HDF_LOGE("hwRender or hwRender->proxyRemoteHandle is NULL");
622         return AUDIO_HAL_ERR_INVALID_PARAM;
623     }
624 
625     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
626         HDF_LOGE("AudioProxyRenderReqMmapBuffer FAIL");
627         return AUDIO_HAL_ERR_INTERNAL;
628     }
629     if (AudioProxyReqMmapBufferWrite(data, reqSize, desc) < 0) {
630         AudioProxyBufReplyRecycle(data, reply);
631         return AUDIO_HAL_ERR_INTERNAL;
632     }
633     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_REQ_MMAP_BUFFER, data, reply);
634     if (ret < 0) {
635         HDF_LOGE("AudioProxyRenderReqMmapBuffer FAIL");
636         AudioProxyBufReplyRecycle(data, reply);
637         return ret;
638     }
639 
640     AudioProxyBufReplyRecycle(data, reply);
641     return ret;
642 }
643 
AudioProxyRenderGetMmapPosition(AudioHandle handle,uint64_t * frames,struct AudioTimeStamp * time)644 int32_t AudioProxyRenderGetMmapPosition(AudioHandle handle, uint64_t *frames, struct AudioTimeStamp *time)
645 {
646     if (handle == NULL || frames == NULL || time == NULL) {
647         return AUDIO_HAL_ERR_INVALID_PARAM;
648     }
649     struct HdfSBuf *data = NULL;
650     struct HdfSBuf *reply = NULL;
651     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(handle);
652     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
653         HDF_LOGE("The parameter is empty");
654         return AUDIO_HAL_ERR_INVALID_PARAM;
655     }
656 
657     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
658         HDF_LOGE("AudioProxyRenderGetMmapPosition FAIL");
659         return AUDIO_HAL_ERR_INTERNAL;
660     }
661     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_GET_MMAP_POSITION, data, reply);
662     if (ret < 0) {
663         AudioProxyBufReplyRecycle(data, reply);
664         HDF_LOGE("AudioProxyRenderGetMmapPosition FAIL");
665         return ret;
666     }
667     if (AudioProxyGetMmapPositionRead(reply, frames, time) < 0) {
668         AudioProxyBufReplyRecycle(data, reply);
669         return AUDIO_HAL_ERR_INTERNAL;
670     }
671     AudioProxyBufReplyRecycle(data, reply);
672     return AUDIO_HAL_SUCCESS;
673 }
674 
AudioProxyRenderTurnStandbyMode(AudioHandle handle)675 int32_t AudioProxyRenderTurnStandbyMode(AudioHandle handle)
676 {
677     if (handle == NULL) {
678         return AUDIO_HAL_ERR_INVALID_PARAM;
679     }
680     struct HdfSBuf *data = NULL;
681     struct HdfSBuf *reply = NULL;
682     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(handle);
683     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
684         HDF_LOGE("parameter is empty");
685         return AUDIO_HAL_ERR_INVALID_PARAM;
686     }
687 
688     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
689         HDF_LOGE("AudioProxyRenderTurnStandbyMode FAIL");
690         return AUDIO_HAL_ERR_INTERNAL;
691     }
692     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_TURN_STAND_BY_MODE, data, reply);
693     if (ret < 0) {
694         HDF_LOGE("AudioProxyRenderTurnStandbyMode FAIL");
695         AudioProxyBufReplyRecycle(data, reply);
696         return ret;
697     }
698     AudioProxyBufReplyRecycle(data, reply);
699     return ret;
700 }
AudioProxyRenderAudioDevDump(AudioHandle handle,int32_t range,int32_t fd)701 int32_t AudioProxyRenderAudioDevDump(AudioHandle handle, int32_t range, int32_t fd)
702 {
703     if (handle == NULL) {
704         return AUDIO_HAL_ERR_INVALID_PARAM;
705     }
706     struct HdfSBuf *data = NULL;
707     struct HdfSBuf *reply = NULL;
708     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(handle);
709     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
710         HDF_LOGE("The hwRender parameter is empty");
711         return AUDIO_HAL_ERR_INVALID_PARAM;
712     }
713     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
714         HDF_LOGE("AudioProxyRenderAudioDevDump FAIL");
715         return AUDIO_HAL_ERR_INTERNAL;
716     }
717     if (!HdfSbufWriteInt32(data, range)) {
718         AudioProxyBufReplyRecycle(data, reply);
719         HDF_LOGE("Write FAIL");
720         return AUDIO_HAL_ERR_INTERNAL;
721     }
722     if (!HdfSbufWriteInt32(data, fd)) {
723         AudioProxyBufReplyRecycle(data, reply);
724         return AUDIO_HAL_ERR_INTERNAL;
725     }
726     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_DEV_DUMP, data, reply);
727     if (ret < 0) {
728         HDF_LOGE("AudioProxyRenderAudioDevDump FAIL");
729         AudioProxyBufReplyRecycle(data, reply);
730         return ret;
731     }
732     AudioProxyBufReplyRecycle(data, reply);
733     return ret;
734 }
AudioProxyRenderRegCallback(struct AudioRender * render,RenderCallback callback,void * cookie)735 int32_t AudioProxyRenderRegCallback(struct AudioRender *render, RenderCallback callback, void *cookie)
736 {
737     if (render == NULL || callback == NULL || cookie == NULL) {
738         return AUDIO_HAL_ERR_INVALID_PARAM;
739     }
740     struct HdfSBuf *data = NULL;
741     struct HdfSBuf *reply = NULL;
742     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(render);
743     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
744         HDF_LOGE("The parameter is empty");
745         return AUDIO_HAL_ERR_INVALID_PARAM;
746     }
747     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
748         HDF_LOGE("AudioProxyRenderRegCallback FAIL");
749         return AUDIO_HAL_ERR_INTERNAL;
750     }
751     uint64_t tempAddr = (uint64_t)(uintptr_t)cookie;
752     if (!HdfSbufWriteUint64(data, tempAddr)) {
753         AudioProxyBufReplyRecycle(data, reply);
754         return AUDIO_HAL_ERR_INTERNAL;
755     }
756     tempAddr = (uint64_t)callback;
757     if (!HdfSbufWriteUint64(data, tempAddr)) {
758         AudioProxyBufReplyRecycle(data, reply);
759         return AUDIO_HAL_ERR_INTERNAL;
760     }
761     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_REG_CALLBACK, data, reply);
762     if (ret < 0) {
763         HDF_LOGE("AudioProxyRenderRegCallback FAIL");
764         AudioProxyBufReplyRecycle(data, reply);
765         return ret;
766     }
767     AudioProxyBufReplyRecycle(data, reply);
768     return ret;
769 }
AudioProxyRenderDrainBuffer(struct AudioRender * render,AudioDrainNotifyType * type)770 int32_t AudioProxyRenderDrainBuffer(struct AudioRender *render, AudioDrainNotifyType *type)
771 {
772     if (render == NULL) {
773         return AUDIO_HAL_ERR_INVALID_PARAM;
774     }
775     struct HdfSBuf *data = NULL;
776     struct HdfSBuf *reply = NULL;
777     struct AudioHwRender *hwRender = reinterpret_cast<struct AudioHwRender *>(render);
778     if (hwRender == NULL || hwRender->proxyRemoteHandle == NULL) {
779         HDF_LOGE("The hwRender parameter is empty");
780         return AUDIO_HAL_ERR_INVALID_PARAM;
781     }
782     if (AudioProxyPreprocessRender(hwRender, &data, &reply) < 0) {
783         HDF_LOGE("AudioProxyRenderDrainBuffer FAIL");
784         return AUDIO_HAL_ERR_INTERNAL;
785     }
786     uint32_t tempType = (uint32_t)(uintptr_t)type;
787     if (!HdfSbufWriteUint32(data, tempType)) {
788         AudioProxyBufReplyRecycle(data, reply);
789         return AUDIO_HAL_ERR_INTERNAL;
790     }
791     int32_t ret = AudioProxyDispatchCall(hwRender->proxyRemoteHandle, AUDIO_HDI_RENDER_DRAIN_BUFFER, data, reply);
792     if (ret < 0) {
793         HDF_LOGE("AudioProxyRenderDrainBuffer FAIL");
794         AudioProxyBufReplyRecycle(data, reply);
795         return ret;
796     }
797     AudioProxyBufReplyRecycle(data, reply);
798     return ret;
799 }
800 }