]> Repos - portaudio/commitdiff
hotplug: added connectionId parameter to PaDeviceInfo and bumped struct version numbe...
authorRoss Bencina <rossb@audiomulch.com>
Fri, 2 Sep 2016 10:27:39 +0000 (20:27 +1000)
committerRoss Bencina <rossb@audiomulch.com>
Fri, 2 Sep 2016 10:27:39 +0000 (20:27 +1000)
14 files changed:
include/portaudio.h
src/common/pa_front.c
src/common/pa_hostapi.h
src/hostapi/alsa/pa_linux_alsa.c
src/hostapi/asihpi/pa_linux_asihpi.c
src/hostapi/asio/pa_asio.cpp
src/hostapi/coreaudio/pa_mac_core.c
src/hostapi/dsound/pa_win_ds.c
src/hostapi/jack/pa_jack.c
src/hostapi/oss/pa_unix_oss.c
src/hostapi/wasapi/pa_win_wasapi.c
src/hostapi/wdmks/pa_win_wdmks.c
src/hostapi/wmme/pa_win_wmme.c
test/patest_refresh_device_list.c

index 655c52d56d404950c5ed704c7b3bb4c74539b667..e5a40d4c8782bd61ff37dae5847933d95241882e 100644 (file)
@@ -500,7 +500,7 @@ typedef void PaDevicesChangedCallback( void *userData );
 
  @see PaStreamFinishedCallback
 */
-PaError Pa_SetDevicesChangedCallback( void *userData, PaStreamFinishedCallback* devicesChangedCallback );
+PaError Pa_SetDevicesChangedCallback( void *userData, PaDevicesChangedCallback* devicesChangedCallback );
 
 
 /** The type used to represent monotonic time in seconds. PaTime is 
@@ -548,12 +548,20 @@ typedef unsigned long PaSampleFormat;
 
 #define paNonInterleaved ((PaSampleFormat) 0x80000000) /**< @see PaSampleFormat */
 
+
+/** A unique stable identifier for the duration of device connection,
+ or PA initialize/terminate, whichever is shorter.
+ @see Pa_RefreshDeviceList()
+*/
+typedef unsigned long PaDeviceConnectionId;
+
+
 /** A structure providing information and capabilities of PortAudio devices.
  Devices may support input, output or both input and output.
 */
 typedef struct PaDeviceInfo
 {
-    int structVersion;  /* this is struct version 2 */
+    int structVersion;  /* this is struct version 3 */
     const char *name;
     PaHostApiIndex hostApi; /**< note this is a host API index, not a type id*/
     
@@ -568,6 +576,8 @@ typedef struct PaDeviceInfo
     PaTime defaultHighOutputLatency;
 
     double defaultSampleRate;
+
+    PaDeviceConnectionId connectionId; /**< @see PaDeviceConnectionId */
 } PaDeviceInfo;
 
 
index def07e32232ab8237b8ddbefd44c7e69a3ac17d4..e552569a17330019c2698662aa9d0a51521c160c 100644 (file)
@@ -1955,3 +1955,9 @@ void PaUtil_DevicesChanged(unsigned state, void* pData)
     PaUtil_UnlockHotPlug();
 }
 
+static PaDeviceConnectionId nextDeviceConnectionId_ = 1000;
+
+PaDeviceConnectionId PaUtil_MakeDeviceConnectionId( void )
+{
+    return nextDeviceConnectionId_++;
+}
index 79e3e88161bcc4f3a5c7d161201cfe3609287dd7..92dc201ab2c497cb3f3109a89ab9a9c137fbc8c0 100644 (file)
@@ -171,6 +171,9 @@ typedef struct PaUtilPrivatePaFrontHostApiInfo {
 }PaUtilPrivatePaFrontHostApiInfo;
 
 
