• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef AUDIO_HOST_H
10 #define AUDIO_HOST_H
11 
12 #include "hdf_base.h"
13 #include "hdf_dlist.h"
14 #include "hdf_device_desc.h"
15 #include "hdf_log.h"
16 #include "device_resource_if.h"
17 #include "osal_mem.h"
18 #include "osal_mutex.h"
19 #include "securec.h"
20 
21 #ifdef __cplusplus
22 #if __cplusplus
23 extern "C" {
24 #endif
25 #endif /* __cplusplus */
26 
27 #define ADM_LOG_ERR(fmt, arg...) do { \
28     HDF_LOGE("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
29     } while (0)
30 
31 #define ADM_LOG_INFO(fmt, arg...) do { \
32     HDF_LOGI("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
33     } while (0)
34 
35 #define ADM_LOG_WARNING(fmt, arg...) do { \
36     HDF_LOGW("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
37     } while (0)
38 
39 #define ADM_LOG_DEBUG(fmt, arg...) do { \
40     HDF_LOGD("[%s][line:%d]: " fmt, __func__, __LINE__, ##arg); \
41     } while (0)
42 
43 #define BUFF_SIZE_MAX 64
44 
45 #define AUDIO_LIST_HEAD_INIT(name) { &(name), &(name) }
46 
47 #define AUDIO_LIST_HEAD(name) \
48     struct DListHead name = AUDIO_LIST_HEAD_INIT(name)
49 
50 struct AudioConfigData {
51     const char *cardServiceName;
52     const char *codecName;
53     const char *platformName;
54     const char *cpuDaiName;
55     const char *codecDaiName;
56     const char *accessoryName;
57     const char *accessoryDaiName;
58     const char *dspName;
59     const char *dspDaiName;
60 };
61 
62 enum AudioFormat {
63     AUDIO_FORMAT_PCM_8_BIT  = 0x1u,       /**< 8-bit PCM */
64     AUDIO_FORMAT_PCM_16_BIT = 0x2u,       /**< 16-bit PCM */
65     AUDIO_FORMAT_PCM_24_BIT = 0x3u,       /**< 24-bit PCM */
66     AUDIO_FORMAT_PCM_32_BIT = 0x4u,       /**< 32-bit PCM */
67     AUDIO_FORMAT_AAC_MAIN   = 0x1000001u, /**< AAC main */
68     AUDIO_FORMAT_AAC_LC     = 0x1000002u, /**< AAC LC */
69     AUDIO_FORMAT_AAC_LD     = 0x1000003u, /**< AAC LD */
70     AUDIO_FORMAT_AAC_ELD    = 0x1000004u, /**< AAC ELD */
71     AUDIO_FORMAT_AAC_HE_V1  = 0x1000005u, /**< AAC HE_V1 */
72     AUDIO_FORMAT_AAC_HE_V2  = 0x1000006u, /**< AAC HE_V2 */
73     AUDIO_FORMAT_G711A      = 0x2000001u, /**< G711A */
74     AUDIO_FORMAT_G711U      = 0x2000002u, /**< G711u */
75     AUDIO_FORMAT_G726       = 0x2000003u, /**< G726 */
76 };
77 
78 struct AudioCard {
79     struct AudioRuntimeDeivces *rtd;
80     struct AudioConfigData configData;
81 
82     /* Card-specific routes and components. */
83     const struct AudioSapmComponent *sapmComponents;
84     int32_t sapmComponentsNum;
85     const struct AudioSapmRoute *sapmRoutes;
86     int32_t sapmRoutesNum;
87 
88     struct DListHead list;
89     struct DListHead controls; /* all controls for this card */
90     struct DListHead components; /* all components for this card */
91     struct DListHead paths; /* all paths for this card */
92     struct DListHead sapmDirty; /* all dirty for this card */
93     bool sapmSleepState;
94     bool sapmStandbyState;
95     bool sapmMonitorState;
96 };
97 
98 enum CriBuffStatus {
99     ENUM_CIR_BUFF_NORMAL = 1,
100     ENUM_CIR_BUFF_FULL,
101     ENUM_CIR_BUFF_EMPTY,
102 };
103 
104 enum AudioStreamType {
105     AUDIO_CAPTURE_STREAM = 0,
106     AUDIO_RENDER_STREAM,
107 };
108 
109 struct AudioPcmHwParams {
110     /* The stream type in a frame */
111     enum AudioStreamType streamType;
112     /* The number of channels in a frame */
113     uint32_t channels;
114     /* The number of frames per second */
115     uint32_t rate;
116     /* The number of frames in a period */
117     uint32_t periodSize;
118     /* The number of periods in a PCM */
119     uint32_t periodCount;
120     /* The sample format of a PCM */
121     enum AudioFormat format; /* < Audio data format. For details, see {@link AudioFormat}. */
122     const char *cardServiceName;
123     uint32_t period;
124     uint32_t frameSize;
125     bool isBigEndian;
126     bool isSignedData;
127     uint32_t startThreshold;
128     uint32_t stopThreshold;
129     uint32_t silenceThreshold;
130 };
131 
132 struct AudioHost {
133     struct IDeviceIoService service;
134     struct HdfDeviceObject *device;
135     void *priv;
136 };
137 
138 struct AudioTxData {
139     enum CriBuffStatus status;
140     char *buf; /* buf address */
141     unsigned long frames; /* frames number */
142 };
143 
144 struct AudioRxData {
145     enum CriBuffStatus status;
146     char *buf;
147     unsigned long bufSize;
148     unsigned long frames; /* frames number */
149 };
150 
151 struct AudioTxMmapData {
152     void *memoryAddress;                 /**< Pointer to the mmap buffer */
153     int32_t memoryFd;                    /**< File descriptor of the mmap buffer */
154     int32_t totalBufferFrames;           /**< Total size of the mmap buffer (unit: frame )*/
155     int32_t transferFrameSize;           /**< Transfer size (unit: frame) */
156     int32_t isShareable;                 /**< Whether the mmap buffer can be shared among processes */
157     uint32_t offset;
158 };
159 
160 struct AudioRxMmapData {
161     void *memoryAddress;                 /**< Pointer to the mmap buffer */
162     int32_t memoryFd;                    /**< File descriptor of the mmap buffer */
163     int32_t totalBufferFrames;           /**< Total size of the mmap buffer (unit: frame )*/
164     int32_t transferFrameSize;           /**< Transfer size (unit: frame) */
165     int32_t isShareable;                 /**< Whether the mmap buffer can be shared among processes */
166     uint32_t offset;
167 };
168 
169 struct AudioRuntimeDeivces       {
170     /* runtime devices */
171     struct CodecDevice *codec;
172     struct PlatformDevice *platform;
173     struct DaiDevice *codecDai;
174     struct DaiDevice *cpuDai;
175     struct DaiDevice *accessoryDai;
176     struct AccessoryDevice *accessory;
177     struct DspDevice *dsp;
178     struct DaiDevice *dspDai;
179     uint8_t complete;
180     uint32_t frameBits;
181     uint8_t *dmaArea;
182     unsigned long bufferSize;
183 };
184 
185 struct AudioHost *AudioHostCreateAndBind(struct HdfDeviceObject *device);
186 
AudioHostToDevice(struct AudioHost * host)187 static inline struct HdfDeviceObject *AudioHostToDevice(struct AudioHost *host)
188 {
189     return (host == NULL) ? NULL : host->device;
190 }
191 
AudioHostFromDevice(struct HdfDeviceObject * device)192 static inline struct AudioHost *AudioHostFromDevice(struct HdfDeviceObject *device)
193 {
194     return (device == NULL) ? NULL : (struct AudioHost *)device->service;
195 }
196 
197 /* Get a sound card instance */
198 struct AudioCard *GetCardInstance(const char *serviceName);
199 
200 #ifdef __cplusplus
201 #if __cplusplus
202 }
203 #endif
204 #endif /* __cplusplus */
205 
206 #endif /* AUDIO_HOST_H */
207