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 202267 2010-01-13 22:22:16Z mav $ 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 d = device_get_softc(dev); \ 41 PCM_BUSYASSERT(d); \ 42 \ 43 if (CHN_EMPTY(d, channels.pcm)) { \ 44 sbuf_printf(s, " (mixer only)"); \ 45 return (0); \ 46 } \ 47 \ 48 if (verbose < 1) { \ 49 sbuf_printf(s, " (%s%s%s", \ 50 d->playcount ? "play" : "", \ 51 (d->playcount && d->reccount) ? "/" : "", \ 52 d->reccount ? "rec" : ""); \ 53 } else { \ 54 sbuf_printf(s, " (%dp:%dv/%dr:%dv", \ 55 d->playcount, d->pvchancount, \ 56 d->reccount, d->rvchancount); \ 57 } \ 58 sbuf_printf(s, "%s)%s", \ 59 ((d->playcount != 0 && d->reccount != 0) && \ 60 (d->flags & SD_F_SIMPLEX)) ? " simplex" : "", \ 61 (device_get_unit(dev) == snd_unit) ? " default" : "") 62 63 64 #define SNDSTAT_PREPARE_PCM_END() \ 65 if (verbose <= 1) \ 66 return (0); \ 67 \ 68 sbuf_printf(s, "\n\t"); \ 69 sbuf_printf(s, "snddev flags=0x%b", d->flags, SD_F_BITS); \ 70 \ 71 CHN_FOREACH(c, d, channels.pcm) { \ 72 \ 73 KASSERT(c->bufhard != NULL && c->bufsoft != NULL, \ 74 ("hosed pcm channel setup")); \ 75 \ 76 sbuf_printf(s, "\n\t"); \ 77 \ 78 sbuf_printf(s, "%s[%s]: ", \ 79 (c->parentchannel != NULL) ? \ 80 c->parentchannel->name : "", c->name); \ 81 sbuf_printf(s, "spd %d", c->speed); \ 82 if (c->speed != sndbuf_getspd(c->bufhard)) \ 83 sbuf_printf(s, "/%d", \ 84 sndbuf_getspd(c->bufhard)); \ 85 sbuf_printf(s, ", fmt 0x%08x", c->format); \ 86 if (c->format != sndbuf_getfmt(c->bufhard)) \ 87 sbuf_printf(s, "/0x%08x", \ 88 sndbuf_getfmt(c->bufhard)); \ 89 sbuf_printf(s, ", flags 0x%08x, 0x%08x", \ 90 c->flags, c->feederflags); \ 91 if (c->pid != -1) \ 92 sbuf_printf(s, ", pid %d (%s)", \ 93 c->pid, c->comm); \ 94 sbuf_printf(s, "\n\t"); \ 95 \ 96 sbuf_printf(s, "interrupts %d, ", c->interrupts); \ 97 \ 98 if (c->direction == PCMDIR_REC) \ 99 sbuf_printf(s, \ 100 "overruns %d, feed %u, hfree %d, " \ 101 "sfree %d [b:%d/%d/%d|bs:%d/%d/%d]", \ 102 c->xruns, c->feedcount, \ 103 sndbuf_getfree(c->bufhard), \ 104 sndbuf_getfree(c->bufsoft), \ 105 sndbuf_getsize(c->bufhard), \ 106 sndbuf_getblksz(c->bufhard), \ 107 sndbuf_getblkcnt(c->bufhard), \ 108 sndbuf_getsize(c->bufsoft), \ 109 sndbuf_getblksz(c->bufsoft), \ 110 sndbuf_getblkcnt(c->bufsoft)); \ 111 else \ 112 sbuf_printf(s, \ 113 "underruns %d, feed %u, ready %d " \ 114 "[b:%d/%d/%d|bs:%d/%d/%d]", \ 115 c->xruns, c->feedcount, \ 116 sndbuf_getready(c->bufsoft), \ 117 sndbuf_getsize(c->bufhard), \ 118 sndbuf_getblksz(c->bufhard), \ 119 sndbuf_getblkcnt(c->bufhard), \ 120 sndbuf_getsize(c->bufsoft), \ 121 sndbuf_getblksz(c->bufsoft), \ 122 sndbuf_getblkcnt(c->bufsoft)); \ 123 sbuf_printf(s, "\n\t"); \ 124 \ 125 sbuf_printf(s, "channel flags=0x%b", c->flags, \ 126 CHN_F_BITS); \ 127 sbuf_printf(s, "\n\t"); \ 128 \ 129 sbuf_printf(s, "{%s}", \ 130 (c->direction == PCMDIR_REC) ? "hardware" : \ 131 "userland"); \ 132 sbuf_printf(s, " -> "); \ 133 f = c->feeder; \ 134 while (f->source != NULL) \ 135 f = f->source; \ 136 while (f != NULL) { \ 137 sbuf_printf(s, "%s", f->class->name); \ 138 if (f->desc->type == FEEDER_FORMAT) \ 139 sbuf_printf(s, "(0x%08x -> 0x%08x)", \ 140 f->desc->in, f->desc->out); \ 141 else if (f->desc->type == FEEDER_MATRIX) \ 142 sbuf_printf(s, "(%d.%d -> %d.%d)", \ 143 AFMT_CHANNEL(f->desc->in) - \ 144 AFMT_EXTCHANNEL(f->desc->in), \ 145 AFMT_EXTCHANNEL(f->desc->in), \ 146 AFMT_CHANNEL(f->desc->out) - \ 147 AFMT_EXTCHANNEL(f->desc->out), \ 148 AFMT_EXTCHANNEL(f->desc->out)); \ 149 else if (f->desc->type == FEEDER_RATE) \ 150 sbuf_printf(s, \ 151 "(0x%08x q:%d %d -> %d)", \ 152 f->desc->out, \ 153 FEEDER_GET(f, FEEDRATE_QUALITY), \ 154 FEEDER_GET(f, FEEDRATE_SRC), \ 155 FEEDER_GET(f, FEEDRATE_DST)); \ 156 else \ 157 sbuf_printf(s, "(0x%08x)", \ 158 f->desc->out); \ 159 sbuf_printf(s, " -> "); \ 160 f = f->parent; \ 161 } \ 162 sbuf_printf(s, "{%s}", \ 163 (c->direction == PCMDIR_REC) ? "userland" : \ 164 "hardware"); \ 165 } \ 166 \ 167 return (0); \ 168 } while (0) 169 170 #endif /* !_SND_SNDSTAT_H_ */ 171