summaryrefslogtreecommitdiffstats
path: root/audio/out
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-09-11 01:56:20 +0200
committerwm4 <wm4@nowhere>2014-09-11 02:03:15 +0200
commit5f80e3f91ad810f7ce03147d24280eecadf494f0 (patch)
tree7995fbd317974efb5de8fd57864937407c613e41 /audio/out
parentf744aadb776dc8269ae6f4cc54c239c548e19a49 (diff)
downloadmpv-5f80e3f91ad810f7ce03147d24280eecadf494f0.tar.bz2
mpv-5f80e3f91ad810f7ce03147d24280eecadf494f0.tar.xz
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.
Diffstat (limited to 'audio/out')
-rw-r--r--audio/out/ao_oss.c49
1 files changed, 17 insertions, 32 deletions
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 <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <poll.h>
#include <errno.h>
#include <string.h>
#include <strings.h>
@@ -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)