]> Repos - portaudio/commitdiff
- Fixes multiple crashes in PortAudio.
authorRoss Bencina <rossb@audiomulch.com>
Sat, 3 Sep 2016 12:46:54 +0000 (22:46 +1000)
committerRoss Bencina <rossb@audiomulch.com>
Sat, 3 Sep 2016 12:46:54 +0000 (22:46 +1000)
- Removes the DirectSound support from PortAudio in order to prevent
  issues with bad audio quality.
  - Attempts to recognize USB PortAudio devices on Windows as such,
    ignores the virtual Microsoft Sound Mapper devices to avoid user
    confusion. Contributed by Vincent Lucas.
    lyubomir committed on Nov 15, 2012
    a93910c from
    https://github.com/jitsi/libsrc/commits/master/portaudio.zip

src/hostapi/wdmks/pa_win_wdmks.c
src/hostapi/wmme/pa_win_wmme.c

index 40297b7e0f3990806eb7905becfab2f7149c96d6..3c215700e93785cea6a531143de7812783611d13 100644 (file)
 
 #ifdef __GNUC__
     #include <initguid.h>
-    #define _WIN32_WINNT 0x0501
-    #define WINVER 0x0501
+    #ifndef _WIN32_WINNT
+        #define _WIN32_WINNT 0x0501
+    #endif /* #ifndef _WIN32_WINNT */
+    #ifndef WINVER
+        #define WINVER 0x0501
+    #endif /* #ifndef WINVER */
 #endif
 
 #include <string.h> /* strlen() */
@@ -76,7 +80,7 @@
 #include "pa_debugprint.h"
 
 #include <windows.h>
-#include <winioctl.h>
+/* #include <winioctl.h> MinGW-w64 4.7.1 from TDM-GCC throws multiple redefinition errors. */
 #include <process.h>
 
 #ifdef __GNUC__
index d6ac91b765798ab48ba9d02a2b3a3be12c92561d..84053ebdd4cf416086d3bedfe4e949c6ae21e48d 100644 (file)
@@ -383,6 +383,25 @@ static PaError CloseHandleWithPaError( HANDLE handle )
     return result;
 }
 
+/**
+ * Sets the <tt>transportType</tt> of a specific <tt>PaDeviceInfo</tt> to a
+ * value deduced by examining the other fields of the specified
+ * <tt>PaDeviceInfo</tt>. For example, if <tt>name</tt> field matches the
+ * regular expression <tt>\(.*USB.*\)</tt>, the <tt>transportType</tt> is set to
+ * <tt>USB</tt>.
+ *
+ * @param deviceInfo the <tt>PaDeviceInfo</tt> to set the <tt>transportType</tt>
+ * of
+ */
+static void SetDeviceInfoTransportType(PaDeviceInfo *deviceInfo)
+{
+    const char *s = deviceInfo->name;
+
+    deviceInfo->transportType
+        = (s && (s = strrchr(s,'(')) && (s = strstr(s,"USB")) && strchr(s,')'))
+            ? "USB"
+            : NULL;
+}
 
 /* PaWinMmeHostApiRepresentation - host api datastructure specific to this implementation */
 
@@ -688,6 +707,12 @@ static PaError InitializeInputDeviceInfo( PaWinMmeHostApiRepresentation *winMmeH
     
     *success = 0;
 
+    /* We do not want Microsoft's Sound Mapper because it is a virtual device
+     * and we want the real (hardware) devices only.
+     */
+    if (WAVE_MAPPER == winMmeInputDeviceId)
+        return paNoError;
+
     mmresult = waveInGetDevCaps( winMmeInputDeviceId, &wic, sizeof( WAVEINCAPS ) );
     if( mmresult == MMSYSERR_NOMEM )
     {
@@ -730,6 +755,9 @@ static PaError InitializeInputDeviceInfo( PaWinMmeHostApiRepresentation *winMmeH
     }
     deviceInfo->name = deviceName;
 
+    /* transportType */
+    SetDeviceInfoTransportType(deviceInfo);
+
     if( wic.wChannels == 0xFFFF || wic.wChannels < 1 || wic.wChannels > 255 ){
         /* For Windows versions using WDM (possibly Windows 98 ME and later)
          * the kernel mixer sits between the application and the driver. As a result,
@@ -856,6 +884,12 @@ static PaError InitializeOutputDeviceInfo( PaWinMmeHostApiRepresentation *winMme
 
     *success = 0;
 
+    /* We do not want Microsoft's Sound Mapper because it is a virtual device
+     * and we want the real (hardware) devices only.
+     */
+    if (WAVE_MAPPER == winMmeOutputDeviceId)
+        return paNoError;
+
     mmresult = waveOutGetDevCaps( winMmeOutputDeviceId, &woc, sizeof( WAVEOUTCAPS ) );
     if( mmresult == MMSYSERR_NOMEM )
     {
@@ -898,6 +932,9 @@ static PaError InitializeOutputDeviceInfo( PaWinMmeHostApiRepresentation *winMme
     }
     deviceInfo->name = deviceName;
 
+    /* transportType */
+    SetDeviceInfoTransportType(deviceInfo);
+
     if( woc.wChannels == 0xFFFF || woc.wChannels < 1 || woc.wChannels > 255 ){
         /* For Windows versions using WDM (possibly Windows 98 ME and later)
          * the kernel mixer sits between the application and the driver. As a result,