[xiph-commits] r17628 - in trunk/ao/src/plugins: alsa dsound esd irix macosx nas oss pulse roar sndio sun

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Thu Nov 18 02:38:55 PST 2010


Author: xiphmont
Date: 2010-11-18 02:38:54 -0800 (Thu, 18 Nov 2010)
New Revision: 17628

Modified:
   trunk/ao/src/plugins/alsa/ao_alsa.c
   trunk/ao/src/plugins/dsound/ao_dsound.c
   trunk/ao/src/plugins/esd/ao_esd.c
   trunk/ao/src/plugins/irix/ao_irix.c
   trunk/ao/src/plugins/macosx/ao_macosx.c
   trunk/ao/src/plugins/nas/ao_nas.c
   trunk/ao/src/plugins/oss/ao_oss.c
   trunk/ao/src/plugins/pulse/ao_pulse.c
   trunk/ao/src/plugins/roar/ao_roar.c
   trunk/ao/src/plugins/sndio/ao_sndio.c
   trunk/ao/src/plugins/sun/ao_sun.c
Log:
Considerable sloppiness in teardown of a device that fails to open; 
failure to proof partial open state turned out to be present in varying 
degrees across most of the live drivers.



Modified: trunk/ao/src/plugins/alsa/ao_alsa.c
===================================================================
--- trunk/ao/src/plugins/alsa/ao_alsa.c	2010-11-16 01:17:43 UTC (rev 17627)
+++ trunk/ao/src/plugins/alsa/ao_alsa.c	2010-11-18 10:38:54 UTC (rev 17628)
@@ -621,7 +621,8 @@
             else
               awarn("ao_plugin_device_clear called with uninitialized ao_device->internal->dev\n");
 
-            free(device->internal);
+            free(internal);
+            device->internal=NULL;
           } else
             awarn("ao_plugin_device_clear called with uninitialized ao_device->internal\n");
 	} else

Modified: trunk/ao/src/plugins/dsound/ao_dsound.c
===================================================================
--- trunk/ao/src/plugins/dsound/ao_dsound.c	2010-11-16 01:17:43 UTC (rev 17627)
+++ trunk/ao/src/plugins/dsound/ao_dsound.c	2010-11-18 10:38:54 UTC (rev 17628)
@@ -105,4 +105,5 @@
 
   if (device->internal)
 	  free(internal);
+  device->internal=NULL;
 }

Modified: trunk/ao/src/plugins/esd/ao_esd.c
===================================================================
--- trunk/ao/src/plugins/esd/ao_esd.c	2010-11-16 01:17:43 UTC (rev 17627)
+++ trunk/ao/src/plugins/esd/ao_esd.c	2010-11-18 10:38:54 UTC (rev 17628)
@@ -303,4 +303,5 @@
 
   if(internal->host) free(internal->host);
   free(internal);
+  device->internal=NULL;
 }

Modified: trunk/ao/src/plugins/irix/ao_irix.c
===================================================================
--- trunk/ao/src/plugins/irix/ao_irix.c	2010-11-16 01:17:43 UTC (rev 17627)
+++ trunk/ao/src/plugins/irix/ao_irix.c	2010-11-18 10:38:54 UTC (rev 17628)
@@ -222,8 +222,9 @@
 {
 	ao_irix_internal *internal = (ao_irix_internal *) device->internal;
 
-	alClosePort(internal->alport);
-
+        if(internal->alport)
+          alClosePort(internal->alport);
+        internal->alport=NULL;
 	return 1;
 }
 
@@ -231,6 +232,8 @@
 {
 	ao_irix_internal *internal = (ao_irix_internal *) device->internal;
 
-	alFreeConfig(internal->alconfig);
+        if(internal->alconfig)
+          alFreeConfig(internal->alconfig);
 	free(internal);
+        device->internal=NULL;
 }

