diff options
Diffstat (limited to 'audio/out/ao_opensles.c')
-rw-r--r-- | audio/out/ao_opensles.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/audio/out/ao_opensles.c b/audio/out/ao_opensles.c index 40ab5324b5..6d4b6a78db 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), NULL, true, true); 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; |