31
29
#include <pulsecore/memblockq.h>
32
30
#include <pulsecore/log.h>
32
static void dump(pa_memblockq *bq) {
41
if (pa_memblockq_peek(bq, &out) < 0)
44
q = pa_memblock_acquire(out.memblock);
45
for (e = (char*) q + out.index, n = 0; n < out.length; n++)
47
pa_memblock_release(out.memblock);
49
pa_memblock_unref(out.memblock);
50
pa_memblockq_drop(bq, out.length);
34
56
int main(int argc, char *argv[]) {
39
61
pa_memchunk chunk1, chunk2, chunk3, chunk4;
42
64
pa_log_set_maximal_level(PA_LOG_DEBUG);
44
p = pa_mempool_new(0);
46
silence = pa_memblock_new_fixed(p, (char*) "__", 2, 1);
49
bq = pa_memblockq_new(0, 40, 10, 2, 4, 4, silence);
66
p = pa_mempool_new(FALSE, 0);
68
silence.memblock = pa_memblock_new_fixed(p, (char*) "__", 2, 1);
69
assert(silence.memblock);
71
silence.length = pa_memblock_get_length(silence.memblock);
73
bq = pa_memblockq_new(0, 40, 10, 2, 4, 4, 40, &silence);
52
76
chunk1.memblock = pa_memblock_new_fixed(p, (char*) "11", 2, 1);
72
96
ret = pa_memblockq_push(bq, &chunk1);
75
ret = pa_memblockq_push(bq, &chunk1);
78
ret = pa_memblockq_push(bq, &chunk2);
81
ret = pa_memblockq_push(bq, &chunk2);
99
ret = pa_memblockq_push(bq, &chunk2);
102
ret = pa_memblockq_push(bq, &chunk3);
105
ret = pa_memblockq_push(bq, &chunk4);
84
108
pa_memblockq_seek(bq, -6, 0);
88
112
pa_memblockq_seek(bq, -2, 0);
89
ret = pa_memblockq_push(bq, &chunk3);
113
ret = pa_memblockq_push(bq, &chunk1);
92
116
pa_memblockq_seek(bq, -10, 0);
119
143
ret = pa_memblockq_push(bq, &chunk3);
120
144
assert(ret == 0);
122
pa_memblockq_shorten(bq, pa_memblockq_get_length(bq)-2);
131
if (pa_memblockq_peek(bq, &out) < 0)
134
p = pa_memblock_acquire(out.memblock);
135
for (e = (char*) p + out.index, n = 0; n < out.length; n++)
137
pa_memblock_release(out.memblock);
139
pa_memblock_unref(out.memblock);
140
pa_memblockq_drop(bq, out.length);
146
pa_memblockq_seek(bq, 30, PA_SEEK_RELATIVE);
150
pa_memblockq_rewind(bq, 52);
145
154
pa_memblockq_free(bq);
146
pa_memblock_unref(silence);
155
pa_memblock_unref(silence.memblock);
147
156
pa_memblock_unref(chunk1.memblock);
148
157
pa_memblock_unref(chunk2.memblock);
149
158
pa_memblock_unref(chunk3.memblock);
150
159
pa_memblock_unref(chunk4.memblock);