• 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_audio_server_render.h"
16 #include "audio_uhdf_log.h"
17 #include "hdf_audio_server_common.h"
18 #include "osal_mutex.h"
19 
20 #define HDF_LOG_TAG HDF_AUDIO_HAL_STUB
21 struct OsalMutex g_renderLock;
22 
GetInitRenderParaAttrs(struct HdfSBuf * data,struct AudioSampleAttributes * attrs)23 static int32_t GetInitRenderParaAttrs(struct HdfSBuf *data, struct AudioSampleAttributes *attrs)
24 {
25     if (data == NULL || attrs == NULL) {
26         return HDF_FAILURE;
27     }
28     uint32_t tempRenderPara = 0;
29     if (!HdfSbufReadUint32(data, &tempRenderPara)) {
30         AUDIO_FUNC_LOGE("read tempRenderPara fail");
31         return HDF_FAILURE;
32     }
33     attrs->type = (enum AudioCategory)tempRenderPara;
34     if (!HdfSbufReadUint32(data, &attrs->period)) {
35         AUDIO_FUNC_LOGE("read period fail");
36         return HDF_FAILURE;
37     }
38     if (!HdfSbufReadUint32(data, &attrs->frameSize)) {
39         AUDIO_FUNC_LOGE("read frameSize fail");
40         return HDF_FAILURE;
41     }
42     if (!HdfSbufReadUint32(data, &attrs->startThreshold)) {
43         AUDIO_FUNC_LOGE("read startThreshold fail");
44         return HDF_FAILURE;
45     }
46     if (!HdfSbufReadUint32(data, &attrs->stopThreshold)) {
47         AUDIO_FUNC_LOGE("read stopThreshold fail");
48         return HDF_FAILURE;
49     }
50     if (!HdfSbufReadUint32(data, &attrs->silenceThreshold)) {
51         AUDIO_FUNC_LOGE("read silenceThreshold fail");
52         return HDF_FAILURE;
53     }
54     if (!HdfSbufReadUint32(data, &tempRenderPara)) {
55         AUDIO_FUNC_LOGE("read bool isBigEndian fail");
56         return HDF_FAILURE;
57     }
58     attrs->isBigEndian = (bool)tempRenderPara;
59     return HDF_SUCCESS;
60 }
61 
GetInitRenderPara(struct HdfSBuf * data,struct AudioDeviceDescriptor * devDesc,struct AudioSampleAttributes * attrs)62 static int32_t GetInitRenderPara(struct HdfSBuf *data, struct AudioDeviceDescriptor *devDesc,
63     struct AudioSampleAttributes *attrs)
64 {
65     if (data == NULL || devDesc == NULL || attrs == NULL) {
66         return HDF_FAILURE;
67     }
68     uint32_t tempRenderPara = 0;
69     if (!HdfSbufReadUint32(data, &tempRenderPara)) {
70         AUDIO_FUNC_LOGE("read attrs format fail");
71         return HDF_FAILURE;
72     }
73     attrs->format = (enum AudioFormat)tempRenderPara;
74     if (!HdfSbufReadUint32(data, &attrs->channelCount)) {
75         AUDIO_FUNC_LOGE("read channelCount fail");
76         return HDF_FAILURE;
77     }
78     if (!HdfSbufReadUint32(data, &attrs->sampleRate)) {
79         AUDIO_FUNC_LOGE("read sampleRate fail");
80         return HDF_FAILURE;
81     }
82     if (!HdfSbufReadUint32(data, &tempRenderPara)) {
83         AUDIO_FUNC_LOGE("read attrs interleaved fail");
84         return HDF_FAILURE;
85     }
86     attrs->interleaved = (bool)tempRenderPara;
87     if (GetInitRenderParaAttrs(data, attrs) < 0) {
88         return HDF_FAILURE;
89     }
90     if (!HdfSbufReadUint32(data, &tempRenderPara)) {
91         AUDIO_FUNC_LOGE("read attrs isSignedData fail");
92         return HDF_FAILURE;
93     }
94     attrs->isSignedData = (bool)tempRenderPara;
95     if (!HdfSbufReadUint32(data, &devDesc->portId)) {
96         AUDIO_FUNC_LOGE("read portId fail");
97         return HDF_FAILURE;
98     }
99     if (!HdfSbufReadUint32(data, &tempRenderPara)) {
100         AUDIO_FUNC_LOGE("read tempRenderPara fail");
101         return HDF_FAILURE;
102     }
103     devDesc->pins = (enum AudioPortPin)tempRenderPara;
104     devDesc->desc = NULL;
105     return HDF_SUCCESS;
106 }
107 
HdiServiceCreatRender(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)108 int32_t HdiServiceCreatRender(const struct HdfDeviceIoClient *client,
109     struct HdfSBuf *data, struct HdfSBuf *reply)
110 {
111     if (client == NULL || data == NULL || reply == NULL) {
112         return AUDIO_HAL_ERR_INVALID_PARAM;
113     }
114     struct AudioAdapter *adapter = NULL;
115     struct AudioDeviceDescriptor devDesc;
116     struct AudioSampleAttributes attrs;
117     struct AudioRender *render = NULL;
118     const char *adapterName = NULL;
119     uint32_t renderPid = 0;
120     if ((adapterName = HdfSbufReadString(data)) == NULL) {
121         AUDIO_FUNC_LOGE("adapterNameCase Is NULL");
122         return AUDIO_HAL_ERR_INVALID_PARAM;
123     }
124     if (!HdfSbufReadUint32(data, &renderPid)) {
125         return AUDIO_HAL_ERR_INTERNAL;
126     }
127     int32_t ret = GetInitRenderPara(data, &devDesc, &attrs);
128     if (ret < 0) {
129         AUDIO_FUNC_LOGE("GetInitRenderPara fail");
130         return AUDIO_HAL_ERR_INTERNAL;
131     }
132     if (AudioAdapterListGetAdapter(adapterName, &adapter) < 0) {
133         AUDIO_FUNC_LOGE("fail");
134         return AUDIO_HAL_ERR_INTERNAL;
135     }
136     if (adapter == NULL) {
137         AUDIO_FUNC_LOGE("adapter is NULL!");
138         return AUDIO_HAL_ERR_INVALID_PARAM;
139     }
140     const int32_t priority = attrs.type;
141     ret = AudioCreatRenderCheck(adapterName, priority);
142     if (ret < 0) {
143         AUDIO_FUNC_LOGE("AudioCreatRenderCheck: Render is working can not replace!");
144         return ret;
145     }
146     if (adapter->CreateRender == NULL) {
147         AUDIO_FUNC_LOGE("CreateRender is NULL");
148         return AUDIO_HAL_ERR_INTERNAL;
149     }
150     ret = adapter->CreateRender(adapter, &devDesc, &attrs, &render);
151     if (render == NULL || ret < 0) {
152         AUDIO_FUNC_LOGE("Failed to CreateRender");
153         return AUDIO_HAL_ERR_INTERNAL;
154     }
155     if (AudioAddRenderInfoInAdapter(adapterName, render, adapter, priority, renderPid)) {
156         AUDIO_FUNC_LOGE("AudioAddRenderInfoInAdapter");
157         adapter->DestroyRender(adapter, render);
158         return AUDIO_HAL_ERR_INTERNAL;
159     }
160     OsalMutexInit(&g_renderLock);
161     return AUDIO_HAL_SUCCESS;
162 }
163 
HdiServiceRenderDestory(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)164 int32_t HdiServiceRenderDestory(const struct HdfDeviceIoClient *client,
165     struct HdfSBuf *data, struct HdfSBuf *reply)
166 {
167     if (client == NULL || data == NULL || reply == NULL) {
168         return AUDIO_HAL_ERR_INVALID_PARAM;
169     }
170     struct AudioAdapter *adapter = NULL;
171     struct AudioRender *render = NULL;
172     const char *adapterName = NULL;
173     uint32_t pid = 0;
174 
175     OsalMutexDestroy(&g_renderLock);
176     if (HdiServiceRenderCaptureReadData(data, &adapterName, &pid) < 0) {
177         return AUDIO_HAL_ERR_INTERNAL;
178     }
179     int32_t ret = AudioAdapterListGetRender(adapterName, &render, pid);
180     if (ret < 0) {
181         return ret;
182     }
183     ret = AudioAdapterListGetAdapterRender(adapterName, &adapter, &render);
184     if (ret < 0) {
185         return ret;
186     }
187     if (adapter == NULL || render == NULL) {
188         return AUDIO_HAL_ERR_INVALID_PARAM;
189     }
190     if (adapter->DestroyRender == NULL) {
191         AUDIO_FUNC_LOGE("DestroyRender is NULL");
192         return AUDIO_HAL_ERR_INTERNAL;
193     }
194     ret = adapter->DestroyRender(adapter, render);
195     if (ret < 0) {
196         AUDIO_FUNC_LOGE("DestroyRender failed!");
197         return ret;
198     }
199     if (AudioDestroyRenderInfoInAdapter(adapterName) < 0) {
200         return AUDIO_HAL_ERR_INTERNAL;
201     }
202     return AUDIO_HAL_SUCCESS;
203 }
204 
HdiServiceRenderStart(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)205 int32_t HdiServiceRenderStart(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
206 {
207     if (client == NULL || data == NULL || reply == NULL) {
208         return AUDIO_HAL_ERR_INVALID_PARAM;
209     }
210     struct AudioRender *render = NULL;
211     int ret = AudioAdapterListCheckAndGetRender(&render, data);
212     if (ret < 0) {
213         return ret;
214     }
215     if (render == NULL || render->control.Start == NULL) {
216         AUDIO_FUNC_LOGE("render or Start is NULL");
217         return AUDIO_HAL_ERR_INTERNAL;
218     }
219     return render->control.Start((AudioHandle)render);
220 }
221 
HdiServiceRenderStop(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)222 int32_t HdiServiceRenderStop(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
223 {
224     if (client == NULL || data == NULL || reply == NULL) {
225         return AUDIO_HAL_ERR_INVALID_PARAM;
226     }
227     struct AudioRender *render = NULL;
228     int ret = AudioAdapterListCheckAndGetRender(&render, data);
229     if (ret < 0) {
230         return ret;
231     }
232     if (render == NULL || render->control.Stop == NULL) {
233         AUDIO_FUNC_LOGE("render or Stop is NULL");
234         return AUDIO_HAL_ERR_INTERNAL;
235     }
236     return render->control.Stop((AudioHandle)render);
237 }
238 
HdiServiceRenderPause(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)239 int32_t HdiServiceRenderPause(const struct HdfDeviceIoClient *client,
240     struct HdfSBuf *data, struct HdfSBuf *reply)
241 {
242     if (client == NULL || data == NULL || reply == NULL) {
243         return AUDIO_HAL_ERR_INVALID_PARAM;
244     }
245     struct AudioRender *render = NULL;
246     int ret = AudioAdapterListCheckAndGetRender(&render, data);
247     if (ret < 0) {
248         return ret;
249     }
250     if (render == NULL || render->control.Pause == NULL) {
251         AUDIO_FUNC_LOGE("render or Pause is NULL");
252         return AUDIO_HAL_ERR_INTERNAL;
253     }
254     return render->control.Pause((AudioHandle)render);
255 }
256 
HdiServiceRenderResume(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)257 int32_t HdiServiceRenderResume(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
258 {
259     if (client == NULL || data == NULL || reply == NULL) {
260         return AUDIO_HAL_ERR_INVALID_PARAM;
261     }
262     struct AudioRender *render = NULL;
263     int ret = AudioAdapterListCheckAndGetRender(&render, data);
264     if (ret < 0) {
265         return ret;
266     }
267     if (render == NULL || render->control.Resume == NULL) {
268         AUDIO_FUNC_LOGE("render or Resume is NULL");
269         return AUDIO_HAL_ERR_INTERNAL;
270     }
271     return render->control.Resume((AudioHandle)render);
272 }
273 
HdiServiceRenderFlush(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)274 int32_t HdiServiceRenderFlush(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
275 {
276     if (client == NULL || data == NULL || reply == NULL) {
277         AUDIO_FUNC_LOGE("The parameter is empty");
278         return AUDIO_HAL_ERR_INVALID_PARAM;
279     }
280     struct AudioRender *render = NULL;
281     int ret = AudioAdapterListCheckAndGetRender(&render, data);
282     if (ret < 0) {
283         return ret;
284     }
285     if (render == NULL || render->control.Flush == NULL) {
286         AUDIO_FUNC_LOGE("render or Flush is NULL");
287         return AUDIO_HAL_ERR_INTERNAL;
288     }
289     return render->control.Flush((AudioHandle)render);
290 }
291 
HdiServiceRenderGetFrameSize(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)292 int32_t HdiServiceRenderGetFrameSize(const struct HdfDeviceIoClient *client,
293     struct HdfSBuf *data, struct HdfSBuf *reply)
294 {
295     if (client == NULL || data == NULL || reply == NULL) {
296         return AUDIO_HAL_ERR_INVALID_PARAM;
297     }
298     uint64_t size;
299     struct AudioRender *render = NULL;
300     int ret = AudioAdapterListCheckAndGetRender(&render, data);
301     if (ret < 0) {
302         return ret;
303     }
304     if (render == NULL || render->attr.GetFrameSize == NULL) {
305         AUDIO_FUNC_LOGE("render or GetFrameSize is NULL");
306         return AUDIO_HAL_ERR_INTERNAL;
307     }
308     if (render->attr.GetFrameSize((AudioHandle)render, &size)) {
309         return AUDIO_HAL_ERR_INTERNAL;
310     }
311     if (!HdfSbufWriteUint64(reply, size)) {
312         return AUDIO_HAL_ERR_INTERNAL;
313     }
314     return AUDIO_HAL_SUCCESS;
315 }
316 
HdiServiceRenderGetFrameCount(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)317 int32_t HdiServiceRenderGetFrameCount(const struct HdfDeviceIoClient *client,
318     struct HdfSBuf *data, struct HdfSBuf *reply)
319 {
320     if (client == NULL || data == NULL || reply == NULL) {
321         AUDIO_FUNC_LOGE("client or data or reply is NULL!");
322         return AUDIO_HAL_ERR_INVALID_PARAM;
323     }
324     uint64_t count;
325     struct AudioRender *render = NULL;
326     int ret = AudioAdapterListCheckAndGetRender(&render, data);
327     if (ret < 0) {
328         return ret;
329     }
330     if (render == NULL || render->attr.GetFrameCount == NULL) {
331         AUDIO_FUNC_LOGE("render or GetFrameCount is NULL");
332         return AUDIO_HAL_ERR_INTERNAL;
333     }
334     if (render->attr.GetFrameCount((AudioHandle)render, &count)) {
335         return AUDIO_HAL_ERR_INTERNAL;
336     }
337     if (!HdfSbufWriteUint64(reply, count)) {
338         return AUDIO_HAL_ERR_INTERNAL;
339     }
340     return AUDIO_HAL_SUCCESS;
341 }
342 
HdiServiceRenderSetSampleAttr(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)343 int32_t HdiServiceRenderSetSampleAttr(const struct HdfDeviceIoClient *client,
344     struct HdfSBuf *data, struct HdfSBuf *reply)
345 {
346     if (client == NULL || data == NULL || reply == NULL) {
347         return AUDIO_HAL_ERR_INVALID_PARAM;
348     }
349     int ret;
350     struct AudioSampleAttributes attrs;
351     struct AudioRender *render = NULL;
352     ret = AudioAdapterListCheckAndGetRender(&render, data);
353     if (ret < 0) {
354         return ret;
355     }
356     if (ReadAudioSapmleAttrbutes(data, &attrs) < 0) {
357         return AUDIO_HAL_ERR_INTERNAL;
358     }
359     if (render == NULL || render->attr.SetSampleAttributes == NULL) {
360         AUDIO_FUNC_LOGE("render or SetSampleAttributes is NULL");
361         return AUDIO_HAL_ERR_INTERNAL;
362     }
363     return render->attr.SetSampleAttributes((AudioHandle)render, &attrs);
364 }
365 
HdiServiceRenderGetSampleAttr(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)366 int32_t HdiServiceRenderGetSampleAttr(const struct HdfDeviceIoClient *client,
367     struct HdfSBuf *data, struct HdfSBuf *reply)
368 {
369     if (client == NULL || data == NULL || reply == NULL) {
370         return AUDIO_HAL_ERR_INVALID_PARAM;
371     }
372     struct AudioSampleAttributes attrs;
373     struct AudioRender *render = NULL;
374     int32_t ret = AudioAdapterListCheckAndGetRender(&render, data);
375     if (ret < 0) {
376         return ret;
377     }
378     if (render == NULL || render->attr.GetSampleAttributes == NULL) {
379         AUDIO_FUNC_LOGE("render or GetSampleAttributes is NULL");
380         return AUDIO_HAL_ERR_INTERNAL;
381     }
382     ret = render->attr.GetSampleAttributes((AudioHandle)render, &attrs);
383     if (ret < 0) {
384         return ret;
385     }
386     if (WriteAudioSampleAttributes(reply, &attrs) < 0) {
387         return AUDIO_HAL_ERR_INTERNAL;
388     }
389     return AUDIO_HAL_SUCCESS;
390 }
391 
HdiServiceRenderGetCurChannelId(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)392 int32_t HdiServiceRenderGetCurChannelId(const struct HdfDeviceIoClient *client,
393     struct HdfSBuf *data, struct HdfSBuf *reply)
394 {
395     if (client == NULL || data == NULL || reply == NULL) {
396         return AUDIO_HAL_ERR_INVALID_PARAM;
397     }
398     uint32_t channelId;
399     struct AudioRender *render = NULL;
400     int ret = AudioAdapterListCheckAndGetRender(&render, data);
401     if (ret < 0) {
402         return ret;
403     }
404     if (render == NULL || render->attr.GetCurrentChannelId == NULL) {
405         AUDIO_FUNC_LOGE("render or GetCurrentChannelId is NULL");
406         return AUDIO_HAL_ERR_INTERNAL;
407     }
408     ret = render->attr.GetCurrentChannelId((AudioHandle)render, &channelId);
409     if (ret < 0) {
410         return ret;
411     }
412     if (!HdfSbufWriteUint32(reply, channelId)) {
413         return AUDIO_HAL_ERR_INTERNAL;
414     }
415     return AUDIO_HAL_SUCCESS;
416 }
417 
HdiServiceRenderCheckSceneCapability(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)418 int32_t HdiServiceRenderCheckSceneCapability(const struct HdfDeviceIoClient *client,
419     struct HdfSBuf *data, struct HdfSBuf *reply)
420 {
421     if (client == NULL || data == NULL || reply == NULL) {
422         return AUDIO_HAL_ERR_INVALID_PARAM;
423     }
424     uint32_t temporaryPins = 0;
425     struct AudioSceneDescriptor scene;
426     bool supported = false;
427     struct AudioRender *render = NULL;
428     int ret = AudioAdapterListCheckAndGetRender(&render, data);
429     if (ret < 0) {
430         return ret;
431     }
432     if (!HdfSbufReadUint32(data, &scene.scene.id)) {
433         return AUDIO_HAL_ERR_INTERNAL;
434     }
435     if (!HdfSbufReadUint32(data, &temporaryPins)) {
436         return AUDIO_HAL_ERR_INTERNAL;
437     }
438     scene.desc.pins = (enum AudioPortPin)temporaryPins;
439     if (render == NULL || render->scene.CheckSceneCapability == NULL) {
440         AUDIO_FUNC_LOGE("render or CheckSceneCapability is NULL");
441         return AUDIO_HAL_ERR_INTERNAL;
442     }
443     ret = render->scene.CheckSceneCapability((AudioHandle)render, &scene, &supported);
444     if (ret < 0) {
445         return ret;
446     }
447     uint32_t tempSupported = (uint32_t)supported;
448     if (!HdfSbufWriteUint32(reply, tempSupported)) {
449         return AUDIO_HAL_ERR_INTERNAL;
450     }
451     return AUDIO_HAL_SUCCESS;
452 }
453 
HdiServiceRenderSelectScene(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)454 int32_t HdiServiceRenderSelectScene(const struct HdfDeviceIoClient *client,
455     struct HdfSBuf *data, struct HdfSBuf *reply)
456 {
457     if (client == NULL || data == NULL || reply == NULL) {
458         return AUDIO_HAL_ERR_INVALID_PARAM;
459     }
460     uint32_t tempPins = 0;
461     struct AudioSceneDescriptor scene;
462     struct AudioRender *render = NULL;
463     int ret = AudioAdapterListCheckAndGetRender(&render, data);
464     if (ret < 0) {
465         return ret;
466     }
467     if (!HdfSbufReadUint32(data, &scene.scene.id)) {
468         AUDIO_FUNC_LOGI("Read id Fail");
469         return AUDIO_HAL_ERR_INTERNAL;
470     }
471     if (!HdfSbufReadUint32(data, &tempPins)) {
472         AUDIO_FUNC_LOGI("Read tempPins Fail");
473         return AUDIO_HAL_ERR_INTERNAL;
474     }
475     scene.desc.pins = (enum AudioPortPin)tempPins;
476     if (render == NULL || render->scene.SelectScene == NULL) {
477         AUDIO_FUNC_LOGE("render or SelectScene is NULL");
478         return AUDIO_HAL_ERR_INTERNAL;
479     }
480     return render->scene.SelectScene((AudioHandle)render, &scene);
481 }
482 
HdiServiceRenderGetMute(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)483 int32_t HdiServiceRenderGetMute(const struct HdfDeviceIoClient *client,
484     struct HdfSBuf *data, struct HdfSBuf *reply)
485 {
486     if (client == NULL || data == NULL || reply == NULL) {
487         AUDIO_FUNC_LOGI("parameter is empty");
488         return AUDIO_HAL_ERR_INVALID_PARAM;
489     }
490     bool mute = false;
491     struct AudioRender *render = NULL;
492     int ret = AudioAdapterListCheckAndGetRender(&render, data);
493     if (ret < 0) {
494         return ret;
495     }
496     if (render == NULL || render->volume.GetMute == NULL) {
497         AUDIO_FUNC_LOGE("render or GetMute is NULL");
498         return AUDIO_HAL_ERR_INTERNAL;
499     }
500     ret = render->volume.GetMute((AudioHandle)render, &mute);
501     if (ret < 0) {
502         return ret;
503     }
504     uint32_t tempMute = (uint32_t)mute;
505     if (!HdfSbufWriteUint32(reply, tempMute)) {
506         return AUDIO_HAL_ERR_INTERNAL;
507     }
508     return AUDIO_HAL_SUCCESS;
509 }
510 
HdiServiceRenderSetMute(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)511 int32_t HdiServiceRenderSetMute(const struct HdfDeviceIoClient *client,
512     struct HdfSBuf *data, struct HdfSBuf *reply)
513 {
514     if (client == NULL || data == NULL || reply == NULL) {
515         return AUDIO_HAL_ERR_INVALID_PARAM;
516     }
517     bool mute = false;
518     struct AudioRender *render = NULL;
519     int ret = AudioAdapterListCheckAndGetRender(&render, data);
520     if (ret < 0) {
521         return ret;
522     }
523     uint32_t tempMute = 0;
524     if (!HdfSbufReadUint32(data, &tempMute)) {
525         return AUDIO_HAL_ERR_INTERNAL;
526     }
527     mute = (bool)tempMute;
528     if (render == NULL || render->volume.SetMute == NULL) {
529         AUDIO_FUNC_LOGE("render or SetMute is NULL");
530         return AUDIO_HAL_ERR_INTERNAL;
531     }
532     return render->volume.SetMute((AudioHandle)render, mute);
533 }
534 
HdiServiceRenderSetVolume(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)535 int32_t HdiServiceRenderSetVolume(const struct HdfDeviceIoClient *client,
536     struct HdfSBuf *data, struct HdfSBuf *reply)
537 {
538     if (client == NULL || data == NULL || reply == NULL) {
539         return AUDIO_HAL_ERR_INVALID_PARAM;
540     }
541     uint32_t volume = 0;
542     struct AudioRender *render = NULL;
543     int ret = AudioAdapterListCheckAndGetRender(&render, data);
544     if (ret < 0) {
545         return ret;
546     }
547     if (!HdfSbufReadUint32(data, &volume)) {
548         return AUDIO_HAL_ERR_INTERNAL;
549     }
550     float setVolume = (float)volume / VOLUME_CHANGE;
551     if (render == NULL || render->volume.SetVolume == NULL) {
552         AUDIO_FUNC_LOGE("render or SetVolume is NULL");
553         return AUDIO_HAL_ERR_INTERNAL;
554     }
555     return render->volume.SetVolume((AudioHandle)render, setVolume);
556 }
557 
HdiServiceRenderGetVolume(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)558 int32_t HdiServiceRenderGetVolume(const struct HdfDeviceIoClient *client,
559     struct HdfSBuf *data, struct HdfSBuf *reply)
560 {
561     if (client == NULL || data == NULL || reply == NULL) {
562         return AUDIO_HAL_ERR_INVALID_PARAM;
563     }
564     float volume;
565     struct AudioRender *render = NULL;
566     int ret = AudioAdapterListCheckAndGetRender(&render, data);
567     if (ret < 0) {
568         return ret;
569     }
570     if (render == NULL || render->volume.GetVolume == NULL) {
571         AUDIO_FUNC_LOGE("render or GetVolume is NULL");
572         return AUDIO_HAL_ERR_INTERNAL;
573     }
574     ret = render->volume.GetVolume((AudioHandle)render, &volume);
575     if (ret < 0) {
576         return ret;
577     }
578     uint32_t tempVolume = (uint32_t)(volume * VOLUME_CHANGE);
579     if (!HdfSbufWriteUint32(reply, tempVolume)) {
580         return AUDIO_HAL_ERR_INTERNAL;
581     }
582     return AUDIO_HAL_SUCCESS;
583 }
584 
HdiServiceRenderGetGainThreshold(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)585 int32_t HdiServiceRenderGetGainThreshold(const struct HdfDeviceIoClient *client,
586     struct HdfSBuf *data, struct HdfSBuf *reply)
587 {
588     if (client == NULL || data == NULL || reply == NULL) {
589         return AUDIO_HAL_ERR_INVALID_PARAM;
590     }
591     float min, max;
592     struct AudioRender *render = NULL;
593     int ret = AudioAdapterListCheckAndGetRender(&render, data);
594     if (ret < 0) {
595         return ret;
596     }
597     if (render == NULL || render->volume.GetGainThreshold == NULL) {
598         AUDIO_FUNC_LOGE("render or GetGainThreshold is NULL");
599         return AUDIO_HAL_ERR_INTERNAL;
600     }
601     ret = render->volume.GetGainThreshold((AudioHandle)render, &min, &max);
602     if (ret < 0) {
603         return ret;
604     }
605     uint32_t temporaryMin = (uint32_t)min;
606     if (!HdfSbufWriteUint32(reply, temporaryMin)) {
607         return AUDIO_HAL_ERR_INTERNAL;
608     }
609     uint32_t temporaryMax = (uint32_t)max;
610     if (!HdfSbufWriteUint32(reply, temporaryMax)) {
611         return AUDIO_HAL_ERR_INTERNAL;
612     }
613     return AUDIO_HAL_SUCCESS;
614 }
615 
HdiServiceRenderGetGain(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)616 int32_t HdiServiceRenderGetGain(const struct HdfDeviceIoClient *client,
617     struct HdfSBuf *data, struct HdfSBuf *reply)
618 {
619     if (client == NULL || data == NULL || reply == NULL) {
620         return AUDIO_HAL_ERR_INVALID_PARAM;
621     }
622     float gain;
623     struct AudioRender *render = NULL;
624     int ret = AudioAdapterListCheckAndGetRender(&render, data);
625     if (ret < 0) {
626         return ret;
627     }
628     if (render == NULL || render->volume.GetGain == NULL) {
629         AUDIO_FUNC_LOGE("render or GetGain is NULL");
630         return AUDIO_HAL_ERR_INTERNAL;
631     }
632     ret = render->volume.GetGain((AudioHandle)render, &gain);
633     if (ret < 0) {
634         return ret;
635     }
636     uint32_t tempGain = (uint32_t)gain;
637     if (!HdfSbufWriteUint32(reply, tempGain)) {
638         return AUDIO_HAL_ERR_INTERNAL;
639     }
640     return AUDIO_HAL_SUCCESS;
641 }
642 
HdiServiceRenderSetGain(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)643 int32_t HdiServiceRenderSetGain(const struct HdfDeviceIoClient *client,
644     struct HdfSBuf *data, struct HdfSBuf *reply)
645 {
646     if (client == NULL || data == NULL || reply == NULL) {
647         return AUDIO_HAL_ERR_INVALID_PARAM;
648     }
649     uint32_t tempGain = 0;
650     struct AudioRender *render = NULL;
651     int ret = AudioAdapterListCheckAndGetRender(&render, data);
652     if (ret < 0) {
653         return ret;
654     }
655     if (!HdfSbufReadUint32(data, &tempGain)) {
656         return AUDIO_HAL_ERR_INTERNAL;
657     }
658     if (render == NULL || render->volume.SetGain == NULL) {
659         AUDIO_FUNC_LOGE("render or SetGain is NULL");
660         return AUDIO_HAL_ERR_INTERNAL;
661     }
662     return render->volume.SetGain((AudioHandle)render, (float)tempGain);
663 }
664 
HdiServiceRenderGetLatency(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)665 int32_t HdiServiceRenderGetLatency(const struct HdfDeviceIoClient *client,
666     struct HdfSBuf *data, struct HdfSBuf *reply)
667 {
668     if (client == NULL || data == NULL || reply == NULL) {
669         return AUDIO_HAL_ERR_INVALID_PARAM;
670     }
671     uint32_t ms;
672     struct AudioRender *render = NULL;
673     int ret = AudioAdapterListCheckAndGetRender(&render, data);
674     if (ret < 0) {
675         return ret;
676     }
677     if (render == NULL || render->GetLatency == NULL) {
678         AUDIO_FUNC_LOGE("render or GetLatency is NULL");
679         return AUDIO_HAL_ERR_INTERNAL;
680     }
681     ret = render->GetLatency((AudioHandle)render, &ms);
682     if (ret < 0) {
683         return ret;
684     }
685     if (!HdfSbufWriteUint32(reply, ms)) {
686         return AUDIO_HAL_ERR_INTERNAL;
687     }
688     return AUDIO_HAL_SUCCESS;
689 }
690 
HdiServiceRenderRenderFrame(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)691 int32_t HdiServiceRenderRenderFrame(const struct HdfDeviceIoClient *client,
692     struct HdfSBuf *data, struct HdfSBuf *reply)
693 {
694     if (client == NULL || data == NULL || reply == NULL) {
695         return AUDIO_HAL_ERR_INVALID_PARAM;
696     }
697     char *frame = NULL;
698     uint32_t requestBytes = 0;
699     uint64_t replyBytes = 0;
700     struct AudioRender *render = NULL;
701     const char *adapterName = NULL;
702     uint32_t pid = 0;
703     if (HdiServiceRenderCaptureReadData(data, &adapterName, &pid) < 0) {
704         AUDIO_FUNC_LOGE("HdiServiceRenderCaptureReadData fail!");
705         return AUDIO_HAL_ERR_INTERNAL;
706     }
707     int32_t ret = AudioAdapterListGetRender(adapterName, &render, pid);
708     if (ret < 0) {
709         AUDIO_FUNC_LOGE("AudioAdapterListGetRender fail");
710         return ret;
711     }
712     ret = AudioGetRenderStatus(adapterName);
713     if (ret < 0) {
714         AUDIO_FUNC_LOGE("AudioGetRenderStatus fail");
715         return ret;
716     }
717     if (!HdfSbufReadBuffer(data, (const void **)&frame, &requestBytes)) {
718         AUDIO_FUNC_LOGE("AudioAdapterListGetRender:HdfSbufReadBuffer fail");
719         return AUDIO_HAL_ERR_INTERNAL;
720     }
721     AudioSetRenderStatus(adapterName, true);
722     (void)OsalMutexLock(&g_renderLock);
723     if (render == NULL || render->RenderFrame == NULL) {
724         AUDIO_FUNC_LOGE("render or RenderFrame is NULL");
725         return AUDIO_HAL_ERR_INTERNAL;
726     }
727     ret = render->RenderFrame((AudioHandle)render, (const void *)frame, (uint64_t)requestBytes, &replyBytes);
728     (void)OsalMutexUnlock(&g_renderLock);
729     AudioSetRenderStatus(adapterName, false);
730     if (ret < 0) {
731         AUDIO_FUNC_LOGE("HdiServiceRenderRenderFrame fail");
732         return ret;
733     }
734     return AUDIO_HAL_SUCCESS;
735 }
736 
HdiServiceRenderGetRenderPosition(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)737 int32_t HdiServiceRenderGetRenderPosition(const struct HdfDeviceIoClient *client,
738     struct HdfSBuf *data, struct HdfSBuf *reply)
739 {
740     if (client == NULL || data == NULL || reply == NULL) {
741         return AUDIO_HAL_ERR_INVALID_PARAM;
742     }
743     struct AudioTimeStamp time;
744     struct AudioRender *render = NULL;
745     uint64_t frames;
746     int ret = AudioAdapterListCheckAndGetRender(&render, data);
747     if (ret < 0) {
748         return ret;
749     }
750     (void)OsalMutexLock(&g_renderLock);
751     if (render == NULL || render->GetRenderPosition == NULL) {
752         AUDIO_FUNC_LOGE("render or GetRenderPosition is NULL");
753         return AUDIO_HAL_ERR_INTERNAL;
754     }
755     ret = render->GetRenderPosition((AudioHandle)render, &frames, &time);
756     (void)OsalMutexUnlock(&g_renderLock);
757     if (ret < 0) {
758         return ret;
759     }
760     ret = HdiServicePositionWrite(reply, frames, time);
761     if (ret < 0) {
762         return AUDIO_HAL_ERR_INTERNAL;
763     }
764     return AUDIO_HAL_SUCCESS;
765 }
766 
HdiServiceRenderGetSpeed(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)767 int32_t HdiServiceRenderGetSpeed(const struct HdfDeviceIoClient *client,
768     struct HdfSBuf *data, struct HdfSBuf *reply)
769 {
770     if (client == NULL || data == NULL || reply == NULL) {
771         return AUDIO_HAL_ERR_INVALID_PARAM;
772     }
773     float speed;
774     struct AudioRender *render = NULL;
775     int ret = AudioAdapterListCheckAndGetRender(&render, data);
776     if (ret < 0) {
777         return ret;
778     }
779     if (render == NULL || render->GetRenderSpeed == NULL) {
780         AUDIO_FUNC_LOGE("render or GetRenderSpeed is NULL");
781         return AUDIO_HAL_ERR_INTERNAL;
782     }
783     ret = render->GetRenderSpeed((AudioHandle)render, &speed);
784     if (ret < 0) {
785         return ret;
786     }
787     uint64_t tempSpeed = (uint64_t)speed;
788     if (!HdfSbufWriteUint64(reply, tempSpeed)) {
789         return AUDIO_HAL_ERR_INTERNAL;
790     }
791     return AUDIO_HAL_SUCCESS;
792 }
793 
HdiServiceRenderSetSpeed(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)794 int32_t HdiServiceRenderSetSpeed(const struct HdfDeviceIoClient *client,
795     struct HdfSBuf *data, struct HdfSBuf *reply)
796 {
797     if (client == NULL || data == NULL || reply == NULL) {
798         return AUDIO_HAL_ERR_INVALID_PARAM;
799     }
800     uint64_t speed = 0;
801     struct AudioRender *render = NULL;
802     int ret = AudioAdapterListCheckAndGetRender(&render, data);
803     if (ret < 0) {
804         return ret;
805     }
806     if (!HdfSbufReadUint64(data, &speed)) {
807         return AUDIO_HAL_ERR_INTERNAL;
808     }
809     if (render == NULL || render->SetRenderSpeed == NULL) {
810         AUDIO_FUNC_LOGE("render or SetRenderSpeed is NULL");
811         return AUDIO_HAL_ERR_INTERNAL;
812     }
813     return render->SetRenderSpeed((AudioHandle)render, (float)speed);
814 }
815 
HdiServiceRenderSetChannelMode(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)816 int32_t HdiServiceRenderSetChannelMode(const struct HdfDeviceIoClient *client,
817     struct HdfSBuf *data, struct HdfSBuf *reply)
818 {
819     if (client == NULL || data == NULL || reply == NULL) {
820         return AUDIO_HAL_ERR_INVALID_PARAM;
821     }
822     enum AudioChannelMode mode;
823     struct AudioRender *render = NULL;
824     int ret = AudioAdapterListCheckAndGetRender(&render, data);
825     if (ret < 0) {
826         AUDIO_FUNC_LOGE("AudioAdapterListCheckAndGetRender failed.");
827         return ret;
828     }
829     uint32_t tempMode = 0;
830     if (!HdfSbufReadUint32(data, &tempMode)) {
831         return AUDIO_HAL_ERR_INTERNAL;
832     }
833     mode = (enum AudioChannelMode)tempMode;
834     if (render == NULL || render->SetChannelMode == NULL) {
835         AUDIO_FUNC_LOGE("render or SetChannelMode is NULL");
836         return AUDIO_HAL_ERR_INTERNAL;
837     }
838     return render->SetChannelMode((AudioHandle)render, mode);
839 }
840 
HdiServiceRenderGetChannelMode(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)841 int32_t HdiServiceRenderGetChannelMode(const struct HdfDeviceIoClient *client,
842     struct HdfSBuf *data, struct HdfSBuf *reply)
843 {
844     if (client == NULL || data == NULL || reply == NULL) {
845         return AUDIO_HAL_ERR_INVALID_PARAM;
846     }
847     enum AudioChannelMode mode;
848     struct AudioRender *render = NULL;
849     int ret = AudioAdapterListCheckAndGetRender(&render, data);
850     if (ret < 0) {
851         AUDIO_FUNC_LOGE("CheckAndGetRender failed.");
852         return ret;
853     }
854     if (render == NULL || render->GetChannelMode == NULL) {
855         AUDIO_FUNC_LOGE("render or GetChannelMode is NULL");
856         return AUDIO_HAL_ERR_INTERNAL;
857     }
858     ret = render->GetChannelMode((AudioHandle)render, &mode);
859     if (ret < 0) {
860         return ret;
861     }
862     uint32_t tempMode = (uint32_t)mode;
863     if (!HdfSbufWriteUint32(reply, tempMode)) {
864         return AUDIO_HAL_ERR_INTERNAL;
865     }
866     return AUDIO_HAL_SUCCESS;
867 }
868 
HdiServiceRenderSetExtraParams(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)869 int32_t HdiServiceRenderSetExtraParams(const struct HdfDeviceIoClient *client,
870     struct HdfSBuf *data, struct HdfSBuf *reply)
871 {
872     if (client == NULL || data == NULL || reply == NULL) {
873         return AUDIO_HAL_ERR_INVALID_PARAM;
874     }
875     struct AudioRender *render = NULL;
876     int32_t ret = AudioAdapterListCheckAndGetRender(&render, data);
877     if (ret < 0) {
878         return ret;
879     }
880     const char *keyValueList = NULL;
881     if ((keyValueList = HdfSbufReadString(data)) == NULL) {
882         AUDIO_FUNC_LOGE("keyValueList Is NULL");
883         return AUDIO_HAL_ERR_INTERNAL;
884     }
885     if (render == NULL || render->attr.SetExtraParams == NULL) {
886         AUDIO_FUNC_LOGE("render or SetExtraParams is NULL");
887         return AUDIO_HAL_ERR_INTERNAL;
888     }
889     return render->attr.SetExtraParams((AudioHandle)render, keyValueList);
890 }
891 
HdiServiceRenderGetExtraParams(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)892 int32_t HdiServiceRenderGetExtraParams(const struct HdfDeviceIoClient *client,
893     struct HdfSBuf *data, struct HdfSBuf *reply)
894 {
895     if (client == NULL || data == NULL || reply == NULL) {
896         return AUDIO_HAL_ERR_INVALID_PARAM;
897     }
898     int32_t listLenth = 0;
899     struct AudioRender *render = NULL;
900     int ret = AudioAdapterListCheckAndGetRender(&render, data);
901     if (ret < 0) {
902         return ret;
903     }
904     if (!HdfSbufReadInt32(data, &listLenth)) {
905         return AUDIO_HAL_ERR_INTERNAL;
906     }
907     if (listLenth <= 0 || listLenth > STR_MAX - 1) {
908         return AUDIO_HAL_ERR_INTERNAL;
909     }
910     char keyValueList[STR_MAX] = { 0 };
911     if (render == NULL || render->attr.GetExtraParams == NULL) {
912         AUDIO_FUNC_LOGE("render or GetExtraParams is NULL");
913         return AUDIO_HAL_ERR_INTERNAL;
914     }
915     ret = render->attr.GetExtraParams((AudioHandle)render, keyValueList, listLenth);
916     if (ret < 0) {
917         return ret;
918     }
919     if (!HdfSbufWriteString(reply, keyValueList)) {
920         return AUDIO_HAL_ERR_INTERNAL;
921     }
922     return AUDIO_HAL_SUCCESS;
923 }
924 
HdiServiceRenderReqMmapBuffer(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)925 int32_t HdiServiceRenderReqMmapBuffer(const struct HdfDeviceIoClient *client,
926     struct HdfSBuf *data, struct HdfSBuf *reply)
927 {
928     if (client == NULL || data == NULL || reply == NULL) {
929         return AUDIO_HAL_ERR_INVALID_PARAM;
930     }
931     struct AudioMmapBufferDescripter desc;
932     int32_t reqSize = 0;
933     struct AudioRender *render = NULL;
934     int ret = AudioAdapterListCheckAndGetRender(&render, data);
935     if (ret < 0) {
936         return ret;
937     }
938     if (!HdfSbufReadInt32(data, &reqSize)) {
939         return AUDIO_HAL_ERR_INTERNAL;
940     }
941     if (HdiServiceReqMmapBuffer(&desc, data) < 0) {
942         return AUDIO_HAL_ERR_INTERNAL;
943     }
944     if (render == NULL || render->attr.ReqMmapBuffer == NULL) {
945         AUDIO_FUNC_LOGE("render or ReqMmapBuffer is NULL");
946         return AUDIO_HAL_ERR_INTERNAL;
947     }
948     return render->attr.ReqMmapBuffer((AudioHandle)render, reqSize, &desc);
949 }
950 
HdiServiceRenderGetMmapPosition(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)951 int32_t HdiServiceRenderGetMmapPosition(const struct HdfDeviceIoClient *client,
952     struct HdfSBuf *data, struct HdfSBuf *reply)
953 {
954     AUDIO_FUNC_LOGD("enter");
955     if (client == NULL || data == NULL || reply == NULL) {
956         return AUDIO_HAL_ERR_INVALID_PARAM;
957     }
958     uint64_t frames;
959     struct AudioTimeStamp time;
960     struct AudioRender *render = NULL;
961     int ret = AudioAdapterListCheckAndGetRender(&render, data);
962     if (ret < 0) {
963         return ret;
964     }
965     if (render == NULL || render->attr.GetMmapPosition == NULL) {
966         AUDIO_FUNC_LOGE("render or GetMmapPosition is NULL");
967         return AUDIO_HAL_ERR_INTERNAL;
968     }
969     ret = render->attr.GetMmapPosition((AudioHandle)render, &frames, &time);
970     if (ret < 0) {
971         return ret;
972     }
973     if (HdiServicePositionWrite(reply, frames, time) < 0) {
974         return AUDIO_HAL_ERR_INTERNAL;
975     }
976     AUDIO_FUNC_LOGD("out");
977     return AUDIO_HAL_SUCCESS;
978 }
979 
HdiServiceRenderAddEffect(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)980 int32_t HdiServiceRenderAddEffect(const struct HdfDeviceIoClient *client,
981     struct HdfSBuf *data, struct HdfSBuf *reply)
982 {
983     (void)client;
984     (void)reply;
985     uint64_t effectid = 0;
986     struct AudioRender *render = NULL;
987     if (data == NULL) {
988         return AUDIO_HAL_ERR_INVALID_PARAM;
989     }
990 
991     int32_t ret = AudioAdapterListCheckAndGetRender(&render, data);
992     if (ret < 0 || render == NULL) {
993         AUDIO_FUNC_LOGE("render is null or ret = %{public}d", ret);
994         return ret;
995     }
996 
997     if (!HdfSbufReadUint64(data, &effectid)) {
998         AUDIO_FUNC_LOGE("HdfSbufReadUint64 failed.");
999         return HDF_FAILURE;
1000     }
1001 
1002     if (render->attr.AddAudioEffect == NULL) {
1003         AUDIO_FUNC_LOGE("AddAudioEffect is NULL");
1004         return AUDIO_HAL_ERR_INTERNAL;
1005     }
1006     return render->attr.AddAudioEffect((AudioHandle)render, effectid);
1007 }
1008 
HdiServiceRenderRemoveEffect(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)1009 int32_t HdiServiceRenderRemoveEffect(const struct HdfDeviceIoClient *client,
1010     struct HdfSBuf *data, struct HdfSBuf *reply)
1011 {
1012     (void)client;
1013     (void)reply;
1014     uint64_t effectid = 0;
1015     if (data == NULL) {
1016         return AUDIO_HAL_ERR_INVALID_PARAM;
1017     }
1018 
1019     struct AudioRender *render = NULL;
1020     int32_t ret = AudioAdapterListCheckAndGetRender(&render, data);
1021     if (ret < 0 || render == NULL) {
1022         AUDIO_FUNC_LOGE("render is NULL or ret = %{public}d", ret);
1023         return ret;
1024     }
1025 
1026     if (!HdfSbufReadUint64(data, &effectid)) {
1027         AUDIO_FUNC_LOGE("read buf fail ");
1028         return HDF_FAILURE;
1029     }
1030 
1031     if (render->attr.RemoveAudioEffect == NULL) {
1032         AUDIO_FUNC_LOGE("RemoveAudioEffect is NULL");
1033         return AUDIO_HAL_ERR_INTERNAL;
1034     }
1035     return render->attr.RemoveAudioEffect((AudioHandle)render, effectid);
1036 }
1037 
HdiServiceRenderTurnStandbyMode(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)1038 int32_t HdiServiceRenderTurnStandbyMode(const struct HdfDeviceIoClient *client,
1039     struct HdfSBuf *data, struct HdfSBuf *reply)
1040 {
1041     if (client == NULL || data == NULL || reply == NULL) {
1042         AUDIO_FUNC_LOGE("The pointer is null");
1043         return AUDIO_HAL_ERR_INVALID_PARAM;
1044     }
1045     struct AudioRender *render = NULL;
1046     int ret = AudioAdapterListCheckAndGetRender(&render, data);
1047     if (ret < 0) {
1048         return ret;
1049     }
1050     if (render == NULL || render->control.Stop == NULL) {
1051         AUDIO_FUNC_LOGE("render or Stop is NULL");
1052         return AUDIO_HAL_ERR_INTERNAL;
1053     }
1054     return render->control.Stop((AudioHandle)render);
1055 }
1056 
HdiServiceRenderDevDump(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)1057 int32_t HdiServiceRenderDevDump(const struct HdfDeviceIoClient *client,
1058     struct HdfSBuf *data, struct HdfSBuf *reply)
1059 {
1060     if (client == NULL || data == NULL || reply == NULL) {
1061         return AUDIO_HAL_ERR_INVALID_PARAM;
1062     }
1063     int32_t range = 0;
1064     struct AudioRender *render = NULL;
1065     int ret = AudioAdapterListCheckAndGetRender(&render, data);
1066     if (ret < 0) {
1067         return ret;
1068     }
1069     if (!HdfSbufReadInt32(data, &range)) {
1070         return AUDIO_HAL_ERR_INTERNAL;
1071     }
1072     ret = HdfSbufReadFileDescriptor(data);
1073     if (ret < 0) {
1074         return AUDIO_HAL_ERR_INTERNAL;
1075     }
1076     int32_t fd = ret;
1077     if (render == NULL || render->control.AudioDevDump == NULL) {
1078         AUDIO_FUNC_LOGE("render or AudioDevDump is NULL");
1079         return AUDIO_HAL_ERR_INTERNAL;
1080     }
1081     return render->control.AudioDevDump((AudioHandle)render, range, fd);
1082 }
1083 
HdiServiceRenderRegCallback(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)1084 int32_t HdiServiceRenderRegCallback(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
1085 {
1086     if (client == NULL || data == NULL || reply == NULL) {
1087         return AUDIO_HAL_ERR_INVALID_PARAM;
1088     }
1089     struct AudioRender *render = NULL;
1090     int ret = AudioAdapterListCheckAndGetRender(&render, data);
1091     if (ret < 0) {
1092         return ret;
1093     }
1094     void *cookie;
1095     RenderCallback pCallback;
1096     uint64_t tempAddr = 0;
1097     if (!HdfSbufReadUint64(data, &tempAddr)) {
1098         AUDIO_FUNC_LOGE("read cookie Is NULL");
1099         return AUDIO_HAL_ERR_INTERNAL;
1100     }
1101     cookie = (void *)(uintptr_t)tempAddr;
1102     if (!HdfSbufReadUint64(data, &tempAddr)) {
1103         AUDIO_FUNC_LOGE("read callback pointer Is NULL");
1104         return AUDIO_HAL_ERR_INTERNAL;
1105     }
1106     pCallback = (RenderCallback)(uintptr_t)tempAddr;
1107     if (render == NULL || render->RegCallback == NULL) {
1108         AUDIO_FUNC_LOGE("render or RegCallback is NULL");
1109         return AUDIO_HAL_ERR_INTERNAL;
1110     }
1111     return render->RegCallback((AudioHandle)render, pCallback, cookie);
1112 }
1113 
HdiServiceRenderDrainBuffer(const struct HdfDeviceIoClient * client,struct HdfSBuf * data,struct HdfSBuf * reply)1114 int32_t HdiServiceRenderDrainBuffer(const struct HdfDeviceIoClient *client, struct HdfSBuf *data, struct HdfSBuf *reply)
1115 {
1116     if (client == NULL || data == NULL || reply == NULL) {
1117         return AUDIO_HAL_ERR_INVALID_PARAM;
1118     }
1119     struct AudioRender *render = NULL;
1120     int ret = AudioAdapterListCheckAndGetRender(&render, data);
1121     if (ret < 0) {
1122         return ret;
1123     }
1124     enum AudioDrainNotifyType type;
1125     uint32_t tempType = 0;
1126     if (!HdfSbufReadUint32(data, &tempType)) {
1127         return AUDIO_HAL_ERR_INTERNAL;
1128     }
1129     type = (enum AudioDrainNotifyType)tempType;
1130     if (render == NULL || render->DrainBuffer == NULL) {
1131         AUDIO_FUNC_LOGE("render or DrainBuffer is NULL");
1132         return AUDIO_HAL_ERR_INTERNAL;
1133     }
1134     return render->DrainBuffer((AudioHandle)render, &type);
1135 }
1136 
1137