diff options
author | Alfred E. Heggestad <aeh@db.org> | 2015-11-30 11:13:11 +0100 |
---|---|---|
committer | Alfred E. Heggestad <aeh@db.org> | 2015-11-30 11:13:11 +0100 |
commit | 2bcf2547e5e7423310943e6b00613a0f702d28ed (patch) | |
tree | c170035e7f48ce411206db08437d709e051f55d0 /modules | |
parent | b3009aeb15d7eb450657e741493af9409dcf968c (diff) |
oss: added thread for ausrc/recording
- fd_listen with kqueue does not work on FreeBSD 10.2
most likely because /dev/dsp is a device
Diffstat (limited to 'modules')
-rw-r--r-- | modules/oss/oss.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/modules/oss/oss.c b/modules/oss/oss.c index 3d02154..f4fc9e6 100644 --- a/modules/oss/oss.c +++ b/modules/oss/oss.c @@ -34,6 +34,8 @@ struct ausrc_st { const struct ausrc *as; /* inheritance */ + pthread_t thread; + bool run; int fd; int16_t *sampv; size_t sampc; @@ -148,7 +150,6 @@ static void auplay_destructor(void *arg) } if (-1 != st->fd) { - fd_close(st->fd); (void)close(st->fd); } @@ -160,8 +161,12 @@ static void ausrc_destructor(void *arg) { struct ausrc_st *st = arg; + if (st->run) { + st->run = false; + pthread_join(st->thread, NULL); + } + if (-1 != st->fd) { - fd_close(st->fd); (void)close(st->fd); } @@ -169,17 +174,24 @@ static void ausrc_destructor(void *arg) } -static void read_handler(int flags, void *arg) +static void *record_thread(void *arg) { struct ausrc_st *st = arg; int n; - (void)flags; - n = read(st->fd, st->sampv, st->sampc*2); - if (n <= 0) - return; + while (st->run) { + + n = read(st->fd, st->sampv, st->sampc*2); + + re_printf(" ~~ oss read: n=%d\n", n); + + if (n <= 0) + continue; + + st->rh(st->sampv, n/2, st->arg); + } - st->rh(st->sampv, n/2, st->arg); + return NULL; } @@ -243,16 +255,19 @@ static int src_alloc(struct ausrc_st **stp, const struct ausrc *as, goto out; } - err = fd_listen(st->fd, FD_READ, read_handler, st); - if (err) - goto out; - - err = oss_reset(st->fd, prm->srate, prm->ch, st->sampc, 1); + err = oss_reset(st->fd, prm->srate, prm->ch, st->sampc, 0); if (err) goto out; st->as = as; + st->run = true; + err = pthread_create(&st->thread, NULL, record_thread, st); + if (err) { + st->run = false; + goto out; + } + out: if (err) mem_deref(st); |