sndstat.h revision 193640
1/*-
2 * Copyright (c) 2007-2009 Ariff Abdullah <ariff@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/dev/sound/pcm/sndstat.h 193640 2009-06-07 19:12:08Z ariff $
27 */
28
29#ifndef _SND_SNDSTAT_H_
30#define _SND_SNDSTAT_H_
31
32#define SNDSTAT_PREPARE_PCM_ARGS					\
33	struct sbuf *s, device_t dev, int verbose
34
35#define SNDSTAT_PREPARE_PCM_BEGIN()	do {				\
36	struct snddev_info *d;						\
37	struct pcm_channel *c;						\
38	struct pcm_feeder *f;						\
39									\
40	if (verbose < 1)						\
41		return (0);						\
42									\
43	d = device_get_softc(dev);					\
44	PCM_BUSYASSERT(d);						\
45									\
46	if (CHN_EMPTY(d, channels.pcm)) {				\
47		sbuf_printf(s, " (mixer only)");			\
48		return (0);						\
49	}								\
50									\
51	sbuf_printf(s, " (%dp:%dv/%dr:%dv channels %splex%s)",		\
52	    d->playcount, d->pvchancount, d->reccount, d->rvchancount,	\
53	    (d->flags & SD_F_SIMPLEX) ? "sim" : "du",			\
54	    (device_get_unit(dev) == snd_unit) ? " default" : "")
55
56
57#define SNDSTAT_PREPARE_PCM_END()					\
58	if (verbose <= 1)						\
59		return (0);						\
60									\
61	sbuf_printf(s, "\n\t");						\
62	sbuf_printf(s, "snddev flags=0x%b", d->flags, SD_F_BITS);	\
63									\
64	CHN_FOREACH(c, d, channels.pcm) {				\
65									\
66		KASSERT(c->bufhard != NULL && c->bufsoft != NULL,	\
67		    ("hosed pcm channel setup"));			\
68									\
69		sbuf_printf(s, "\n\t");					\
70									\
71		sbuf_printf(s, "%s[%s]: ",				\
72		    (c->parentchannel != NULL) ?			\
73		    c->parentchannel->name : "", c->name);		\
74		sbuf_printf(s, "spd %d", c->speed);			\
75		if (c->speed != sndbuf_getspd(c->bufhard))		\
76			sbuf_printf(s, "/%d",				\
77			    sndbuf_getspd(c->bufhard));			\
78		sbuf_printf(s, ", fmt 0x%08x", c->format);		\
79		if (c->format != sndbuf_getfmt(c->bufhard))		\
80			sbuf_printf(s, "/0x%08x",			\
81			    sndbuf_getfmt(c->bufhard));			\
82		sbuf_printf(s, ", flags 0x%08x, 0x%08x",		\
83		    c->flags, c->feederflags);				\
84		if (c->pid != -1)					\
85			sbuf_printf(s, ", pid %d (%s)",			\
86			    c->pid, c->comm);				\
87		sbuf_printf(s, "\n\t");					\
88									\
89		sbuf_printf(s, "interrupts %d, ", c->interrupts);	\
90									\
91		if (c->direction == PCMDIR_REC)				\
92			sbuf_printf(s,					\
93			    "overruns %d, feed %u, hfree %d, "		\
94			    "sfree %d [b:%d/%d/%d|bs:%d/%d/%d]",	\
95				c->xruns, c->feedcount,			\
96				sndbuf_getfree(c->bufhard),		\
97				sndbuf_getfree(c->bufsoft),		\
98				sndbuf_getsize(c->bufhard),		\
99				sndbuf_getblksz(c->bufhard),		\
100				sndbuf_getblkcnt(c->bufhard),		\
101				sndbuf_getsize(c->bufsoft),		\
102				sndbuf_getblksz(c->bufsoft),		\
103				sndbuf_getblkcnt(c->bufsoft));		\
104		else							\
105			sbuf_printf(s,					\
106			    "underruns %d, feed %u, ready %d "		\
107			    "[b:%d/%d/%d|bs:%d/%d/%d]",			\
108				c->xruns, c->feedcount,			\
109				sndbuf_getready(c->bufsoft),		\
110				sndbuf_getsize(c->bufhard),		\
111				sndbuf_getblksz(c->bufhard),		\
112				sndbuf_getblkcnt(c->bufhard),		\
113				sndbuf_getsize(c->bufsoft),		\
114				sndbuf_getblksz(c->bufsoft),		\
115				sndbuf_getblkcnt(c->bufsoft));		\
116		sbuf_printf(s, "\n\t");					\
117									\
118		sbuf_printf(s, "channel flags=0x%b", c->flags,		\
119		    CHN_F_BITS);					\
120		sbuf_printf(s, "\n\t");					\
121									\
122		sbuf_printf(s, "{%s}",					\
123		    (c->direction == PCMDIR_REC) ? "hardware" :		\
124		    "userland");					\
125		sbuf_printf(s, " -> ");					\
126		f = c->feeder;						\
127		while (f->source != NULL)				\
128			f = f->source;					\
129		while (f != NULL) {					\
130			sbuf_printf(s, "%s", f->class->name);		\
131			if (f->desc->type == FEEDER_FORMAT)		\
132				sbuf_printf(s, "(0x%08x -> 0x%08x)",	\
133				    f->desc->in, f->desc->out);		\
134			else if (f->desc->type == FEEDER_MATRIX)	\
135				sbuf_printf(s, "(%d.%d -> %d.%d)",	\
136				    AFMT_CHANNEL(f->desc->in) -		\
137				    AFMT_EXTCHANNEL(f->desc->in),	\
138				    AFMT_EXTCHANNEL(f->desc->in),	\
139				    AFMT_CHANNEL(f->desc->out) -	\
140				    AFMT_EXTCHANNEL(f->desc->out),	\
141				    AFMT_EXTCHANNEL(f->desc->out));	\
142			else if (f->desc->type == FEEDER_RATE)		\
143				sbuf_printf(s,				\
144				    "(0x%08x q:%d %d -> %d)",		\
145				    f->desc->out,			\
146				    FEEDER_GET(f, FEEDRATE_QUALITY),	\
147				    FEEDER_GET(f, FEEDRATE_SRC),	\
148				    FEEDER_GET(f, FEEDRATE_DST));	\
149			else						\
150				sbuf_printf(s, "(0x%08x)",		\
151				    f->desc->out);			\
152			sbuf_printf(s, " -> ");				\
153			f = f->parent;					\
154		}							\
155		sbuf_printf(s, "{%s}",					\
156		    (c->direction == PCMDIR_REC) ? "userland" :		\
157		    "hardware");					\
158	}								\
159									\
160	return (0);							\
161} while (0)
162
163#endif	/* !_SND_SNDSTAT_H_ */
164