]> code.delx.au - pulseaudio/blob - src/polypcore/memblockq.h
unhide padsp
[pulseaudio] / src / polypcore / memblockq.h
1 #ifndef foomemblockqhfoo
2 #define foomemblockqhfoo
3
4 /* $Id$ */
5
6 /***
7 This file is part of polypaudio.
8
9 polypaudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version.
13
14 polypaudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with polypaudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 USA.
23 ***/
24
25 #include <sys/types.h>
26 #include <inttypes.h>
27
28 #include <polypcore/memblock.h>
29 #include <polypcore/memchunk.h>
30 #include <polyp/def.h>
31
32 /* A memblockq is a queue of pa_memchunks (yepp, the name is not
33 * perfect). It is similar to the ring buffers used by most other
34 * audio software. In contrast to a ring buffer this memblockq data
35 * type doesn't need to copy any data around, it just maintains
36 * references to reference counted memory blocks. */
37
38 typedef struct pa_memblockq pa_memblockq;
39
40
41 /* Parameters:
42
43 - idx: start value for both read and write index
44
45 - maxlength: maximum length of queue. If more data is pushed into
46 the queue, the operation will fail. Must not be 0.
47
48 - tlength: the target length of the queue. Pass 0 for the default.
49
50 - base: a base value for all metrics. Only multiples of this value
51 are popped from the queue or should be pushed into
52 it. Must not be 0.
53
54 - prebuf: If the queue runs empty wait until this many bytes are in
55 queue again before passing the first byte out. If set
56 to 0 pa_memblockq_pop() will return a silence memblock
57 if no data is in the queue and will never fail. Pass
58 (size_t) -1 for the default.
59
60 - minreq: pa_memblockq_missing() will only return values greater
61 than this value. Pass 0 for the default.
62
63 - silence: return this memblock whzen reading unitialized data
64 */
65 pa_memblockq* pa_memblockq_new(
66 int64_t idx,
67 size_t maxlength,
68 size_t tlength,
69 size_t base,
70 size_t prebuf,
71 size_t minreq,
72 pa_memblock *silence,
73 pa_memblock_stat *s);
74
75 void pa_memblockq_free(pa_memblockq*bq);
76
77 /* Push a new memory chunk into the queue. */
78 int pa_memblockq_push(pa_memblockq* bq, const pa_memchunk *chunk);
79
80 /* Push a new memory chunk into the queue, but filter it through a
81 * pa_mcalign object. Don't mix this with pa_memblockq_seek() unless
82 * you know what you do. */
83 int pa_memblockq_push_align(pa_memblockq* bq, const pa_memchunk *chunk);
84
85 /* Return a copy of the next memory chunk in the queue. It is not removed from the queue */
86 int pa_memblockq_peek(pa_memblockq* bq, pa_memchunk *chunk);
87
88 /* Drop the specified bytes from the queue, but only if the first
89 * chunk in the queue matches the one passed here. If NULL is passed,
90 * this check isn't done. */
91 void pa_memblockq_drop(pa_memblockq *bq, const pa_memchunk *chunk, size_t length);
92
93 /* Test if the pa_memblockq is currently readable, that is, more data than base */
94 int pa_memblockq_is_readable(pa_memblockq *bq);
95
96 /* Test if the pa_memblockq is currently writable for the specified amount of bytes */
97 int pa_memblockq_is_writable(pa_memblockq *bq, size_t length);
98
99 /* Return the length of the queue in bytes */
100 size_t pa_memblockq_get_length(pa_memblockq *bq);
101
102 /* Return how many bytes are missing in queue to the specified fill amount */
103 size_t pa_memblockq_missing(pa_memblockq *bq);
104
105 /* Returns the minimal request value */
106 size_t pa_memblockq_get_minreq(pa_memblockq *bq);
107
108 /* Manipulate the write pointer */
109 void pa_memblockq_seek(pa_memblockq *bq, int64_t offset, pa_seek_mode_t seek);
110
111 /* Set the queue to silence, set write index to read index */
112 void pa_memblockq_flush(pa_memblockq *bq);
113
114 /* Get Target length */
115 size_t pa_memblockq_get_tlength(pa_memblockq *bq);
116
117 /* Return the current read index */
118 int64_t pa_memblockq_get_read_index(pa_memblockq *bq);
119
120 /* Return the current write index */
121 int64_t pa_memblockq_get_write_index(pa_memblockq *bq);
122
123 /* Shorten the pa_memblockq to the specified length by dropping data
124 * at the read end of the queue. The read index is increased until the
125 * queue has the specified length */
126 void pa_memblockq_shorten(pa_memblockq *bq, size_t length);
127
128 /* Ignore prebuf for now */
129 void pa_memblockq_prebuf_disable(pa_memblockq *bq);
130
131 /* Force prebuf */
132 void pa_memblockq_prebuf_force(pa_memblockq *bq);
133
134 /* Return the maximum length of the queue in bytes */
135 size_t pa_memblockq_get_maxlength(pa_memblockq *bq);
136
137 /* Return the prebuffer length in bytes */
138 size_t pa_memblockq_get_prebuf(pa_memblockq *bq);
139
140 #endif