1 /* 2 * Copyright (c) 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 16 #ifndef AUDIO_MIXER_H 17 #define AUDIO_MIXER_H 18 19 #include <stdint.h> 20 #include <stdbool.h> 21 22 #include "audio_interface_lib_mixer.h" 23 24 #define CARD_NAME_LEN 32 25 /** bitmask for chan-map */ 26 #define AUDIO_CHMAP_MASK 0xFFFF 27 28 #define STRING(x) (#x) 29 30 #define ERR_LOG(fmt, arg...) \ 31 do { \ 32 printf("[%s]-[%d]: " fmt, __func__, __LINE__, ##arg); \ 33 } while (0) 34 35 #define DEBUG_LOG(fmt, arg...) \ 36 do { \ 37 if (g_debugFlag) { \ 38 printf("[%s]: [%s]-[%d]: " fmt, __FILE__, __func__, __LINE__, ##arg); \ 39 } \ 40 } while (0) 41 42 struct HdfIoService; 43 44 typedef enum { 45 U_SUCCESS = 0, 46 U_FAILURE = -1, 47 U_NOT_SUPPORT = -2, 48 U_INVALID_PARAM = -3, 49 U_MALLOC_FAIL = -6, 50 U_UNKNOW = U_FAILURE, 51 } UTILS_STATUS; 52 53 typedef enum { 54 SND_OTHER = -1, 55 SND_PRIMARY = 0, 56 SND_HDMI, 57 SND_USB, 58 SND_A2DP, 59 } SND_TYPE; 60 61 struct AudioHwCardInfo { 62 int card; /* card number */ 63 unsigned char name[CARD_NAME_LEN]; 64 }; 65 66 typedef enum { 67 PCM_CHMAP_NONE = 0, /* unspecified channel position */ 68 PCM_CHMAP_FIXED, /* fixed channel position */ 69 PCM_CHMAP_FREELY, /* freely swappable channel position */ 70 PCM_CHMAP_PAIRED, /* pair-wise swappable channel position */ 71 PCM_CHMAP_LAST = PCM_CHMAP_PAIRED 72 } AudioPcmChmapType; 73 74 /* Audio mixer element channel identifier */ 75 typedef enum { 76 AMIXER_CHN_UNKNOWN = -1, 77 AMIXER_CHN_FRONT_LEFT = 0, 78 AMIXER_CHN_FRONT_RIGHT, 79 AMIXER_CHN_REAR_LEFT, 80 AMIXER_CHN_REAR_RIGHT, 81 AMIXER_CHN_FRONT_CENTER, 82 AMIXER_CHN_WOOFER, 83 AMIXER_CHN_SIDE_LEFT, 84 AMIXER_CHN_SIDE_RIGHT, 85 AMIXER_CHN_REAR_CENTER, 86 AMIXER_CHN_LAST = 31, 87 AMIXER_CHN_MONO = AMIXER_CHN_FRONT_LEFT 88 } AudioMixerChannelIdType; 89 90 struct ChannelMask { 91 const char *name; 92 uint32_t mask; 93 }; 94 95 struct AudioPcmChmap { 96 uint32_t channels; /* number of channels */ 97 uint32_t pos; /* bit map for channel position */ 98 }; 99 100 struct AudioPcmChmapId { 101 AudioPcmChmapType type; 102 struct ChannelMask map; /* available channel map */ 103 }; 104 105 struct MixerCtsElemIdx { 106 uint32_t index; /* index of item */ 107 struct AudioHwCtlElemId *id; 108 }; 109 110 struct MixerCardCtlInfo { 111 char cardSrvName[AUDIO_CARD_SRV_NAME_LEN]; 112 struct AudioHwCtlElemIndex edx; 113 }; 114 115 struct AudioMixer { 116 /** 117 * @brief Gets a list of controls supported by the current sound card. 118 * 119 * @parm service: Audio binding control service. 120 * @param mixerCts: Control list information, memory control is applied by the interface lib layer, 121 * the caller obtains the information, and releases the corresponding space before exiting. 122 * (Release the mixerCts->data). 123 * 124 * @return Returns <b>0</b> if the getting is successful; returns a negative value otherwise. 125 */ 126 int32_t (*GetElemList)(const struct HdfIoService *service, struct AudioMixerContents *mixerCts); 127 128 /** 129 * @brief Gets the properties of the specified element of the sound card control. 130 * 131 * @parm service: Audio binding control service. 132 * @param infoData: Gets element attribute information. 133 * 134 * @return Returns <b>0</b> if the mute operation is obtained; returns a negative value otherwise. 135 */ 136 int32_t (*GetElemProp)(const struct HdfIoService *service, struct AudioMixerCtlElemInfo *infoData); 137 138 /** 139 * @brief Sets the properties of the specified element of the sound card control. 140 * 141 * @parm service: Audio binding control service. 142 * @param infoData: Sets element attribute information. 143 * 144 * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise. 145 */ 146 int32_t (*SetElemProp)(const struct HdfIoService *service, struct AudioMixerCtlElemInfo *infoData); 147 }; 148 149 void DebugLog(bool flag); 150 const char *ShowVersion(void); 151 struct HdfIoService *MixerBindCrlSrv(const char *serviceName); 152 struct HdfIoService *MixerBindCrlSrvDefault(void); 153 154 void AudioMixerOpsInit(void); 155 int32_t MctlInfo(const struct HdfIoService *service, const char *cardSrv); 156 int32_t MctlList(const struct HdfIoService *service, const char *cardSrv); 157 int32_t MctlGetElem(const struct HdfIoService *service, struct MixerCardCtlInfo *ctlInfo); 158 int32_t MctlSetElem(const struct HdfIoService *srv, 159 struct MixerCardCtlInfo *ctlInfo, 160 unsigned int argc, char *argv[]); 161 bool MixerFindSelem(const struct HdfIoService *srv, const char *cardSrv, const struct AudioHwCtlElemId *eId); 162 int32_t SetChannels(const struct HdfIoService *srv, const char *cardSrv, unsigned int argc, char *argv); 163 int32_t GetLibsoHandle(AudioPcmType pcm); 164 void ReleaseCtlElemList(void); 165 void CloseLibsoHandle(void); 166 void MixerRecycleCrlSrv(struct HdfIoService *srv); 167 int32_t GetAllCards(const struct HdfIoService *service); 168 void UpdateCardSname(int card, const struct HdfIoService *srv, char * const sname, size_t snameLen); 169 170 #endif /* AUDIO_MIXER_H */ 171