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

1.45    ! ratchov     1: /*     $OpenBSD$       */
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"
1.17      ratchov    23: #include "file.h"
1.1       ratchov    24:
                     25: struct abuf;
                     26: struct aproc;
                     27: struct file;
                     28:
                     29: struct aproc_ops {
                     30:        /*
                     31:         * Name of the ops structure, ie type of the unit.
                     32:         */
                     33:        char *name;
                     34:
                     35:        /*
                     36:         * The state of the given input abuf changed (eg. an input block
                     37:         * is ready for processing). This function must get the block
                     38:         * from the input, process it and remove it from the buffer.
                     39:         *
                     40:         * Processing the block will result in a change of the state of
                     41:         * OTHER buffers that are attached to the aproc (eg. the output
                     42:         * buffer was filled), thus this routine MUST notify ALL aproc
                     43:         * structures that are waiting on it; most of the time this
                     44:         * means just calling abuf_flush() on the output buffer.
                     45:         */
                     46:        int (*in)(struct aproc *, struct abuf *);
                     47:
                     48:        /*
                     49:         * The state of the given output abuf changed (eg. space for a
                     50:         * new output block was made available) so processing can
                     51:         * continue.  This function must process more input in order to
                     52:         * fill the output block.
                     53:         *
                     54:         * Producing a block will result in the change of the state of
                     55:         * OTHER buffers that are attached to the aproc, thus this
                     56:         * routine MUST notify ALL aproc structures that are waiting on
                     57:         * it; most of the time this means calling abuf_fill() on the
                     58:         * source buffers.
                     59:         *
                     60:         * Before filling input buffers (using abuf_fill()), this
                     61:         * routine must ALWAYS check for eof condition, and if needed,
                     62:         * handle it appropriately and call abuf_hup() to free the input
                     63:         * buffer.
                     64:         */
                     65:        int (*out)(struct aproc *, struct abuf *);
                     66:
                     67:        /*
                     68:         * The input buffer is empty and we can no more receive data
                     69:         * from it. The buffer will be destroyed as soon as this call
                     70:         * returns so the abuf pointer will stop being valid after this
                     71:         * call returns. There's no need to drain the buffer because the
                     72:         * in() call-back was just called before.
                     73:         *
                     74:         * If this call reads and/or writes data on other buffers,
                     75:         * abuf_flush() and abuf_fill() must be called appropriately.
                     76:         */
                     77:        void (*eof)(struct aproc *, struct abuf *);
                     78:
                     79:        /*
                     80:         * The output buffer can no more accept data (it should be
                     81:         * considered as full). After this function returns, it will be
                     82:         * destroyed and the "abuf" pointer will be no more valid.
                     83:         */
                     84:        void (*hup)(struct aproc *, struct abuf *);
                     85:
                     86:        /*
                     87:         * A new input was connected.
                     88:         */
                     89:        void (*newin)(struct aproc *, struct abuf *);
                     90:
                     91:        /*
                     92:         * A new output was connected
                     93:         */
                     94:        void (*newout)(struct aproc *, struct abuf *);
1.3       ratchov    95:
                     96:        /*
1.6       ratchov    97:         * Real-time record position changed (for input buffer),
1.18      ratchov    98:         * by the given amount of _frames_.
1.6       ratchov    99:         */
                    100:        void (*ipos)(struct aproc *, struct abuf *, int);
                    101:
                    102:        /*
                    103:         * Real-time play position changed (for output buffer),
1.18      ratchov   104:         * by the given amount of _frames_.
1.6       ratchov   105:         */
                    106:        void (*opos)(struct aproc *, struct abuf *, int);
                    107:
                    108:        /*
1.18      ratchov   109:         * Destroy the aproc, called just before to free the
                    110:         * aproc structure.
1.3       ratchov   111:         */
                    112:        void (*done)(struct aproc *);
1.1       ratchov   113: };
                    114:
                    115: /*
                    116:  * The aproc structure represents a simple audio processing unit; they are
                    117:  * interconnected by abuf structures and form a kind of "circuit". The circuit
                    118:  * cannot have loops.
                    119:  */
                    120: struct aproc {
                    121:        char *name;                             /* for debug purposes */
                    122:        struct aproc_ops *ops;                  /* call-backs */
1.35      ratchov   123:        LIST_HEAD(, abuf) ins;                  /* list of inputs */
                    124:        LIST_HEAD(, abuf) outs;                 /* list of outputs */
1.44      ratchov   125:        unsigned int refs;                      /* extern references */
1.27      ratchov   126: #define APROC_ZOMB     1                       /* destroyed but not freed */
                    127: #define APROC_QUIT     2                       /* try to terminate if unused */
                    128: #define APROC_DROP     4                       /* xrun if capable */
1.44      ratchov   129:        unsigned int flags;
1.1       ratchov   130:        union {                                 /* follow type-specific data */
                    131:                struct {                        /* file/device io */
                    132:                        struct file *file;      /* file to read/write */
1.44      ratchov   133:                        unsigned int partial;   /* bytes of partial frame */
1.1       ratchov   134:                } io;
                    135:                struct {
1.44      ratchov   136:                        unsigned int idle;      /* frames since idleing */
                    137:                        unsigned int round;     /* block size, for xruns */
1.6       ratchov   138:                        int lat;                /* current latency */
1.27      ratchov   139:                        int maxlat;             /* max latency allowed */
1.44      ratchov   140:                        unsigned int abspos;    /* frames produced */
1.32      ratchov   141:                        struct aproc *mon;      /* snoop output */
1.44      ratchov   142:                        unsigned int autovol;   /* adjust volume dynamically */
1.43      ratchov   143:                        int master;             /* master attenuation */
1.2       ratchov   144:                } mix;
                    145:                struct {
1.44      ratchov   146:                        unsigned int idle;      /* frames since idleing */
                    147:                        unsigned int round;     /* block size, for xruns */
1.6       ratchov   148:                        int lat;                /* current latency */
1.27      ratchov   149:                        int maxlat;             /* max latency allowed */
1.44      ratchov   150:                        unsigned int abspos;    /* frames consumed */
1.2       ratchov   151:                } sub;
1.7       ratchov   152:                struct {
1.32      ratchov   153:                        int delta;              /* time position */
1.44      ratchov   154:                        unsigned int bufsz;     /* buffer size (latency) */
                    155:                        unsigned int pending;   /* uncommited samples */
1.32      ratchov   156:                } mon;
                    157:                struct {
1.14      ratchov   158: #define RESAMP_NCTX    2
1.44      ratchov   159:                        unsigned int ctx_start;
1.38      ratchov   160:                        adata_t ctx[NCHAN_MAX * RESAMP_NCTX];
1.44      ratchov   161:                        unsigned int iblksz, oblksz;
1.14      ratchov   162:                        int diff;
1.32      ratchov   163:                        int idelta, odelta;     /* remainder of resamp_xpos */
1.7       ratchov   164:                } resamp;
1.9       ratchov   165:                struct {
1.11      ratchov   166:                        int bfirst;             /* bytes to skip at startup */
1.44      ratchov   167:                        unsigned int bps;       /* bytes per sample */
                    168:                        unsigned int shift;     /* shift to get 32bit MSB */
1.11      ratchov   169:                        int sigbit;             /* sign bits to XOR */
                    170:                        int bnext;              /* to reach the next byte */
                    171:                        int snext;              /* to reach the next sample */
                    172:                } conv;
1.17      ratchov   173:                struct {
1.42      ratchov   174:                        struct dev *dev;        /* controlled device */
1.17      ratchov   175:                        struct timo timo;       /* timout for throtteling */
1.44      ratchov   176:                        unsigned int fps;       /* MTC frames per second */
1.27      ratchov   177: #define MTC_FPS_24     0
                    178: #define MTC_FPS_25     1
                    179: #define MTC_FPS_30     3
1.44      ratchov   180:                        unsigned int fps_id;    /* one of above */
                    181:                        unsigned int hr;        /* MTC hours */
                    182:                        unsigned int min;       /* MTC minutes */
                    183:                        unsigned int sec;       /* MTC seconds */
                    184:                        unsigned int fr;        /* MTC frames */
                    185:                        unsigned int qfr;       /* MTC quarter frames */
1.27      ratchov   186:                        int delta;              /* rel. to the last MTC tick */
1.42      ratchov   187:                } midi;
1.1       ratchov   188:        } u;
                    189: };
                    190:
1.32      ratchov   191: /*
                    192:  * Check if the given pointer is a valid aproc structure.
                    193:  *
                    194:  * aproc structures are not free()'d immediately, because
                    195:  * there may be pointers to them, instead the APROC_ZOMB flag
                    196:  * is set which means that they should not be used. When
                    197:  * aprocs reference counter reaches zero, they are actually
                    198:  * freed
                    199:  */
                    200: #define APROC_OK(p) ((p) && !((p)->flags & APROC_ZOMB))
                    201:
                    202:
1.3       ratchov   203: struct aproc *aproc_new(struct aproc_ops *, char *);
1.1       ratchov   204: void aproc_del(struct aproc *);
1.23      ratchov   205: void aproc_dbg(struct aproc *);
1.1       ratchov   206: void aproc_setin(struct aproc *, struct abuf *);
                    207: void aproc_setout(struct aproc *, struct abuf *);
1.45    ! ratchov   208: int aproc_inuse(struct aproc *);
1.17      ratchov   209: int aproc_depend(struct aproc *, struct aproc *);
1.1       ratchov   210:
1.32      ratchov   211: void aproc_ipos(struct aproc *, struct abuf *, int);
                    212: void aproc_opos(struct aproc *, struct abuf *, int);
                    213:
1.28      ratchov   214: struct aproc *rfile_new(struct file *);
                    215: struct aproc *wfile_new(struct file *);