+PaDeviceConnectionId PaUtil_MakeDeviceConnectionId( void );
+
+
 /** The common header for all data structures whose pointers are passed through
  the hostApiSpecificStreamInfo field of the PaStreamParameters structure.
  Note that in order to keep the public PortAudio interface clean, this structure
index dbe2d0445e7f71412430395b37df80992f24ea9a..bb16df6b17c7da8d166baca0bcaf27109b7aa499 100644 (file)
@@ -1189,9 +1189,11 @@ static PaError FillInDevInfo( PaAlsaHostApiRepresentation *alsaApi, HwDevInfo* d
         }
     }
 
-    baseDeviceInfo->structVersion = 2;
+    baseDeviceInfo->structVersion = 3;
     baseDeviceInfo->hostApi = alsaApi->hostApiIndex;
     baseDeviceInfo->name = deviceHwInfo->name;
+    deviceInfo->connectionId = PaUtil_MakeDeviceConnectionId();
+
     devInfo->alsaName = deviceHwInfo->alsaName;
     devInfo->isPlug = deviceHwInfo->isPlug;
 
index ab76d3c5aaa2428f39381726b1219db3642a589f..d1a3f8208d66c975008fb88b79aa41b2d3a6c18f 100644 (file)
@@ -636,7 +636,7 @@ static PaError PaAsiHpi_BuildDeviceList( PaAsiHpiHostApiRepresentation *hpiHostA
                 hpiDevice->streamIndex = j;
                 hpiDevice->streamIsOutput = 0;
                 /* Set common PortAudio device stats */
-                baseDeviceInfo->structVersion = 2;
+                baseDeviceInfo->structVersion = 3;
                 /* Make sure name string is owned by API info structure */
                 sprintf( srcName,
                          "Adapter %d (%4X) - Input Stream %d", i+1, type, j+1 );
