diff options
author | Alfred E. Heggestad <aeh@db.org> | 2015-11-30 11:20:51 +0100 |
---|---|---|
committer | Alfred E. Heggestad <aeh@db.org> | 2015-11-30 11:20:51 +0100 |
commit | 02ab69889505e114941b75456b95884d2847d329 (patch) | |
tree | 9cd23ae2602806a676ace67ca921e03d7af59e90 | |
parent | 5a45ba5c979d4c606c36967b4c59fcc098888f63 (diff) | |
parent | a1f6596e855a9b93147015cbd15077f251239772 (diff) |
Merge pull request #89 from alfredh/oss_thread
Oss thread
-rw-r--r-- | modules/oss/oss.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/modules/oss/oss.c b/modules/oss/oss.c index 3d02154..a6a8015 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,21 @@ 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); + if (n <= 0) + continue; + + st->rh(st->sampv, n/2, st->arg); + } - st->rh(st->sampv, n/2, st->arg); + return NULL; } @@ -243,16 +252,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); |