]>
code.delx.au - pulseaudio/blob - src/tests/memblockq-test.c
2 This file is part of PulseAudio.
4 PulseAudio is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2.1 of the License,
7 or (at your option) any later version.
9 PulseAudio is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with PulseAudio; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <pulsecore/memblockq.h>
29 #include <pulsecore/log.h>
30 #include <pulsecore/macro.h>
32 static void dump_chunk(const pa_memchunk
*chunk
) {
39 q
= pa_memblock_acquire(chunk
->memblock
);
40 for (e
= (char*) q
+ chunk
->index
, n
= 0; n
< chunk
->length
; n
++, e
++)
41 fprintf(stderr
, "%c", *e
);
42 pa_memblock_release(chunk
->memblock
);
45 static void dump(pa_memblockq
*bq
) {
50 /* First let's dump this as fixed block */
51 fprintf(stderr
, "FIXED >");
52 pa_memblockq_peek_fixed_size(bq
, 64, &out
);
54 pa_memblock_unref(out
.memblock
);
55 fprintf(stderr
, "<\n");
57 /* Then let's dump the queue manually */
58 fprintf(stderr
, "MANUAL>");
61 if (pa_memblockq_peek(bq
, &out
) < 0)
65 pa_memblock_unref(out
.memblock
);
66 pa_memblockq_drop(bq
, out
.length
);
69 fprintf(stderr
, "<\n");
72 int main(int argc
, char *argv
[]) {
77 pa_memchunk chunk1
, chunk2
, chunk3
, chunk4
;
80 .format
= PA_SAMPLE_S16LE
,
85 pa_log_set_level(PA_LOG_DEBUG
);
87 p
= pa_mempool_new(FALSE
, 0);
89 pa_assert_se(silence
.memblock
= pa_memblock_new_fixed(p
, (char*) "__", 2, 1));
91 silence
.length
= pa_memblock_get_length(silence
.memblock
);
93 pa_assert_se(bq
= pa_memblockq_new("test memblockq", 0, 200, 10, &ss
, 4, 4, 40, &silence
));
95 pa_assert_se(chunk1
.memblock
= pa_memblock_new_fixed(p
, (char*) "11", 2, 1));
99 pa_assert_se(chunk2
.memblock
= pa_memblock_new_fixed(p
, (char*) "XX22", 4, 1));
103 pa_assert_se(chunk3
.memblock
= pa_memblock_new_fixed(p
, (char*) "3333", 4, 1));
107 pa_assert_se(chunk4
.memblock
= pa_memblock_new_fixed(p
, (char*) "44444444", 8, 1));
111 ret
= pa_memblockq_push(bq
, &chunk1
);
114 ret
= pa_memblockq_push(bq
, &chunk2
);
117 ret
= pa_memblockq_push(bq
, &chunk3
);
120 ret
= pa_memblockq_push(bq
, &chunk4
);
123 pa_memblockq_seek(bq
, -6, 0, TRUE
);
124 ret
= pa_memblockq_push(bq
, &chunk3
);
127 pa_memblockq_seek(bq
, -2, 0, TRUE
);
128 ret
= pa_memblockq_push(bq
, &chunk1
);
131 pa_memblockq_seek(bq
, -10, 0, TRUE
);
132 ret
= pa_memblockq_push(bq
, &chunk4
);
135 pa_memblockq_seek(bq
, 10, 0, TRUE
);
137 ret
= pa_memblockq_push(bq
, &chunk1
);
140 pa_memblockq_seek(bq
, -6, 0, TRUE
);
141 ret
= pa_memblockq_push(bq
, &chunk2
);
145 pa_memblockq_seek(bq
, -12, 0, TRUE
);
146 ret
= pa_memblockq_push(bq
, &chunk1
);
149 pa_memblockq_seek(bq
, 20, 0, TRUE
);
152 ret
= pa_memblockq_push(bq
, &chunk3
);
154 pa_memblockq_seek(bq
, -2, 0, TRUE
);
158 ret
= pa_memblockq_push(bq
, &chunk3
);
161 pa_memblockq_seek(bq
, 30, PA_SEEK_RELATIVE
, TRUE
);
165 pa_memblockq_rewind(bq
, 52);
169 pa_memblockq_free(bq
);
170 pa_memblock_unref(silence
.memblock
);
171 pa_memblock_unref(chunk1
.memblock
);
172 pa_memblock_unref(chunk2
.memblock
);
173 pa_memblock_unref(chunk3
.memblock
);
174 pa_memblock_unref(chunk4
.memblock
);