Merge branch 'master' into config-checks-ipv6
[mono.git] / mcs / class / System / System.Media / AudioDevice.cs
index 628c04d8eddcba9f61fffee9e155e50cbb622eaa..2c54ef71a5ffa86a5a71b268b28d09bee8cbb559 100644 (file)
@@ -48,6 +48,9 @@ namespace Mono.Audio {
                protected uint chunk_size;
                
                static AudioDevice TryAlsa (string name) {
+#if XAMMAC_4_5
+                       return null;
+#else
                        AudioDevice dev;
                        try {
                                dev = new AlsaDevice (name);
@@ -55,6 +58,7 @@ namespace Mono.Audio {
                        } catch {
                                return null;
                        }
+#endif
                }
 
                public static AudioDevice CreateDevice (string name) {
@@ -87,90 +91,91 @@ namespace Mono.Audio {
                }
        }
 
+#if !XAMMAC_4_5
        class AlsaDevice: AudioDevice, IDisposable {
                IntPtr handle;
                IntPtr hw_param;
                IntPtr sw_param;
                
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_open (ref IntPtr handle, string pcm_name, int stream, int mode);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_close (IntPtr handle);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_drain (IntPtr handle);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_writei (IntPtr handle, byte[] buf, int size);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_set_params (IntPtr handle, int format, int access, int channels, int rate, int soft_resample, int latency);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_state (IntPtr handle);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_prepare (IntPtr handle);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_hw_params (IntPtr handle, IntPtr param);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_hw_params_malloc (ref IntPtr param);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern void snd_pcm_hw_params_free (IntPtr param);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_hw_params_any (IntPtr handle, IntPtr param);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_hw_params_set_access (IntPtr handle, IntPtr param, int access);
                
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_hw_params_set_format (IntPtr handle, IntPtr param, int format);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_hw_params_set_channels (IntPtr handle, IntPtr param, uint channel);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_hw_params_set_rate_near (IntPtr handle, IntPtr param, ref uint rate, ref int dir);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_hw_params_set_period_time_near (IntPtr handle, IntPtr param, ref uint period, ref int dir);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_hw_params_get_period_size (IntPtr param, ref uint period, ref int dir);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_hw_params_set_buffer_size_near (IntPtr handle, IntPtr param, ref uint buff_size);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_hw_params_get_buffer_time_max(IntPtr param, ref uint buffer_time, ref int dir);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_hw_params_set_buffer_time_near(IntPtr handle, IntPtr param, ref uint BufferTime, ref int dir);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_hw_params_get_buffer_size(IntPtr param, ref uint BufferSize);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_sw_params (IntPtr handle, IntPtr param);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_sw_params_malloc (ref IntPtr param);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern void snd_pcm_sw_params_free (IntPtr param);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_sw_params_current(IntPtr handle, IntPtr param);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_sw_params_set_avail_min(IntPtr handle, IntPtr param, uint frames);
 
-               [DllImport ("libasound.so.2")]
+               [DllImport ("libasound")]
                static extern int snd_pcm_sw_params_set_start_threshold(IntPtr handle, IntPtr param, uint StartThreshold);
 
                public AlsaDevice (string name) {
@@ -200,6 +205,8 @@ namespace Mono.Audio {
                                snd_pcm_hw_params_free (hw_param);
                        if (handle != IntPtr.Zero)
                                snd_pcm_close (handle);
+                       sw_param = IntPtr.Zero;
+                       hw_param = IntPtr.Zero;
                        handle = IntPtr.Zero;
                }
 
@@ -278,10 +285,14 @@ namespace Mono.Audio {
                                Console.WriteLine ("failed to alloc Alsa sw param struct");
                        }
 
-                       if (hw_param != IntPtr.Zero)
+                       if (hw_param != IntPtr.Zero) {
                                snd_pcm_hw_params_free (hw_param);  // free hw params
-                       if (sw_param != IntPtr.Zero)
+                               hw_param = IntPtr.Zero;
+                       }
+                       if (sw_param != IntPtr.Zero) {
                                snd_pcm_sw_params_free (sw_param);  // free sw params
+                               sw_param = IntPtr.Zero;
+                       }
 
                        return alsa_err == 0;
                }
@@ -313,6 +324,7 @@ namespace Mono.Audio {
                        snd_pcm_drain (handle);
                }
        }
+#endif
 
 }