1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci#ifndef AUDIO_MIXER_H
17094332d3Sopenharmony_ci#define AUDIO_MIXER_H
18094332d3Sopenharmony_ci
19094332d3Sopenharmony_ci#include <stdint.h>
20094332d3Sopenharmony_ci#include <stdbool.h>
21094332d3Sopenharmony_ci
22094332d3Sopenharmony_ci#include "audio_interface_lib_mixer.h"
23094332d3Sopenharmony_ci
24094332d3Sopenharmony_ci#define CARD_NAME_LEN 32
25094332d3Sopenharmony_ci/** bitmask for chan-map */
26094332d3Sopenharmony_ci#define AUDIO_CHMAP_MASK 0xFFFF
27094332d3Sopenharmony_ci
28094332d3Sopenharmony_ci#define STRING(x) (#x)
29094332d3Sopenharmony_ci
30094332d3Sopenharmony_ci#define ERR_LOG(fmt, arg...)                                  \
31094332d3Sopenharmony_ci    do {                                                      \
32094332d3Sopenharmony_ci        printf("[%s]-[%d]: " fmt, __func__, __LINE__, ##arg); \
33094332d3Sopenharmony_ci    } while (0)
34094332d3Sopenharmony_ci
35094332d3Sopenharmony_ci#define DEBUG_LOG(fmt, arg...)                                                    \
36094332d3Sopenharmony_ci    do {                                                                          \
37094332d3Sopenharmony_ci        if (g_debugFlag) {                                                          \
38094332d3Sopenharmony_ci            printf("[%s]: [%s]-[%d]: " fmt, __FILE__, __func__, __LINE__, ##arg); \
39094332d3Sopenharmony_ci        }                                                                         \
40094332d3Sopenharmony_ci    } while (0)
41094332d3Sopenharmony_ci
42094332d3Sopenharmony_cistruct HdfIoService;
43094332d3Sopenharmony_ci
44094332d3Sopenharmony_citypedef enum {
45094332d3Sopenharmony_ci    U_SUCCESS = 0,
46094332d3Sopenharmony_ci    U_FAILURE = -1,
47094332d3Sopenharmony_ci    U_NOT_SUPPORT = -2,
48094332d3Sopenharmony_ci    U_INVALID_PARAM = -3,
49094332d3Sopenharmony_ci    U_MALLOC_FAIL = -6,
50094332d3Sopenharmony_ci    U_UNKNOW = U_FAILURE,
51094332d3Sopenharmony_ci} UTILS_STATUS;
52094332d3Sopenharmony_ci
53094332d3Sopenharmony_citypedef enum {
54094332d3Sopenharmony_ci    SND_OTHER = -1,
55094332d3Sopenharmony_ci    SND_PRIMARY = 0,
56094332d3Sopenharmony_ci    SND_HDMI,
57094332d3Sopenharmony_ci    SND_USB,
58094332d3Sopenharmony_ci    SND_A2DP,
59094332d3Sopenharmony_ci} SND_TYPE;
60094332d3Sopenharmony_ci
61094332d3Sopenharmony_cistruct AudioHwCardInfo {
62094332d3Sopenharmony_ci    int card; /* card number */
63094332d3Sopenharmony_ci    unsigned char name[CARD_NAME_LEN];
64094332d3Sopenharmony_ci};
65094332d3Sopenharmony_ci
66094332d3Sopenharmony_citypedef enum {
67094332d3Sopenharmony_ci    PCM_CHMAP_NONE = 0, /* unspecified channel position */
68094332d3Sopenharmony_ci    PCM_CHMAP_FIXED,    /* fixed channel position */
69094332d3Sopenharmony_ci    PCM_CHMAP_FREELY,   /* freely swappable channel position */
70094332d3Sopenharmony_ci    PCM_CHMAP_PAIRED,   /* pair-wise swappable channel position */
71094332d3Sopenharmony_ci    PCM_CHMAP_LAST = PCM_CHMAP_PAIRED
72094332d3Sopenharmony_ci} AudioPcmChmapType;
73094332d3Sopenharmony_ci
74094332d3Sopenharmony_ci/* Audio mixer element channel identifier */
75094332d3Sopenharmony_citypedef enum {
76094332d3Sopenharmony_ci    AMIXER_CHN_UNKNOWN = -1,
77094332d3Sopenharmony_ci    AMIXER_CHN_FRONT_LEFT = 0,
78094332d3Sopenharmony_ci    AMIXER_CHN_FRONT_RIGHT,
79094332d3Sopenharmony_ci    AMIXER_CHN_REAR_LEFT,
80094332d3Sopenharmony_ci    AMIXER_CHN_REAR_RIGHT,
81094332d3Sopenharmony_ci    AMIXER_CHN_FRONT_CENTER,
82094332d3Sopenharmony_ci    AMIXER_CHN_WOOFER,
83094332d3Sopenharmony_ci    AMIXER_CHN_SIDE_LEFT,
84094332d3Sopenharmony_ci    AMIXER_CHN_SIDE_RIGHT,
85094332d3Sopenharmony_ci    AMIXER_CHN_REAR_CENTER,
86094332d3Sopenharmony_ci    AMIXER_CHN_LAST = 31,
87094332d3Sopenharmony_ci    AMIXER_CHN_MONO = AMIXER_CHN_FRONT_LEFT
88094332d3Sopenharmony_ci} AudioMixerChannelIdType;
89094332d3Sopenharmony_ci
90094332d3Sopenharmony_cistruct ChannelMask {
91094332d3Sopenharmony_ci    const char *name;
92094332d3Sopenharmony_ci    uint32_t mask;
93094332d3Sopenharmony_ci};
94094332d3Sopenharmony_ci
95094332d3Sopenharmony_cistruct AudioPcmChmap {
96094332d3Sopenharmony_ci    uint32_t channels;  /* number of channels */
97094332d3Sopenharmony_ci    uint32_t pos;       /* bit map for channel position */
98094332d3Sopenharmony_ci};
99094332d3Sopenharmony_ci
100094332d3Sopenharmony_cistruct AudioPcmChmapId {
101094332d3Sopenharmony_ci    AudioPcmChmapType type;
102094332d3Sopenharmony_ci    struct ChannelMask map; /* available channel map */
103094332d3Sopenharmony_ci};
104094332d3Sopenharmony_ci
105094332d3Sopenharmony_cistruct MixerCtsElemIdx {
106094332d3Sopenharmony_ci    uint32_t index; /* index of item */
107094332d3Sopenharmony_ci    struct AudioHwCtlElemId *id;
108094332d3Sopenharmony_ci};
109094332d3Sopenharmony_ci
110094332d3Sopenharmony_cistruct MixerCardCtlInfo {
111094332d3Sopenharmony_ci    char cardSrvName[AUDIO_CARD_SRV_NAME_LEN];
112094332d3Sopenharmony_ci    struct AudioHwCtlElemIndex edx;
113094332d3Sopenharmony_ci};
114094332d3Sopenharmony_ci
115094332d3Sopenharmony_cistruct AudioMixer {
116094332d3Sopenharmony_ci    /**
117094332d3Sopenharmony_ci     * @brief Gets a list of controls supported by the current sound card.
118094332d3Sopenharmony_ci     *
119094332d3Sopenharmony_ci     * @parm service: Audio binding control service.
120094332d3Sopenharmony_ci     * @param mixerCts: Control list information, memory control is applied by the interface lib layer,
121094332d3Sopenharmony_ci     * the caller obtains the information, and releases the corresponding space before exiting.
122094332d3Sopenharmony_ci     * (Release the mixerCts->data).
123094332d3Sopenharmony_ci     *
124094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the getting is successful; returns a negative value otherwise.
125094332d3Sopenharmony_ci     */
126094332d3Sopenharmony_ci    int32_t (*GetElemList)(const struct HdfIoService *service, struct AudioMixerContents *mixerCts);
127094332d3Sopenharmony_ci
128094332d3Sopenharmony_ci    /**
129094332d3Sopenharmony_ci     * @brief Gets the properties of the specified element of the sound card control.
130094332d3Sopenharmony_ci     *
131094332d3Sopenharmony_ci     * @parm service: Audio binding control service.
132094332d3Sopenharmony_ci     * @param infoData: Gets element attribute information.
133094332d3Sopenharmony_ci     *
134094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the mute operation is obtained; returns a negative value otherwise.
135094332d3Sopenharmony_ci     */
136094332d3Sopenharmony_ci    int32_t (*GetElemProp)(const struct HdfIoService *service, struct AudioMixerCtlElemInfo *infoData);
137094332d3Sopenharmony_ci
138094332d3Sopenharmony_ci    /**
139094332d3Sopenharmony_ci     * @brief Sets the properties of the specified element of the sound card control.
140094332d3Sopenharmony_ci     *
141094332d3Sopenharmony_ci     * @parm service: Audio binding control service.
142094332d3Sopenharmony_ci     * @param infoData: Sets element attribute information.
143094332d3Sopenharmony_ci     *
144094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the setting is successful; returns a negative value otherwise.
145094332d3Sopenharmony_ci     */
146094332d3Sopenharmony_ci    int32_t (*SetElemProp)(const struct HdfIoService *service, struct AudioMixerCtlElemInfo *infoData);
147094332d3Sopenharmony_ci};
148094332d3Sopenharmony_ci
149094332d3Sopenharmony_civoid DebugLog(bool flag);
150094332d3Sopenharmony_ciconst char *ShowVersion(void);
151094332d3Sopenharmony_cistruct HdfIoService *MixerBindCrlSrv(const char *serviceName);
152094332d3Sopenharmony_cistruct HdfIoService *MixerBindCrlSrvDefault(void);
153094332d3Sopenharmony_ci
154094332d3Sopenharmony_civoid AudioMixerOpsInit(void);
155094332d3Sopenharmony_ciint32_t MctlInfo(const struct HdfIoService *service, const char *cardSrv);
156094332d3Sopenharmony_ciint32_t MctlList(const struct HdfIoService *service, const char *cardSrv);
157094332d3Sopenharmony_ciint32_t MctlGetElem(const struct HdfIoService *service, struct MixerCardCtlInfo *ctlInfo);
158094332d3Sopenharmony_ciint32_t MctlSetElem(const struct HdfIoService *srv,
159094332d3Sopenharmony_ci                    struct MixerCardCtlInfo *ctlInfo,
160094332d3Sopenharmony_ci                    unsigned int argc, char *argv[]);
161094332d3Sopenharmony_cibool MixerFindSelem(const struct HdfIoService *srv, const char *cardSrv, const struct AudioHwCtlElemId *eId);
162094332d3Sopenharmony_ciint32_t SetChannels(const struct HdfIoService *srv, const char *cardSrv, unsigned int argc, char *argv);
163094332d3Sopenharmony_ciint32_t GetLibsoHandle(AudioPcmType pcm);
164094332d3Sopenharmony_civoid ReleaseCtlElemList(void);
165094332d3Sopenharmony_civoid CloseLibsoHandle(void);
166094332d3Sopenharmony_civoid MixerRecycleCrlSrv(struct HdfIoService *srv);
167094332d3Sopenharmony_ciint32_t GetAllCards(const struct HdfIoService *service);
168094332d3Sopenharmony_civoid UpdateCardSname(int card, const struct HdfIoService *srv, char * const sname, size_t snameLen);
169094332d3Sopenharmony_ci
170094332d3Sopenharmony_ci#endif /* AUDIO_MIXER_H */
171