xref: /freebsd/sys/dev/sound/pcm/channel_if.m (revision 031beb4e239bfce798af17f5fe8dba8bcaf13d99)
1#-
2# KOBJ
3#
4# Copyright (c) 2005-2009 Ariff Abdullah <ariff@FreeBSD.org>
5# Portions Copyright (c) Ryan Beasley <ryan.beasley@gmail.com> - GSoC 2006
6# Copyright (c) 2000 Cameron Grant <cg@FreeBSD.org>
7# All rights reserved.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions
11# are met:
12# 1. Redistributions of source code must retain the above copyright
13#    notice, this list of conditions and the following disclaimer.
14# 2. Redistributions in binary form must reproduce the above copyright
15#    notice, this list of conditions and the following disclaimer in the
16#    documentation and/or other materials provided with the distribution.
17#
18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28# SUCH DAMAGE.
29#
30#
31
32#include <dev/sound/pcm/sound.h>
33
34INTERFACE channel;
35
36CODE {
37
38	static int
39	channel_noreset(kobj_t obj, void *data)
40	{
41		return 0;
42	}
43
44	static int
45	channel_noresetdone(kobj_t obj, void *data)
46	{
47		return 0;
48	}
49
50	static int
51	channel_nofree(kobj_t obj, void *data)
52	{
53		return 1;
54	}
55
56	static u_int32_t
57	channel_nogetptr(kobj_t obj, void *data)
58	{
59		return 0;
60	}
61
62	static int
63	channel_nonotify(kobj_t obj, void *data, u_int32_t changed)
64	{
65		return 0;
66	}
67
68	static int
69	channel_nogetpeaks(kobj_t obj, void *data, int *lpeak, int *rpeak)
70	{
71		return -1;
72	}
73
74	static int
75	channel_nogetrates(kobj_t obj, void *data, int **rates)
76	{
77		*rates = NULL;
78		return 0;
79	}
80
81	static int
82	channel_nosetfragments(kobj_t obj, void *data, u_int32_t blocksize, u_int32_t blockcount)
83	{
84		return ENOTSUP;
85	}
86
87	static struct pcmchan_matrix *
88	channel_nogetmatrix(kobj_t obj, void *data, u_int32_t format)
89	{
90		format = feeder_matrix_default_format(format);
91		return (feeder_matrix_format_map(format));
92	}
93
94	static int
95	channel_nosetmatrix(kobj_t obj, void *data, struct pcmchan_matrix *m)
96	{
97		return ENOTSUP;
98	}
99};
100
101METHOD void* init {
102	kobj_t obj;
103	void *devinfo;
104	struct snd_dbuf *b;
105	struct pcm_channel *c;
106	int dir;
107};
108
109METHOD int free {
110	kobj_t obj;
111	void *data;
112} DEFAULT channel_nofree;
113
114METHOD int reset {
115	kobj_t obj;
116	void *data;
117} DEFAULT channel_noreset;
118
119METHOD int resetdone {
120	kobj_t obj;
121	void *data;
122} DEFAULT channel_noresetdone;
123
124METHOD int setformat {
125	kobj_t obj;
126	void *data;
127	u_int32_t format;
128};
129
130METHOD u_int32_t setspeed {
131	kobj_t obj;
132	void *data;
133	u_int32_t speed;
134};
135
136METHOD u_int32_t setblocksize {
137	kobj_t obj;
138	void *data;
139	u_int32_t blocksize;
140};
141
142METHOD int setfragments {
143	kobj_t obj;
144	void *data;
145	u_int32_t blocksize;
146	u_int32_t blockcount;
147} DEFAULT channel_nosetfragments;
148
149METHOD int trigger {
150	kobj_t obj;
151	void *data;
152	int go;
153};
154
155METHOD u_int32_t getptr {
156	kobj_t obj;
157	void *data;
158} DEFAULT channel_nogetptr;
159
160METHOD struct pcmchan_caps* getcaps {
161	kobj_t obj;
162	void *data;
163};
164
165METHOD int notify {
166	kobj_t obj;
167	void *data;
168	u_int32_t changed;
169} DEFAULT channel_nonotify;
170
171/**
172 * @brief Retrieve channel peak values
173 *
174 * This function is intended to obtain peak volume values for samples
175 * played/recorded on a channel.  Values are on a linear scale from 0 to
176 * 32767.  If the channel is monaural, a single value should be recorded
177 * in @c lpeak.
178 *
179 * If hardware support isn't available, the SNDCTL_DSP_GET[IO]PEAKS
180 * operation should return EINVAL.  However, we may opt to provide
181 * software support that the user may toggle via sysctl/mixext.
182 *
183 * @param obj	standard kobj object (usually @c channel->methods)
184 * @param data	driver-specific data (usually @c channel->devinfo)
185 * @param lpeak	pointer to store left peak level
186 * @param rpeak	pointer to store right peak level
187 *
188 * @retval -1	Error; usually operation isn't supported.
189 * @retval 0	success
190 */
191METHOD int getpeaks {
192	kobj_t obj;
193	void *data;
194	int *lpeak;
195	int *rpeak;
196} DEFAULT channel_nogetpeaks;
197
198/**
199 * @brief Retrieve discrete supported sample rates
200 *
201 * Some cards operate at fixed rates, and this call is intended to retrieve
202 * those rates primarily for when in-kernel rate adjustment is undesirable
203 * (e.g., application wants direct DMA access after setting a channel to run
204 * "uncooked").
205 *
206 * The parameter @c rates is a double pointer which will be reset to
207 * point to an array of supported sample rates.  The number of elements
208 * in the array is returned to the caller.
209 *
210 * @param obj	standard kobj object (usually @c channel->methods)
211 * @param data	driver-specific data (usually @c channel->devinfo)
212 * @param rates	rate array pointer
213 *
214 * @return Number of rates in the array
215 */
216METHOD int getrates {
217	kobj_t obj;
218	void *data;
219	int **rates;
220} DEFAULT channel_nogetrates;
221
222METHOD struct pcmchan_matrix * getmatrix {
223	kobj_t obj;
224	void *data;
225	u_int32_t format;
226} DEFAULT channel_nogetmatrix;
227
228METHOD int setmatrix {
229	kobj_t obj;
230	void *data;
231	struct pcmchan_matrix *m;
232} DEFAULT channel_nosetmatrix;
233