diff options
Diffstat (limited to 'modules/opensles')
-rw-r--r-- | modules/opensles/player.c | 16 | ||||
-rw-r--r-- | modules/opensles/recorder.c | 20 |
2 files changed, 29 insertions, 7 deletions
diff --git a/modules/opensles/player.c b/modules/opensles/player.c index a317e5d..b9c9b68 100644 --- a/modules/opensles/player.c +++ b/modules/opensles/player.c @@ -17,7 +17,8 @@ struct auplay_st { struct auplay *ap; /* inheritance */ - int16_t buf[160 * 2]; + int16_t *sampv; + size_t sampc; auplay_write_h *wh; void *arg; @@ -38,6 +39,7 @@ static void auplay_destructor(void *arg) if (st->outputMixObject != NULL) (*st->outputMixObject)->Destroy(st->outputMixObject); + mem_deref(st->sampv); mem_deref(st->ap); } @@ -46,9 +48,9 @@ static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context) { struct auplay_st *st = context; - st->wh((void *)st->buf, sizeof(st->buf), st->arg); + st->wh(st->sampv, st->sampc, st->arg); - (*st->BufferQueue)->Enqueue(bq, st->buf, sizeof(st->buf)); + (*st->BufferQueue)->Enqueue(bq, st->sampv, st->sampc * 2); } @@ -151,6 +153,14 @@ int opensles_player_alloc(struct auplay_st **stp, struct auplay *ap, st->wh = wh; st->arg = arg; + st->sampc = prm->srate * prm->ch * prm->ptime / 1000; + + st->sampv = mem_alloc(2 * st->sampc, NULL); + if (!st->sampv) { + err = ENOMEM; + goto out; + } + err = createOutput(st); if (err) goto out; diff --git a/modules/opensles/recorder.c b/modules/opensles/recorder.c index 6301451..4e1e6c7 100644 --- a/modules/opensles/recorder.c +++ b/modules/opensles/recorder.c @@ -18,7 +18,9 @@ struct ausrc_st { struct ausrc *as; /* inheritance */ - int16_t buf[160]; + int16_t *sampv; + size_t sampc; + uint32_t ptime; pthread_t thread; bool run; ausrc_read_h *rh; @@ -42,6 +44,7 @@ static void ausrc_destructor(void *arg) if (st->recObject != NULL) (*st->recObject)->Destroy(st->recObject); + mem_deref(st->sampv); mem_deref(st->as); } @@ -68,12 +71,13 @@ static void *record_thread(void *arg) #endif r = (*st->recBufferQueue)->Enqueue(st->recBufferQueue, - st->buf, sizeof(st->buf)); + st->sampv, + st->sampc * 2); if (r != SL_RESULT_SUCCESS) { DEBUG_WARNING("Enqueue: r = %d\n", r); } - ts += 20; + ts += st->ptime; } return NULL; @@ -85,7 +89,7 @@ static void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void *context) struct ausrc_st *st = context; (void)bq; - st->rh((void *)st->buf, sizeof(st->buf), st->arg); + st->rh(st->sampv, st->sampc, st->arg); } @@ -192,6 +196,14 @@ int opensles_recorder_alloc(struct ausrc_st **stp, struct ausrc *as, st->as = mem_ref(as); st->rh = rh; st->arg = arg; + st->ptime = prm->ptime; + st->sampc = prm->srate * prm->ch * prm->ptime / 1000; + + st->sampv = mem_alloc(2 * st->sampc, NULL); + if (!st->sampv) { + err = ENOMEM; + goto out; + } err = createAudioRecorder(st, prm); if (err) { |