• 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 AUDIO_LIST_HEAD_INIT(name) { &(name), &(name) }
28 
29 #define AUDIO_LIST_HEAD(name) \
30     struct DListHead name = AUDIO_LIST_HEAD_INIT(name)
31 
32 enum AudioFormat {
33     AUDIO_FORMAT_PCM_8_BIT  = 0x1u,       /**< audio 8-bit PCM */
34     AUDIO_FORMAT_PCM_16_BIT = 0x2u,       /**< audio16-bit PCM */
35     AUDIO_FORMAT_PCM_24_BIT = 0x3u,       /**< audio 24-bit PCM */
36     AUDIO_FORMAT_PCM_32_BIT = 0x4u,       /**< audio 32-bit PCM */
37     AUDIO_FORMAT_AAC_MAIN   = 0x1000001u, /**< audio AAC main */
38     AUDIO_FORMAT_AAC_LC     = 0x1000002u, /**< audio AAC LC */
39     AUDIO_FORMAT_AAC_LD     = 0x1000003u, /**< audio AAC LD */
40     AUDIO_FORMAT_AAC_ELD    = 0x1000004u, /**< audio AAC ELD */
41     AUDIO_FORMAT_AAC_HE_V1  = 0x1000005u, /**< audio AAC HE_V1 */
42     AUDIO_FORMAT_AAC_HE_V2  = 0x1000006u, /**< audio AAC HE_V2 */
43     AUDIO_FORMAT_G711A      = 0x2000001u, /**< audio G711A */
44     AUDIO_FORMAT_G711U      = 0x2000002u, /**< audio G711u */
45     AUDIO_FORMAT_G726       = 0x2000003u, /**< audio G726 */
46 };
47 
48 typedef enum {
49     AUDIO_SAMPLE_RATE_8000   = 8000,    /* 8kHz sample_rate */
50     AUDIO_SAMPLE_RATE_12000  = 12000,   /* 12kHz sample_rate */
51     AUDIO_SAMPLE_RATE_11025  = 11025,   /* 11.025kHz sample_rate */
52     AUDIO_SAMPLE_RATE_16000  = 16000,   /* 16kHz sample_rate */
53     AUDIO_SAMPLE_RATE_22050  = 22050,   /* 22.050kHz sample_rate */
54     AUDIO_SAMPLE_RATE_24000  = 24000,   /* 24kHz sample_rate */
55     AUDIO_SAMPLE_RATE_32000  = 32000,   /* 32kHz sample_rate */
56     AUDIO_SAMPLE_RATE_44100  = 44100,   /* 44.1kHz sample_rate */
57     AUDIO_SAMPLE_RATE_48000  = 48000,   /* 48kHz sample_rate */
58     AUDIO_SAMPLE_RATE_64000  = 64000,   /* 64kHz sample_rate */
59     AUDIO_SAMPLE_RATE_96000  = 96000,   /* 96kHz sample_rate */
60     AUDIO_SAMPLE_RATE_BUTT,
61 } AudioSampleRate;
62 
63 enum AuidoBitWidth {
64     BIT_WIDTH8  =  8,      /* 8 bit witdth */
65     BIT_WIDTH16 =  16,     /* 16 bit witdth */
66     BIT_WIDTH18 =  18,     /* 18 bit witdth */
67     BIT_WIDTH20 =  20,     /* 20 bit witdth */
68     BIT_WIDTH24 =  24,     /* 24 bit witdth */
69     BIT_WIDTH32 =  32,     /* 32 bit witdth */
70 };
71 
72 struct AudioConfigData {
73     const char *cardServiceName;
74     const char *codecName;
75     const char *platformName;
76     const char *cpuDaiName;
77     const char *codecDaiName;
78     const char *accessoryName;
79     const char *accessoryDaiName;
80     const char *dspName;
81     const char *dspDaiName;
82 };
83 
84 enum AudioSapmTurnStandbyMode {
85     AUDIO_SAPM_TURN_STANDBY_LATER = 0,
86     AUDIO_SAPM_TURN_STANDBY_NOW,
87     AUDIO_SAPM_TURN_STANDBY_BUTT,
88 };
89 
90 struct AudioCard {
91     struct HdfDeviceObject *device;
92     struct AudioRuntimeDeivces *rtd;
93     struct AudioConfigData configData;
94 
95     /* Card-specific routes and components. */
96     const struct AudioSapmComponent *sapmComponents;
97     int32_t sapmComponentsNum;
98     const struct AudioSapmRoute *sapmRoutes;
99     int32_t sapmRoutesNum;
100 
101     struct DListHead list;
102     struct DListHead controls; /* all controls for this card */
103     struct DListHead components; /* all components for this card */
104     struct DListHead paths; /* all paths for this card */
105     struct DListHead sapmDirty; /* all dirty for this card */
106     enum AudioSapmTurnStandbyMode standbyMode;
107     bool sapmSleepState;
108     bool sapmStandbyState;
109     bool sapmMonitorState;
110 };
111 
112 enum CriBuffStatus {
113     ENUM_CIR_BUFF_NORMAL = 1,
114     ENUM_CIR_BUFF_FULL,
115     ENUM_CIR_BUFF_EMPTY,
116 };
117 
118 enum AudioStreamType {
119     AUDIO_CAPTURE_STREAM = 0,
120     AUDIO_RENDER_STREAM,
121 };
122 
123 struct PcmInfo {
124     enum AudioStreamType streamType;
125     /* The number of channels in a frame */
126     uint32_t channels;
127     /* The number of frames per second */
128     uint32_t rate;
129     uint32_t bitWidth;
130     uint32_t frameSize;
131     bool isBigEndian;
132     bool isSignedData;
133     uint32_t startThreshold;
134     uint32_t stopThreshold;
135     uint32_t silenceThreshold;
136     uint32_t totalStreamSize;
137     uint32_t interleaved;
138 };
139 
140 struct AudioPcmHwParams {
141     /* The stream type in a frame */
142     enum AudioStreamType streamType;
143     /* The number of channels in a frame */
144     uint32_t channels;
145     /* The number of frames per second */
146     uint32_t rate;
147     /* The number of frames in a period */
148     uint32_t periodSize;
149     /* The number of periods in a PCM */
150     uint32_t periodCount;
151     /* The sample format of a PCM */
152     enum AudioFormat format; /* < Audio data format. For details, see {@link AudioFormat}. */
153     const char *cardServiceName;
154     uint32_t period;
155     uint32_t frameSize;
156     bool isBigEndian;
157     bool isSignedData;
158     uint32_t startThreshold;
159     uint32_t stopThreshold;
160     uint32_t silenceThreshold;
161 };
162 
163 struct AudioHost {
164     struct IDeviceIoService service;
165     struct HdfDeviceObject *device;
166     void *priv;
167 };
168 
169 struct AudioTxData {
170     enum CriBuffStatus status;
171     char *buf; /* buf address */
172     unsigned long frames; /* frames number */
173 };
174 
175 struct AudioRxData {
176     enum CriBuffStatus status;
177     char *buf;
178     unsigned long bufSize;
179     unsigned long frames; /* frames number */
180 };
181 
182 struct AudioMmapData {
183     void *memoryAddress;                 /**< Pointer to the mmap buffer */
184     int32_t memoryFd;                    /**< File descriptor of the mmap buffer */
185     int32_t totalBufferFrames;           /**< Total size of the mmap buffer (unit: frame )*/
186     int32_t transferFrameSize;           /**< Transfer size (unit: frame) */
187     int32_t isShareable;                 /**< Whether the mmap buffer can be shared among processes */
188     uint32_t offset;
189 };
190 
191 struct AudioRuntimeDeivces       {
192     /* runtime devices */
193     struct CodecDevice *codec;
194     struct PlatformDevice *platform;
195     struct DaiDevice *codecDai;
196     struct DaiDevice *cpuDai;
197     struct DaiDevice *accessoryDai;
198     struct AccessoryDevice *accessory;
199     struct DspDevice *dsp;
200     struct DaiDevice *dspDai;
201     uint8_t complete;
202     uint32_t frameBits;
203     uint8_t *dmaArea;
204     unsigned long bufferSize;
205 };
206 
207 struct AudioHost *AudioHostCreateAndBind(struct HdfDeviceObject *device);
208 
209 /* Get a sound card instance */
210 struct AudioCard *GetCardInstance(const char *serviceName);
211 
212 #ifdef __cplusplus
213 #if __cplusplus
214 }
215 #endif
216 #endif /* __cplusplus */
217 
218 #endif /* AUDIO_HOST_H */
219