diff options
Diffstat (limited to 'audio/out/ao_opensles.c')
-rw-r--r-- | audio/out/ao_opensles.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/audio/out/ao_opensles.c b/audio/out/ao_opensles.c index 482a85afea..ddcff1904a 100644 --- a/audio/out/ao_opensles.c +++ b/audio/out/ao_opensles.c @@ -23,13 +23,12 @@ #include "common/msg.h" #include "audio/format.h" #include "options/m_option.h" +#include "osdep/threads.h" #include "osdep/timer.h" #include <SLES/OpenSLES.h> #include <SLES/OpenSLES_Android.h> -#include <pthread.h> - struct priv { SLObjectItf sl, output_mix, player; SLBufferQueueItf buffer_queue; @@ -37,7 +36,7 @@ struct priv { SLPlayItf play; void *buf; int bytes_per_enqueue; - pthread_mutex_t buffer_lock; + mp_mutex buffer_lock; double audio_latency; int frames_per_enqueue; @@ -62,7 +61,7 @@ static void uninit(struct ao *ao) p->engine = NULL; p->play = NULL; - pthread_mutex_destroy(&p->buffer_lock); + mp_mutex_destroy(&p->buffer_lock); free(p->buf); p->buf = NULL; @@ -77,18 +76,18 @@ static void buffer_callback(SLBufferQueueItf buffer_queue, void *context) SLresult res; double delay; - pthread_mutex_lock(&p->buffer_lock); + mp_mutex_lock(&p->buffer_lock); delay = p->frames_per_enqueue / (double)ao->samplerate; delay += p->audio_latency; ao_read_data(ao, &p->buf, p->frames_per_enqueue, - mp_time_us() + 1000000LL * delay); + mp_time_ns() + MP_TIME_S_TO_NS(delay)); res = (*buffer_queue)->Enqueue(buffer_queue, p->buf, p->bytes_per_enqueue); if (res != SL_RESULT_SUCCESS) MP_ERR(ao, "Failed to Enqueue: %d\n", res); - pthread_mutex_unlock(&p->buffer_lock); + mp_mutex_unlock(&p->buffer_lock); } #define CHK(stmt) \ @@ -111,6 +110,8 @@ static int init(struct ao *ao) // This AO only supports two channels at the moment mp_chmap_from_channels(&ao->channels, 2); + // Upstream "Wilhelm" supports only 8000 <= rate <= 192000 + ao->samplerate = MPCLAMP(ao->samplerate, 8000, 192000); CHK(slCreateEngine(&p->sl, 0, NULL, 0, NULL, NULL)); CHK((*p->sl)->Realize(p->sl, SL_BOOLEAN_FALSE)); @@ -168,7 +169,7 @@ static int init(struct ao *ao) goto error; } - int r = pthread_mutex_init(&p->buffer_lock, NULL); + int r = mp_mutex_init(&p->buffer_lock); if (r) { MP_ERR(ao, "Failed to initialize the mutex: %d\n", r); goto error; @@ -247,15 +248,17 @@ const struct ao_driver audio_out_opensles = { .init = init, .uninit = uninit, .reset = reset, - .resume = resume, + .start = resume, .priv_size = sizeof(struct priv), .priv_defaults = &(const struct priv) { .buffer_size_in_ms = 250, }, .options = (const struct m_option[]) { - OPT_INTRANGE("frames-per-enqueue", frames_per_enqueue, 0, 1, 96000), - OPT_INTRANGE("buffer-size-in-ms", buffer_size_in_ms, 0, 0, 500), + {"frames-per-enqueue", OPT_INT(frames_per_enqueue), + M_RANGE(1, 96000)}, + {"buffer-size-in-ms", OPT_INT(buffer_size_in_ms), + M_RANGE(0, 500)}, {0} }, .options_prefix = "opensles", |