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

Annotation of src/usr.bin/aucat/aproc.h, Revision 1.11

1.11    ! ratchov     1: /*     $OpenBSD: aproc.h,v 1.10 2008/11/04 18:24:06 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 APROC_H
                     18: #define APROC_H
                     19:
                     20: #include <sys/queue.h>
                     21:
                     22: #include "aparams.h"
                     23:
                     24: struct abuf;
                     25: struct aproc;
                     26: struct file;
                     27:
                     28: struct aproc_ops {
                     29:        /*
                     30:         * Name of the ops structure, ie type of the unit.
                     31:         */
                     32:        char *name;
                     33:
                     34:        /*
                     35:         * The state of the given input abuf changed (eg. an input block
                     36:         * is ready for processing). This function must get the block
                     37:         * from the input, process it and remove it from the buffer.
                     38:         *
                     39:         * Processing the block will result in a change of the state of
                     40:         * OTHER buffers that are attached to the aproc (eg. the output
                     41:         * buffer was filled), thus this routine MUST notify ALL aproc
                     42:         * structures that are waiting on it; most of the time this
                     43:         * means just calling abuf_flush() on the output buffer.
                     44:         */
                     45:        int (*in)(struct aproc *, struct abuf *);
                     46:
                     47:        /*
                     48:         * The state of the given output abuf changed (eg. space for a
                     49:         * new output block was made available) so processing can
                     50:         * continue.  This function must process more input in order to
                     51:         * fill the output block.
                     52:         *
                     53:         * Producing a block will result in the change of the state of
                     54:         * OTHER buffers that are attached to the aproc, thus this
                     55:         * routine MUST notify ALL aproc structures that are waiting on
                     56:         * it; most of the time this means calling abuf_fill() on the
                     57:         * source buffers.
                     58:         *
                     59:         * Before filling input buffers (using abuf_fill()), this
                     60:         * routine must ALWAYS check for eof condition, and if needed,
                     61:         * handle it appropriately and call abuf_hup() to free the input
                     62:         * buffer.
                     63:         */
                     64:        int (*out)(struct aproc *, struct abuf *);
                     65:
                     66:        /*
                     67:         * The input buffer is empty and we can no more receive data
                     68:         * from it. The buffer will be destroyed as soon as this call
                     69:         * returns so the abuf pointer will stop being valid after this
                     70:         * call returns. There's no need to drain the buffer because the
                     71:         * in() call-back was just called before.
                     72:         *
                     73:         * If this call reads and/or writes data on other buffers,
                     74:         * abuf_flush() and abuf_fill() must be called appropriately.
                     75:         */
                     76:        void (*eof)(struct aproc *, struct abuf *);
                     77:
                     78:        /*
                     79:         * The output buffer can no more accept data (it should be
                     80:         * considered as full). After this function returns, it will be
                     81:         * destroyed and the "abuf" pointer will be no more valid.
                     82:         */
                     83:        void (*hup)(struct aproc *, struct abuf *);
                     84:
                     85:        /*
                     86:         * A new input was connected.
                     87:         */
                     88:        void (*newin)(struct aproc *, struct abuf *);
                     89:
                     90:        /*
                     91:         * A new output was connected
                     92:         */
                     93:        void (*newout)(struct aproc *, struct abuf *);
1.3       ratchov    94:
                     95:        /*
1.6       ratchov    96:         * Real-time record position changed (for input buffer),
                     97:         * by the given amount of _frames_
                     98:         */
                     99:        void (*ipos)(struct aproc *, struct abuf *, int);
                    100:
                    101:        /*
                    102:         * Real-time play position changed (for output buffer),
                    103:         * by the given amount of _frames_
                    104:         */
                    105:        void (*opos)(struct aproc *, struct abuf *, int);
                    106:
                    107:        /*
1.3       ratchov   108:         * destroy the aproc, called just before to free the
                    109:         * aproc structure
                    110:         */
                    111:        void (*done)(struct aproc *);
