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