[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.6

1.6     ! ratchov     1: /*     $OpenBSD: abuf.h,v 1.5 2008/08/14 09:39:16 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;
                     24:
                     25: struct abuf {
                     26:        /*
1.4       ratchov    27:         * Misc aproc-specific per-buffer parameters.
                     28:         * since the buffer can connect any pair of aproc structure,
                     29:         * each aproc must have it's own specific data. Thus we cannot
                     30:         * use an union. The only exception is the xrun field, because
                     31:         * there can be only one aproc that absorbs xruns in any
                     32:         * intput->output path.
1.1       ratchov    33:         */
                     34:        int mixvol;             /* input gain */
                     35:        unsigned mixdone;       /* input of mixer */
                     36:        unsigned mixtodo;       /* output of mixer */
                     37:        unsigned subdone;       /* output if sub */
1.4       ratchov    38: #define XRUN_IGNORE    0       /* on xrun silently insert/discard samples */
                     39: #define XRUN_SYNC      1       /* catchup to sync to the mix/sub */
                     40: #define XRUN_ERROR     2       /* xruns are errors, eof/hup buffer */
                     41:        unsigned xrun;          /* common to mix and sub */
1.1       ratchov    42:        LIST_ENTRY(abuf) ient;  /* for mix inputs list */
                     43:        LIST_ENTRY(abuf) oent;  /* for sub outputs list */
                     44:
                     45:        /*
                     46:         * fifo parameters
                     47:         */
                     48:        unsigned bpf;           /* bytes per frame */
                     49:        unsigned start;         /* offset where data starts */
                     50:        unsigned used;          /* valid data */
                     51:        unsigned len;           /* size of the ring */
1.6     ! ratchov    52:        unsigned silence;       /* silence to insert on next write */
        !            53:        unsigned drop;          /* frames to drop on next read */
1.1       ratchov    54:        struct aproc *rproc;    /* reader */
                     55:        struct aproc *wproc;    /* writer */
1.6     ! ratchov    56:        unsigned char *data;    /* actual data (immediately following) */
1.1       ratchov    57: };
                     58:
                     59: /*
                     60:  * the buffer contains at least one frame. This macro should
                     61:  * be used to check if the buffer can be flushed
                     62:  */
                     63: #define ABUF_ROK(b) ((b)->used >= (b)->bpf)
                     64:
                     65: /*
                     66:  * there's room for at least one frame
                     67:  */
                     68: #define ABUF_WOK(b) ((b)->len - (b)->used >= (b)->bpf)
                     69:
                     70: /*
                     71:  * the buffer is empty and has no more writer
                     72:  */
                     73: #define ABUF_EOF(b) (!ABUF_ROK(b) && (b)->wproc == NULL)
                     74:
                     75: /*
                     76:  * similar to !ABUF_WOK, but is used for file i/o, where
                     77:  * operation may not involve an integer number of frames
                     78:  */
                     79: #define ABUF_FULL(b) ((b)->used == (b)->len)
                     80:
                     81: /*
                     82:  * same as !ABUF_ROK, but used for files, where
                     83:  * operations are byte orientated, not frame-oriented
                     84:  */
                     85: #define ABUF_EMPTY(b) ((b)->used == 0)
                     86:
                     87: struct abuf *abuf_new(unsigned, unsigned);
                     88: void abuf_del(struct abuf *);
                     89: unsigned char *abuf_rgetblk(struct abuf *, unsigned *, unsigned);
                     90: unsigned char *abuf_wgetblk(struct abuf *, unsigned *, unsigned);
1.5       ratchov    91: void abuf_rdiscard(struct abuf *, unsigned);
                     92: void abuf_wcommit(struct abuf *, unsigned);
1.1       ratchov    93: void abuf_fill(struct abuf *);
                     94: void abuf_flush(struct abuf *);
                     95: void abuf_eof(struct abuf *);
                     96: void abuf_hup(struct abuf *);
                     97: void abuf_run(struct abuf *);
                     98:
                     99: #endif /* !defined(ABUF_H) */