1.1       ratchov   112: };
                    113:
                    114: /*
                    115:  * The aproc structure represents a simple audio processing unit; they are
                    116:  * interconnected by abuf structures and form a kind of "circuit". The circuit
                    117:  * cannot have loops.
                    118:  */
                    119: struct aproc {
                    120:        char *name;                             /* for debug purposes */
                    121:        struct aproc_ops *ops;                  /* call-backs */
                    122:        LIST_HEAD(, abuf) ibuflist;             /* list of inputs */
                    123:        LIST_HEAD(, abuf) obuflist;             /* list of outputs */
                    124:        union {                                 /* follow type-specific data */
                    125:                struct {                        /* file/device io */
                    126:                        struct file *file;      /* file to read/write */
                    127:                } io;
                    128:                struct {
1.4       ratchov   129: #define MIX_DROP       1
                    130: #define MIX_AUTOQUIT   2
1.6       ratchov   131:                        unsigned flags;         /* bit mask of above */
                    132:                        int lat;                /* current latency */
                    133:                        int maxlat;             /* max latency allowed*/
1.2       ratchov   134:                } mix;
                    135:                struct {
1.4       ratchov   136: #define SUB_DROP       1
                    137: #define SUB_AUTOQUIT   2
1.6       ratchov   138:                        unsigned flags;         /* bit mask of above */
                    139:                        int lat;                /* current latency */
                    140:                        int maxlat;             /* max latency allowed*/
1.2       ratchov   141:                } sub;
1.7       ratchov   142:                struct {
                    143:                        short ctx[NCHAN_MAX];
                    144:                        unsigned irate, orate;
                    145:                        int ipos, opos;
                    146:                        int idelta, odelta;     /* reminder of conv_[io]pos */
                    147:                } resamp;
1.9       ratchov   148:                struct {
                    149:                        short ctx[NCHAN_MAX];
                    150:                } cmap;
1.11    ! ratchov   151:                struct {
        !           152:                        int bfirst;             /* bytes to skip at startup */
        !           153:                        unsigned bps;           /* bytes per sample */
        !           154:                        unsigned shift;         /* shift to get 32bit MSB */
        !           155:                        int sigbit;             /* sign bits to XOR */
        !           156:                        int bnext;              /* to reach the next byte */
        !           157:                        int snext;              /* to reach the next sample */
        !           158:                } conv;
1.1       ratchov   159:        } u;
                    160: };
                    161:
1.3       ratchov   162: struct aproc *aproc_new(struct aproc_ops *, char *);
1.1       ratchov   163: void aproc_del(struct aproc *);
                    164: void aproc_setin(struct aproc *, struct abuf *);
                    165: void aproc_setout(struct aproc *, struct abuf *);
                    166:
                    167: struct aproc *rpipe_new(struct file *);
1.3       ratchov   168: int rpipe_in(struct aproc *, struct abuf *);
                    169: int rpipe_out(struct aproc *, struct abuf *);
                    170: void rpipe_done(struct aproc *);
                    171: void rpipe_eof(struct aproc *, struct abuf *);
                    172: void rpipe_hup(struct aproc *, struct abuf *);
                    173:
1.1       ratchov   174: struct aproc *wpipe_new(struct file *);
1.3       ratchov   175: void wpipe_done(struct aproc *);
                    176: int wpipe_in(struct aproc *, struct abuf *);
                    177: int wpipe_out(struct aproc *, struct abuf *);
                    178: void wpipe_eof(struct aproc *, struct abuf *);
                    179: void wpipe_hup(struct aproc *, struct abuf *);
                    180:
1.6       ratchov   181: struct aproc *mix_new(char *, int);
                    182: struct aproc *sub_new(char *, int);
1.7       ratchov   183: struct aproc *resamp_new(char *, struct aparams *, struct aparams *);
1.9       ratchov   184: struct aproc *cmap_new(char *, struct aparams *, struct aparams *);
1.11    ! ratchov   185: struct aproc *enc_new(char *, struct aparams *);
        !           186: struct aproc *dec_new(char *, struct aparams *);
1.5       ratchov   187:
                    188: void mix_pushzero(struct aproc *);
                    189: void mix_setmaster(struct aproc *);
1.1       ratchov   190:
1.11    ! ratchov   191: #endif /* !defined(APROC_H) */