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