]> code.delx.au - pulseaudio/blob - src/pulsecore/memblockq.h
remap: Change remapping function argument type from void to int16_t / float as approp...
[pulseaudio] / src / pulsecore / memblockq.h
1 #ifndef foomemblockqhfoo
2 #define foomemblockqhfoo
3
4 /***
5 This file is part of PulseAudio.
6
7 Copyright 2004-2006 Lennart Poettering
8
9 PulseAudio 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.1 of the
12 License, or (at your option) any later version.
13
14 PulseAudio 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 PulseAudio; 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 <pulsecore/memblock.h>
29 #include <pulsecore/memchunk.h>
30 #include <pulse/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 /* Parameters:
41
42 - name: name for debugging purposes
43
44 - idx: start value for both read and write index
45
46 - maxlength: maximum length of queue. If more data is pushed into
47 the queue, the operation will fail. Must not be 0.
48
49 - tlength: the target length of the queue. Pass 0 for the default.
50
51 - ss: Sample spec describing the queue contents. Only multiples
52 of the frame size as implied by the sample spec are
53 allowed into the queue or can be popped from it.
54
55 - prebuf: If the queue runs empty wait until this many bytes are in
56 queue again before passing the first byte out. If set
57 to 0 pa_memblockq_pop() will return a silence memblock
58 if no data is in the queue and will never fail. Pass
59 (size_t) -1 for the default.
60
61 - minreq: pa_memblockq_missing() will only return values greater
62 than this value. Pass 0 for the default.
63
64 - maxrewind: how many bytes of history to keep in the queue
65
66 - silence: return this memchunk when reading uninitialized data
67 */
68 pa_memblockq* pa_memblockq_new(
69 const char *name,
70 int64_t idx,
71 size_t maxlength,
72 size_t tlength,
73 const pa_sample_spec *sample_spec,
74 size_t prebuf,
75 size_t minreq,
76 size_t maxrewind,
77 pa_memchunk *silence);
78
79 void pa_memblockq_free(pa_memblockq*bq);
80
81 /* Push a new memory chunk into the queue. */
82 int pa_memblockq_push(pa_memblockq* bq, const pa_memchunk *chunk);
83
84 /* Push a new memory chunk into the queue, but filter it through a
85 * pa_mcalign object. Don't mix this with pa_memblockq_seek() unless
86 * you know what you do. */
87 int pa_memblockq_push_align(pa_memblockq* bq, const pa_memchunk *chunk);
88
89 /* Manipulate the write pointer */
90 void pa_memblockq_seek(pa_memblockq *bq, int64_t offset, pa_seek_mode_t seek, bool account);
91
92 /* Return a copy of the next memory chunk in the queue. It is not
93 * removed from the queue. There are two reasons this function might
94 * fail: 1. prebuffering is active, 2. queue is empty and no silence
95 * memblock was passed at initialization. If the queue is not empty,
96 * but we're currently at a hole in the queue and no silence memblock
97 * was passed we return the length of the hole in chunk->length. */
98 int pa_memblockq_peek(pa_memblockq* bq, pa_memchunk *chunk);
99
100 /* Much like pa_memblockq_peek, but guarantees that the returned chunk
101 * will have a length of the block size passed. You must configure a
102 * silence memchunk for this memblockq if you use this call. */
103 int pa_memblockq_peek_fixed_size(pa_memblockq *bq, size_t block_size, pa_memchunk *chunk);
104
105 /* Drop the specified bytes from the queue. */
106 void pa_memblockq_drop(pa_memblockq *bq, size_t length);
107
108 /* Rewind the read index. If the history is shorter than the specified length we'll point to silence afterwards. */
109 void pa_memblockq_rewind(pa_memblockq *bq, size_t length);
110
111 /* Test if the pa_memblockq is currently readable, that is, more data than base */
112 bool pa_memblockq_is_readable(pa_memblockq *bq);
113
114 /* Return the length of the queue in bytes */
115 size_t pa_memblockq_get_length(pa_memblockq *bq);
116
117 /* Return how many bytes are missing in queue to the specified fill amount */
118 size_t pa_memblockq_missing(pa_memblockq *bq);
119
120 /* Return the number of bytes that are missing since the last call to
121 * this function, reset the internal counter to 0. */
122 size_t pa_memblockq_pop_missing(pa_memblockq *bq);
123
124 /* Directly moves the data from the source memblockq into bq */
125 int pa_memblockq_splice(pa_memblockq *bq, pa_memblockq *source);
126
127 /* Set the queue to silence, set write index to read index */
128 void pa_memblockq_flush_write(pa_memblockq *bq, bool account);
129
130 /* Set the queue to silence, set write read index to write index*/
131 void pa_memblockq_flush_read(pa_memblockq *bq);
132
133 /* Ignore prebuf for now */
134 void pa_memblockq_prebuf_disable(pa_memblockq *bq);
135
136 /* Force prebuf */
137 void pa_memblockq_prebuf_force(pa_memblockq *bq);
138
139 /* Return the maximum length of the queue in bytes */
140 size_t pa_memblockq_get_maxlength(pa_memblockq *bq);
141
142 /* Get Target length */
143 size_t pa_memblockq_get_tlength(pa_memblockq *bq);
144
145 /* Return the prebuffer length in bytes */
146 size_t pa_memblockq_get_prebuf(pa_memblockq *bq);
147
148 /* Returns the minimal request value */
149 size_t pa_memblockq_get_minreq(pa_memblockq *bq);
150
151 /* Returns the maximal rewind value */
152 size_t pa_memblockq_get_maxrewind(pa_memblockq *bq);
153
154 /* Return the base unit in bytes */
155 size_t pa_memblockq_get_base(pa_memblockq *bq);
156
157 /* Return the current read index */
158 int64_t pa_memblockq_get_read_index(pa_memblockq *bq);
159
160 /* Return the current write index */
161 int64_t pa_memblockq_get_write_index(pa_memblockq *bq);
162
163 /* Change metrics. Always call in order. */
164 void pa_memblockq_set_maxlength(pa_memblockq *memblockq, size_t maxlength); /* might modify tlength, prebuf, minreq too */
165 void pa_memblockq_set_tlength(pa_memblockq *memblockq, size_t tlength); /* might modify minreq, too */
166 void pa_memblockq_set_minreq(pa_memblockq *memblockq, size_t minreq); /* might modify prebuf, too */
167 void pa_memblockq_set_prebuf(pa_memblockq *memblockq, size_t prebuf);
168 void pa_memblockq_set_maxrewind(pa_memblockq *memblockq, size_t maxrewind); /* Set the maximum history size */
169 void pa_memblockq_set_silence(pa_memblockq *memblockq, pa_memchunk *silence);
170
171 /* Apply the data from pa_buffer_attr */
172 void pa_memblockq_apply_attr(pa_memblockq *memblockq, const pa_buffer_attr *a);
173 void pa_memblockq_get_attr(pa_memblockq *bq, pa_buffer_attr *a);
174
175 /* Call pa_memchunk_will_need() for every chunk in the queue from the current read pointer to the end */
176 void pa_memblockq_willneed(pa_memblockq *bq);
177
178 /* Check whether the memblockq is completely empty, i.e. no data
179 * neither left nor right of the read pointer, and hence no buffered
180 * data for the future nor data in the backlog. */
181 bool pa_memblockq_is_empty(pa_memblockq *bq);
182
183 /* Drop everything in the queue, but don't modify the indexes */
184 void pa_memblockq_silence(pa_memblockq *bq);
185
186 /* Check whether we currently are in prebuf state */
187 bool pa_memblockq_prebuf_active(pa_memblockq *bq);
188
189 /* Return how many items are currently stored in the queue */
190 unsigned pa_memblockq_get_nblocks(pa_memblockq *bq);
191
192 #endif