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