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

1.22    ! ratchov     1: /*     $OpenBSD: abuf.h,v 1.21 2010/04/03 17:59:17 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:
1.19      ratchov    22: #define XRUN_IGNORE    0       /* on xrun silently insert/discard samples */
                     23: #define XRUN_SYNC      1       /* catchup to sync to the mix/sub */
                     24: #define XRUN_ERROR     2       /* xruns are errors, eof/hup buffer */
                     25: #define MIDI_MSGMAX    16      /* max size of MIDI messaage */
                     26:
1.1       ratchov    27: struct aproc;
1.16      ratchov    28: struct aparams;
1.1       ratchov    29:
                     30: struct abuf {
1.19      ratchov    31:        LIST_ENTRY(abuf) ient;  /* reader's list of inputs entry */
                     32:        LIST_ENTRY(abuf) oent;  /* writer's list of outputs entry */
1.15      ratchov    33:
1.1       ratchov    34:        /*
                     35:         * fifo parameters
                     36:         */
                     37:        unsigned bpf;           /* bytes per frame */
1.10      ratchov    38:        unsigned cmin, cmax;    /* channel range of this buf */
1.1       ratchov    39:        unsigned start;         /* offset where data starts */
                     40:        unsigned used;          /* valid data */
                     41:        unsigned len;           /* size of the ring */
                     42:        struct aproc *rproc;    /* reader */
                     43:        struct aproc *wproc;    /* writer */
1.9       ratchov    44:        struct abuf *duplex;    /* link to buffer of the other direction */
                     45:        unsigned inuse;         /* in abuf_{flush,fill,run}() */
1.19      ratchov    46:        unsigned tickets;       /* max data to (if throttling) */
                     47:
                     48:        /*
                     49:         * Misc reader aproc-specific per-buffer parameters.
                     50:         */
                     51:        union {
                     52:                struct {
                     53:                        int weight;     /* dynamic range */
                     54:                        int maxweight;  /* max dynamic range allowed */
                     55:                        unsigned vol;   /* volume within the dynamic range */
1.22    ! ratchov    56:                        unsigned done;  /* frames ready */
1.19      ratchov    57:                        unsigned xrun;  /* underrun policy */
1.22    ! ratchov    58:                        int drop;       /* frames to drop on next read */
1.19      ratchov    59:                } mix;
                     60:                struct {
                     61:                        unsigned st;    /* MIDI running status */
                     62:                        unsigned used;  /* bytes used from ``msg'' */
                     63:                        unsigned idx;   /* actual MIDI message size */
                     64:                        unsigned len;   /* MIDI message length */
                     65:                        unsigned char msg[MIDI_MSGMAX];
                     66:                } midi;
                     67:        } r;
                     68:
                     69:        /*
                     70:         * Misc reader aproc-specific per-buffer parameters.
                     71:         */
                     72:        union {
                     73:                struct {
1.22    ! ratchov    74:                        unsigned todo;  /* frames to process */
1.19      ratchov    75:                } mix;
                     76:                struct {
1.22    ! ratchov    77:                        unsigned done;  /* frames copied */
1.19      ratchov    78:                        unsigned xrun;  /* overrun policy */
1.22    ! ratchov    79:                        int silence;    /* silence to add on next write */
1.19      ratchov    80:                } sub;
                     81:        } w;
1.1       ratchov    82: };
                     83:
                     84: /*
                     85:  * the buffer contains at least one frame. This macro should
                     86:  * be used to check if the buffer can be flushed
                     87:  */
1.22    ! ratchov    88: #define ABUF_ROK(b) ((b)->used > 0)
1.1       ratchov    89:
                     90: /*
                     91:  * there's room for at least one frame
                     92:  */
1.22    ! ratchov    93: #define ABUF_WOK(b) ((b)->len - (b)->used > 0)
1.1       ratchov    94:
                     95: /*
1.17      ratchov    96:  * the buffer is empty and has no writer anymore
1.1       ratchov    97:  */
                     98: #define ABUF_EOF(b) (!ABUF_ROK(b) && (b)->wproc == NULL)
                     99:
                    100: /*
1.17      ratchov   101:  * the buffer has no reader anymore, note that it's not
                    102:  * enough the buffer to be disconnected, because it can
                    103:  * be not yet connected buffer (eg. socket play buffer)
1.9       ratchov   104:  */
                    105: #define ABUF_HUP(b) (!ABUF_WOK(b) && (b)->rproc == NULL)
1.1       ratchov   106:
1.10      ratchov   107: struct abuf *abuf_new(unsigned, struct aparams *);
1.1       ratchov   108: void abuf_del(struct abuf *);
1.18      ratchov   109: void abuf_dbg(struct abuf *);
1.12      ratchov   110: void abuf_clear(struct abuf *);
1.1       ratchov   111: unsigned char *abuf_rgetblk(struct abuf *, unsigned *, unsigned);
                    112: unsigned char *abuf_wgetblk(struct abuf *, unsigned *, unsigned);
1.5       ratchov   113: void abuf_rdiscard(struct abuf *, unsigned);
                    114: void abuf_wcommit(struct abuf *, unsigned);
1.9       ratchov   115: int abuf_fill(struct abuf *);
                    116: int abuf_flush(struct abuf *);
1.1       ratchov   117: void abuf_eof(struct abuf *);
                    118: void abuf_hup(struct abuf *);
                    119: void abuf_run(struct abuf *);
1.9       ratchov   120: void abuf_ipos(struct abuf *, int);
                    121: void abuf_opos(struct abuf *, int);
1.1       ratchov   122:
                    123: #endif /* !defined(ABUF_H) */