merge 'lennart' branch back into trunk.

git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1971 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2007-10-28 19:13:50 +00:00
parent 6687dd0131
commit a67c21f093
294 changed files with 79057 additions and 11614 deletions

110
src/tests/asyncmsgq-test.c Normal file
View file

@ -0,0 +1,110 @@
/* $Id$ */
/***
This file is part of PulseAudio.
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <pulse/util.h>
#include <pulse/xmalloc.h>
#include <pulsecore/asyncmsgq.h>
#include <pulsecore/thread.h>
#include <pulsecore/log.h>
#include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
enum {
OPERATION_A,
OPERATION_B,
OPERATION_C,
QUIT
};
static void the_thread(void *_q) {
pa_asyncmsgq *q = _q;
int quit = 0;
do {
int code = 0;
pa_assert_se(pa_asyncmsgq_get(q, NULL, &code, NULL, NULL, NULL, 1) == 0);
switch (code) {
case OPERATION_A:
printf("Operation A\n");
break;
case OPERATION_B:
printf("Operation B\n");
break;
case OPERATION_C:
printf("Operation C\n");
break;
case QUIT:
printf("quit\n");
quit = 1;
break;
}
pa_asyncmsgq_done(q, 0);
} while (!quit);
}
int main(int argc, char *argv[]) {
pa_asyncmsgq *q;
pa_thread *t;
pa_assert_se(q = pa_asyncmsgq_new(0));
pa_assert_se(t = pa_thread_new(the_thread, q));
printf("Operation A post\n");
pa_asyncmsgq_post(q, NULL, OPERATION_A, NULL, 0, NULL, NULL);
pa_thread_yield();
printf("Operation B post\n");
pa_asyncmsgq_post(q, NULL, OPERATION_B, NULL, 0, NULL, NULL);
pa_thread_yield();
printf("Operation C send\n");
pa_asyncmsgq_send(q, NULL, OPERATION_C, NULL, 0, NULL);
pa_thread_yield();
printf("Quit post\n");
pa_asyncmsgq_post(q, NULL, QUIT, NULL, 0, NULL, NULL);
pa_thread_free(t);
pa_asyncmsgq_unref(q);
return 0;
}

87
src/tests/asyncq-test.c Normal file
View file

@ -0,0 +1,87 @@
/* $Id$ */
/***
This file is part of PulseAudio.
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <pulse/util.h>
#include <pulse/xmalloc.h>
#include <pulsecore/asyncq.h>
#include <pulsecore/thread.h>
#include <pulsecore/log.h>
#include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
static void producer(void *_q) {
pa_asyncq *q = _q;
int i;
for (i = 0; i < 1000; i++) {
printf("pushing %i\n", i);
pa_asyncq_push(q, PA_UINT_TO_PTR(i+1), 1);
}
pa_asyncq_push(q, PA_UINT_TO_PTR(-1), 1);
printf("pushed end\n");
}
static void consumer(void *_q) {
pa_asyncq *q = _q;
void *p;
int i;
sleep(1);
for (i = 0;; i++) {
p = pa_asyncq_pop(q, 1);
if (p == PA_UINT_TO_PTR(-1))
break;
pa_assert(p == PA_UINT_TO_PTR(i+1));
printf("popped %i\n", i);
}
printf("popped end\n");
}
int main(int argc, char *argv[]) {
pa_asyncq *q;
pa_thread *t1, *t2;
pa_assert_se(q = pa_asyncq_new(0));
pa_assert_se(t1 = pa_thread_new(producer, q));
pa_assert_se(t2 = pa_thread_new(consumer, q));
pa_thread_free(t1);
pa_thread_free(t2);
pa_asyncq_free(q, NULL);
return 0;
}

View file

@ -1,5 +1,9 @@
/* $Id$ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <pulsecore/hook-list.h>
#include <pulsecore/log.h>

View file

@ -137,7 +137,7 @@ int main(int argc, char *argv[]) {
pa_gettimeofday(&now);
rtc = pa_timeval_diff(&now, &start);
printf("%i\t%llu\t%llu\t%llu\t%llu\t%u\n", k, rtc, t, rtc-old_rtc, t-old_t, changed);
printf("%i\t%llu\t%llu\t%llu\t%llu\t%u\n", k, (unsigned long long) rtc, (unsigned long long) t, (unsigned long long) (rtc-old_rtc), (unsigned long long) (t-old_t), changed);
old_t = t;
old_rtc = rtc;
}

View file

@ -59,24 +59,29 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
c.index = c.length = 0;
}
assert(c.index < c.memblock->length);
assert(c.index < pa_memblock_get_length(c.memblock));
l = c.memblock->length - c.index;
l = pa_memblock_get_length(c.memblock) - c.index;
l = l <= 1 ? l : rand() % (l-1) +1 ;
if ((r = read(STDIN_FILENO, (uint8_t*) c.memblock->data + c.index, l)) <= 0) {
p = pa_memblock_acquire(c.memblock);
if ((r = read(STDIN_FILENO, (uint8_t*) p + c.index, l)) <= 0) {
pa_memblock_release(c.memblock);
fprintf(stderr, "read() failed: %s\n", r < 0 ? strerror(errno) : "EOF");
break;
}
pa_memblock_release(c.memblock);
c.length = r;
pa_mcalign_push(a, &c);
fprintf(stderr, "Read %ld bytes\n", (long)r);
c.index += r;
if (c.index >= c.memblock->length) {
if (c.index >= pa_memblock_get_length(c.memblock)) {
pa_memblock_unref(c.memblock);
pa_memchunk_reset(&c);
}
@ -87,7 +92,9 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
if (pa_mcalign_pop(a, &t) < 0)
break;
pa_loop_write(STDOUT_FILENO, (uint8_t*) t.memblock->data + t.index, t.length, NULL);
p = pa_memblock_acquire(t.memblock);
pa_loop_write(STDOUT_FILENO, (uint8_t*) p + t.index, t.length, NULL);
pa_memblock_release(t.memblock);
fprintf(stderr, "Wrote %lu bytes.\n", (unsigned long) t.length);
pa_memblock_unref(t.memblock);

View file

@ -23,11 +23,11 @@
#include <config.h>
#endif
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <pulsecore/memblock.h>
#include <pulsecore/macro.h>
#include <pulse/xmalloc.h>
static void release_cb(pa_memimport *i, uint32_t block_id, void *userdata) {
@ -76,6 +76,7 @@ int main(int argc, char *argv[]) {
pa_memblock* blocks[5];
uint32_t id, shm_id;
size_t offset, size;
char *x;
const char txt[] = "This is a test!";
@ -87,13 +88,20 @@ int main(int argc, char *argv[]) {
pa_mempool_get_shm_id(pool_b, &id_b);
pa_mempool_get_shm_id(pool_c, &id_c);
assert(pool_a && pool_b && pool_c);
pa_assert(pool_a && pool_b && pool_c);
blocks[0] = pa_memblock_new_fixed(pool_a, (void*) txt, sizeof(txt), 1);
blocks[1] = pa_memblock_new(pool_a, sizeof(txt));
snprintf(blocks[1]->data, blocks[1]->length, "%s", txt);
x = pa_memblock_acquire(blocks[1]);
snprintf(x, pa_memblock_get_length(blocks[1]), "%s", txt);
pa_memblock_release(blocks[1]);
blocks[2] = pa_memblock_new_pool(pool_a, sizeof(txt));
snprintf(blocks[2]->data, blocks[2]->length, "%s", txt);
x = pa_memblock_acquire(blocks[2]);
snprintf(x, pa_memblock_get_length(blocks[2]), "%s", txt);
pa_memblock_release(blocks[2]);
blocks[3] = pa_memblock_new_malloced(pool_a, pa_xstrdup(txt), sizeof(txt));
blocks[4] = NULL;
@ -101,43 +109,47 @@ int main(int argc, char *argv[]) {
printf("Memory block %u\n", i);
mb_a = blocks[i];
assert(mb_a);
pa_assert(mb_a);
export_a = pa_memexport_new(pool_a, revoke_cb, (void*) "A");
export_b = pa_memexport_new(pool_b, revoke_cb, (void*) "B");
assert(export_a && export_b);
pa_assert(export_a && export_b);
import_b = pa_memimport_new(pool_b, release_cb, (void*) "B");
import_c = pa_memimport_new(pool_c, release_cb, (void*) "C");
assert(import_b && import_c);
pa_assert(import_b && import_c);
r = pa_memexport_put(export_a, mb_a, &id, &shm_id, &offset, &size);
assert(r >= 0);
assert(shm_id == id_a);
pa_assert(r >= 0);
pa_assert(shm_id == id_a);
printf("A: Memory block exported as %u\n", id);
mb_b = pa_memimport_get(import_b, id, shm_id, offset, size);
assert(mb_b);
pa_assert(mb_b);
r = pa_memexport_put(export_b, mb_b, &id, &shm_id, &offset, &size);
assert(r >= 0);
assert(shm_id == id_a || shm_id == id_b);
pa_assert(r >= 0);
pa_assert(shm_id == id_a || shm_id == id_b);
pa_memblock_unref(mb_b);
printf("B: Memory block exported as %u\n", id);
mb_c = pa_memimport_get(import_c, id, shm_id, offset, size);
assert(mb_c);
printf("1 data=%s\n", (char*) mb_c->data);
pa_assert(mb_c);
x = pa_memblock_acquire(mb_c);
printf("1 data=%s\n", x);
pa_memblock_release(mb_c);
print_stats(pool_a, "A");
print_stats(pool_b, "B");
print_stats(pool_c, "C");
pa_memexport_free(export_b);
printf("2 data=%s\n", (char*) mb_c->data);
x = pa_memblock_acquire(mb_c);
printf("2 data=%s\n", x);
pa_memblock_release(mb_c);
pa_memblock_unref(mb_c);
pa_memimport_free(import_b);

View file

@ -26,6 +26,7 @@
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <signal.h>
#include <pulsecore/memblockq.h>
#include <pulsecore/log.h>
@ -48,22 +49,22 @@ int main(int argc, char *argv[]) {
bq = pa_memblockq_new(0, 40, 10, 2, 4, 4, silence);
assert(bq);
chunk1.memblock = pa_memblock_new_fixed(p, (char*) "AA", 2, 1);
chunk1.memblock = pa_memblock_new_fixed(p, (char*) "11", 2, 1);
chunk1.index = 0;
chunk1.length = 2;
assert(chunk1.memblock);
chunk2.memblock = pa_memblock_new_fixed(p, (char*) "TTBB", 4, 1);
chunk2.memblock = pa_memblock_new_fixed(p, (char*) "XX22", 4, 1);
chunk2.index = 2;
chunk2.length = 2;
assert(chunk2.memblock);
chunk3.memblock = pa_memblock_new_fixed(p, (char*) "ZZZZ", 4, 1);
chunk3.memblock = pa_memblock_new_fixed(p, (char*) "3333", 4, 1);
chunk3.index = 0;
chunk3.length = 4;
assert(chunk3.memblock);
chunk4.memblock = pa_memblock_new_fixed(p, (char*) "KKKKKKKK", 8, 1);
chunk4.memblock = pa_memblock_new_fixed(p, (char*) "44444444", 8, 1);
chunk4.index = 0;
chunk4.length = 8;
assert(chunk4.memblock);
@ -115,13 +116,12 @@ int main(int argc, char *argv[]) {
chunk3.index += 2;
chunk3.length -= 2;
ret = pa_memblockq_push(bq, &chunk3);
assert(ret == 0);
printf(">");
pa_memblockq_shorten(bq, pa_memblockq_get_length(bq)-2);
pa_memblockq_shorten(bq, 6);
printf(">");
for (;;) {
pa_memchunk out;
@ -131,11 +131,13 @@ int main(int argc, char *argv[]) {
if (pa_memblockq_peek(bq, &out) < 0)
break;
for (e = (char*) out.memblock->data + out.index, n = 0; n < out.length; n++)
p = pa_memblock_acquire(out.memblock);
for (e = (char*) p + out.index, n = 0; n < out.length; n++)
printf("%c", *e);
pa_memblock_release(out.memblock);
pa_memblock_unref(out.memblock);
pa_memblockq_drop(bq, &out, out.length);
pa_memblockq_drop(bq, out.length);
}
printf("<\n");

69
src/tests/queue-test.c Normal file
View file

@ -0,0 +1,69 @@
/* $Id$ */
/***
This file is part of PulseAudio.
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <pulse/util.h>
#include <pulse/xmalloc.h>
#include <pulsecore/queue.h>
#include <pulsecore/log.h>
#include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
int main(int argc, char *argv[]) {
pa_queue *q;
pa_assert_se(q = pa_queue_new());
pa_assert(pa_queue_is_empty(q));
pa_queue_push(q, (void*) "eins");
pa_log("%s\n", (char*) pa_queue_pop(q));
pa_assert(pa_queue_is_empty(q));
pa_queue_push(q, (void*) "zwei");
pa_queue_push(q, (void*) "drei");
pa_queue_push(q, (void*) "vier");
pa_log("%s\n", (char*) pa_queue_pop(q));
pa_log("%s\n", (char*) pa_queue_pop(q));
pa_queue_push(q, (void*) "fuenf");
pa_log("%s\n", (char*) pa_queue_pop(q));
pa_log("%s\n", (char*) pa_queue_pop(q));
pa_assert(pa_queue_is_empty(q));
pa_queue_push(q, (void*) "sechs");
pa_queue_push(q, (void*) "sieben");
pa_queue_free(q, NULL, NULL);
return 0;
}

227
src/tests/resampler-test.c Normal file
View file

@ -0,0 +1,227 @@
/* $Id$ */
/***
This file is part of PulseAudio.
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <pulse/sample.h>
#include <pulse/volume.h>
#include <pulsecore/resampler.h>
#include <pulsecore/macro.h>
#include <pulsecore/endianmacros.h>
#include <pulsecore/memblock.h>
#include <pulsecore/sample-util.h>
#include <liboil/liboil.h>
static float swap_float(float a) {
uint32_t *b = (uint32_t*) &a;
*b = PA_UINT32_SWAP(*b);
return a;
}
static void dump_block(const pa_sample_spec *ss, const pa_memchunk *chunk) {
void *d;
unsigned i;
d = pa_memblock_acquire(chunk->memblock);
switch (ss->format) {
case PA_SAMPLE_U8:
case PA_SAMPLE_ULAW:
case PA_SAMPLE_ALAW: {
uint8_t *u = d;
for (i = 0; i < chunk->length / pa_frame_size(ss); i++)
printf("0x%02x ", *(u++));
break;
}
case PA_SAMPLE_S16NE:
case PA_SAMPLE_S16RE: {
uint16_t *u = d;
for (i = 0; i < chunk->length / pa_frame_size(ss); i++)
printf("0x%04x ", *(u++));
break;
}
case PA_SAMPLE_FLOAT32NE:
case PA_SAMPLE_FLOAT32RE: {
float *u = d;
for (i = 0; i < chunk->length / pa_frame_size(ss); i++) {
printf("%1.3g ", ss->format == PA_SAMPLE_FLOAT32NE ? *u : swap_float(*u));
u++;
}
break;
}
default:
pa_assert_not_reached();
}
printf("\n");
pa_memblock_release(chunk->memblock);
}
static pa_memblock* generate_block(pa_mempool *pool, const pa_sample_spec *ss) {
pa_memblock *r;
void *d;
unsigned i;
pa_assert_se(r = pa_memblock_new(pool, pa_frame_size(ss) * 10));
d = pa_memblock_acquire(r);
switch (ss->format) {
case PA_SAMPLE_U8:
case PA_SAMPLE_ULAW:
case PA_SAMPLE_ALAW: {
uint8_t *u = d;
u[0] = 0x00;
u[1] = 0xFF;
u[2] = 0x7F;
u[3] = 0x80;
u[4] = 0x9f;
u[5] = 0x3f;
u[6] = 0x1;
u[7] = 0xF0;
u[8] = 0x20;
u[9] = 0x21;
break;
}
case PA_SAMPLE_S16NE:
case PA_SAMPLE_S16RE: {
uint16_t *u = d;
u[0] = 0x0000;
u[1] = 0xFFFF;
u[2] = 0x7FFF;
u[3] = 0x8000;
u[4] = 0x9fff;
u[5] = 0x3fff;
u[6] = 0x1;
u[7] = 0xF000;
u[8] = 0x20;
u[9] = 0x21;
break;
}
case PA_SAMPLE_FLOAT32NE:
case PA_SAMPLE_FLOAT32RE: {
float *u = d;
u[0] = 0.0;
u[1] = -1.0;
u[2] = 1.0;
u[3] = 4711;
u[4] = 0.222;
u[5] = 0.33;
u[6] = -.3;
u[7] = 99;
u[8] = -0.555;
u[9] = -.123;
if (ss->format == PA_SAMPLE_FLOAT32RE)
for (i = 0; i < 10; i++)
u[i] = swap_float(u[i]);
break;
}
default:
pa_assert_not_reached();
}
pa_memblock_release(r);
return r;
}
int main(int argc, char *argv[]) {
pa_mempool *pool;
pa_sample_spec a, b;
pa_cvolume v;
oil_init();
pa_log_set_maximal_level(PA_LOG_DEBUG);
pa_assert_se(pool = pa_mempool_new(FALSE));
a.channels = b.channels = 1;
a.rate = b.rate = 44100;
v.channels = a.channels;
v.values[0] = pa_sw_volume_from_linear(0.5);
for (a.format = 0; a.format < PA_SAMPLE_MAX; a.format ++) {
for (b.format = 0; b.format < PA_SAMPLE_MAX; b.format ++) {
pa_resampler *forth, *back;
pa_memchunk i, j, k;
printf("=== %s -> %s -> %s -> /2\n",
pa_sample_format_to_string(a.format),
pa_sample_format_to_string(b.format),
pa_sample_format_to_string(a.format));
pa_assert_se(forth = pa_resampler_new(pool, &a, NULL, &b, NULL, PA_RESAMPLER_AUTO, FALSE));
pa_assert_se(back = pa_resampler_new(pool, &b, NULL, &a, NULL, PA_RESAMPLER_AUTO, FALSE));
i.memblock = generate_block(pool, &a);
i.length = pa_memblock_get_length(i.memblock);
i.index = 0;
pa_resampler_run(forth, &i, &j);
pa_resampler_run(back, &j, &k);
dump_block(&a, &i);
dump_block(&b, &j);
dump_block(&a, &k);
pa_memblock_unref(j.memblock);
pa_memblock_unref(k.memblock);
pa_volume_memchunk(&i, &a, &v);
dump_block(&a, &i);
pa_memblock_unref(i.memblock);
pa_resampler_free(forth);
pa_resampler_free(back);
}
}
pa_mempool_free(pool);
return 0;
}

91
src/tests/rtpoll-test.c Normal file
View file

@ -0,0 +1,91 @@
/* $Id: thread-test.c 1621 2007-08-10 22:00:22Z lennart $ */
/***
This file is part of PulseAudio.
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <signal.h>
#include <poll.h>
#include <pulsecore/log.h>
#include <pulsecore/rtpoll.h>
#include <pulsecore/rtsig.h>
static int before(pa_rtpoll_item *i) {
pa_log("before");
return 0;
}
static void after(pa_rtpoll_item *i) {
pa_log("after");
}
static int worker(pa_rtpoll_item *w) {
pa_log("worker");
return 0;
}
int main(int argc, char *argv[]) {
pa_rtpoll *p;
pa_rtpoll_item *i, *w;
struct pollfd *pollfd;
pa_rtsig_configure(SIGRTMIN+10, SIGRTMAX);
p = pa_rtpoll_new();
i = pa_rtpoll_item_new(p, PA_RTPOLL_EARLY, 1);
pa_rtpoll_item_set_before_callback(i, before);
pa_rtpoll_item_set_after_callback(i, after);
pollfd = pa_rtpoll_item_get_pollfd(i, NULL);
pollfd->fd = 0;
pollfd->events = POLLIN;
w = pa_rtpoll_item_new(p, PA_RTPOLL_NORMAL, 0);
pa_rtpoll_item_set_before_callback(w, worker);
pa_rtpoll_install(p);
pa_rtpoll_set_timer_periodic(p, 10000000); /* 10 s */
pa_rtpoll_run(p, 1);
pa_rtpoll_item_free(i);
i = pa_rtpoll_item_new(p, PA_RTPOLL_EARLY, 1);
pa_rtpoll_item_set_before_callback(i, before);
pa_rtpoll_item_set_after_callback(i, after);
pollfd = pa_rtpoll_item_get_pollfd(i, NULL);
pollfd->fd = 0;
pollfd->events = POLLIN;
pa_rtpoll_run(p, 1);
pa_rtpoll_item_free(i);
pa_rtpoll_item_free(w);
pa_rtpoll_free(p);
return 0;
}

