2 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
27 #include <dev/sound/pcm/sound.h>
29 #include "feeder_if.h"
31 SND_DECLARE_FILE("$FreeBSD$");
33 MALLOC_DEFINE(M_FEEDER, "feeder", "pcm feeder");
35 #define MAXFEEDERS 256
38 int feeder_buffersize = FEEDBUFSZ;
39 TUNABLE_INT("hw.snd.feeder_buffersize", &feeder_buffersize);
43 sysctl_hw_snd_feeder_buffersize(SYSCTL_HANDLER_ARGS)
47 val = feeder_buffersize;
48 err = sysctl_handle_int(oidp, &val, 0, req);
50 if (err != 0 || req->newptr == NULL)
53 if (val < FEEDBUFSZ_MIN || val > FEEDBUFSZ_MAX)
60 if (i > val && (i >> 1) > 0 && (i >> 1) >= ((val * 3) >> 2))
63 feeder_buffersize = i;
67 SYSCTL_PROC(_hw_snd, OID_AUTO, feeder_buffersize, CTLTYPE_INT | CTLFLAG_RW,
68 0, sizeof(int), sysctl_hw_snd_feeder_buffersize, "I",
69 "feeder buffer size");
71 SYSCTL_INT(_hw_snd, OID_AUTO, feeder_buffersize, CTLFLAG_RD,
72 &feeder_buffersize, FEEDBUFSZ, "feeder buffer size");
75 struct feedertab_entry {
76 SLIST_ENTRY(feedertab_entry) link;
77 struct feeder_class *feederclass;
78 struct pcm_feederdesc *desc;
82 static SLIST_HEAD(, feedertab_entry) feedertab;
84 /*****************************************************************************/
87 feeder_register(void *p)
89 static int feedercnt = 0;
91 struct feeder_class *fc = p;
92 struct feedertab_entry *fte;
96 KASSERT(fc->desc == NULL, ("first feeder not root: %s", fc->name));
98 SLIST_INIT(&feedertab);
99 fte = malloc(sizeof(*fte), M_FEEDER, M_NOWAIT | M_ZERO);
101 printf("can't allocate memory for root feeder: %s\n",
106 fte->feederclass = fc;
108 fte->idx = feedercnt;
109 SLIST_INSERT_HEAD(&feedertab, fte, link);
112 /* initialize global variables */
114 if (snd_verbose < 0 || snd_verbose > 4)
117 /* initialize unit numbering */
119 if (snd_unit < 0 || snd_unit > PCMMAXUNIT)
122 if (snd_maxautovchans < 0 ||
123 snd_maxautovchans > SND_MAXVCHANS)
124 snd_maxautovchans = 0;
126 if (chn_latency < CHN_LATENCY_MIN ||
127 chn_latency > CHN_LATENCY_MAX)
128 chn_latency = CHN_LATENCY_DEFAULT;
130 if (chn_latency_profile < CHN_LATENCY_PROFILE_MIN ||
131 chn_latency_profile > CHN_LATENCY_PROFILE_MAX)
132 chn_latency_profile = CHN_LATENCY_PROFILE_DEFAULT;
134 if (feeder_buffersize < FEEDBUFSZ_MIN ||
135 feeder_buffersize > FEEDBUFSZ_MAX)
136 feeder_buffersize = FEEDBUFSZ;
138 if (feeder_rate_min < FEEDRATE_MIN ||
139 feeder_rate_max < FEEDRATE_MIN ||
140 feeder_rate_min > FEEDRATE_MAX ||
141 feeder_rate_max > FEEDRATE_MAX ||
142 !(feeder_rate_min < feeder_rate_max)) {
143 feeder_rate_min = FEEDRATE_RATEMIN;
144 feeder_rate_max = FEEDRATE_RATEMAX;
147 if (feeder_rate_round < FEEDRATE_ROUNDHZ_MIN ||
148 feeder_rate_round > FEEDRATE_ROUNDHZ_MAX)
149 feeder_rate_round = FEEDRATE_ROUNDHZ;
152 printf("%s: snd_unit=%d snd_maxautovchans=%d "
153 "latency=%d feeder_buffersize=%d "
154 "feeder_rate_min=%d feeder_rate_max=%d "
155 "feeder_rate_round=%d\n",
156 __func__, snd_unit, snd_maxautovchans,
157 chn_latency, feeder_buffersize,
158 feeder_rate_min, feeder_rate_max,
161 /* we've got our root feeder so don't veto pcm loading anymore */
167 KASSERT(fc->desc != NULL, ("feeder '%s' has no descriptor", fc->name));
169 /* beyond this point failure is non-fatal but may result in some translations being unavailable */
171 while ((feedercnt < MAXFEEDERS) && (fc->desc[i].type > 0)) {
172 /* printf("adding feeder %s, %x -> %x\n", fc->name, fc->desc[i].in, fc->desc[i].out); */
173 fte = malloc(sizeof(*fte), M_FEEDER, M_NOWAIT | M_ZERO);
175 printf("can't allocate memory for feeder '%s', %x -> %x\n", fc->name, fc->desc[i].in, fc->desc[i].out);
179 fte->feederclass = fc;
180 fte->desc = &fc->desc[i];
181 fte->idx = feedercnt;
182 fte->desc->idx = feedercnt;
183 SLIST_INSERT_HEAD(&feedertab, fte, link);
187 if (feedercnt >= MAXFEEDERS)
188 printf("MAXFEEDERS (%d >= %d) exceeded\n", feedercnt, MAXFEEDERS);
192 feeder_unregisterall(void *p)
194 struct feedertab_entry *fte, *next;
196 next = SLIST_FIRST(&feedertab);
197 while (next != NULL) {
199 next = SLIST_NEXT(fte, link);
205 cmpdesc(struct pcm_feederdesc *n, struct pcm_feederdesc *m)
207 return ((n->type == m->type) &&
208 ((n->in == 0) || (n->in == m->in)) &&
209 ((n->out == 0) || (n->out == m->out)) &&
210 (n->flags == m->flags));
214 feeder_destroy(struct pcm_feeder *f)
217 kobj_delete((kobj_t)f, M_FEEDER);
220 static struct pcm_feeder *
221 feeder_create(struct feeder_class *fc, struct pcm_feederdesc *desc)
223 struct pcm_feeder *f;
226 f = (struct pcm_feeder *)kobj_create((kobj_class_t)fc, M_FEEDER, M_NOWAIT | M_ZERO);
230 f->align = fc->align;
235 f->desc = &(f->desc_static);
240 f->desc->type = FEEDER_ROOT;
247 err = FEEDER_INIT(f);
249 printf("feeder_init(%p) on %s returned %d\n", f, fc->name, err);
258 struct feeder_class *
259 feeder_getclass(struct pcm_feederdesc *desc)
261 struct feedertab_entry *fte;
263 SLIST_FOREACH(fte, &feedertab, link) {
264 if ((desc == NULL) && (fte->desc == NULL))
265 return fte->feederclass;
266 if ((fte->desc != NULL) && (desc != NULL) && cmpdesc(desc, fte->desc))
267 return fte->feederclass;
273 chn_addfeeder(struct pcm_channel *c, struct feeder_class *fc, struct pcm_feederdesc *desc)
275 struct pcm_feeder *nf;
277 nf = feeder_create(fc, desc);
281 nf->source = c->feeder;
283 /* XXX we should use the lowest common denominator for align */
285 c->align += nf->align;
286 else if (nf->align < 0 && c->align < -nf->align)
287 c->align = -nf->align;
288 if (c->feeder != NULL)
289 c->feeder->parent = nf;
296 chn_removefeeder(struct pcm_channel *c)
298 struct pcm_feeder *f;
300 if (c->feeder == NULL)
303 c->feeder = c->feeder->source;
310 chn_findfeeder(struct pcm_channel *c, u_int32_t type)
312 struct pcm_feeder *f;
316 if (f->desc->type == type)
325 chainok(struct pcm_feeder *test, struct pcm_feeder *stop)
327 u_int32_t visited[MAXFEEDERS / 32];
330 bzero(visited, sizeof(visited));
331 while (test && (test != stop)) {
332 idx = test->desc->idx;
334 panic("bad idx %d", idx);
335 if (idx >= MAXFEEDERS)
336 panic("bad idx %d", idx);
337 mask = 1 << (idx & 31);
339 if (visited[idx] & mask)
341 visited[idx] |= mask;
349 * See feeder_fmtchain() for the mumbo-jumbo ridiculous explanation
350 * of what the heck is this FMT_Q_*
355 #define FMT_Q_MULTI 4
358 * 14bit format scoring
359 * --------------------
361 * 13 12 11 10 9 8 2 1 0 offset
362 * +---+---+---+---+---+---+-------------+---+---+
363 * | X | X | X | X | X | X | X X X X X X | X | X |
364 * +---+---+---+---+---+---+-------------+---+---+
366 * | | | | | | | | +--> signed?
368 * | | | | | | | +------> bigendian?
370 * | | | | | | +---------------> total channels
372 * | | | | | +------------------------> AFMT_A_LAW
374 * | | | | +----------------------------> AFMT_MU_LAW
376 * | | | +--------------------------------> AFMT_8BIT
378 * | | +------------------------------------> AFMT_16BIT
380 * | +----------------------------------------> AFMT_24BIT
382 * +--------------------------------------------> AFMT_32BIT
384 #define score_signeq(s1, s2) (((s1) & 0x1) == ((s2) & 0x1))
385 #define score_endianeq(s1, s2) (((s1) & 0x2) == ((s2) & 0x2))
386 #define score_cheq(s1, s2) (((s1) & 0xfc) == ((s2) & 0xfc))
387 #define score_val(s1) ((s1) & 0x3f00)
388 #define score_cse(s1) ((s1) & 0x7f)
391 chn_fmtscore(u_int32_t fmt)
396 if (fmt & AFMT_SIGNED)
398 if (fmt & AFMT_BIGENDIAN)
400 if (fmt & AFMT_STEREO)
401 ret |= (2 & 0x3f) << 2;
403 ret |= (1 & 0x3f) << 2;
404 if (fmt & AFMT_A_LAW)
406 else if (fmt & AFMT_MU_LAW)
408 else if (fmt & AFMT_8BIT)
410 else if (fmt & AFMT_16BIT)
412 else if (fmt & AFMT_24BIT)
414 else if (fmt & AFMT_32BIT)
421 chn_fmtbestfunc(u_int32_t fmt, u_int32_t *fmts, int cheq)
423 u_int32_t best, score, score2, oldscore;
426 if (fmt == 0 || fmts == NULL || fmts[0] == 0)
429 if (fmtvalid(fmt, fmts))
433 score = chn_fmtscore(fmt);
435 for (i = 0; fmts[i] != 0; i++) {
436 score2 = chn_fmtscore(fmts[i]);
437 if (cheq && !score_cheq(score, score2))
440 (score_val(score2) == score_val(score)) ||
441 (score_val(score2) == score_val(oldscore)) ||
442 (score_val(score2) > score_val(oldscore) &&
443 score_val(score2) < score_val(score)) ||
444 (score_val(score2) < score_val(oldscore) &&
445 score_val(score2) > score_val(score)) ||
446 (score_val(oldscore) < score_val(score) &&
447 score_val(score2) > score_val(oldscore))) {
448 if (score_val(oldscore) != score_val(score2) ||
449 score_cse(score) == score_cse(score2) ||
450 ((score_cse(oldscore) != score_cse(score) &&
451 !score_endianeq(score, oldscore) &&
452 (score_endianeq(score, score2) ||
453 (!score_signeq(score, oldscore) &&
454 score_signeq(score, score2)))))) {
464 chn_fmtbestbit(u_int32_t fmt, u_int32_t *fmts)
466 return chn_fmtbestfunc(fmt, fmts, 0);
470 chn_fmtbeststereo(u_int32_t fmt, u_int32_t *fmts)
472 return chn_fmtbestfunc(fmt, fmts, 1);
476 chn_fmtbest(u_int32_t fmt, u_int32_t *fmts)
478 u_int32_t best1, best2;
479 u_int32_t score, score1, score2;
481 if (fmtvalid(fmt, fmts))
484 best1 = chn_fmtbeststereo(fmt, fmts);
485 best2 = chn_fmtbestbit(fmt, fmts);
487 if (best1 != 0 && best2 != 0 && best1 != best2) {
488 if (fmt & AFMT_STEREO)
491 score = score_val(chn_fmtscore(fmt));
492 score1 = score_val(chn_fmtscore(best1));
493 score2 = score_val(chn_fmtscore(best2));
494 if (score1 == score2 || score1 == score)
496 else if (score2 == score)
498 else if (score1 > score2)
502 } else if (best2 == 0)
508 static struct pcm_feeder *
509 feeder_fmtchain(u_int32_t *to, struct pcm_feeder *source, struct pcm_feeder *stop, int maxdepth)
511 struct feedertab_entry *fte, *ftebest;
512 struct pcm_feeder *try, *ret;
513 uint32_t fl, qout, qsrc, qdst;
516 if (to == NULL || to[0] == 0)
519 DEB(printf("trying %s (0x%08x -> 0x%08x)...\n", source->class->name, source->desc->in, source->desc->out));
520 if (fmtvalid(source->desc->out, to)) {
521 DEB(printf("got it\n"));
529 * WARNING: THIS IS _NOT_ FOR THE FAINT HEART
530 * Disclaimer: I don't expect anybody could understand this
531 * without deep logical and mathematical analysis
532 * involving various unnamed probability theorem.
534 * This "Best Fit Random Chain Selection" (BLEHBLEHWHATEVER) algorithm
535 * is **extremely** difficult to digest especially when applied to
536 * large sets / numbers of random chains (feeders), each with
537 * unique characteristic providing different sets of in/out format.
539 * Basically, our FEEDER_FMT (see feeder_fmt.c) chains characteristic:
541 * 1.1 "8bit to any, not to 8bit"
542 * 1.1.1 sign can remain consistent, e.g: u8 -> u16[le|be]
543 * 1.1.2 sign can be changed, e.g: u8 -> s16[le|be]
544 * 1.1.3 endian can be changed, e.g: u8 -> u16[le|be]
545 * 1.1.4 both can be changed, e.g: u8 -> [u|s]16[le|be]
546 * 1.2 "Any to 8bit, not from 8bit"
547 * 1.2.1 sign can remain consistent, e.g: s16le -> s8
548 * 1.2.2 sign can be changed, e.g: s16le -> u8
549 * 1.2.3 source endian can be anything e.g: s16[le|be] -> s8
550 * 1.2.4 source endian / sign can be anything e.g: [u|s]16[le|be] -> u8
551 * 1.3 "Any to any where BOTH input and output either 8bit or non-8bit"
552 * 1.3.1 endian MUST remain consistent
553 * 1.3.2 sign CAN be changed
554 * 1.4 "Long jump" is allowed, e.g: from 16bit to 32bit, excluding
556 * 2) Channel chains (mono <-> stereo)
557 * 2.1 Both endian and sign MUST remain consistent
558 * 3) Endian chains (big endian <-> little endian)
559 * 3.1 Channels and sign MUST remain consistent
560 * 4) Sign chains (signed <-> unsigned)
561 * 4.1 Channels and endian MUST remain consistent
563 * .. and the mother of all chaining rules:
565 * Rules 0: Source and destination MUST not contain multiple selections.
566 * (qtype != FMT_Q_MULTI)
568 * First of all, our caller ( chn_fmtchain() ) will reduce the possible
569 * multiple from/to formats to a single best format using chn_fmtbest().
570 * Then, using chn_fmtscore(), we determine the chaining characteristic.
571 * Our main goal is to narrow it down until it reach FMT_Q_EQ chaining
572 * type while still adhering above chaining rules.
574 * The need for this complicated chaining procedures is inevitable,
575 * since currently we have more than 200 different types of FEEDER_FMT
576 * doing various unique format conversion. Without this (the old way),
577 * it is possible to generate broken chain since it doesn't do any
578 * sanity checking to ensure that the output format is "properly aligned"
579 * with the direction of conversion (quality up/down/equal).
581 * Conversion: s24le to s32le
582 * Possible chain: 1) s24le -> s32le (correct, optimized)
583 * 2) s24le -> s16le -> s32le
584 * (since we have feeder_24to16 and feeder_16to32)
585 * +-- obviously broken!
587 * Using scoring mechanisme, this will ensure that the chaining
588 * process do the right thing, or at least, give the best chain
589 * possible without causing quality (the 'Q') degradation.
592 qdst = chn_fmtscore(to[0]);
593 qsrc = chn_fmtscore(source->desc->out);
595 #define score_q(s1) score_val(s1)
596 #define score_8bit(s1) ((s1) & 0x700)
597 #define score_non8bit(s1) (!score_8bit(s1))
598 #define score_across8bit(s1, s2) ((score_8bit(s1) && score_non8bit(s2)) || \
599 (score_8bit(s2) && score_non8bit(s1)))
601 #define FMT_CHAIN_Q_UP(s1, s2) (score_q(s1) < score_q(s2))
602 #define FMT_CHAIN_Q_DOWN(s1, s2) (score_q(s1) > score_q(s2))
603 #define FMT_CHAIN_Q_EQ(s1, s2) (score_q(s1) == score_q(s2))
604 #define FMT_Q_DOWN_FLAGS(s1, s2) (0x1 | (score_across8bit(s1, s2) ? \
606 #define FMT_Q_UP_FLAGS(s1, s2) FMT_Q_DOWN_FLAGS(s1, s2)
607 #define FMT_Q_EQ_FLAGS(s1, s2) (0x3ffc | \
608 ((score_cheq(s1, s2) && \
609 score_endianeq(s1, s2)) ? \
611 ((score_cheq(s1, s2) && \
612 score_signeq(s1, s2)) ? \
615 /* Determine chaining direction and set matching flag */
619 printf("%s: WARNING: FMT_Q_MULTI chaining. Expect the unexpected.\n", __func__);
620 } else if (FMT_CHAIN_Q_DOWN(qsrc, qdst)) {
622 fl = FMT_Q_DOWN_FLAGS(qsrc, qdst);
623 } else if (FMT_CHAIN_Q_UP(qsrc, qdst)) {
625 fl = FMT_Q_UP_FLAGS(qsrc, qdst);
628 fl = FMT_Q_EQ_FLAGS(qsrc, qdst);
633 SLIST_FOREACH(fte, &feedertab, link) {
634 if (fte->desc == NULL)
636 if (fte->desc->type != FEEDER_FMT)
638 qout = chn_fmtscore(fte->desc->out);
639 #define FMT_Q_MULTI_VALIDATE(qt) ((qt) == FMT_Q_MULTI)
640 #define FMT_Q_FL_MATCH(qfl, s1, s2) (((s1) & (qfl)) == ((s2) & (qfl)))
641 #define FMT_Q_UP_VALIDATE(qt, s1, s2, s3) ((qt) == FMT_Q_UP && \
642 score_q(s3) >= score_q(s1) && \
643 score_q(s3) <= score_q(s2))
644 #define FMT_Q_DOWN_VALIDATE(qt, s1, s2, s3) ((qt) == FMT_Q_DOWN && \
645 score_q(s3) <= score_q(s1) && \
646 score_q(s3) >= score_q(s2))
647 #define FMT_Q_EQ_VALIDATE(qt, s1, s2) ((qt) == FMT_Q_EQ && \
648 score_q(s1) == score_q(s2))
649 if (fte->desc->in == source->desc->out &&
650 (FMT_Q_MULTI_VALIDATE(qtype) ||
651 (FMT_Q_FL_MATCH(fl, qout, qdst) &&
652 (FMT_Q_UP_VALIDATE(qtype, qsrc, qdst, qout) ||
653 FMT_Q_DOWN_VALIDATE(qtype, qsrc, qdst, qout) ||
654 FMT_Q_EQ_VALIDATE(qtype, qdst, qout))))) {
655 try = feeder_create(fte->feederclass, fte->desc);
657 try->source = source;
658 ret = chainok(try, stop) ? feeder_fmtchain(to, try, stop, maxdepth - 1) : NULL;
663 } else if (fte->desc->in == source->desc->out) {
664 /* XXX quality must be considered! */
670 if (ftebest != NULL) {
671 try = feeder_create(ftebest->feederclass, ftebest->desc);
673 try->source = source;
674 ret = chainok(try, stop) ? feeder_fmtchain(to, try, stop, maxdepth - 1) : NULL;
681 /* printf("giving up %s...\n", source->class->name); */
687 chn_fmtchain(struct pcm_channel *c, u_int32_t *to)
689 struct pcm_feeder *try, *del, *stop;
690 u_int32_t tmpfrom[2], tmpto[2], best, *from;
693 KASSERT(c != NULL, ("c == NULL"));
694 KASSERT(c->feeder != NULL, ("c->feeder == NULL"));
695 KASSERT(to != NULL, ("to == NULL"));
696 KASSERT(to[0] != 0, ("to[0] == 0"));
698 if (c == NULL || c->feeder == NULL || to == NULL || to[0] == 0)
704 if (c->direction == PCMDIR_REC && c->feeder->desc->type == FEEDER_ROOT) {
705 from = chn_getcaps(c)->fmtlist;
707 best = chn_fmtbest(to[0], from);
715 tmpfrom[0] = c->feeder->desc->out;
719 best = chn_fmtbest(from[0], to);
728 #define FEEDER_FMTCHAIN_MAXDEPTH 8
732 if (to[0] != 0 && from[0] != 0 &&
733 to[1] == 0 && from[1] == 0) {
736 c->feeder->desc->out = best;
738 try = feeder_fmtchain(to, c->feeder, stop, max);
739 DEB(if (try != NULL) {
740 printf("%s: 0x%08x -> 0x%08x (maxdepth: %d)\n",
741 __func__, from[0], to[0], max);
743 } while (try == NULL && max++ < FEEDER_FMTCHAIN_MAXDEPTH);
745 printf("%s: Using the old-way format chaining!\n", __func__);
749 while (from[i] != 0) {
750 c->feeder->desc->out = from[i];
754 try = feeder_fmtchain(to, c->feeder, stop, max);
755 } while (try == NULL && max++ < FEEDER_FMTCHAIN_MAXDEPTH);
756 if (try != NULL && max < bestmax) {
760 while (try != NULL && try != stop) {
770 c->feeder->desc->out = best;
771 try = feeder_fmtchain(to, c->feeder, stop, bestmax);
779 printf("\n\nchain: ");
781 while (try && (try != stop)) {
783 printf("%s [%d]", try->class->name, try->desc->idx);
788 try->source->parent = try;
790 c->align += try->align;
791 else if (try->align < 0 && c->align < -try->align)
792 c->align = -try->align;
796 printf("%s [%d]\n", try->class->name, try->desc->idx);
799 if (c->direction == PCMDIR_REC) {
801 while (try != NULL) {
802 if (try->desc->type == FEEDER_ROOT)
803 return try->desc->out;
808 return c->feeder->desc->out;
812 feeder_printchain(struct pcm_feeder *head)
814 struct pcm_feeder *f;
816 printf("feeder chain (head @%p)\n", head);
819 printf("%s/%d @ %p\n", f->class->name, f->desc->idx, f);
825 /*****************************************************************************/
828 feed_root(struct pcm_feeder *feeder, struct pcm_channel *ch, u_int8_t *buffer, u_int32_t count, void *source)
830 struct snd_dbuf *src = source;
833 KASSERT(count > 0, ("feed_root: count == 0"));
834 /* count &= ~((1 << ch->align) - 1); */
835 KASSERT(count > 0, ("feed_root: aligned count == 0 (align = %d)", ch->align));
837 if (++ch->feedcount == 0)
840 l = min(count, sndbuf_getready(src));
842 /* When recording only return as much data as available */
843 if (ch->direction == PCMDIR_REC) {
844 sndbuf_dispose(src, buffer, l);
853 printf("%s: (%s) %spending %d bytes "
854 "(count=%d l=%d feed=%d)\n",
856 (ch->flags & CHN_F_VIRTUAL) ? "virtual" : "hardware",
857 (ch->feedcount == 1) ? "pre" : "ap",
858 offset, count, l, ch->feedcount);
860 if (ch->feedcount == 1) {
862 sndbuf_zerodata(sndbuf_getfmt(src)),
865 sndbuf_dispose(src, buffer + offset, l);
870 sndbuf_dispose(src, buffer, l);
872 sndbuf_zerodata(sndbuf_getfmt(src)),
874 if (!(ch->flags & CHN_F_CLOSING))
878 sndbuf_dispose(src, buffer, l);
883 static kobj_method_t feeder_root_methods[] = {
884 KOBJMETHOD(feeder_feed, feed_root),
887 static struct feeder_class feeder_root_class = {
888 .name = "feeder_root",
889 .methods = feeder_root_methods,
890 .size = sizeof(struct pcm_feeder),
895 SYSINIT(feeder_root, SI_SUB_DRIVERS, SI_ORDER_FIRST, feeder_register, &feeder_root_class);
896 SYSUNINIT(feeder_root, SI_SUB_DRIVERS, SI_ORDER_FIRST, feeder_unregisterall, NULL);