1d5ac70f0Sopenharmony_ci/**
2d5ac70f0Sopenharmony_ci * \file include/control_external.h
3d5ac70f0Sopenharmony_ci * \brief External control plugin SDK
4d5ac70f0Sopenharmony_ci * \author Takashi Iwai <tiwai@suse.de>
5d5ac70f0Sopenharmony_ci * \date 2005
6d5ac70f0Sopenharmony_ci *
7d5ac70f0Sopenharmony_ci * External control plugin SDK.
8d5ac70f0Sopenharmony_ci */
9d5ac70f0Sopenharmony_ci
10d5ac70f0Sopenharmony_ci/*
11d5ac70f0Sopenharmony_ci *   This library is free software; you can redistribute it and/or modify
12d5ac70f0Sopenharmony_ci *   it under the terms of the GNU Lesser General Public License as
13d5ac70f0Sopenharmony_ci *   published by the Free Software Foundation; either version 2.1 of
14d5ac70f0Sopenharmony_ci *   the License, or (at your option) any later version.
15d5ac70f0Sopenharmony_ci *
16d5ac70f0Sopenharmony_ci *   This program is distributed in the hope that it will be useful,
17d5ac70f0Sopenharmony_ci *   but WITHOUT ANY WARRANTY; without even the implied warranty of
18d5ac70f0Sopenharmony_ci *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19d5ac70f0Sopenharmony_ci *   GNU Lesser General Public License for more details.
20d5ac70f0Sopenharmony_ci *
21d5ac70f0Sopenharmony_ci *   You should have received a copy of the GNU Lesser General Public
22d5ac70f0Sopenharmony_ci *   License along with this library; if not, write to the Free Software
23d5ac70f0Sopenharmony_ci *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24d5ac70f0Sopenharmony_ci *
25d5ac70f0Sopenharmony_ci */
26d5ac70f0Sopenharmony_ci#ifndef __ALSA_CONTROL_EXTERNAL_H
27d5ac70f0Sopenharmony_ci#define __ALSA_CONTROL_EXTERNAL_H
28d5ac70f0Sopenharmony_ci
29d5ac70f0Sopenharmony_ci#include "control.h"
30d5ac70f0Sopenharmony_ci
31d5ac70f0Sopenharmony_ci#ifdef __cplusplus
32d5ac70f0Sopenharmony_ciextern "C" {
33d5ac70f0Sopenharmony_ci#endif
34d5ac70f0Sopenharmony_ci
35d5ac70f0Sopenharmony_ci/**
36d5ac70f0Sopenharmony_ci *  \defgroup CtlPlugin_SDK External Control Plugin SDK
37d5ac70f0Sopenharmony_ci *  \{
38d5ac70f0Sopenharmony_ci */
39d5ac70f0Sopenharmony_ci
40d5ac70f0Sopenharmony_ci/**
41d5ac70f0Sopenharmony_ci * Define the object entry for external control plugins
42d5ac70f0Sopenharmony_ci */
43d5ac70f0Sopenharmony_ci#define SND_CTL_PLUGIN_ENTRY(name) _snd_ctl_##name##_open
44d5ac70f0Sopenharmony_ci
45d5ac70f0Sopenharmony_ci/**
46d5ac70f0Sopenharmony_ci * Define the symbols of the given control plugin with versions
47d5ac70f0Sopenharmony_ci */
48d5ac70f0Sopenharmony_ci#define SND_CTL_PLUGIN_SYMBOL(name) SND_DLSYM_BUILD_VERSION(SND_CTL_PLUGIN_ENTRY(name), SND_CONTROL_DLSYM_VERSION);
49d5ac70f0Sopenharmony_ci
50d5ac70f0Sopenharmony_ci/**
51d5ac70f0Sopenharmony_ci * Define the control plugin
52d5ac70f0Sopenharmony_ci */
53d5ac70f0Sopenharmony_ci#define SND_CTL_PLUGIN_DEFINE_FUNC(plugin) \
54d5ac70f0Sopenharmony_ciint SND_CTL_PLUGIN_ENTRY(plugin) (snd_ctl_t **handlep, const char *name,\
55d5ac70f0Sopenharmony_ci				  snd_config_t *root, snd_config_t *conf, int mode)
56d5ac70f0Sopenharmony_ci
57d5ac70f0Sopenharmony_ci/** External control plugin handle */
58d5ac70f0Sopenharmony_citypedef struct snd_ctl_ext snd_ctl_ext_t;
59d5ac70f0Sopenharmony_ci/** Callback table of control ext */
60d5ac70f0Sopenharmony_citypedef struct snd_ctl_ext_callback snd_ctl_ext_callback_t;
61d5ac70f0Sopenharmony_ci/** Key to access a control pointer */
62d5ac70f0Sopenharmony_citypedef unsigned long snd_ctl_ext_key_t;
63d5ac70f0Sopenharmony_ci#ifdef DOC_HIDDEN
64d5ac70f0Sopenharmony_ci/* redefine typedef's for stupid doxygen */
65d5ac70f0Sopenharmony_citypedef snd_ctl_ext snd_ctl_ext_t;
66d5ac70f0Sopenharmony_citypedef snd_ctl_ext_callback snd_ctl_ext_callback_t;
67d5ac70f0Sopenharmony_ci#endif
68d5ac70f0Sopenharmony_ci/** Callback to handle TLV commands. */
69d5ac70f0Sopenharmony_citypedef int (snd_ctl_ext_tlv_rw_t)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, int op_flag, unsigned int numid,
70d5ac70f0Sopenharmony_ci				   unsigned int *tlv, unsigned int tlv_size);
71d5ac70f0Sopenharmony_ci
72d5ac70f0Sopenharmony_ci/*
73d5ac70f0Sopenharmony_ci * Protocol version
74d5ac70f0Sopenharmony_ci */
75d5ac70f0Sopenharmony_ci#define SND_CTL_EXT_VERSION_MAJOR	1	/**< Protocol major version */
76d5ac70f0Sopenharmony_ci#define SND_CTL_EXT_VERSION_MINOR	0	/**< Protocol minor version */
77d5ac70f0Sopenharmony_ci#define SND_CTL_EXT_VERSION_TINY	1	/**< Protocol tiny version */
78d5ac70f0Sopenharmony_ci/**
79d5ac70f0Sopenharmony_ci * external plugin protocol version
80d5ac70f0Sopenharmony_ci */
81d5ac70f0Sopenharmony_ci#define SND_CTL_EXT_VERSION		((SND_CTL_EXT_VERSION_MAJOR<<16) |\
82d5ac70f0Sopenharmony_ci					 (SND_CTL_EXT_VERSION_MINOR<<8) |\
83d5ac70f0Sopenharmony_ci					 (SND_CTL_EXT_VERSION_TINY))
84d5ac70f0Sopenharmony_ci
85d5ac70f0Sopenharmony_ci/** Handle of control ext */
86d5ac70f0Sopenharmony_cistruct snd_ctl_ext {
87d5ac70f0Sopenharmony_ci	/**
88d5ac70f0Sopenharmony_ci	 * protocol version; #SND_CTL_EXT_VERSION must be filled here
89d5ac70f0Sopenharmony_ci	 * before calling #snd_ctl_ext_create()
90d5ac70f0Sopenharmony_ci	 */
91d5ac70f0Sopenharmony_ci	unsigned int version;
92d5ac70f0Sopenharmony_ci	/**
93d5ac70f0Sopenharmony_ci	 * Index of this card; must be filled before calling #snd_ctl_ext_create()
94d5ac70f0Sopenharmony_ci	 */
95d5ac70f0Sopenharmony_ci	int card_idx;
96d5ac70f0Sopenharmony_ci	/**
97d5ac70f0Sopenharmony_ci	 * ID string of this card; must be filled before calling #snd_ctl_ext_create()
98d5ac70f0Sopenharmony_ci	 */
99d5ac70f0Sopenharmony_ci	char id[16];
100d5ac70f0Sopenharmony_ci	/**
101d5ac70f0Sopenharmony_ci	 * Driver name of this card; must be filled before calling #snd_ctl_ext_create()
102d5ac70f0Sopenharmony_ci	 */
103d5ac70f0Sopenharmony_ci	char driver[16];
104d5ac70f0Sopenharmony_ci	/**
105d5ac70f0Sopenharmony_ci	 * short name of this card; must be filled before calling #snd_ctl_ext_create()
106d5ac70f0Sopenharmony_ci	 */
107d5ac70f0Sopenharmony_ci	char name[32];
108d5ac70f0Sopenharmony_ci	/**
109d5ac70f0Sopenharmony_ci	 * Long name of this card; must be filled before calling #snd_ctl_ext_create()
110d5ac70f0Sopenharmony_ci	 */
111d5ac70f0Sopenharmony_ci	char longname[80];
112d5ac70f0Sopenharmony_ci	/**
113d5ac70f0Sopenharmony_ci	 * Mixer name of this card; must be filled before calling #snd_ctl_ext_create()
114d5ac70f0Sopenharmony_ci	 */
115d5ac70f0Sopenharmony_ci	char mixername[80];
116d5ac70f0Sopenharmony_ci	/**
117d5ac70f0Sopenharmony_ci	 * poll descriptor
118d5ac70f0Sopenharmony_ci	 */
119d5ac70f0Sopenharmony_ci	int poll_fd;
120d5ac70f0Sopenharmony_ci
121d5ac70f0Sopenharmony_ci	/**
122d5ac70f0Sopenharmony_ci	 * callbacks of this plugin; must be filled before calling #snd_pcm_ioplug_create()
123d5ac70f0Sopenharmony_ci	 */
124d5ac70f0Sopenharmony_ci	const snd_ctl_ext_callback_t *callback;
125d5ac70f0Sopenharmony_ci	/**
126d5ac70f0Sopenharmony_ci	 * private data, which can be used freely in the driver callbacks
127d5ac70f0Sopenharmony_ci	 */
128d5ac70f0Sopenharmony_ci	void *private_data;
129d5ac70f0Sopenharmony_ci	/**
130d5ac70f0Sopenharmony_ci	 * control handle filled by #snd_ctl_ext_create()
131d5ac70f0Sopenharmony_ci	 */
132d5ac70f0Sopenharmony_ci	snd_ctl_t *handle;
133d5ac70f0Sopenharmony_ci
134d5ac70f0Sopenharmony_ci	int nonblock;			/**< non-block mode; read-only */
135d5ac70f0Sopenharmony_ci	int subscribed;			/**< events subscribed; read-only */
136d5ac70f0Sopenharmony_ci
137d5ac70f0Sopenharmony_ci	/**
138d5ac70f0Sopenharmony_ci	 * optional TLV data for the control (since protocol 1.0.1)
139d5ac70f0Sopenharmony_ci	 */
140d5ac70f0Sopenharmony_ci	union {
141d5ac70f0Sopenharmony_ci		snd_ctl_ext_tlv_rw_t *c;
142d5ac70f0Sopenharmony_ci		const unsigned int *p;
143d5ac70f0Sopenharmony_ci	} tlv;
144d5ac70f0Sopenharmony_ci};
145d5ac70f0Sopenharmony_ci
146d5ac70f0Sopenharmony_ci/** Callback table of ext. */
147d5ac70f0Sopenharmony_cistruct snd_ctl_ext_callback {
148d5ac70f0Sopenharmony_ci	/**
149d5ac70f0Sopenharmony_ci	 * close the control handle; optional
150d5ac70f0Sopenharmony_ci	 */
151d5ac70f0Sopenharmony_ci	void (*close)(snd_ctl_ext_t *ext);
152d5ac70f0Sopenharmony_ci	/**
153d5ac70f0Sopenharmony_ci	 * return the total number of elements; required
154d5ac70f0Sopenharmony_ci	 */
155d5ac70f0Sopenharmony_ci	int (*elem_count)(snd_ctl_ext_t *ext);
156d5ac70f0Sopenharmony_ci	/**
157d5ac70f0Sopenharmony_ci	 * return the element id of the given offset (array index); required
158d5ac70f0Sopenharmony_ci	 */
159d5ac70f0Sopenharmony_ci	int (*elem_list)(snd_ctl_ext_t *ext, unsigned int offset, snd_ctl_elem_id_t *id);
160d5ac70f0Sopenharmony_ci	/**
161d5ac70f0Sopenharmony_ci	 * convert the element id to a search key; required
162d5ac70f0Sopenharmony_ci	 */
163d5ac70f0Sopenharmony_ci	snd_ctl_ext_key_t (*find_elem)(snd_ctl_ext_t *ext, const snd_ctl_elem_id_t *id);
164d5ac70f0Sopenharmony_ci	/**
165d5ac70f0Sopenharmony_ci	 * the destructor of the key; optional
166d5ac70f0Sopenharmony_ci	 */
167d5ac70f0Sopenharmony_ci	void (*free_key)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key);
168d5ac70f0Sopenharmony_ci	/**
169d5ac70f0Sopenharmony_ci	 * get the attribute of the element; required
170d5ac70f0Sopenharmony_ci	 */
171d5ac70f0Sopenharmony_ci	int (*get_attribute)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key,
172d5ac70f0Sopenharmony_ci			     int *type, unsigned int *acc, unsigned int *count);
173d5ac70f0Sopenharmony_ci	/**
174d5ac70f0Sopenharmony_ci	 * get the element information of integer type
175d5ac70f0Sopenharmony_ci	 */
176d5ac70f0Sopenharmony_ci	int (*get_integer_info)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key,
177d5ac70f0Sopenharmony_ci				long *imin, long *imax, long *istep);
178d5ac70f0Sopenharmony_ci	/**
179d5ac70f0Sopenharmony_ci	 * get the element information of integer64 type
180d5ac70f0Sopenharmony_ci	 */
181d5ac70f0Sopenharmony_ci	int (*get_integer64_info)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key,
182d5ac70f0Sopenharmony_ci				  int64_t *imin, int64_t *imax, int64_t *istep);
183d5ac70f0Sopenharmony_ci	/**
184d5ac70f0Sopenharmony_ci	 * get the element information of enumerated type
185d5ac70f0Sopenharmony_ci	 */
186d5ac70f0Sopenharmony_ci	int (*get_enumerated_info)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned int *items);
187d5ac70f0Sopenharmony_ci	/**
188d5ac70f0Sopenharmony_ci	 * get the name of the enumerated item
189d5ac70f0Sopenharmony_ci	 */
190d5ac70f0Sopenharmony_ci	int (*get_enumerated_name)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned int item,
191d5ac70f0Sopenharmony_ci				   char *name, size_t name_max_len);
192d5ac70f0Sopenharmony_ci	/**
193d5ac70f0Sopenharmony_ci	 * read the current values of integer type
194d5ac70f0Sopenharmony_ci	 */
195d5ac70f0Sopenharmony_ci	int (*read_integer)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *value);
196d5ac70f0Sopenharmony_ci	/**
197d5ac70f0Sopenharmony_ci	 * read the current values of integer64 type
198d5ac70f0Sopenharmony_ci	 */
199d5ac70f0Sopenharmony_ci	int (*read_integer64)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, int64_t *value);
200d5ac70f0Sopenharmony_ci	/**
201d5ac70f0Sopenharmony_ci	 * read the current values of enumerated type
202d5ac70f0Sopenharmony_ci	 */
203d5ac70f0Sopenharmony_ci	int (*read_enumerated)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned int *items);
204d5ac70f0Sopenharmony_ci	/**
205d5ac70f0Sopenharmony_ci	 * read the current values of bytes type
206d5ac70f0Sopenharmony_ci	 */
207d5ac70f0Sopenharmony_ci	int (*read_bytes)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned char *data,
208d5ac70f0Sopenharmony_ci			  size_t max_bytes);
209d5ac70f0Sopenharmony_ci	/**
210d5ac70f0Sopenharmony_ci	 * read the current values of iec958 type
211d5ac70f0Sopenharmony_ci	 */
212d5ac70f0Sopenharmony_ci	int (*read_iec958)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, snd_aes_iec958_t *iec958);
213d5ac70f0Sopenharmony_ci	/**
214d5ac70f0Sopenharmony_ci	 * update the current values of integer type with the given values
215d5ac70f0Sopenharmony_ci	 */
216d5ac70f0Sopenharmony_ci	int (*write_integer)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *value);
217d5ac70f0Sopenharmony_ci	/**
218d5ac70f0Sopenharmony_ci	 * update the current values of integer64 type with the given values
219d5ac70f0Sopenharmony_ci	 */
220d5ac70f0Sopenharmony_ci	int (*write_integer64)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, int64_t *value);
221d5ac70f0Sopenharmony_ci	/**
222d5ac70f0Sopenharmony_ci	 * update the current values of enumerated type with the given values
223d5ac70f0Sopenharmony_ci	 */
224d5ac70f0Sopenharmony_ci	int (*write_enumerated)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned int *items);
225d5ac70f0Sopenharmony_ci	/**
226d5ac70f0Sopenharmony_ci	 * update the current values of bytes type with the given values
227d5ac70f0Sopenharmony_ci	 */
228d5ac70f0Sopenharmony_ci	int (*write_bytes)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned char *data,
229d5ac70f0Sopenharmony_ci			   size_t max_bytes);
230d5ac70f0Sopenharmony_ci	/**
231d5ac70f0Sopenharmony_ci	 * update the current values of iec958 type with the given values
232d5ac70f0Sopenharmony_ci	 */
233d5ac70f0Sopenharmony_ci	int (*write_iec958)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, snd_aes_iec958_t *iec958);
234d5ac70f0Sopenharmony_ci	/**
235d5ac70f0Sopenharmony_ci	 * subscribe/unsubscribe the event notification; optional
236d5ac70f0Sopenharmony_ci	 */
237d5ac70f0Sopenharmony_ci	void (*subscribe_events)(snd_ctl_ext_t *ext, int subscribe);
238d5ac70f0Sopenharmony_ci	/**
239d5ac70f0Sopenharmony_ci	 * read a pending notification event; optional
240d5ac70f0Sopenharmony_ci	 */
241d5ac70f0Sopenharmony_ci	int (*read_event)(snd_ctl_ext_t *ext, snd_ctl_elem_id_t *id, unsigned int *event_mask);
242d5ac70f0Sopenharmony_ci	/**
243d5ac70f0Sopenharmony_ci	 * return the number of poll descriptors; optional
244d5ac70f0Sopenharmony_ci	 */
245d5ac70f0Sopenharmony_ci	int (*poll_descriptors_count)(snd_ctl_ext_t *ext);
246d5ac70f0Sopenharmony_ci	/**
247d5ac70f0Sopenharmony_ci	 * fill the poll descriptors; optional
248d5ac70f0Sopenharmony_ci	 */
249d5ac70f0Sopenharmony_ci	int (*poll_descriptors)(snd_ctl_ext_t *ext, struct pollfd *pfds, unsigned int space);
250d5ac70f0Sopenharmony_ci	/**
251d5ac70f0Sopenharmony_ci	 * mangle the revents of poll descriptors
252d5ac70f0Sopenharmony_ci	 */
253d5ac70f0Sopenharmony_ci	int (*poll_revents)(snd_ctl_ext_t *ext, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
254d5ac70f0Sopenharmony_ci};
255d5ac70f0Sopenharmony_ci
256d5ac70f0Sopenharmony_ci/**
257d5ac70f0Sopenharmony_ci * The access type bits stored in get_attribute callback
258d5ac70f0Sopenharmony_ci */
259d5ac70f0Sopenharmony_citypedef enum snd_ctl_ext_access {
260d5ac70f0Sopenharmony_ci	SND_CTL_EXT_ACCESS_READ = (1<<0),
261d5ac70f0Sopenharmony_ci	SND_CTL_EXT_ACCESS_WRITE = (1<<1),
262d5ac70f0Sopenharmony_ci	SND_CTL_EXT_ACCESS_READWRITE = (3<<0),
263d5ac70f0Sopenharmony_ci	SND_CTL_EXT_ACCESS_VOLATILE = (1<<2),
264d5ac70f0Sopenharmony_ci	SND_CTL_EXT_ACCESS_TLV_READ = (1<<4),
265d5ac70f0Sopenharmony_ci	SND_CTL_EXT_ACCESS_TLV_WRITE = (1<<5),
266d5ac70f0Sopenharmony_ci	SND_CTL_EXT_ACCESS_TLV_READWRITE = (3<<4),
267d5ac70f0Sopenharmony_ci	SND_CTL_EXT_ACCESS_TLV_COMMAND = (1<<6),
268d5ac70f0Sopenharmony_ci	SND_CTL_EXT_ACCESS_INACTIVE = (1<<8),
269d5ac70f0Sopenharmony_ci	SND_CTL_EXT_ACCESS_TLV_CALLBACK = (1<<28),
270d5ac70f0Sopenharmony_ci} snd_ctl_ext_access_t;
271d5ac70f0Sopenharmony_ci
272d5ac70f0Sopenharmony_ci/**
273d5ac70f0Sopenharmony_ci * find_elem callback returns this if no matching control element is found
274d5ac70f0Sopenharmony_ci */
275d5ac70f0Sopenharmony_ci#define SND_CTL_EXT_KEY_NOT_FOUND	(snd_ctl_ext_key_t)(-1)
276d5ac70f0Sopenharmony_ci
277d5ac70f0Sopenharmony_ciint snd_ctl_ext_create(snd_ctl_ext_t *ext, const char *name, int mode);
278d5ac70f0Sopenharmony_ciint snd_ctl_ext_delete(snd_ctl_ext_t *ext);
279d5ac70f0Sopenharmony_ci
280d5ac70f0Sopenharmony_ci/** \} */
281d5ac70f0Sopenharmony_ci
282d5ac70f0Sopenharmony_ci#ifdef __cplusplus
283d5ac70f0Sopenharmony_ci}
284d5ac70f0Sopenharmony_ci#endif
285d5ac70f0Sopenharmony_ci
286d5ac70f0Sopenharmony_ci#endif /* __ALSA_CONTROL_EXTERNAL_H */
287