39
src/tests/sig2str-test.c Normal file
View file

@ -0,0 +1,39 @@
/* $Id$ */
/***
This file is part of PulseAudio.
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <signal.h>
#include <stdio.h>
#include <pulsecore/macro.h>
#include <pulsecore/core-util.h>
int main(int argc, char *argv[]) {
int sig;
for (sig = -1; sig <= NSIG; sig++)
printf("%i = %s\n", sig, pa_sig2str(sig));
return 0;
}

80
src/tests/smoother-test.c Normal file
View file

@ -0,0 +1,80 @@
/* $Id$ */
/***
This file is part of PulseAudio.
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <pulsecore/time-smoother.h>
#include <pulse/timeval.h>
int main(int argc, char*argv[]) {
pa_usec_t x;
unsigned u = 0;
pa_smoother *s;
int m;
/* unsigned msec[] = { */
/* 200, 200, */
/* 300, 320, */
/* 400, 400, */
/* 500, 480, */
/* 0, 0 */
/* }; */
int msec[200];
srand(0);
for (m = 0, u = 0; u < PA_ELEMENTSOF(msec)-2; u+= 2) {
msec[u] = m+1;
msec[u+1] = m + rand() % 2000 - 1000;
m += rand() % 100;
if (msec[u+1] < 0)
msec[u+1] = 0;
}
msec[PA_ELEMENTSOF(msec)-2] = 0;
msec[PA_ELEMENTSOF(msec)-1] = 0;
s = pa_smoother_new(1000*PA_USEC_PER_MSEC, 2000*PA_USEC_PER_MSEC, TRUE);
for (x = 0, u = 0; x < PA_USEC_PER_SEC * 10; x += PA_USEC_PER_MSEC) {
while (msec[u] > 0 && (pa_usec_t) msec[u]*PA_USEC_PER_MSEC < x) {
pa_smoother_put(s, msec[u]*PA_USEC_PER_MSEC, msec[u+1]*PA_USEC_PER_MSEC);
printf("%i\t\t%i\n", msec[u], msec[u+1]);
u += 2;
}
printf("%llu\t%llu\n", x/PA_USEC_PER_MSEC, pa_smoother_get(s, x)/PA_USEC_PER_MSEC);
}
pa_smoother_free(s);
return 0;
}