1.44      ratchov   216: struct aproc *mix_new(char *, int, unsigned int, unsigned int, unsigned int);
                    217: struct aproc *sub_new(char *, int, unsigned int);
                    218: struct aproc *resamp_new(char *, unsigned int, unsigned int);
1.11      ratchov   219: struct aproc *enc_new(char *, struct aparams *);
                    220: struct aproc *dec_new(char *, struct aparams *);
1.34      ratchov   221: struct aproc *join_new(char *);
1.44      ratchov   222: struct aproc *mon_new(char *, unsigned int);
1.32      ratchov   223:
                    224: int rfile_in(struct aproc *, struct abuf *);
                    225: int rfile_out(struct aproc *, struct abuf *);
                    226: void rfile_eof(struct aproc *, struct abuf *);
                    227: void rfile_hup(struct aproc *, struct abuf *);
                    228: void rfile_done(struct aproc *);
1.44      ratchov   229: int rfile_do(struct aproc *, unsigned int, unsigned int *);
1.32      ratchov   230:
                    231: int wfile_in(struct aproc *, struct abuf *);
                    232: int wfile_out(struct aproc *, struct abuf *);
                    233: void wfile_eof(struct aproc *, struct abuf *);
                    234: void wfile_hup(struct aproc *, struct abuf *);
                    235: void wfile_done(struct aproc *);
1.44      ratchov   236: int wfile_do(struct aproc *, unsigned int, unsigned int *);
1.5       ratchov   237:
                    238: void mix_setmaster(struct aproc *);
1.12      ratchov   239: void mix_clear(struct aproc *);
1.29      ratchov   240: void mix_prime(struct aproc *);
1.36      ratchov   241: void mix_quit(struct aproc *);
1.32      ratchov   242: void mix_drop(struct abuf *, int);
                    243: void sub_silence(struct abuf *, int);
1.12      ratchov   244: void sub_clear(struct aproc *);
1.44      ratchov   245: void mon_snoop(struct aproc *, struct abuf *, unsigned int, unsigned int);
1.32      ratchov   246: void mon_clear(struct aproc *);
1.1       ratchov   247:
1.11      ratchov   248: #endif /* !defined(APROC_H) */