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