1 #ifndef foomemblockqhfoo
2 #define foomemblockqhfoo
7 This file is part of PulseAudio.
9 Copyright 2004-2006 Lennart Poettering
11 PulseAudio is free software; you can redistribute it and/or modify
12 it under the terms of the GNU Lesser General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version.
16 PulseAudio is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU Lesser General Public
22 License along with PulseAudio; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 #include <sys/types.h>
30 #include <pulsecore/memblock.h>
31 #include <pulsecore/memchunk.h>
32 #include <pulse/def.h>
34 /* A memblockq is a queue of pa_memchunks (yepp, the name is not
35 * perfect). It is similar to the ring buffers used by most other
36 * audio software. In contrast to a ring buffer this memblockq data
37 * type doesn't need to copy any data around, it just maintains
38 * references to reference counted memory blocks. */
40 typedef struct pa_memblockq pa_memblockq;
45 - idx: start value for both read and write index
47 - maxlength: maximum length of queue. If more data is pushed into
48 the queue, the operation will fail. Must not be 0.
50 - tlength: the target length of the queue. Pass 0 for the default.
52 - base: a base value for all metrics. Only multiples of this value
53 are popped from the queue or should be pushed into
56 - prebuf: If the queue runs empty wait until this many bytes are in
57 queue again before passing the first byte out. If set
58 to 0 pa_memblockq_pop() will return a silence memblock
59 if no data is in the queue and will never fail. Pass
60 (size_t) -1 for the default.
62 - minreq: pa_memblockq_missing() will only return values greater
63 than this value. Pass 0 for the default.
65 - maxrewind: how many bytes of history to keep in the queue
67 - silence: return this memchunk when reading unitialized data
69 pa_memblockq* pa_memblockq_new(
77 pa_memchunk *silence);
79 void pa_memblockq_free(pa_memblockq*bq);
81 /* Push a new memory chunk into the queue. */
82 int pa_memblockq_push(pa_memblockq* bq, const pa_memchunk *chunk);
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);
89 /* Return a copy of the next memory chunk in the queue. It is not
90 * removed from the queue. There are two reasons this function might
91 * fail: 1. prebuffering is active, 2. queue is empty and no silence
92 * memblock was passed at initialization. If the queue is not empty,
93 * but we're currently at a hole in the queue and no silence memblock
94 * was passed we return the length of the hole in chunk->length. */
95 int pa_memblockq_peek(pa_memblockq* bq, pa_memchunk *chunk);
97 /* Drop the specified bytes from the queue. */
98 void pa_memblockq_drop(pa_memblockq *bq, size_t length);
100 /* Test if the pa_memblockq is currently readable, that is, more data than base */
101 pa_bool_t pa_memblockq_is_readable(pa_memblockq *bq);
103 /* Return the length of the queue in bytes */
104 size_t pa_memblockq_get_length(pa_memblockq *bq);
106 /* Return how many bytes are missing in queue to the specified fill amount */
107 size_t pa_memblockq_missing(pa_memblockq *bq);
109 /* Return the number of bytes that are missing since the last call to
110 * this function, reset the internal counter to 0. */
111 size_t pa_memblockq_pop_missing(pa_memblockq *bq);
113 /* Directly moves the data from the source memblockq into bq */
114 int pa_memblockq_splice(pa_memblockq *bq, pa_memblockq *source);
116 /* Returns the minimal request value */
117 size_t pa_memblockq_get_minreq(pa_memblockq *bq);
119 /* Manipulate the write pointer */
120 void pa_memblockq_seek(pa_memblockq *bq, int64_t offset, pa_seek_mode_t seek);
122 /* Set the queue to silence, set write index to read index */
123 void pa_memblockq_flush(pa_memblockq *bq);
125 /* Get Target length */
126 size_t pa_memblockq_get_tlength(pa_memblockq *bq);
128 /* Return the current read index */
129 int64_t pa_memblockq_get_read_index(pa_memblockq *bq);
131 /* Return the current write index */
132 int64_t pa_memblockq_get_write_index(pa_memblockq *bq);
134 /* Rewind the read index. If the history is shorter than the specified length we'll point to silence afterwards. */
135 void pa_memblockq_rewind(pa_memblockq *bq, size_t length);
137 /* Ignore prebuf for now */
138 void pa_memblockq_prebuf_disable(pa_memblockq *bq);
141 void pa_memblockq_prebuf_force(pa_memblockq *bq);
143 /* Return the maximum length of the queue in bytes */
144 size_t pa_memblockq_get_maxlength(pa_memblockq *bq);
146 /* Return the prebuffer length in bytes */
147 size_t pa_memblockq_get_prebuf(pa_memblockq *bq);
149 /* Change metrics. Always call in order. */
150 void pa_memblockq_set_maxlength(pa_memblockq *memblockq, size_t maxlength); /* might modify tlength, prebuf, minreq too */
151 void pa_memblockq_set_tlength(pa_memblockq *memblockq, size_t tlength); /* might modify minreq, too */
152 void pa_memblockq_set_prebuf(pa_memblockq *memblockq, size_t prebuf); /* might modify minreq, too */
153 void pa_memblockq_set_minreq(pa_memblockq *memblockq, size_t minreq);
154 void pa_memblockq_set_maxrewind(pa_memblockq *memblockq, size_t rewind); /* Set the maximum history size */
155 void pa_memblockq_set_silence(pa_memblockq *memblockq, pa_memchunk *silence);
157 /* Call pa_memchunk_willneed() for every chunk in the queue from the current read pointer to the end */
158 void pa_memblockq_willneed(pa_memblockq *bq);
160 /* Check whether the memblockq is completely empty, i.e. no data
161 * neither left nor right of the read pointer, and hence no buffered
162 * data for the future nor data in the backlog. */
163 pa_bool_t pa_memblockq_is_empty(pa_memblockq *bq);
165 void pa_memblockq_silence(pa_memblockq *bq);
167 /* Check whether we currently are in prebuf state */
168 pa_bool_t pa_memblockq_prebuf_active(pa_memblockq *bq);
170 unsigned pa_memblockq_get_nblocks(pa_memblockq *bq);