Modified: trunk/ao/src/plugins/macosx/ao_macosx.c
===================================================================
--- trunk/ao/src/plugins/macosx/ao_macosx.c	2010-11-16 01:17:43 UTC (rev 17627)
+++ trunk/ao/src/plugins/macosx/ao_macosx.c	2010-11-18 10:38:54 UTC (rev 17628)
@@ -73,6 +73,7 @@
 {
   /* Stuff describing the CoreAudio device */
   ComponentInstance       outputAudioUnit;
+  int                     output_p;
 
   /* Keep track of whether the output stream has actually been
      started/stopped */
@@ -188,7 +189,7 @@
 {
   ao_macosx_internal *internal;
 
-  internal = (ao_macosx_internal *) malloc(sizeof(ao_macosx_internal));
+  internal = (ao_macosx_internal *) calloc(1,sizeof(ao_macosx_internal));
 
   if (internal == NULL)	
     return 0; /* Could not initialize device memory */
@@ -250,6 +251,7 @@
     aerror("AudioComponentInstanceNew() error => %d\n",(int)result);
     return 0;
   }
+  internal->output_p=1;
 
   /* Request desired format of the audio unit.  Let HAL do all
      conversion since it will probably be doing some internal
@@ -476,56 +478,61 @@
   // start now.
 
   pthread_mutex_lock(&mutex);
-  internal->isStopping = true;
 
-  if(!internal->started && internal->validByteCount){
-    status = AudioOutputUnitStart(internal->outputAudioUnit);
-    adebug("Starting audio output unit\n");
-    if(status){
-      pthread_mutex_unlock(&mutex);
-      aerror("Failed to start audio output => %d\n",(int)status);
-      return 0;
+  if(internal->output_p){
+    internal->output_p=0;
+    internal->isStopping = true;
+
+    if(!internal->started && internal->validByteCount){
+      status = AudioOutputUnitStart(internal->outputAudioUnit);
+      adebug("Starting audio output unit\n");
+      if(status){
+        pthread_mutex_unlock(&mutex);
+        aerror("Failed to start audio output => %d\n",(int)status);
+        return 0;
+      }
+      internal->started = true;
     }
-    internal->started = true;
-  }
 
-  // For some rare cases (using atexit in your program) Coreaudio tears
-  // down the HAL itself, so we do not need to do that here.
-  // We wouldn't get an error if we did, but AO would hang waiting for the 
-  // AU to flush the buffer
-  sizeof_running = sizeof(UInt32);
-  AudioUnitGetProperty(internal->outputAudioUnit, 
-		       kAudioDevicePropertyDeviceIsRunning,
-		       kAudioUnitScope_Input,
-		       0,
-		       &running, 
-		       &sizeof_running);
+    // For some rare cases (using atexit in your program) Coreaudio tears
+    // down the HAL itself, so we do not need to do that here.
+    // We wouldn't get an error if we did, but AO would hang waiting for the 
+    // AU to flush the buffer
+    sizeof_running = sizeof(UInt32);
+    AudioUnitGetProperty(internal->outputAudioUnit, 
+                         kAudioDevicePropertyDeviceIsRunning,
+                         kAudioUnitScope_Input,
+                         0,
+                         &running, 
+                         &sizeof_running);
 
-  if (!running) {
-    pthread_mutex_unlock(&mutex);
-    return 1;
-  }
+    if (!running) {
+      pthread_mutex_unlock(&mutex);
+      return 1;
+    }
 
-  // Only stop if we ever got started
-  if (internal->started) {
+    // Only stop if we ever got started
+    if (internal->started) {
 
-    // Wait for any pending data to get flushed
-    while (internal->validByteCount)
-      pthread_cond_wait(&cond, &mutex);
+      // Wait for any pending data to get flushed
+      while (internal->validByteCount)
+        pthread_cond_wait(&cond, &mutex);
 
-    pthread_mutex_unlock(&mutex);
+      pthread_mutex_unlock(&mutex);
     
-    status = AudioOutputUnitStop(internal->outputAudioUnit);
-    if (status) {
-      awarn("AudioOutputUnitStop returned %d\n", (int)status);
-      return 0;
-    }
+      status = AudioOutputUnitStop(internal->outputAudioUnit);
+      if (status) {
+        awarn("AudioOutputUnitStop returned %d\n", (int)status);
+        return 0;
+      }
 
-    status = CloseComponent(internal->outputAudioUnit);
-    if (status) {
-      awarn("CloseComponent returned %d\n", (int)status);
-      return 0;
-    }
+      status = CloseComponent(internal->outputAudioUnit);
+      if (status) {
+        awarn("CloseComponent returned %d\n", (int)status);
+        return 0;
+      }
+    }else
+      pthread_mutex_unlock(&mutex);
   }else
     pthread_mutex_unlock(&mutex);
 
@@ -537,7 +544,9 @@
 {
   ao_macosx_internal *internal = (ao_macosx_internal *) device->internal;
 
-  free(internal->buffer);
+  if(internal->buffer)
+    free(internal->buffer);
   free(internal);
+  device->internal=NULL;
 }
 

Modified: trunk/ao/src/plugins/nas/ao_nas.c
===================================================================
--- trunk/ao/src/plugins/nas/ao_nas.c	2010-11-16 01:17:43 UTC (rev 17627)
+++ trunk/ao/src/plugins/nas/ao_nas.c	2010-11-18 10:38:54 UTC (rev 17628)
@@ -246,8 +246,10 @@
 {
 	ao_nas_internal *internal = (ao_nas_internal *) device->internal;
 
-	AuStopFlow(internal->aud, internal->flow, 0);
-	AuCloseServer(internal->aud);
+        if(internal->aud){
+          AuStopFlow(internal->aud, internal->flow, 0);
+          AuCloseServer(internal->aud);
+        }
 	return 1;
 }
 
@@ -256,6 +258,8 @@
 {
 	ao_nas_internal *internal = (ao_nas_internal *) device->internal;
 
-	free(internal->host);
+        if(internal->host)
+          free(internal->host);
 	free(internal);
+        device->internal=NULL;
 }

Modified: trunk/ao/src/plugins/oss/ao_oss.c
===================================================================
--- trunk/ao/src/plugins/oss/ao_oss.c	2010-11-16 01:17:43 UTC (rev 17627)
+++ trunk/ao/src/plugins/oss/ao_oss.c	2010-11-18 10:38:54 UTC (rev 17628)
@@ -340,8 +340,11 @@
 int ao_plugin_close(ao_device *device)
 {
 	ao_oss_internal *internal = (ao_oss_internal *) device->internal;
-	close(internal->fd);
 
+        if(internal->fd>=0)
+          close(internal->fd);
+        internal->fd=-1;
+
 	return 1;
 }
 
@@ -350,6 +353,8 @@
 {
 	ao_oss_internal *internal = (ao_oss_internal *) device->internal;
 
-	free(internal->dev);
+        if(internal->dev)
+          free(internal->dev);
 	free(internal);
+        device->internal=NULL;
 }

Modified: trunk/ao/src/plugins/pulse/ao_pulse.c
===================================================================
--- trunk/ao/src/plugins/pulse/ao_pulse.c	2010-11-16 01:17:43 UTC (rev 17627)
+++ trunk/ao/src/plugins/pulse/ao_pulse.c	2010-11-18 10:38:54 UTC (rev 17628)
@@ -247,9 +247,11 @@
     assert(device && device->internal);
     ao_pulse_internal *internal = (ao_pulse_internal *) device->internal;
 
-    pa_simple_drain(internal->simple, NULL);
-    pa_simple_free(internal->simple);
-    internal->simple = NULL;
+    if(internal->simple){
+      pa_simple_drain(internal->simple, NULL);
+      pa_simple_free(internal->simple);
+      internal->simple = NULL;
+    }
 
     return 1;
 }
@@ -258,8 +260,10 @@
     assert(device && device->internal);
     ao_pulse_internal *internal = (ao_pulse_internal *) device->internal;
 
-    free(internal->server);
-    free(internal->sink);
+    if(internal->server)
+      free(internal->server);
+    if(internal->sink)
+      free(internal->sink);
     free(internal);
     device->internal = NULL;
 }

Modified: trunk/ao/src/plugins/roar/ao_roar.c
===================================================================
--- trunk/ao/src/plugins/roar/ao_roar.c	2010-11-16 01:17:43 UTC (rev 17627)
+++ trunk/ao/src/plugins/roar/ao_roar.c	2010-11-18 10:38:54 UTC (rev 17628)
@@ -64,6 +64,7 @@
 
 typedef struct ao_roar_internal {
   struct roar_vio_calls svio;
+  int svio_p;
   char * host;
 } ao_roar_internal;
 
@@ -123,7 +124,7 @@
   if ( roar_vio_simple_stream(&(internal->svio), format->rate, format->channels, format->bits,
                              ROAR_CODEC_DEFAULT, internal->host, ROAR_DIR_PLAY, "libao client") == -1 )
     return 0;
-
+  internal->svio_p=1;
   device->driver_byte_format = AO_FMT_NATIVE;
 
   if(!device->inter_matrix){ /* It would be set if an app or user force-sets the mapping; don't overwrite! */
@@ -158,7 +159,9 @@
 int ao_plugin_close(ao_device * device) {
   ao_roar_internal * internal = (ao_roar_internal *) device->internal;
 
-  roar_vio_close(&(internal->svio));
+  if(internal->svio_p)
+    roar_vio_close(&(internal->svio));
+  internal->svio_p=0;
 
   return 1;
 }
@@ -171,4 +174,5 @@
     free(internal->host);
 
   free(internal);
+  device->internal=NULL;
 }

