From 5f80e3f91ad810f7ce03147d24280eecadf494f0 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Sep 2014 01:56:20 +0200 Subject: ao_oss: use poll(), drop --disable-audio-select support Replace select() usage with poll() (and reduce code duplication). Also, while we're at it, drop --disable-audio-select, since it has the wrong name anyway. And I have doubts that this is needed anywhere. If it is, it should probably fallback to doing the right thing by default, instead of requiring the user to do it manually. Since nobody has done that yet, and since this configure option has been part of MPlayer ever since ao_oss was added, it's probably safe to say it's not needed. The '#ifdef SNDCTL_DSP_GETOSPACE' was pointless, since it's already used unconditionally in another place. --- audio/out/ao_oss.c | 49 +++++++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) (limited to 'audio') diff --git a/audio/out/ao_oss.c b/audio/out/ao_oss.c index af6048b7b5..6767fda168 100644 --- a/audio/out/ao_oss.c +++ b/audio/out/ao_oss.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -219,6 +220,14 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg) return CONTROL_UNKNOWN; } +// 1: ok, 0: not writable, -1: error +static int device_writable(struct ao *ao) +{ + struct priv *p = ao->priv; + struct pollfd fd = {.fd = p->audio_fd, .events = POLLOUT}; + return poll(&fd, 1, 0); +} + // open & setup audio device // return: 0=success -1=fail static int init(struct ao *ao) @@ -393,30 +402,22 @@ ac3_retry: if (p->buffersize == -1) { // Measuring buffer size: - void *data; + void *data = malloc(p->outburst); + if (!data) { + MP_ERR(ao, "Out of memory, or broken outburst size.\n"); + return -1; + } p->buffersize = 0; -#if HAVE_AUDIO_SELECT - data = malloc(p->outburst); memset(data, 0, p->outburst); - while (p->buffersize < 0x40000) { - fd_set rfds; - struct timeval tv; - FD_ZERO(&rfds); - FD_SET(p->audio_fd, &rfds); - tv.tv_sec = 0; - tv.tv_usec = 0; - if (!select(p->audio_fd + 1, NULL, &rfds, NULL, &tv)) - break; + while (p->buffersize < 0x40000 && device_writable(ao) > 0) { write(p->audio_fd, data, p->outburst); p->buffersize += p->outburst; } free(data); if (p->buffersize == 0) { - MP_ERR(ao, "*** Your audio driver DOES NOT support select() ***\n"); - MP_ERR(ao, "Recompile mpv with #define HAVE_AUDIO_SELECT 0 in config.h!\n"); + MP_ERR(ao, "Your OSS audio driver DOES NOT support poll().\n"); return -1; } -#endif } ao->bps = ao->channels.num * af_fmt2bps(ao->format); @@ -500,28 +501,12 @@ static int get_space(struct ao *ao) { struct priv *p = ao->priv; -#ifdef SNDCTL_DSP_GETOSPACE if (ioctl(p->audio_fd, SNDCTL_DSP_GETOSPACE, &p->zz) != -1) { // calculate exact buffer space: return p->zz.fragments * p->zz.fragsize / ao->sstride; } -#endif - - // check buffer -#if HAVE_AUDIO_SELECT - { - fd_set rfds; - struct timeval tv; - FD_ZERO(&rfds); - FD_SET(p->audio_fd, &rfds); - tv.tv_sec = 0; - tv.tv_usec = 0; - if (!select(p->audio_fd + 1, NULL, &rfds, NULL, &tv)) - return 0; // not block! - } -#endif - return p->outburst / ao->sstride; + return device_writable(ao) > 0 ? p->outburst / ao->sstride : 0; } // stop playing, keep buffers (for pause) -- cgit v1.2.3