1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "audio_interface_lib_common.h"
17 #include "audio_uhdf_log.h"
18
19 #define HDF_LOG_TAG HDF_AUDIO_HAL_LIB
20
HdfIoServiceBindName(const char * serviceName)21 struct HdfIoService *HdfIoServiceBindName(const char *serviceName)
22 {
23 if (serviceName == NULL) {
24 AUDIO_FUNC_LOGE("service name NULL!");
25 return NULL;
26 }
27 if (strcmp(serviceName, "hdf_audio_control") == 0) {
28 return (HdfIoServiceBind("hdf_audio_control"));
29 }
30 if (strcmp(serviceName, "hdf_audio_render") == 0) {
31 return (HdfIoServiceBind("hdf_audio_render"));
32 }
33 if (strcmp(serviceName, "hdf_audio_capture") == 0) {
34 return (HdfIoServiceBind("hdf_audio_capture"));
35 }
36 AUDIO_FUNC_LOGE("service name not support!");
37 return NULL;
38 }
39
AudioBufReplyRecycle(struct HdfSBuf * sBuf,struct HdfSBuf * reply)40 void AudioBufReplyRecycle(struct HdfSBuf *sBuf, struct HdfSBuf *reply)
41 {
42 if (sBuf != NULL) {
43 HdfSbufRecycle(sBuf);
44 sBuf = NULL;
45 }
46 if (reply != NULL) {
47 HdfSbufRecycle(reply);
48 reply = NULL;
49 }
50 }
51
AudioSbufRecycle(struct HdfSBuf * sBuf)52 void AudioSbufRecycle(struct HdfSBuf *sBuf)
53 {
54 if (sBuf != NULL) {
55 HdfSbufRecycle(sBuf);
56 sBuf = NULL;
57 }
58 }
59
AudioServiceDispatch(struct HdfIoService * service,int cmdId,struct HdfSBuf * sBuf,struct HdfSBuf * reply)60 int32_t AudioServiceDispatch(struct HdfIoService *service,
61 int cmdId, struct HdfSBuf *sBuf, struct HdfSBuf *reply)
62 {
63 if (service == NULL || service->dispatcher == NULL ||
64 service->dispatcher->Dispatch == NULL || sBuf == NULL) {
65 AUDIO_FUNC_LOGE("param is null!");
66 return HDF_FAILURE;
67 }
68
69 return service->dispatcher->Dispatch(&(service->object), cmdId, sBuf, reply);
70 }
71
AudioObtainHdfSBuf(void)72 struct HdfSBuf *AudioObtainHdfSBuf(void)
73 {
74 #ifdef AUDIO_HDF_SBUF_IPC
75 return HdfSbufTypedObtain(SBUF_IPC);
76 #else
77 return HdfSbufTypedObtain(SBUF_RAW);
78 #endif
79 }
80
AudioCtlGetVolThresholdRead(struct HdfSBuf * reply,struct AudioCtrlElemInfo * volThreshold)81 int32_t AudioCtlGetVolThresholdRead(struct HdfSBuf *reply, struct AudioCtrlElemInfo *volThreshold)
82 {
83 if (reply == NULL || volThreshold == NULL) {
84 AUDIO_FUNC_LOGE("reply or volThreshold is null!");
85 return HDF_FAILURE;
86 }
87 if (!HdfSbufReadInt32(reply, &volThreshold->type)) {
88 AUDIO_FUNC_LOGE("Failed to Get Volume sBuf!");
89 return HDF_FAILURE;
90 }
91 if (!HdfSbufReadInt32(reply, &volThreshold->max)) {
92 return HDF_FAILURE;
93 }
94 if (!HdfSbufReadInt32(reply, &volThreshold->min)) {
95 return HDF_FAILURE;
96 }
97 return HDF_SUCCESS;
98 }
99