@@ -656,6 +656,7 @@ static PaError PaAsiHpi_BuildDeviceList( PaAsiHpiHostApiRepresentation *hpiHostA
                 /* HPI interface can actually handle any sampling rate to 1 Hz accuracy,
                 * so this default is as good as any */
                 baseDeviceInfo->defaultSampleRate = 44100;
+                baseDeviceInfo->connectionId = PaUtil_MakeDeviceConnectionId();
 
                 /* Store device in global PortAudio list */
                 hostApi->deviceInfos[deviceIndex++] = (PaDeviceInfo *) hpiDevice;
@@ -678,7 +679,7 @@ static PaError PaAsiHpi_BuildDeviceList( PaAsiHpiHostApiRepresentation *hpiHostA
                 hpiDevice->streamIndex = j;
                 hpiDevice->streamIsOutput = 1;
                 /* Set common PortAudio device stats */
-                baseDeviceInfo->structVersion = 2;
+                baseDeviceInfo->structVersion = 3;
                 /* Make sure name string is owned by API info structure */
                 sprintf( srcName,
                          "Adapter %d (%4X) - Output Stream %d", i+1, type, j+1 );
@@ -698,6 +699,7 @@ static PaError PaAsiHpi_BuildDeviceList( PaAsiHpiHostApiRepresentation *hpiHostA
                 /* HPI interface can actually handle any sampling rate to 1 Hz accuracy,
                 * so this default is as good as any */
                 baseDeviceInfo->defaultSampleRate = 44100;
+                baseDeviceInfo->connectionId = PaUtil_MakeDeviceConnectionId();
 
                 /* Store device in global PortAudio list */
                 hostApi->deviceInfos[deviceIndex++] = (PaDeviceInfo *) hpiDevice;
index 47c5761fea9016bbd1204c81ec31e5ec66e45671..fe6884cba986a41b4aeebd8db723b6991071a260 100644 (file)
@@ -1322,10 +1322,11 @@ PaError PaAsio_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex
                 PaAsioDeviceInfo *asioDeviceInfo = &deviceInfoArray[ (*hostApi)->info.deviceCount ];
                 PaDeviceInfo *deviceInfo = &asioDeviceInfo->commonDeviceInfo;
 
-                deviceInfo->structVersion = 2;
+                deviceInfo->structVersion = 3;
                 deviceInfo->hostApi = hostApiIndex;
 
                 deviceInfo->name = names[i];
+                deviceInfo->connectionId = PaUtil_MakeDeviceConnectionId();
 
                 if( InitPaDeviceInfoFromAsioDriver( asioHostApi, names[i], i, deviceInfo, asioDeviceInfo ) == paNoError )
                 {
index 4e352661932b0c36dfcd773788de9e170d0769a0..87430664d61c828b2c4e88163a0b806d0c5e3f32 100644 (file)
@@ -659,7 +659,7 @@ static PaError InitializeDeviceInfo( PaMacAUHAL *auhalHostApi,
 
     memset(deviceInfo, 0, sizeof(PaDeviceInfo));
 
-    deviceInfo->structVersion = 2;
+    deviceInfo->structVersion = 3;
     deviceInfo->hostApi = hostApiIndex;
   
     /* Get the device name using CFString */
@@ -693,6 +693,7 @@ static PaError InitializeDeviceInfo( PaMacAUHAL *auhalHostApi,
                CFRelease(nameRef);
        }
     deviceInfo->name = name;
+    deviceInfo->connectionId = PaUtil_MakeDeviceConnectionId();
 
     /* Try to get the default sample rate.  Don't fail if we can't get this. */
     propSize = sizeof(Float64);
index 0a40797e6bfe889f09742e96148be2c66fd59f27..ffd95f97303fd8a710982ccefac22006c6b48c7e 100644 (file)
@@ -993,6 +993,7 @@ static PaError AddOutputDeviceInfoFromDirectSound(
     }
 
     deviceInfo->name = name;
+    deviceInfo->connectionId = PaUtil_MakeDeviceConnectionId();
 
     return result;
 
@@ -1162,7 +1163,8 @@ http://www.winehq.com/hypermail/wine-patches/2003/01/0290.html
     }
 
     deviceInfo->name = name;
-   
+    deviceInfo->connectionId = PaUtil_MakeDeviceConnectionId();
+
     return result;
 
 error:
@@ -1482,7 +1484,7 @@ static PaError ScanDeviceInfos( struct PaUtilHostApiRepresentation *hostApi, PaH
         for( i = 0 ; i < maximumNewDeviceCount; ++i )
         {
             PaDeviceInfo *deviceInfo  = &deviceInfoArray[i].inheritedDeviceInfo;
-            deviceInfo->structVersion = 2;
+            deviceInfo->structVersion = 3;
             deviceInfo->hostApi       = hostApiIndex;
             deviceInfo->name          = 0;
 
index ab6af78dfb8459f8e7b60e332ea707d59c526034..792b0b4b82e6f7cf8ddf2dfb44ba772bae6dcbd0 100644 (file)
@@ -573,7 +573,7 @@ static PaError BuildDeviceList( PaJackHostApiRepresentation *jackApi )
                     strlen(client_names[client_index]) + 1 ), paInsufficientMemory );
         strcpy( (char *)curDevInfo->name, client_names[client_index] );
 
-        curDevInfo->structVersion = 2;
+        curDevInfo->structVersion = 3;
         curDevInfo->hostApi = jackApi->hostApiIndex;
 
         /* JACK is very inflexible: there is one sample rate the whole
@@ -634,6 +634,8 @@ static PaError BuildDeviceList( PaJackHostApiRepresentation *jackApi )
             commonApi->info.defaultInputDevice = client_index;
         if( commonApi->info.defaultOutputDevice == paNoDevice && curDevInfo->maxOutputChannels > 0 )
             commonApi->info.defaultOutputDevice = client_index;
+
+        deviceInfo->connectionId = PaUtil_MakeDeviceConnectionId();
     }
 
 error:
index b0ce4c32bee1e119ef04c8a4146a96269285d2f3..1a3d7bb37f76864ac28072b4b7145033ee475df3 100644 (file)
@@ -298,7 +298,7 @@ PaError PaUtil_InitializeDeviceInfo( PaDeviceInfo *deviceInfo, const char *name,
 {
     PaError result = paNoError;
 
-    deviceInfo->structVersion = 2;
+    deviceInfo->structVersion = 3;
     if( allocations )
     {
         size_t len = strlen( name ) + 1;
@@ -316,6 +316,7 @@ PaError PaUtil_InitializeDeviceInfo( PaDeviceInfo *deviceInfo, const char *name,
     deviceInfo->defaultHighInputLatency = defaultHighInputLatency;
     deviceInfo->defaultHighOutputLatency = defaultHighOutputLatency;
     deviceInfo->defaultSampleRate = defaultSampleRate;
+    deviceInfo->connectionId = PaUtil_MakeDeviceConnectionId();
 
 error:
     return result;
index 67618c893038c828d2f29d55659a74ec1fbb5498..d764324a703cbfa142f8bd17d1290db8dc8c6851 100644 (file)
@@ -1314,7 +1314,7 @@ PaError PaWasapi_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInd
                {
                        DWORD state                               = 0;
             PaDeviceInfo *deviceInfo  = &deviceInfoArray[i];
-            deviceInfo->structVersion = 2;
+            deviceInfo->structVersion = 3;
             deviceInfo->hostApi       = hostApiIndex;
 
                        PA_DEBUG(("WASAPI: device idx: %02d\n", i));
@@ -1508,6 +1508,8 @@ PaError PaWasapi_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInd
                                 break;
             }
 
+            deviceInfo->connectionId = PaUtil_MakeDeviceConnectionId();
+
             (*hostApi)->deviceInfos[i] = deviceInfo;
             ++(*hostApi)->info.deviceCount;
         }
index e01f24969dd94067463c5568c0550cb9056164c7..44ec1740b371f7751bf82fb424113cc06747f304 100644 (file)
@@ -3530,7 +3530,7 @@ static PaError ScanDeviceInfos( struct PaUtilHostApiRepresentation *hostApi, PaH
         for( i = 0 ; i < totalDeviceCount; ++i )
         {
             PaDeviceInfo *deviceInfo  = &deviceInfoArray[i].inheritedDeviceInfo;
-            deviceInfo->structVersion = 2;
+            deviceInfo->structVersion = 3;
             deviceInfo->hostApi       = hostApiIndex;
             deviceInfo->name          = 0;
             outArgument->deviceInfos[ i ] = deviceInfo;
@@ -3573,11 +3573,13 @@ static PaError ScanDeviceInfos( struct PaUtilHostApiRepresentation *hostApi, PaH
 
                     wdmDeviceInfo->filter = pFilter;
 
-                    deviceInfo->structVersion = 2;
+                    deviceInfo->structVersion = 3;
                     deviceInfo->hostApi = hostApiIndex;
                     deviceInfo->name = wdmDeviceInfo->compositeName;
                     /* deviceInfo->hostApiSpecificDeviceInfo = &pFilter->devInfo; */
 
+                    deviceInfo->connectionId = PaUtil_MakeDeviceConnectionId();
+
                     wdmDeviceInfo->pin = pin->pinId;
 
                     /* Get the name of the "device" */
index 4f4c872038107b6c5c499a3810df7555db4c4a9b..5afaf8e675a17fdd74e86b874ce85d9878966510 100644 (file)
@@ -789,6 +789,8 @@ static PaError InitializeInputDeviceInfo( PaWinMmeHostApiRepresentation *winMmeH
     DetectDefaultSampleRate( winMmeDeviceInfo, winMmeInputDeviceId,
             QueryInputWaveFormatEx, deviceInfo->maxInputChannels );
 
+    deviceInfo->connectionId = PaUtil_MakeDeviceConnectionId();
+
     *success = 1;
     
 error:
@@ -924,6 +926,8 @@ static PaError InitializeOutputDeviceInfo( PaWinMmeHostApiRepresentation *winMme
     DetectDefaultSampleRate( winMmeDeviceInfo, winMmeOutputDeviceId,
             QueryOutputWaveFormatEx, deviceInfo->maxOutputChannels );
 
+    deviceInfo->connectionId = PaUtil_MakeDeviceConnectionId();
+
     *success = 1;
     
 error:
@@ -1069,7 +1073,7 @@ PaError PaWinMme_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInd
                 UINT winMmeDeviceId = (UINT)((i==-1) ? WAVE_MAPPER : i);
                 PaWinMmeDeviceInfo *wmmeDeviceInfo = &deviceInfoArray[ (*hostApi)->info.deviceCount ];
                 PaDeviceInfo *deviceInfo = &wmmeDeviceInfo->inheritedDeviceInfo;
-                deviceInfo->structVersion = 2;
+                deviceInfo->structVersion = 3;
                 deviceInfo->hostApi = hostApiIndex;
 
                 deviceInfo->maxInputChannels = 0;
@@ -1112,7 +1116,7 @@ PaError PaWinMme_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInd
                 UINT winMmeDeviceId = (UINT)((i==-1) ? WAVE_MAPPER : i);
                 PaWinMmeDeviceInfo *wmmeDeviceInfo = &deviceInfoArray[ (*hostApi)->info.deviceCount ];
                 PaDeviceInfo *deviceInfo = &wmmeDeviceInfo->inheritedDeviceInfo;
-                deviceInfo->structVersion = 2;
+                deviceInfo->structVersion = 3;
                 deviceInfo->hostApi = hostApiIndex;
 
                 deviceInfo->maxInputChannels = 0;
index 69adae9369694aba93608f81cfb9373c8c4414fd..6c138f0dfa2157b0675a612bbb62273602ec690e 100644 (file)
@@ -13,8 +13,9 @@ void printDevices()
         const PaHostApiInfo *hostApiInfo = Pa_GetHostApiInfo( deviceInfo->hostApi );
 
         assert( deviceInfo != 0 );
+        assert( deviceInfo->structVersion >= 3 ); /* should be the case if all APIs have implemented connectionId */
 
-        printf( "%d %s (%s)\n", i, deviceInfo->name, hostApiInfo->name );
+        printf( "%d (conn id: %d) %s (%s)\n", i, deviceInfo->connectionId, deviceInfo->name, hostApiInfo->name );
     }
 }