channel_if.m revision 167645
1178479Sjb#-
2178479Sjb# KOBJ
3178479Sjb#
4178479Sjb# Copyright (c) 2000 Cameron Grant <cg@freebsd.org>
5210767Srpaulo# All rights reserved.
6210767Srpaulo#
7178479Sjb# Redistribution and use in source and binary forms, with or without
8178479Sjb# modification, are permitted provided that the following conditions
9178479Sjb# are met:
10178479Sjb# 1. Redistributions of source code must retain the above copyright
11178479Sjb#    notice, this list of conditions and the following disclaimer.
12178479Sjb# 2. Redistributions in binary form must reproduce the above copyright
13178479Sjb#    notice, this list of conditions and the following disclaimer in the
14178479Sjb#    documentation and/or other materials provided with the distribution.
15178479Sjb#
16178479Sjb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17178479Sjb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18178479Sjb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19178479Sjb# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20178479Sjb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21210767Srpaulo# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22178479Sjb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23210767Srpaulo# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24178479Sjb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25178479Sjb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26178479Sjb# SUCH DAMAGE.
27178479Sjb#
28178479Sjb# $FreeBSD: head/sys/dev/sound/pcm/channel_if.m 167645 2007-03-16 17:16:24Z ariff $
29178479Sjb#
30178479Sjb
31178479Sjb#include <dev/sound/pcm/sound.h>
32210767Srpaulo
33178479SjbINTERFACE channel;
34178479Sjb
35178479SjbCODE {
36178479Sjb
37178479Sjb	static int
38178479Sjb	channel_nosetdir(kobj_t obj, void *data, int dir)
39178479Sjb	{
40178479Sjb		return 0;
41178479Sjb	}
42210767Srpaulo
43210767Srpaulo	static int
44210767Srpaulo	channel_noreset(kobj_t obj, void *data)
45178479Sjb	{
46178479Sjb		return 0;
47178479Sjb	}
48178479Sjb
49178479Sjb	static int
50178479Sjb	channel_noresetdone(kobj_t obj, void *data)
51178479Sjb	{
52178479Sjb		return 0;
53178479Sjb	}
54178479Sjb
55178479Sjb	static int
56178479Sjb	channel_nofree(kobj_t obj, void *data)
57178479Sjb	{
58178479Sjb		return 1;
59178479Sjb	}
60178479Sjb
61178479Sjb	static u_int32_t
62178479Sjb	channel_nogetptr(kobj_t obj, void *data)
63178479Sjb	{
64178479Sjb		return 0;
65178479Sjb	}
66178479Sjb
67178479Sjb	static int
68178479Sjb	channel_nonotify(kobj_t obj, void *data, u_int32_t changed)
69178479Sjb	{
70178479Sjb		return 0;
71178479Sjb	}
72178479Sjb
73178479Sjb	static int
74178479Sjb	channel_nogetpeaks(kobj_t obj, void *data, int *lpeak, int *rpeak)
75178479Sjb	{
76178479Sjb		return -1;
77178479Sjb	}
78178479Sjb
79178479Sjb	static int
80178479Sjb	channel_nogetrates(kobj_t obj, void *data, int **rates)
81178479Sjb	{
82178479Sjb		*rates = NULL;
83178479Sjb		return 0;
84178479Sjb	}
85178479Sjb
86178479Sjb	static int
87178479Sjb	channel_nosetfragments(kobj_t obj, void *data, u_int32_t blocksize, u_int32_t blockcount)
88178479Sjb	{
89178479Sjb		return 0;
90178479Sjb	}
91178479Sjb
92178479Sjb};
93178479Sjb
94178479SjbMETHOD void* init {
95178479Sjb	kobj_t obj;
96178479Sjb	void *devinfo;
97178479Sjb	struct snd_dbuf *b;
98178479Sjb	struct pcm_channel *c;
99178479Sjb	int dir;
100178479Sjb};
101178479Sjb
102178479SjbMETHOD int free {
103178479Sjb	kobj_t obj;
104178479Sjb	void *data;
105178479Sjb} DEFAULT channel_nofree;
106178479Sjb
107178479SjbMETHOD int reset {
108178479Sjb	kobj_t obj;
109178479Sjb	void *data;
110178479Sjb} DEFAULT channel_noreset;
111178479Sjb
112178479SjbMETHOD int resetdone {
113178479Sjb	kobj_t obj;
114178479Sjb	void *data;
115178479Sjb} DEFAULT channel_noresetdone;
116178479Sjb
117178479SjbMETHOD int setdir {
118178479Sjb	kobj_t obj;
119178479Sjb	void *data;
120178479Sjb	int dir;
121178479Sjb} DEFAULT channel_nosetdir;
122178479Sjb
123178479SjbMETHOD u_int32_t setformat {
124178479Sjb	kobj_t obj;
125178479Sjb	void *data;
126178479Sjb	u_int32_t format;
127178479Sjb};
128178479Sjb
129178479SjbMETHOD u_int32_t setspeed {
130178479Sjb	kobj_t obj;
131178479Sjb	void *data;
132178479Sjb	u_int32_t speed;
133178479Sjb};
134178479Sjb
135178479SjbMETHOD u_int32_t setblocksize {
136178479Sjb	kobj_t obj;
137178479Sjb	void *data;
138178479Sjb	u_int32_t blocksize;
139178479Sjb};
140178479Sjb
141178479SjbMETHOD int setfragments {
142178479Sjb	kobj_t obj;
143178479Sjb	void *data;
144178479Sjb	u_int32_t blocksize;
145178479Sjb	u_int32_t blockcount;
146178479Sjb} DEFAULT channel_nosetfragments;
147178479Sjb
148178479SjbMETHOD int trigger {
149178479Sjb	kobj_t obj;
150178479Sjb	void *data;
151178479Sjb	int go;
152178479Sjb};
153178479Sjb
154178479SjbMETHOD u_int32_t getptr {
155178479Sjb	kobj_t obj;
156178479Sjb	void *data;
157178479Sjb} DEFAULT channel_nogetptr;
158178479Sjb
159178479SjbMETHOD struct pcmchan_caps* getcaps {
160178479Sjb	kobj_t obj;
161178479Sjb	void *data;
162178479Sjb};
163178479Sjb
164178479SjbMETHOD int notify {
165178479Sjb	kobj_t obj;
166178479Sjb	void *data;
167178479Sjb	u_int32_t changed;
168178479Sjb} DEFAULT channel_nonotify;
169178479Sjb
170178479Sjb/**
171178479Sjb * @brief Retrieve channel peak values
172178479Sjb *
173178479Sjb * This function is intended to obtain peak volume values for samples
174178479Sjb * played/recorded on a channel.  Values are on a linear scale from 0 to
175178479Sjb * 32767.  If the channel is monaural, a single value should be recorded
176178479Sjb * in @c lpeak.
177178479Sjb *
178178479Sjb * If hardware support isn't available, the SNDCTL_DSP_GET[IO]PEAKS
179178479Sjb * operation should return EINVAL.  However, we may opt to provide
180178479Sjb * software support that the user may toggle via sysctl/mixext.
181178479Sjb *
182178479Sjb * @param obj	standard kobj object (usually @c channel->methods)
183178479Sjb * @param data	driver-specific data (usually @c channel->devinfo)
184178479Sjb * @param lpeak	pointer to store left peak level
185178479Sjb * @param rpeak	pointer to store right peak level
186178479Sjb *
187178479Sjb * @retval -1	Error; usually operation isn't supported.
188178479Sjb * @retval 0	success
189178479Sjb */
190178479SjbMETHOD int getpeaks {
191178479Sjb	kobj_t obj;
192178479Sjb	void *data;
193178479Sjb	int *lpeak;
194178479Sjb	int *rpeak;
195178479Sjb} DEFAULT channel_nogetpeaks;
196178479Sjb
197178479Sjb/**
198178479Sjb * @brief Retrieve discrete supported sample rates
199178479Sjb *
200178479Sjb * Some cards operate at fixed rates, and this call is intended to retrieve
201178479Sjb * those rates primarily for when in-kernel rate adjustment is undesirable
202178479Sjb * (e.g., application wants direct DMA access after setting a channel to run
203178479Sjb * "uncooked").
204178479Sjb *
205178479Sjb * The parameter @c rates is a double pointer which will be reset to
206178479Sjb * point to an array of supported sample rates.  The number of elements
207178479Sjb * in the array is returned to the caller.
208178479Sjb *
209178479Sjb * @param obj	standard kobj object (usually @c channel->methods)
210178479Sjb * @param data	driver-specific data (usually @c channel->devinfo)
211178479Sjb * @param rates	rate array pointer
212178479Sjb *
213178479Sjb * @return Number of rates in the array
214178479Sjb */
215178479SjbMETHOD int getrates {
216178479Sjb	kobj_t obj;
217178479Sjb	void *data;
218178479Sjb	int **rates;
219178479Sjb} DEFAULT channel_nogetrates;
220178479Sjb