[BACK]Return to abuf.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / aucat

Annotation of src/usr.bin/aucat/abuf.h, Revision 1.13

1.13    ! ratchov     1: /*     $OpenBSD: abuf.h,v 1.12 2008/11/09 16:26:07 ratchov Exp $       */
1.1       ratchov     2: /*
                      3:  * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
                      4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:  */
                     17: #ifndef ABUF_H
                     18: #define ABUF_H
                     19:
                     20: #include <sys/queue.h>
                     21:
                     22: struct abuf;
                     23: struct aproc;
1.10      ratchov    24: struct aparam;
1.1       ratchov    25:
                     26: struct abuf {
                     27:        /*
1.4       ratchov    28:         * Misc aproc-specific per-buffer parameters.
                     29:         * since the buffer can connect any pair of aproc structure,
                     30:         * each aproc must have it's own specific data. Thus we cannot
                     31:         * use an union. The only exception is the xrun field, because
                     32:         * there can be only one aproc that absorbs xruns in any
                     33:         * intput->output path.
1.1       ratchov    34:         */
1.13    ! ratchov    35:        int mixweight;          /* volume of the source stream */
        !            36:        unsigned mixvol;        /* volume in the range defined by wight */
1.11      ratchov    37:        unsigned mixodone;      /* bytes done on the dest stream */
                     38:        unsigned mixitodo;      /* bytes to do on the source stream */
                     39:        unsigned subidone;      /* bytes copied from the source stream */
1.4       ratchov    40: #define XRUN_IGNORE    0       /* on xrun silently insert/discard samples */
                     41: #define XRUN_SYNC      1       /* catchup to sync to the mix/sub */
                     42: #define XRUN_ERROR     2       /* xruns are errors, eof/hup buffer */
                     43:        unsigned xrun;          /* common to mix and sub */
1.1       ratchov    44:        LIST_ENTRY(abuf) ient;  /* for mix inputs list */
                     45:        LIST_ENTRY(abuf) oent;  /* for sub outputs list */
1.9       ratchov    46:
1.1       ratchov    47:        /*
                     48:         * fifo parameters
                     49:         */
                     50:        unsigned bpf;           /* bytes per frame */
1.10      ratchov    51:        unsigned cmin, cmax;    /* channel range of this buf */
1.1       ratchov    52:        unsigned start;         /* offset where data starts */
                     53:        unsigned used;          /* valid data */
                     54:        unsigned len;           /* size of the ring */
1.7       ratchov    55:        unsigned abspos;        /* frame number of the start position */
1.6       ratchov    56:        unsigned silence;       /* silence to insert on next write */
1.8       ratchov    57:        unsigned drop;          /* bytes to drop on next read */
1.1       ratchov    58:        struct aproc *rproc;    /* reader */
                     59:        struct aproc *wproc;    /* writer */
1.9       ratchov    60:        struct abuf *duplex;    /* link to buffer of the other direction */
                     61:        unsigned inuse;         /* in abuf_{flush,fill,run}() */
1.6       ratchov    62:        unsigned char *data;    /* actual data (immediately following) */
1.1       ratchov    63: };
                     64:
                     65: /*
                     66:  * the buffer contains at least one frame. This macro should
                     67:  * be used to check if the buffer can be flushed
                     68:  */
                     69: #define ABUF_ROK(b) ((b)->used >= (b)->bpf)
                     70:
                     71: /*
                     72:  * there's room for at least one frame
                     73:  */
                     74: #define ABUF_WOK(b) ((b)->len - (b)->used >= (b)->bpf)
                     75:
                     76: /*
                     77:  * the buffer is empty and has no more writer
                     78:  */
                     79: #define ABUF_EOF(b) (!ABUF_ROK(b) && (b)->wproc == NULL)
                     80:
                     81: /*
1.9       ratchov    82:  * the buffer is empty and has no more writer
                     83:  */
                     84: #define ABUF_HUP(b) (!ABUF_WOK(b) && (b)->rproc == NULL)
                     85:
                     86: /*
1.1       ratchov    87:  * similar to !ABUF_WOK, but is used for file i/o, where
                     88:  * operation may not involve an integer number of frames
                     89:  */
                     90: #define ABUF_FULL(b) ((b)->used == (b)->len)
                     91:
                     92: /*
                     93:  * same as !ABUF_ROK, but used for files, where
                     94:  * operations are byte orientated, not frame-oriented
                     95:  */
                     96: #define ABUF_EMPTY(b) ((b)->used == 0)
                     97:
1.10      ratchov    98: struct abuf *abuf_new(unsigned, struct aparams *);
1.1       ratchov    99: void abuf_del(struct abuf *);
1.12      ratchov   100: void abuf_clear(struct abuf *);
1.1       ratchov   101: unsigned char *abuf_rgetblk(struct abuf *, unsigned *, unsigned);
                    102: unsigned char *abuf_wgetblk(struct abuf *, unsigned *, unsigned);
1.5       ratchov   103: void abuf_rdiscard(struct abuf *, unsigned);
                    104: void abuf_wcommit(struct abuf *, unsigned);
1.9       ratchov   105: int abuf_fill(struct abuf *);
                    106: int abuf_flush(struct abuf *);
1.1       ratchov   107: void abuf_eof(struct abuf *);
                    108: void abuf_hup(struct abuf *);
                    109: void abuf_run(struct abuf *);
1.9       ratchov   110: void abuf_ipos(struct abuf *, int);
                    111: void abuf_opos(struct abuf *, int);
1.1       ratchov   112:
                    113: #endif /* !defined(ABUF_H) */