1 /*
2 * Copyright (c) 2019-2025 Allwinner Technology Co., Ltd. ALL rights reserved.
3 *
4 * Allwinner is a trademark of Allwinner Technology Co.,Ltd., registered in
5 * the the people's Republic of China and other countries.
6 * All Allwinner Technology Co.,Ltd. trademarks are used with permission.
7 *
8 * DISCLAIMER
9 * THIRD PARTY LICENCES MAY BE REQUIRED TO IMPLEMENT THE SOLUTION/PRODUCT.
10 * IF YOU NEED TO INTEGRATE THIRD PARTY’S TECHNOLOGY (SONY, DTS, DOLBY, AVS OR MPEGLA, ETC.)
11 * IN ALLWINNERS’SDK OR PRODUCTS, YOU SHALL BE SOLELY RESPONSIBLE TO OBTAIN
12 * ALL APPROPRIATELY REQUIRED THIRD PARTY LICENCES.
13 * ALLWINNER SHALL HAVE NO WARRANTY, INDEMNITY OR OTHER OBLIGATIONS WITH RESPECT TO MATTERS
14 * COVERED UNDER ANY REQUIRED THIRD PARTY LICENSE.
15 * YOU ARE SOLELY RESPONSIBLE FOR YOUR USAGE OF THIRD PARTY’S TECHNOLOGY.
16 *
17 *
18 * THIS SOFTWARE IS PROVIDED BY ALLWINNER"AS IS" AND TO THE MAXIMUM EXTENT
19 * PERMITTED BY LAW, ALLWINNER EXPRESSLY DISCLAIMS ALL WARRANTIES OF ANY KIND,
20 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION REGARDING
21 * THE TITLE, NON-INFRINGEMENT, ACCURACY, CONDITION, COMPLETENESS, PERFORMANCE
22 * OR MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 * IN NO EVENT SHALL ALLWINNER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS, OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30 * OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #ifndef __AW_ALSA_PCM_EXTPLUG_H
34 #define __AW_ALSA_PCM_EXTPLUG_H
35
36 #include <aw-alsa-lib/pcm.h>
37
38 /** hw constraints for extplug */
39 enum {
40 SND_PCM_EXTPLUG_HW_FORMAT, /**< format */
41 SND_PCM_EXTPLUG_HW_CHANNELS, /**< channels */
42 SND_PCM_EXTPLUG_HW_PARAMS /**< max number of hw constraints */
43 };
44
45 /** Handle of external filter plugin */
46 typedef struct snd_pcm_extplug snd_pcm_extplug_t;
47 /** Callback table of extplug */
48 typedef struct snd_pcm_extplug_callback snd_pcm_extplug_callback_t;
49
50 /** Handle of extplug */
51 struct snd_pcm_extplug {
52 /**
53 * name of this plugin; must be filled before calling #snd_pcm_extplug_create()
54 */
55 const char *name;
56 /**
57 * callbacks of this plugin; must be filled before calling #snd_pcm_extplug_create()
58 */
59 const snd_pcm_extplug_callback_t *callback;
60 /**
61 * private data, which can be used freely in the driver callbacks
62 */
63 void *private_data;
64 /**
65 * PCM handle filled by #snd_pcm_extplug_create()
66 */
67 snd_pcm_t *pcm;
68 /**
69 * stream direction; read-only status
70 */
71 snd_pcm_stream_t stream;
72 /**
73 * format hw parameter; filled after hw_params is caled
74 */
75 snd_pcm_format_t format;
76 /**
77 * subformat hw parameter; filled after hw_params is caled
78 */
79 //snd_pcm_subformat_t subformat;
80 /**
81 * channels hw parameter; filled after hw_params is caled
82 */
83 unsigned int channels;
84 /**
85 * rate hw parameter; filled after hw_params is caled
86 */
87 unsigned int rate;
88 /**
89 * slave_format hw parameter; filled after hw_params is caled
90 */
91 snd_pcm_format_t slave_format;
92 /**
93 * slave_channels hw parameter; filled after hw_params is caled
94 */
95 unsigned int slave_channels;
96 };
97
98 /** Callback table of extplug */
99 struct snd_pcm_extplug_callback {
100 /**
101 * transfer between source and destination; this is a required callback
102 */
103 snd_pcm_sframes_t (*transfer)(snd_pcm_extplug_t *ext,
104 const snd_pcm_channel_area_t *dst_areas,
105 snd_pcm_uframes_t dst_offset,
106 const snd_pcm_channel_area_t *src_areas,
107 snd_pcm_uframes_t src_offset,
108 snd_pcm_uframes_t size);
109 /**
110 * close the PCM; optional
111 */
112 int (*close)(snd_pcm_extplug_t *ext);
113 /**
114 * hw_params; optional
115 */
116 int (*hw_params)(snd_pcm_extplug_t *ext, snd_pcm_hw_params_t *params);
117 /**
118 * hw_free; optional
119 */
120 int (*hw_free)(snd_pcm_extplug_t *ext);
121 /**
122 * dump; optional
123 */
124 void (*dump)(snd_pcm_extplug_t *ext);
125 /**
126 * init; optional initialization called at prepare or reset
127 */
128 int (*init)(snd_pcm_extplug_t *ext);
129 /**
130 * query the channel maps; optional; since v1.0.2
131 */
132 //snd_pcm_chmap_query_t **(*query_chmaps)(snd_pcm_extplug_t *ext);
133 /**
134 * get the channel map; optional; since v1.0.2
135 */
136 //snd_pcm_chmap_t *(*get_chmap)(snd_pcm_extplug_t *ext);
137 /**
138 * set the channel map; optional; since v1.0.2
139 */
140 //int (*set_chmap)(snd_pcm_extplug_t *ext, const snd_pcm_chmap_t *map);
141 };
142
143 int snd_pcm_extplug_create(snd_pcm_extplug_t *extplug, const char *name,
144 const char *spcm_name, snd_pcm_stream_t stream, int mode);
145
146 /* clear hw_parameter setting */
147 void snd_pcm_extplug_params_reset(snd_pcm_extplug_t *ext);
148
149 /* hw_parameter setting */
150 int snd_pcm_extplug_set_param_list(snd_pcm_extplug_t *extplug, int type, unsigned int num_list, const unsigned int *list);
151 int snd_pcm_extplug_set_param_minmax(snd_pcm_extplug_t *extplug, int type, unsigned int min, unsigned int max);
152 int snd_pcm_extplug_set_slave_param_list(snd_pcm_extplug_t *extplug, int type, unsigned int num_list, const unsigned int *list);
153 int snd_pcm_extplug_set_slave_param_minmax(snd_pcm_extplug_t *extplug, int type, unsigned int min, unsigned int max);
154
155 /**
156 * set the parameter constraint with a single value
157 */
snd_pcm_extplug_set_param(snd_pcm_extplug_t * extplug,int type,unsigned int val)158 static __inline__ int snd_pcm_extplug_set_param(snd_pcm_extplug_t *extplug, int type, unsigned int val)
159 {
160 return snd_pcm_extplug_set_param_list(extplug, type, 1, &val);
161 }
162
163 /**
164 * set the parameter constraint for slave PCM with a single value
165 */
snd_pcm_extplug_set_slave_param(snd_pcm_extplug_t * extplug,int type,unsigned int val)166 static __inline__ int snd_pcm_extplug_set_slave_param(snd_pcm_extplug_t *extplug, int type, unsigned int val)
167 {
168 return snd_pcm_extplug_set_slave_param_list(extplug, type, 1, &val);
169 }
170
171 #endif /* __AW_ALSA_PCM_EXTPLUG_H */
172