[MPlayer-dev-eng] Patch to prevent blocking in ao_oss
Fredrik Kuivinen
freku045 at student.liu.se
Fri Oct 26 17:29:12 CEST 2001
Hello
Attached is a small patch that disables sound if the audio device is used by
another program. Instead of blocking which mplayer currently do.
BTW currently a lot of things are detected at compile time such as MMX, DGA,
3DNOW etc. And in the sources there are lots of #ifdef MMX etc... Are there
any plans of changing this into runtime detection instead?
/ Fredrik Kuivinen
-------------- next part --------------
--- /home/ksorim/src/MPlayer-20011023/libao2/ao_oss.c Thu Oct 4 20:25:50 2001
+++ libao2/ao_oss.c Fri Oct 26 16:56:05 2001
@@ -7,6 +7,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <errno.h>
//#include <sys/soundcard.h>
#include "../config.h"
@@ -112,12 +113,21 @@
if (verbose)
printf("audio_setup: using '%s' dsp device\n", dsp);
- audio_fd=open(dsp, O_WRONLY);
+ /* The open call will block if some other program is using the device if we
+ * don't pass O_NONBLOCK to open */
+ audio_fd=open(dsp, O_WRONLY|O_NONBLOCK);
if(audio_fd<0){
- printf("Can't open audio device %s -> nosound\n",dsp);
+ printf("Can't open audio device %s: %s -> nosound\n", dsp, strerror(errno));
return 0;
}
+ /* Remove O_NONBLOCK that we got from open */
+ if(fcntl(audio_fd, F_SETFL, 0) != 0) {
+ printf("fcntl failed: %s This should never happen. " \
+ "Please report as a bug\n");
+ return 0;
+ }
+
ao_format=format;
ioctl (audio_fd, SNDCTL_DSP_SETFMT, &ao_format);
if(format == AFMT_AC3 && ao_format != AFMT_AC3) {
@@ -191,17 +201,25 @@
// stop playing and empty buffers (for seeking/pause)
static void reset(){
uninit();
- audio_fd=open(dsp, O_WRONLY);
+ audio_fd=open(dsp, O_WRONLY|O_NONBLOCK);
if(audio_fd<0){
- printf("\nFatal error: *** CANNOT RE-OPEN / RESET AUDIO DEVICE ***\n");
+ printf("\nFatal error: %s *** CANNOT RE-OPEN / RESET AUDIO DEVICE " \
+ "***\n", strerror(errno));
return;
}
- ioctl (audio_fd, SNDCTL_DSP_SETFMT, &ao_format);
- if(ao_format != AFMT_AC3) {
- ioctl (audio_fd, SNDCTL_DSP_STEREO, &ao_channels);
- ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_samplerate);
- }
+ if(fcntl(audio_fd, F_SETFL, 0) != 0) {
+ printf("Error during fcntl: %s While re-opening audio device. This " \
+ "should never happen. Please report as a bug.\n",
+ strerror(errno));
+ return;
+ }
+
+ ioctl (audio_fd, SNDCTL_DSP_SETFMT, &ao_format);
+ if(ao_format != AFMT_AC3) {
+ ioctl (audio_fd, SNDCTL_DSP_STEREO, &ao_channels);
+ ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_samplerate);
+ }
}
// stop playing, keep buffers (for pause)
More information about the MPlayer-dev-eng
mailing list