=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/aucat/Attic/aproc.c,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- src/usr.bin/aucat/Attic/aproc.c 2009/07/25 10:52:18 1.33 +++ src/usr.bin/aucat/Attic/aproc.c 2009/09/27 11:51:20 1.34 @@ -1,4 +1,4 @@ -/* $OpenBSD: aproc.c,v 1.33 2009/07/25 10:52:18 ratchov Exp $ */ +/* $OpenBSD: aproc.c,v 1.34 2009/09/27 11:51:20 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov * @@ -33,19 +33,8 @@ * * - resamp: resample streams in native format * - * TODO - * - * (easy) split the "conv" into 2 converters: one for input (that - * convers anything to 16bit signed) and one for the output (that - * converts 16bit signed to anything) - * - * (hard) add a lowpass filter for the resampler. Quality is - * not acceptable as is. - * */ #include -#include -#include #include #include @@ -55,6 +44,7 @@ #include "conf.h" #include "file.h" + struct aproc * aproc_new(struct aproc_ops *ops, char *name) { @@ -76,11 +66,14 @@ { struct abuf *i; - DPRINTF("aproc_del: %s(%s): terminating...\n", p->ops->name, p->name); + /* + * XXX: souldn't call ops->done() and friends twice + * use a ``zomb'' flag or whatever + */ - if (p->ops->done) + if (p->ops->done) { p->ops->done(p); - + } while (!LIST_EMPTY(&p->ibuflist)) { i = LIST_FIRST(&p->ibuflist); abuf_hup(i); @@ -89,11 +82,8 @@ i = LIST_FIRST(&p->obuflist); abuf_eof(i); } - if (p->refs > 0) { - DPRINTF("aproc_del: %s(%s): has refs\n", p->ops->name, p->name); + if (p->refs > 0) return; - } - DPRINTF("aproc_del: %s(%s): freed\n", p->ops->name, p->name); free(p); } @@ -120,8 +110,6 @@ { struct abuf *obuf; - DPRINTFN(3, "aproc_ipos: %s: delta = %d\n", p->name, delta); - LIST_FOREACH(obuf, &p->obuflist, oent) { abuf_ipos(obuf, delta); } @@ -132,8 +120,6 @@ { struct abuf *ibuf; - DPRINTFN(3, "aproc_opos: %s: delta = %d\n", p->name, delta); - LIST_FOREACH(ibuf, &p->ibuflist, ient) { abuf_opos(ibuf, delta); } @@ -152,7 +138,6 @@ if (i->inuse) return 1; } - DPRINTFN(3, "aproc_inuse: %s: not inuse\n", p->name); return 0; } @@ -178,8 +163,6 @@ unsigned char *data; unsigned count; - DPRINTFN(3, "rpipe_in: %s\n", p->name); - if (ABUF_FULL(obuf) || !(f->state & FILE_ROK)) return 0; data = abuf_wgetblk(obuf, &count, 0); @@ -201,8 +184,6 @@ if (f->state & FILE_RINUSE) return 0; - DPRINTFN(3, "rpipe_out: %s\n", p->name); - if (ABUF_FULL(obuf) || !(f->state & FILE_ROK)) return 0; data = abuf_wgetblk(obuf, &count, 0); @@ -229,14 +210,12 @@ void rpipe_eof(struct aproc *p, struct abuf *ibuf_dummy) { - DPRINTFN(3, "rpipe_eof: %s\n", p->name); aproc_del(p); } void rpipe_hup(struct aproc *p, struct abuf *obuf) { - DPRINTFN(3, "rpipe_hup: %s\n", p->name); aproc_del(p); } @@ -286,8 +265,6 @@ if (f->state & FILE_WINUSE) return 0; - DPRINTFN(3, "wpipe_in: %s\n", p->name); - if (ABUF_EMPTY(ibuf) || !(f->state & FILE_WOK)) return 0; data = abuf_rgetblk(ibuf, &count, 0); @@ -306,17 +283,13 @@ unsigned char *data; unsigned count; - DPRINTFN(3, "wpipe_out: %s\n", p->name); - - if (!abuf_fill(ibuf)) { - DPRINTFN(3, "wpipe_out: fill failed\n"); + if (!abuf_fill(ibuf)) return 0; - } if (ABUF_EMPTY(ibuf) || !(f->state & FILE_WOK)) return 0; data = abuf_rgetblk(ibuf, &count, 0); if (count == 0) { - DPRINTF("wpipe_out: %s: underrun\n", p->name); + /* XXX: this can't happen, right ? */ return 0; } count = file_write(f, data, count); @@ -329,14 +302,12 @@ void wpipe_eof(struct aproc *p, struct abuf *ibuf) { - DPRINTFN(3, "wpipe_eof: %s\n", p->name); aproc_del(p); } void wpipe_hup(struct aproc *p, struct abuf *obuf_dummy) { - DPRINTFN(3, "wpipe_hup: %s\n", p->name); aproc_del(p); } @@ -374,7 +345,6 @@ short *odata; unsigned ocount; - DPRINTFN(4, "mix_bzero: used = %u, zcount = %u\n", obuf->used, zcount); odata = (short *)abuf_wgetblk(obuf, &ocount, obuf->mixitodo); ocount -= ocount % obuf->bpf; if (ocount > zcount) @@ -394,9 +364,6 @@ unsigned scount, icount, ocount, zcount; int vol; - DPRINTFN(4, "mix_badd: todo = %u, done = %u\n", - obuf->mixitodo, ibuf->mixodone); - /* * Calculate the maximum we can read. */ @@ -437,8 +404,6 @@ abuf_rdiscard(ibuf, scount * ibuf->bpf); ibuf->mixodone += scount * obuf->bpf; - DPRINTFN(4, "mix_badd: added %u, done = %u, todo = %u\n", - scount, ibuf->mixodone, obuf->mixitodo); } /* @@ -463,12 +428,10 @@ else { abuf_opos(i, -(int)fdrop); if (i->duplex) { - DPRINTF("mix_xrun: duplex %u\n", fdrop); i->duplex->drop += fdrop * i->duplex->bpf; abuf_ipos(i->duplex, -(int)fdrop); } } - DPRINTF("mix_xrun: drop = %u\n", i->drop); return 1; } @@ -478,9 +441,6 @@ struct abuf *i, *inext, *obuf = LIST_FIRST(&p->obuflist); unsigned odone; - DPRINTFN(4, "mix_in: used/len = %u/%u, done/todo = %u/%u\n", - ibuf->used, ibuf->len, ibuf->mixodone, obuf->mixitodo); - if (!ABUF_ROK(ibuf)) return 0; odone = obuf->len; @@ -511,9 +471,6 @@ struct abuf *i, *inext; unsigned odone; - DPRINTFN(4, "mix_out: used/len = %u/%u, todo/len = %u/%u\n", - obuf->used, obuf->len, obuf->mixitodo, obuf->len); - if (!ABUF_WOK(obuf)) return 0; odone = obuf->len; @@ -533,7 +490,6 @@ } if (LIST_EMPTY(&p->ibuflist)) { if (p->u.mix.flags & MIX_AUTOQUIT) { - DPRINTF("mix_out: nothing more to do...\n"); aproc_del(p); return 0; } @@ -560,11 +516,9 @@ struct abuf *i, *obuf = LIST_FIRST(&p->obuflist); unsigned odone; - DPRINTF("mix_eof: %s: detached\n", p->name); mix_setmaster(p); if (!aproc_inuse(p)) { - DPRINTF("mix_eof: %s: from input\n", p->name); /* * Find a blocked input. */ @@ -588,19 +542,12 @@ void mix_hup(struct aproc *p, struct abuf *obuf) { - DPRINTF("mix_hup: %s: done\n", p->name); aproc_del(p); } void mix_newin(struct aproc *p, struct abuf *ibuf) { - struct abuf *obuf = LIST_FIRST(&p->obuflist); - - if (!obuf || ibuf->cmin < obuf->cmin || ibuf->cmax > obuf->cmax) { - fprintf(stderr, "mix_newin: channel ranges mismatch\n"); - abort(); - } p->u.mix.idle = 0; ibuf->mixodone = 0; ibuf->mixvol = ADATA_UNIT; @@ -612,14 +559,12 @@ void mix_newout(struct aproc *p, struct abuf *obuf) { - DPRINTF("mix_newout: using %u fpb\n", obuf->len / obuf->bpf); obuf->mixitodo = 0; } void mix_opos(struct aproc *p, struct abuf *obuf, int delta) { - DPRINTFN(3, "mix_opos: lat = %d/%d\n", p->u.mix.lat, p->u.mix.maxlat); p->u.mix.lat -= delta; aproc_opos(p, obuf, delta); } @@ -669,8 +614,6 @@ if (weight > buf->mixmaxweight) weight = buf->mixmaxweight; buf->mixweight = weight; - DPRINTF("mix_setmaster: %p: %d/%d -> %d\n", buf, - buf->mixweight, buf->mixmaxweight, weight); } } @@ -716,7 +659,6 @@ } abuf_wcommit(obuf, scount * obuf->bpf); obuf->subidone += scount * ibuf->bpf; - DPRINTFN(4, "sub_bcopy: %u frames\n", scount); } /* @@ -739,13 +681,11 @@ else { abuf_ipos(i, -(int)fdrop); if (i->duplex) { - DPRINTF("sub_xrun: duplex %u\n", fdrop); i->duplex->silence += fdrop * i->duplex->bpf; abuf_opos(i->duplex, -(int)fdrop); } } i->subidone += fdrop * ibuf->bpf; - DPRINTF("sub_xrun: silence = %u\n", i->silence); return 1; } @@ -774,7 +714,6 @@ } if (LIST_EMPTY(&p->obuflist)) { if (p->u.sub.flags & SUB_AUTOQUIT) { - DPRINTF("sub_in: nothing more to do...\n"); aproc_del(p); return 0; } @@ -826,7 +765,6 @@ void sub_eof(struct aproc *p, struct abuf *ibuf) { - DPRINTF("sub_hup: %s: eof\n", p->name); aproc_del(p); } @@ -836,10 +774,7 @@ struct abuf *i, *ibuf = LIST_FIRST(&p->ibuflist); unsigned idone; - DPRINTF("sub_hup: %s: detached\n", p->name); - if (!aproc_inuse(p)) { - DPRINTF("sub_hup: %s: from input\n", p->name); /* * Find a blocked output. */ @@ -863,12 +798,6 @@ void sub_newout(struct aproc *p, struct abuf *obuf) { - struct abuf *ibuf = LIST_FIRST(&p->ibuflist); - - if (!ibuf || obuf->cmin < ibuf->cmin || obuf->cmax > ibuf->cmax) { - fprintf(stderr, "sub_newout: channel ranges mismatch\n"); - abort(); - } p->u.sub.idle = 0; obuf->subidone = 0; obuf->xrun = XRUN_IGNORE; @@ -878,7 +807,6 @@ sub_ipos(struct aproc *p, struct abuf *ibuf, int delta) { p->u.sub.lat += delta; - DPRINTFN(3, "sub_ipos: lat = %d/%d\n", p->u.sub.lat, p->u.sub.maxlat); aproc_ipos(p, ibuf, delta); } @@ -961,7 +889,6 @@ /* * Start conversion. */ - DPRINTFN(4, "resamp_bcopy: ifr=%d ofr=%d\n", ifr, ofr); for (;;) { if (diff < 0) { if (ifr == 0) @@ -990,8 +917,6 @@ } p->u.resamp.diff = diff; p->u.resamp.ctx_start = ctx_start; - DPRINTFN(4, "resamp_bcopy: done, ifr=%d ofr=%d\n", ifr, ofr); - /* * Update FIFO pointers. */ @@ -1006,8 +931,6 @@ { struct abuf *obuf = LIST_FIRST(&p->obuflist); - DPRINTFN(4, "resamp_in: %s\n", p->name); - if (!ABUF_WOK(obuf) || !ABUF_ROK(ibuf)) return 0; resamp_bcopy(p, ibuf, obuf); @@ -1021,8 +944,6 @@ { struct abuf *ibuf = LIST_FIRST(&p->ibuflist); - DPRINTFN(4, "resamp_out: %s\n", p->name); - if (!abuf_fill(ibuf)) return 0; if (!ABUF_WOK(obuf) || !ABUF_ROK(ibuf)) @@ -1034,16 +955,12 @@ void resamp_eof(struct aproc *p, struct abuf *ibuf) { - DPRINTFN(4, "resamp_eof: %s\n", p->name); - aproc_del(p); } void resamp_hup(struct aproc *p, struct abuf *obuf) { - DPRINTFN(4, "resamp_hup: %s\n", p->name); - aproc_del(p); } @@ -1054,8 +971,6 @@ long long ipos; int ifac, ofac; - DPRINTFN(3, "resamp_ipos: %d\n", delta); - ifac = p->u.resamp.iblksz; ofac = p->u.resamp.oblksz; ipos = p->u.resamp.idelta + (long long)delta * ofac; @@ -1071,8 +986,6 @@ long long opos; int ifac, ofac; - DPRINTFN(3, "resamp_opos: %d\n", delta); - ifac = p->u.resamp.iblksz; ofac = p->u.resamp.oblksz; opos = p->u.resamp.odelta + (long long)delta * ifac; @@ -1109,10 +1022,6 @@ p->u.resamp.ctx_start = 0; for (i = 0; i < NCHAN_MAX * RESAMP_NCTX; i++) p->u.resamp.ctx[i] = 0; -#ifdef DEBUG - if (debug_level > 0) - fprintf(stderr, "resamp_new: %u/%u\n", iblksz, oblksz); -#endif return p; } @@ -1160,7 +1069,6 @@ ctx++; } } - DPRINTFN(4, "cmap_bcopy: scount = %u\n", scount); abuf_rdiscard(ibuf, scount * ibuf->bpf); abuf_wcommit(obuf, scount * obuf->bpf); } @@ -1170,8 +1078,6 @@ { struct abuf *obuf = LIST_FIRST(&p->obuflist); - DPRINTFN(4, "cmap_in: %s\n", p->name); - if (!ABUF_WOK(obuf) || !ABUF_ROK(ibuf)) return 0; cmap_bcopy(p, ibuf, obuf); @@ -1185,8 +1091,6 @@ { struct abuf *ibuf = LIST_FIRST(&p->ibuflist); - DPRINTFN(4, "cmap_out: %s\n", p->name); - if (!abuf_fill(ibuf)) return 0; if (!ABUF_WOK(obuf) || !ABUF_ROK(ibuf)) @@ -1198,16 +1102,12 @@ void cmap_eof(struct aproc *p, struct abuf *ibuf) { - DPRINTFN(4, "cmap_eof: %s\n", p->name); - aproc_del(p); } void cmap_hup(struct aproc *p, struct abuf *obuf) { - DPRINTFN(4, "cmap_hup: %s\n", p->name); - aproc_del(p); } @@ -1233,13 +1133,6 @@ p = aproc_new(&cmap_ops, name); for (i = 0; i < NCHAN_MAX; i++) p->u.cmap.ctx[i] = 0; -#ifdef DEBUG - if (debug_level > 0) { - fprintf(stderr, "cmap_new: %s: ", p->name); - aparams_print2(ipar, opar); - fprintf(stderr, "\n"); - } -#endif return p; } @@ -1274,8 +1167,6 @@ return; scount = (icount < ocount) ? icount : ocount; nch = ibuf->cmax - ibuf->cmin + 1; - DPRINTFN(4, "enc_bcopy: scount = %u, nch = %u\n", scount, nch); - /* * Partially copy structures into local variables, to avoid * unnecessary indirections; this also allows the compiler to @@ -1316,8 +1207,6 @@ { struct abuf *obuf = LIST_FIRST(&p->obuflist); - DPRINTFN(4, "enc_in: %s\n", p->name); - if (!ABUF_WOK(obuf) || !ABUF_ROK(ibuf)) return 0; enc_bcopy(p, ibuf, obuf); @@ -1331,8 +1220,6 @@ { struct abuf *ibuf = LIST_FIRST(&p->ibuflist); - DPRINTFN(4, "enc_out: %s\n", p->name); - if (!abuf_fill(ibuf)) return 0; if (!ABUF_WOK(obuf) || !ABUF_ROK(ibuf)) @@ -1344,16 +1231,12 @@ void enc_eof(struct aproc *p, struct abuf *ibuf) { - DPRINTFN(4, "enc_eof: %s\n", p->name); - aproc_del(p); } void enc_hup(struct aproc *p, struct abuf *obuf) { - DPRINTFN(4, "enc_hup: %s\n", p->name); - aproc_del(p); } @@ -1392,13 +1275,6 @@ p->u.conv.bnext = 1; p->u.conv.snext = 0; } -#ifdef DEBUG - if (debug_level > 0) { - fprintf(stderr, "enc_new: %s: ", p->name); - aparams_print(par); - fprintf(stderr, "\n"); - } -#endif return p; } @@ -1433,8 +1309,6 @@ return; scount = (icount < ocount) ? icount : ocount; nch = obuf->cmax - obuf->cmin + 1; - DPRINTFN(4, "dec_bcopy: scount = %u, nch = %u\n", scount, nch); - /* * Partially copy structures into local variables, to avoid * unnecessary indirections; this also allows the compiler to @@ -1475,8 +1349,6 @@ { struct abuf *obuf = LIST_FIRST(&p->obuflist); - DPRINTFN(4, "dec_in: %s\n", p->name); - if (!ABUF_WOK(obuf) || !ABUF_ROK(ibuf)) return 0; dec_bcopy(p, ibuf, obuf); @@ -1490,8 +1362,6 @@ { struct abuf *ibuf = LIST_FIRST(&p->ibuflist); - DPRINTFN(4, "dec_out: %s\n", p->name); - if (!abuf_fill(ibuf)) return 0; if (!ABUF_WOK(obuf) || !ABUF_ROK(ibuf)) @@ -1503,16 +1373,12 @@ void dec_eof(struct aproc *p, struct abuf *ibuf) { - DPRINTFN(4, "dec_eof: %s\n", p->name); - aproc_del(p); } void dec_hup(struct aproc *p, struct abuf *obuf) { - DPRINTFN(4, "dec_hup: %s\n", p->name); - aproc_del(p); } @@ -1551,12 +1417,5 @@ p->u.conv.bnext = 1; p->u.conv.snext = 0; } -#ifdef DEBUG - if (debug_level > 0) { - fprintf(stderr, "dec_new: %s: ", p->name); - aparams_print(par); - fprintf(stderr, "\n"); - } -#endif return p; }