View file

@ -23,18 +23,19 @@
#include <config.h>
#endif
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <pulse/timeval.h>
#include <pulse/util.h>
#include <pulsecore/gccmacro.h>
#include <pulse/thread-mainloop.h>
#include <pulsecore/gccmacro.h>
#include <pulsecore/macro.h>
static void tcb(pa_mainloop_api*a, pa_time_event *e, const struct timeval *tv, void *userdata) {
pa_assert_se(pa_threaded_mainloop_in_thread(userdata));
fprintf(stderr, "TIME EVENT START\n");
pa_threaded_mainloop_signal(userdata, 1);
fprintf(stderr, "TIME EVENT END\n");
@ -45,15 +46,15 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
pa_threaded_mainloop *m;
struct timeval tv;
m = pa_threaded_mainloop_new();
assert(m);
a = pa_threaded_mainloop_get_api(m);
assert(a);
pa_assert_se(m = pa_threaded_mainloop_new());
pa_assert_se(a = pa_threaded_mainloop_get_api(m));
pa_threaded_mainloop_start(m);
pa_threaded_mainloop_lock(m);
pa_assert_se(!pa_threaded_mainloop_in_thread(m));
pa_gettimeofday(&tv);
tv.tv_sec += 5;
a->time_new(a, &tv, tcb, m);

View file

@ -42,7 +42,7 @@ static void once_func(void) {
pa_log("once!");
}
static pa_once_t once = PA_ONCE_INIT;
static pa_once once = PA_ONCE_INIT;
static void thread_func(void *data) {
pa_tls_set(tls, data);
@ -72,7 +72,7 @@ static void thread_func(void *data) {
pa_mutex_unlock(mutex);
pa_once(&once, once_func);
pa_run_once(&once, once_func);
pa_cond_signal(cond2, 0);
@ -98,7 +98,7 @@ int main(int argc, char *argv[]) {
assert(pa_thread_is_running(pa_thread_self()));
mutex = pa_mutex_new(0);
mutex = pa_mutex_new(FALSE, FALSE);
cond1 = pa_cond_new();
cond2 = pa_cond_new();
tls = pa_tls_new(pa_xfree);