1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-25 08:12:17 +00:00

ao_opensles: do one buffer only

Doing two buffers causes stutters upon (re)start of playback on Android O for all kinds of sinks.
This commit is contained in:
Tom Yan 2018-03-13 03:04:21 +08:00 committed by Jan Ekström
parent 596f66cccf
commit 5a8c48fde2

View File

@ -35,7 +35,7 @@ struct priv {
SLBufferQueueItf buffer_queue;
SLEngineItf engine;
SLPlayItf play;
char *curbuf, *buf1, *buf2;
char *buf;
size_t buffer_size;
pthread_mutex_t buffer_lock;
double audio_latency;
@ -70,9 +70,8 @@ static void uninit(struct ao *ao)
pthread_mutex_destroy(&p->buffer_lock);
free(p->buf1);
free(p->buf2);
p->curbuf = p->buf1 = p->buf2 = NULL;
free(p->buf);
p->buf = NULL;
p->buffer_size = 0;
}
@ -88,17 +87,15 @@ static void buffer_callback(SLBufferQueueItf buffer_queue, void *context)
pthread_mutex_lock(&p->buffer_lock);
data[0] = p->curbuf;
data[0] = p->buf;
delay = 2 * p->buffer_size / (double)ao->bps;
delay += p->audio_latency;
ao_read_data(ao, data, p->buffer_size / ao->sstride,
mp_time_us() + 1000000LL * delay);
res = (*buffer_queue)->Enqueue(buffer_queue, p->curbuf, p->buffer_size);
res = (*buffer_queue)->Enqueue(buffer_queue, p->buf, p->buffer_size);
if (res != SL_RESULT_SUCCESS)
MP_ERR(ao, "Failed to Enqueue: %d\n", res);
else
p->curbuf = (p->curbuf == p->buf1) ? p->buf2 : p->buf1;
pthread_mutex_unlock(&p->buffer_lock);
}
@ -133,7 +130,7 @@ static int init(struct ao *ao)
CHK((*p->output_mix)->Realize(p->output_mix, SL_BOOLEAN_FALSE));
locator_buffer_queue.locatorType = SL_DATALOCATOR_BUFFERQUEUE;
locator_buffer_queue.numBuffers = 2;
locator_buffer_queue.numBuffers = 1;
pcm.formatType = SL_DATAFORMAT_PCM;
pcm.numChannels = 2;
@ -168,10 +165,8 @@ static int init(struct ao *ao)
ao->device_buffer = ao->samplerate * DEFAULT_BUFFER_SIZE_MS / 1000;
p->buffer_size = ao->device_buffer * ao->channels.num *
af_fmt_to_bytes(ao->format);
p->buf1 = calloc(1, p->buffer_size);
p->buf2 = calloc(1, p->buffer_size);
p->curbuf = p->buf1;
if (!p->buf1 || !p->buf2) {
p->buf = calloc(1, p->buffer_size);
if (!p->buf) {
MP_ERR(ao, "Failed to allocate device buffer\n");
goto error;
}
@ -243,8 +238,6 @@ static void reset(struct ao *ao)
static void resume(struct ao *ao)
{
struct priv *p = ao->priv;
// enqueue two buffers
buffer_callback(p->buffer_queue, ao);
buffer_callback(p->buffer_queue, ao);
}