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