Modified: trunk/ao/src/plugins/sndio/ao_sndio.c
===================================================================
--- trunk/ao/src/plugins/sndio/ao_sndio.c	2010-11-16 01:17:43 UTC (rev 17627)
+++ trunk/ao/src/plugins/sndio/ao_sndio.c	2010-11-18 10:38:54 UTC (rev 17628)
@@ -131,8 +131,9 @@
   ao_sndio_internal *internal = (ao_sndio_internal *) device->internal;
   struct sio_hdl *hdl = internal->hdl;
 
-  if (!sio_stop(hdl))
-    return 0;
+  if(hdl)
+    if (!sio_stop(hdl))
+      return 0;
   return 1;
 }
 
@@ -141,8 +142,10 @@
   ao_sndio_internal *internal = (ao_sndio_internal *) device->internal;
   struct sio_hdl *hdl = internal->hdl;
 
-  sio_close(hdl);
+  if(hdl)
+    sio_close(hdl);
   if(internal->dev)
     free(internal->dev);
-  internal->dev=NULL;
+  free(internal);
+  device->internal=NULL;
 }

Modified: trunk/ao/src/plugins/sun/ao_sun.c
===================================================================
--- trunk/ao/src/plugins/sun/ao_sun.c	2010-11-16 01:17:43 UTC (rev 17627)
+++ trunk/ao/src/plugins/sun/ao_sun.c	2010-11-18 10:38:54 UTC (rev 17628)
@@ -197,7 +197,9 @@
 {
 	ao_sun_internal *internal = (ao_sun_internal *) device->internal;
 
-	close(internal->fd);
+        if(internal->fd>=0)
+          close(internal->fd);
+        internal->fd=-1;
 
 	return 1;
 }
@@ -207,6 +209,8 @@
 {
 	ao_sun_internal *internal = (ao_sun_internal *) device->internal;
 
-	free(internal->dev);
+        if(internal->dev)
+          free(internal->dev);
 	free(internal);
+        device->internal=NULL;
 }



More information about the commits mailing list