[MPlayer-cvslog] r37810 - trunk/libao2/ao_oss.c

reimar subversion at mplayerhq.hu
Fri Feb 26 21:47:16 CET 2016


Author: reimar
Date: Fri Feb 26 21:47:16 2016
New Revision: 37810

Log:
ao_oss: check ioctl return values.

Modified:
   trunk/libao2/ao_oss.c

Modified: trunk/libao2/ao_oss.c
==============================================================================
--- trunk/libao2/ao_oss.c	Fri Feb 26 21:24:09 2016	(r37809)
+++ trunk/libao2/ao_oss.c	Fri Feb 26 21:47:16 2016	(r37810)
@@ -185,19 +185,22 @@ static int control(int cmd,void *arg){
 
 	    if ((fd = open(oss_mixer_device, O_RDONLY)) != -1)
 	    {
-		ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs);
+		if (ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs) == -1)
+		    return CONTROL_ERROR;
 		if (devs & (1 << oss_mixer_channel))
 		{
 		    if (cmd == AOCONTROL_GET_VOLUME)
 		    {
-		        ioctl(fd, MIXER_READ(oss_mixer_channel), &v);
+		        if (ioctl(fd, MIXER_READ(oss_mixer_channel), &v) == -1)
+			    return CONTROL_ERROR;
 			vol->right = (v & 0xFF00) >> 8;
 			vol->left = v & 0x00FF;
 		    }
 		    else
 		    {
 		        v = ((int)vol->right << 8) | (int)vol->left;
-			ioctl(fd, MIXER_WRITE(oss_mixer_channel), &v);
+			if (ioctl(fd, MIXER_WRITE(oss_mixer_channel), &v) == -1)
+			    return CONTROL_ERROR;
 		    }
 		}
 		else
@@ -251,7 +254,8 @@ static int init(int rate,int channels,in
       mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_OSS_CantOpenMixer,
         oss_mixer_device, strerror(errno));
     }else{
-      ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs);
+      if (ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs) == -1)
+        devs = 0;
       close(fd);
 
       for (i=0; i<SOUND_MIXER_NRDEVICES; i++){
@@ -300,7 +304,8 @@ static int init(int rate,int channels,in
 
   if(AF_FORMAT_IS_AC3(format)) {
     ao_data.samplerate=rate;
-    ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate);
+    if (ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate) == -1)
+      mp_msg(MSGT_AO,MSGL_WARN, "OSS: Failed setting AC3 sample-rate %i %s\n", rate, strerror(errno));
   }
 
 ac3_retry:
@@ -355,7 +360,8 @@ ac3_retry:
     mp_msg(MSGT_AO,MSGL_V,"audio_setup: using %d channels (requested: %d)\n", ao_data.channels, channels);
     // set rate
     ao_data.samplerate=rate;
-    ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate);
+    if (ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate) == -1)
+      mp_msg(MSGT_AO,MSGL_WARN, "OSS: Failed setting sample-rate %i %s\n", rate, strerror(errno));
     mp_msg(MSGT_AO,MSGL_V,"audio_setup: using %d Hz samplerate (requested: %d)\n",ao_data.samplerate,rate);
   }
 
@@ -437,6 +443,7 @@ static void uninit(int immed){
 
 // stop playing and empty buffers (for seeking/pause)
 static void reset(void){
+  int fail = 0;
   int oss_format;
     uninit(1);
     audio_fd=open(dsp, O_WRONLY);
@@ -451,17 +458,18 @@ static void reset(void){
 
   oss_format = format2oss(ao_data.format);
   if(AF_FORMAT_IS_AC3(ao_data.format))
-    ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate);
-  ioctl (audio_fd, SNDCTL_DSP_SETFMT, &oss_format);
+    fail |= ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate) == -1;
+  fail |= ioctl (audio_fd, SNDCTL_DSP_SETFMT, &oss_format) == -1;
   if(!AF_FORMAT_IS_AC3(ao_data.format)) {
     if (ao_data.channels > 2)
-      ioctl (audio_fd, SNDCTL_DSP_CHANNELS, &ao_data.channels);
+      fail |= ioctl (audio_fd, SNDCTL_DSP_CHANNELS, &ao_data.channels) == -1;
     else {
       int c = ao_data.channels-1;
-      ioctl (audio_fd, SNDCTL_DSP_STEREO, &c);
+      fail |= ioctl (audio_fd, SNDCTL_DSP_STEREO, &c) == -1;
     }
-    ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate);
+    fail |= ioctl (audio_fd, SNDCTL_DSP_SPEED, &ao_data.samplerate) == -1;
   }
+  mp_msg(MSGT_AO,MSGL_WARN, "OSS: Reset failed\n");
 }
 
 // stop playing, keep buffers (for pause)


More information about the MPlayer-cvslog mailing list