2004-11-21 21:31:28 +00:00
|
|
|
/***
|
2006-06-19 21:53:48 +00:00
|
|
|
This file is part of PulseAudio.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
2004-11-21 21:31:28 +00:00
|
|
|
it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
|
License, or (at your option) any later version.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
2004-11-21 21:31:28 +00:00
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Lesser General Public License for more details.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-21 21:31:28 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2006-06-19 21:53:48 +00:00
|
|
|
License along with PulseAudio; if not, write to the Free Software
|
2004-11-21 21:31:28 +00:00
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-11-17 00:05:25 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
2008-05-15 23:34:41 +00:00
|
|
|
#include <pulse/gccmacro.h>
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulsecore/core-util.h>
|
|
|
|
|
#include <pulsecore/mcalign.h>
|
2004-11-17 00:05:25 +00:00
|
|
|
|
2004-11-21 21:31:28 +00:00
|
|
|
/* A simple program for testing pa_mcalign */
|
|
|
|
|
|
2008-08-09 16:20:29 +02:00
|
|
|
int main(int argc, char *argv[]) {
|
2006-08-18 19:56:11 +00:00
|
|
|
pa_mempool *p;
|
|
|
|
|
pa_mcalign *a;
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_memchunk c;
|
2004-11-17 00:05:25 +00:00
|
|
|
|
2006-08-18 19:56:11 +00:00
|
|
|
p = pa_mempool_new(0);
|
|
|
|
|
|
|
|
|
|
a = pa_mcalign_new(11);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-17 00:05:25 +00:00
|
|
|
pa_memchunk_reset(&c);
|
|
|
|
|
|
2008-08-19 22:39:54 +02:00
|
|
|
srand((unsigned) time(NULL));
|
2004-11-17 00:05:25 +00:00
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
ssize_t r;
|
|
|
|
|
size_t l;
|
|
|
|
|
|
|
|
|
|
if (!c.memblock) {
|
2006-08-18 19:56:11 +00:00
|
|
|
c.memblock = pa_memblock_new(p, 2048);
|
2004-11-17 00:05:25 +00:00
|
|
|
c.index = c.length = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
assert(c.index < pa_memblock_get_length(c.memblock));
|
2004-11-17 00:05:25 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
l = pa_memblock_get_length(c.memblock) - c.index;
|
2004-11-17 00:05:25 +00:00
|
|
|
|
2008-08-19 22:39:54 +02:00
|
|
|
l = l <= 1 ? l : (size_t) rand() % (l-1) +1;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
p = pa_memblock_acquire(c.memblock);
|
|
|
|
|
|
|
|
|
|
if ((r = read(STDIN_FILENO, (uint8_t*) p + c.index, l)) <= 0) {
|
|
|
|
|
pa_memblock_release(c.memblock);
|
2004-11-17 00:05:25 +00:00
|
|
|
fprintf(stderr, "read() failed: %s\n", r < 0 ? strerror(errno) : "EOF");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-11-06 13:06:01 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_memblock_release(c.memblock);
|
|
|
|
|
|
2008-08-19 22:39:54 +02:00
|
|
|
c.length = (size_t) r;
|
2004-11-17 00:05:25 +00:00
|
|
|
pa_mcalign_push(a, &c);
|
2006-03-31 08:54:24 +00:00
|
|
|
fprintf(stderr, "Read %ld bytes\n", (long)r);
|
2004-11-17 00:05:25 +00:00
|
|
|
|
2008-08-19 22:39:54 +02:00
|
|
|
c.index += (size_t) r;
|
2004-11-17 00:05:25 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (c.index >= pa_memblock_get_length(c.memblock)) {
|
2004-11-17 00:05:25 +00:00
|
|
|
pa_memblock_unref(c.memblock);
|
|
|
|
|
pa_memchunk_reset(&c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_memchunk t;
|
2004-11-17 00:05:25 +00:00
|
|
|
|
|
|
|
|
if (pa_mcalign_pop(a, &t) < 0)
|
|
|
|
|
break;
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
p = pa_memblock_acquire(t.memblock);
|
|
|
|
|
pa_loop_write(STDOUT_FILENO, (uint8_t*) p + t.index, t.length, NULL);
|
|
|
|
|
pa_memblock_release(t.memblock);
|
2004-11-23 13:00:53 +00:00
|
|
|
fprintf(stderr, "Wrote %lu bytes.\n", (unsigned long) t.length);
|
2004-11-17 00:05:25 +00:00
|
|
|
|
|
|
|
|
pa_memblock_unref(t.memblock);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pa_mcalign_free(a);
|
|
|
|
|
|
|
|
|
|
if (c.memblock)
|
|
|
|
|
pa_memblock_unref(c.memblock);
|
2006-03-04 17:31:23 +00:00
|
|
|
|
2006-08-18 19:56:11 +00:00
|
|
|
pa_mempool_free(p);
|
|
|
|
|
|
2006-03-04 17:31:23 +00:00
|
|
|
return 0;
|
2004-11-17 00:05:25 +00:00
|
|
|
}
|