Add copyright notices to all relevant files. (based on svn log)
[profile/ivi/pulseaudio.git] / src / pulsecore / memblockq.h
1 #ifndef foomemblockqhfoo
2 #define foomemblockqhfoo
3
4 /* $Id$ */
5
6 /***
7   This file is part of PulseAudio.
8
9   Copyright 2004-2006 Lennart Poettering
10
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.
15
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.
20
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
24   USA.
25 ***/
26
27 #include <sys/types.h>
28 #include <inttypes.h>
29
30 #include <pulsecore/memblock.h>
31 #include <pulsecore/memchunk.h>
32 #include <pulse/def.h>
33
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. */
39
40 typedef struct pa_memblockq pa_memblockq;
41
42
43 /* Parameters:
44
45    - idx:       start value for both read and write index
46
47    - maxlength: maximum length of queue. If more data is pushed into
48                 the queue, the operation will fail. Must not be 0.
49
50    - tlength:   the target length of the queue. Pass 0 for the default.
51
52    - base:      a base value for all metrics. Only multiples of this value
53                 are popped from the queue or should be pushed into
54                 it. Must not be 0.
55
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.
61
62    - minreq:    pa_memblockq_missing() will only return values greater
63                 than this value. Pass 0 for the default.
64
65    - silence:   return this memblock whzen reading unitialized data
66 */
67 pa_memblockq* pa_memblockq_new(
68         int64_t idx,
69         size_t maxlength,
70         size_t tlength,
71         size_t base,
72         size_t prebuf,
73         size_t minreq,
74         pa_memblock *silence);
75
76 void pa_memblockq_free(pa_memblockq*bq);
77
78 /* Push a new memory chunk into the queue.  */
79 int pa_memblockq_push(pa_memblockq* bq, const pa_memchunk *chunk);
80
81 /* Push a new memory chunk into the queue, but filter it through a
82  * pa_mcalign object. Don't mix this with pa_memblockq_seek() unless
83  * you know what you do. */
84 int pa_memblockq_push_align(pa_memblockq* bq, const pa_memchunk *chunk);
85
86 /* Return a copy of the next memory chunk in the queue. It is not removed from the queue */
87 int pa_memblockq_peek(pa_memblockq* bq, pa_memchunk *chunk);
88
89 /* Drop the specified bytes from the queue, but only if the first
90  * chunk in the queue matches the one passed here. If NULL is passed,
91  * this check isn't done. */
92 void pa_memblockq_drop(pa_memblockq *bq, const pa_memchunk *chunk, size_t length);
93
94 /* Test if the pa_memblockq is currently readable, that is, more data than base */
95 int pa_memblockq_is_readable(pa_memblockq *bq);
96
97 /* Test if the pa_memblockq is currently writable for the specified amount of bytes */
98 int pa_memblockq_is_writable(pa_memblockq *bq, size_t length);
99
100 /* Return the length of the queue in bytes */
101 size_t pa_memblockq_get_length(pa_memblockq *bq);
102
103 /* Return how many bytes are missing in queue to the specified fill amount */
104 size_t pa_memblockq_missing(pa_memblockq *bq);
105
106 /* Returns the minimal request value */
107 size_t pa_memblockq_get_minreq(pa_memblockq *bq);
108
109 /* Manipulate the write pointer */
110 void pa_memblockq_seek(pa_memblockq *bq, int64_t offset, pa_seek_mode_t seek);
111
112 /* Set the queue to silence, set write index to read index */
113 void pa_memblockq_flush(pa_memblockq *bq);
114
115 /* Get Target length */
116 size_t pa_memblockq_get_tlength(pa_memblockq *bq);
117
118 /* Return the current read index */
119 int64_t pa_memblockq_get_read_index(pa_memblockq *bq);
120
121 /* Return the current write index */
122 int64_t pa_memblockq_get_write_index(pa_memblockq *bq);
123
124 /* Shorten the pa_memblockq to the specified length by dropping data
125  * at the read end of the queue. The read index is increased until the
126  * queue has the specified length */
127 void pa_memblockq_shorten(pa_memblockq *bq, size_t length);
128
129 /* Ignore prebuf for now */
130 void pa_memblockq_prebuf_disable(pa_memblockq *bq);
131
132 /* Force prebuf */
133 void pa_memblockq_prebuf_force(pa_memblockq *bq);
134
135 /* Return the maximum length of the queue in bytes */
136 size_t pa_memblockq_get_maxlength(pa_memblockq *bq);
137
138 /* Return the prebuffer length in bytes */
139 size_t pa_memblockq_get_prebuf(pa_memblockq *bq);
140
141 #endif