audio, client API: check mp_make_wakeup_pipe() return value

Could fail e.g. due to FD exhaustion.
This commit is contained in:
wm4 2014-07-25 14:30:59 +02:00
parent 18c432b83a
commit ef600041ba
2 changed files with 11 additions and 8 deletions

View File

@ -364,17 +364,19 @@ static int init(struct ao *ao)
pthread_mutex_init(&p->lock, NULL); pthread_mutex_init(&p->lock, NULL);
pthread_cond_init(&p->wakeup, NULL); pthread_cond_init(&p->wakeup, NULL);
pthread_cond_init(&p->wakeup_drain, NULL); pthread_cond_init(&p->wakeup_drain, NULL);
mp_make_wakeup_pipe(p->wakeup_pipe); if (mp_make_wakeup_pipe(p->wakeup_pipe) < 0)
goto err;
p->buffer = mp_audio_buffer_create(ao); p->buffer = mp_audio_buffer_create(ao);
mp_audio_buffer_reinit_fmt(p->buffer, ao->format, mp_audio_buffer_reinit_fmt(p->buffer, ao->format,
&ao->channels, ao->samplerate); &ao->channels, ao->samplerate);
mp_audio_buffer_preallocate_min(p->buffer, ao->buffer); mp_audio_buffer_preallocate_min(p->buffer, ao->buffer);
if (pthread_create(&p->thread, NULL, playthread, ao)) { if (pthread_create(&p->thread, NULL, playthread, ao))
goto err;
return 0;
err:
ao->driver->uninit(ao); ao->driver->uninit(ao);
return -1; return -1;
}
return 0;
} }
const struct ao_driver ao_api_push = { const struct ao_driver ao_api_push = {

View File

@ -1331,11 +1331,12 @@ int mpv_get_wakeup_pipe(mpv_handle *ctx)
{ {
pthread_mutex_lock(&ctx->wakeup_lock); pthread_mutex_lock(&ctx->wakeup_lock);
if (ctx->wakeup_pipe[0] == -1) { if (ctx->wakeup_pipe[0] == -1) {
mp_make_wakeup_pipe(ctx->wakeup_pipe); if (mp_make_wakeup_pipe(ctx->wakeup_pipe) >= 0)
write(ctx->wakeup_pipe[1], &(char){0}, 1); write(ctx->wakeup_pipe[1], &(char){0}, 1);
} }
int fd = ctx->wakeup_pipe[0];
pthread_mutex_unlock(&ctx->wakeup_lock); pthread_mutex_unlock(&ctx->wakeup_lock);
return ctx->wakeup_pipe[0]; return fd;
} }
unsigned long mpv_client_api_version(void) unsigned long mpv_client_api_version(void)