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