• 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 *dspName;
79     const char *dspDaiName;
80 };
81 
82 enum AudioSapmTurnStandbyMode {
83     AUDIO_SAPM_TURN_STANDBY_LATER = 0,
84     AUDIO_SAPM_TURN_STANDBY_NOW,
85     AUDIO_SAPM_TURN_STANDBY_BUTT,
86 };
87 
88 struct AudioCard {
89     struct HdfDeviceObject *device;
90     struct AudioRuntimeDeivces *rtd;
91     struct AudioConfigData configData;
92 
93     /* Card-specific routes and components. */
94     const struct AudioSapmComponent *sapmComponents;
95     int32_t sapmComponentsNum;
96     const struct AudioSapmRoute *sapmRoutes;
97     int32_t sapmRoutesNum;
98 
99     struct DListHead list;
100     struct DListHead controls; /* all controls for this card */
101     struct DListHead components; /* all components for this card */
102     struct DListHead paths; /* all paths for this card */
103     struct DListHead sapmDirty; /* all dirty for this card */
104     enum AudioSapmTurnStandbyMode standbyMode;
105     uint64_t time;
106     bool sapmSleepState;
107     bool sapmStandbyState;
108     bool sapmMonitorState;
109     bool sapmStandbyStartTimeFlag;
110     bool sapmSleepStartTimeFlag;
111 };
112 
113 enum CriBuffStatus {
114     ENUM_CIR_BUFF_NORMAL    = -1,
115     ENUM_CIR_BUFF_FULL      = -2,
116     ENUM_CIR_BUFF_EMPTY     = -3,
117 };
118 
119 enum AudioStreamType {
120     AUDIO_CAPTURE_STREAM = 0,
121     AUDIO_RENDER_STREAM,
122 };
123 
124 struct PcmInfo {
125     enum AudioStreamType streamType;
126     /* The number of channels in a frame */
127     uint32_t channels;
128     /* The number of frames per second */
129     uint32_t rate;
130     uint32_t bitWidth;
131     uint32_t frameSize;
132     bool isBigEndian;
133     bool isSignedData;
134     uint32_t startThreshold;
135     uint32_t stopThreshold;
136     uint32_t silenceThreshold;
137     uint32_t totalStreamSize;
138     uint32_t interleaved;
139 };
140 
141 struct AudioPcmHwParams {
142     /* The stream type in a frame */
143     enum AudioStreamType streamType;
144     /* The number of channels in a frame */
145     uint32_t channels;
146     /* The number of frames per second */
147     uint32_t rate;
148     /* The number of frames in a period */
149     uint32_t periodSize;
150     /* The number of periods in a PCM */
151     uint32_t periodCount;
152     /* The sample format of a PCM */
153     enum AudioFormat format; /* < Audio data format. For details, see {@link AudioFormat}. */
154     const char *cardServiceName;
155     uint32_t period;
156     uint32_t frameSize;
157     bool isBigEndian;
158     bool isSignedData;
159     uint32_t startThreshold;
160     uint32_t stopThreshold;
161     uint32_t silenceThreshold;
162 };
163 
164 struct AudioHost {
165     struct IDeviceIoService service;
166     struct HdfDeviceObject *device;
167     void *priv;
168 };
169 
170 struct AudioTxData {
171     int32_t status;
172     char *buf; /* buf address */
173     unsigned long frames; /* frames number */
174 };
175 
176 struct AudioRxData {
177     int32_t status;
178     char *buf;
179     unsigned long bufSize;
180     unsigned long frames; /* frames number */
181 };
182 
183 struct AudioMmapData {
184     void *memoryAddress;                 /**< Pointer to the mmap buffer */
185     int32_t memoryFd;                    /**< File descriptor of the mmap buffer */
186     int32_t totalBufferFrames;           /**< Total size of the mmap buffer (unit: frame )*/
187     int32_t transferFrameSize;           /**< Transfer size (unit: frame) */
188     int32_t isShareable;                 /**< Whether the mmap buffer can be shared among processes */
189     uint32_t offset;
190 };
191 
192 struct AudioRuntimeDeivces       {
193     /* runtime devices */
194     struct CodecDevice *codec;
195     struct PlatformDevice *platform;
196     struct DaiDevice *codecDai;
197     struct DaiDevice *cpuDai;
198     struct DspDevice *dsp;
199     struct DaiDevice *dspDai;
200     uint8_t complete;
201     uint32_t frameBits;
202     uint8_t *dmaArea;
203     unsigned long bufferSize;
204 };
205 
206 struct AudioHost *AudioHostCreateAndBind(struct HdfDeviceObject *device);
207 
208 /* Get a sound card instance */
209 struct AudioCard *GetCardInstance(const char *serviceName);
210 
211 #ifdef __cplusplus
212 #if __cplusplus
213 }
214 #endif
215 #endif /* __cplusplus */
216 
217 #endif /* AUDIO_HOST_H */
218