]> code.delx.au - pulseaudio/blob - src/polypcore/memblockq.h
Reorganised the source tree. We now have src/ with a couple of subdirs:
[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
27 #include "memblock.h"
28 #include "memchunk.h"
29
30 /* A memblockq is a queue of pa_memchunks (yepp, the name is not
31 * perfect). It is similar to the ring buffers used by most other
32 * audio software. In contrast to a ring buffer this memblockq data
33 * type doesn't need to copy any data around, it just maintains
34 * references to reference counted memory blocks. */
35
36 typedef struct pa_memblockq pa_memblockq;
37
38 /* Parameters:
39 - maxlength: maximum length of queue. If more data is pushed into the queue, data from the front is dropped
40 - length: the target length of the queue.
41 - base: a base value for all metrics. Only multiples of this value are popped from the queue
42 - prebuf: before passing the first byte out, make sure that enough bytes are in the queue
43 - minreq: pa_memblockq_missing() will only return values greater than this value
44 */
45 pa_memblockq* pa_memblockq_new(size_t maxlength,
46 size_t tlength,
47 size_t base,
48 size_t prebuf,
49 size_t minreq,
50 pa_memblock_stat *s);
51 void pa_memblockq_free(pa_memblockq*bq);
52
53 /* Push a new memory chunk into the queue. Optionally specify a value for future cancellation. */
54 void pa_memblockq_push(pa_memblockq* bq, const pa_memchunk *chunk, size_t delta);
55
56 /* Same as pa_memblockq_push(), however chunks are filtered through a mcalign object, and thus aligned to multiples of base */
57 void pa_memblockq_push_align(pa_memblockq* bq, const pa_memchunk *chunk, size_t delta);
58
59 /* Return a copy of the next memory chunk in the queue. It is not removed from the queue */
60 int pa_memblockq_peek(pa_memblockq* bq, pa_memchunk *chunk);
61
62 /* Drop the specified bytes from the queue, only valid aufter pa_memblockq_peek() */
63 void pa_memblockq_drop(pa_memblockq *bq, const pa_memchunk *chunk, size_t length);
64
65 /* Drop the specified bytes from the queue */
66 void pa_memblockq_skip(pa_memblockq *bq, size_t length);
67
68 /* Shorten the pa_memblockq to the specified length by dropping data at the end of the queue */
69 void pa_memblockq_shorten(pa_memblockq *bq, size_t length);
70
71 /* Empty the pa_memblockq */
72 void pa_memblockq_empty(pa_memblockq *bq);
73
74 /* Test if the pa_memblockq is currently readable, that is, more data than base */
75 int pa_memblockq_is_readable(pa_memblockq *bq);
76
77 /* Test if the pa_memblockq is currently writable for the specified amount of bytes */
78 int pa_memblockq_is_writable(pa_memblockq *bq, size_t length);
79
80 /* Return the length of the queue in bytes */
81 uint32_t pa_memblockq_get_length(pa_memblockq *bq);
82
83 /* Return how many bytes are missing in queue to the specified fill amount */
84 uint32_t pa_memblockq_missing(pa_memblockq *bq);
85
86 /* Returns the minimal request value */
87 uint32_t pa_memblockq_get_minreq(pa_memblockq *bq);
88
89 /* Force disabling of pre-buf even when the pre-buffer is not yet filled */
90 void pa_memblockq_prebuf_disable(pa_memblockq *bq);
91
92 /* Reenable pre-buf to the initial level */
93 void pa_memblockq_prebuf_reenable(pa_memblockq *bq);
94
95 /* Manipulate the write pointer */
96 void pa_memblockq_seek(pa_memblockq *bq, size_t delta);
97
98 /* Flush the queue */
99 void pa_memblockq_flush(pa_memblockq *bq);
100
101 /* Get Target length */
102 uint32_t pa_memblockq_get_tlength(pa_memblockq *bq);
103
104 #endif