1139749Simp/*-
2193640Sariff * Copyright (c) 2005-2009 Ariff Abdullah <ariff@FreeBSD.org>
3193640Sariff * Copyright (c) 2001 Cameron Grant <cg@FreeBSD.org>
477269Scg * All rights reserved.
577269Scg *
677269Scg * Redistribution and use in source and binary forms, with or without
777269Scg * modification, are permitted provided that the following conditions
877269Scg * are met:
977269Scg * 1. Redistributions of source code must retain the above copyright
1077269Scg *    notice, this list of conditions and the following disclaimer.
1177269Scg * 2. Redistributions in binary form must reproduce the above copyright
1277269Scg *    notice, this list of conditions and the following disclaimer in the
1377269Scg *    documentation and/or other materials provided with the distribution.
1477269Scg *
1577269Scg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1677269Scg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1777269Scg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1877269Scg * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1977269Scg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2077269Scg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2177269Scg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2277269Scg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2377269Scg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2477269Scg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2577269Scg * SUCH DAMAGE.
2677269Scg *
2777269Scg * $FreeBSD$
2877269Scg */
2977269Scg
30193640Sariff#ifndef _SND_VCHAN_H_
31193640Sariff#define _SND_VCHAN_H_
3277269Scg
33193640Sariffint vchan_create(struct pcm_channel *, int);
34193640Sariffint vchan_destroy(struct pcm_channel *);
35193640Sariff
36193640Sariff#ifdef SND_DEBUG
37193640Sariffint vchan_passthrough(struct pcm_channel *, const char *);
38193640Sariff#define vchan_sync(c)		vchan_passthrough(c, __func__)
39193640Sariff#else
40193640Sariffint vchan_sync(struct pcm_channel *);
41193640Sariff#endif
42193640Sariff
43193640Sariff#define VCHAN_SYNC_REQUIRED(c)						\
44193640Sariff	(((c)->flags & CHN_F_VIRTUAL) && (((c)->flags & CHN_F_DIRTY) ||	\
45193640Sariff	sndbuf_getfmt((c)->bufhard) != (c)->parentchannel->format ||	\
46193640Sariff	sndbuf_getspd((c)->bufhard) != (c)->parentchannel->speed))
47193640Sariff
48193640Sariffvoid vchan_initsys(device_t);
49193640Sariff
50170161Sariff/*
51193640Sariff * Default format / rate
52170161Sariff */
53193640Sariff#define VCHAN_DEFAULT_FORMAT	SND_FORMAT(AFMT_S16_LE, 2, 0)
54193640Sariff#define VCHAN_DEFAULT_RATE	48000
5577269Scg
56170161Sariff#define VCHAN_PLAY		0
57170161Sariff#define VCHAN_REC		1
58170161Sariff
59170161Sariff/*
60170161Sariff * Offset by +/- 1 so we can distinguish bogus pointer.
61170161Sariff */
62170161Sariff#define VCHAN_SYSCTL_DATA(x, y)						\
63170161Sariff		((void *)((intptr_t)(((((x) + 1) & 0xfff) << 2) |	\
64170161Sariff		(((VCHAN_##y) + 1) & 0x3))))
65170161Sariff
66170161Sariff#define VCHAN_SYSCTL_DATA_SIZE	sizeof(void *)
67170161Sariff#define VCHAN_SYSCTL_UNIT(x)	((int)(((intptr_t)(x) >> 2) & 0xfff) - 1)
68170161Sariff#define VCHAN_SYSCTL_DIR(x)	((int)((intptr_t)(x) & 0x3) - 1)
69193640Sariff
70193640Sariff#endif	/* _SND_VCHAN_H_ */
71