Commit b77487ae authored by robiwan's avatar robiwan

Committing Lelands patch for WDM-KS, should take care of some of the problems...

Committing Lelands patch for WDM-KS, should take care of some of the problems referenced here http://music.columbia.edu/pipermail/portaudio/2014-August/016246.html

git-svn-id: https://subversion.assembla.com/svn/portaudio/portaudio/trunk@1932 0f58301d-fd10-0410-b4af-bbb618454e57
parent cf397b6d
...@@ -1012,7 +1012,7 @@ static ULONG GetNumberOfConnectionsTo(const KSTOPOLOGY_CONNECTION* pTo, PaWinWdm ...@@ -1012,7 +1012,7 @@ static ULONG GetNumberOfConnectionsTo(const KSTOPOLOGY_CONNECTION* pTo, PaWinWdm
ULONG retval = 0; ULONG retval = 0;
unsigned i; unsigned i;
const KSTOPOLOGY_CONNECTION* connections = (const KSTOPOLOGY_CONNECTION*)(filter->connections + 1); const KSTOPOLOGY_CONNECTION* connections = (const KSTOPOLOGY_CONNECTION*)(filter->connections + 1);
PA_DEBUG(("GetNumberOfConnectionsTo: Checking %u connections...", filter->connections->Count)); PA_DEBUG(("GetNumberOfConnectionsTo: Checking %u connections...\n", filter->connections->Count));
for (i = 0; i < filter->connections->Count; ++i) for (i = 0; i < filter->connections->Count; ++i)
{ {
const KSTOPOLOGY_CONNECTION* pConn = connections + i; const KSTOPOLOGY_CONNECTION* pConn = connections + i;
...@@ -1022,6 +1022,7 @@ static ULONG GetNumberOfConnectionsTo(const KSTOPOLOGY_CONNECTION* pTo, PaWinWdm ...@@ -1022,6 +1022,7 @@ static ULONG GetNumberOfConnectionsTo(const KSTOPOLOGY_CONNECTION* pTo, PaWinWdm
++retval; ++retval;
} }
} }
PA_DEBUG(("GetNumberOfConnectionsTo: Returning %d\n", retval));
return retval; return retval;
} }
...@@ -1031,16 +1032,18 @@ static const KSTOPOLOGY_CONNECTION* FindStartConnectionFrom(ULONG startPin, PaWi ...@@ -1031,16 +1032,18 @@ static const KSTOPOLOGY_CONNECTION* FindStartConnectionFrom(ULONG startPin, PaWi
{ {
unsigned i; unsigned i;
const KSTOPOLOGY_CONNECTION* connections = (const KSTOPOLOGY_CONNECTION*)(filter->connections + 1); const KSTOPOLOGY_CONNECTION* connections = (const KSTOPOLOGY_CONNECTION*)(filter->connections + 1);
PA_DEBUG(("FindStartConnectionFrom: Checking %u connections...", filter->connections->Count)); PA_DEBUG(("FindStartConnectionFrom: Checking %u connections...\n", filter->connections->Count));
for (i = 0; i < filter->connections->Count; ++i) for (i = 0; i < filter->connections->Count; ++i)
{ {
const KSTOPOLOGY_CONNECTION* pConn = connections + i; const KSTOPOLOGY_CONNECTION* pConn = connections + i;
if (pConn->ToNode == KSFILTER_NODE && pConn->ToNodePin == startPin) if (pConn->ToNode == KSFILTER_NODE && pConn->ToNodePin == startPin)
{ {
PA_DEBUG(("FindStartConnectionFrom: returning %p\n", pConn));
return pConn; return pConn;
} }
} }
PA_DEBUG(("FindStartConnectionFrom: returning NULL\n"));
assert(FALSE); assert(FALSE);
return 0; return 0;
} }
...@@ -1049,26 +1052,36 @@ static const KSTOPOLOGY_CONNECTION* FindStartConnectionTo(ULONG startPin, PaWinW ...@@ -1049,26 +1052,36 @@ static const KSTOPOLOGY_CONNECTION* FindStartConnectionTo(ULONG startPin, PaWinW
{ {
unsigned i; unsigned i;
const KSTOPOLOGY_CONNECTION* connections = (const KSTOPOLOGY_CONNECTION*)(filter->connections + 1); const KSTOPOLOGY_CONNECTION* connections = (const KSTOPOLOGY_CONNECTION*)(filter->connections + 1);
PA_DEBUG(("FindStartConnectionTo: Checking %u connections...", filter->connections->Count)); PA_DEBUG(("FindStartConnectionTo: Checking %u connections...\n", filter->connections->Count));
for (i = 0; i < filter->connections->Count; ++i) for (i = 0; i < filter->connections->Count; ++i)
{ {
const KSTOPOLOGY_CONNECTION* pConn = connections + i; const KSTOPOLOGY_CONNECTION* pConn = connections + i;
if (pConn->FromNode == KSFILTER_NODE && pConn->FromNodePin == startPin) if (pConn->FromNode == KSFILTER_NODE && pConn->FromNodePin == startPin)
{ {
PA_DEBUG(("FindStartConnectionTo: returning %p\n", pConn));
return pConn; return pConn;
} }
} }
PA_DEBUG(("FindStartConnectionTo: returning NULL\n"));
assert(FALSE); assert(FALSE);
return 0; return 0;
} }
static ULONG GetConnectedPin(ULONG startPin, BOOL forward, PaWinWdmFilter* filter, int muxPosition, ULONG *muxInputPinId, ULONG *muxNodeId) static ULONG GetConnectedPin(ULONG startPin, BOOL forward, PaWinWdmFilter* filter, int muxPosition, ULONG *muxInputPinId, ULONG *muxNodeId)
{ {
int limit=1000;
const KSTOPOLOGY_CONNECTION *conn = NULL; const KSTOPOLOGY_CONNECTION *conn = NULL;
TFnGetConnection fnGetConnection = forward ? GetConnectionTo : GetConnectionFrom ; TFnGetConnection fnGetConnection = forward ? GetConnectionTo : GetConnectionFrom ;
PA_LOGE_;
while (1) while (1)
{ {
limit--;
if (limit == 0) {
PA_DEBUG(("GetConnectedPin: LOOP LIMIT REACHED\n"));
break;
}
if (conn == NULL) if (conn == NULL)
{ {
conn = forward ? FindStartConnectionTo(startPin, filter) : FindStartConnectionFrom(startPin, filter); conn = forward ? FindStartConnectionTo(startPin, filter) : FindStartConnectionFrom(startPin, filter);
...@@ -1114,6 +1127,7 @@ static ULONG GetConnectedPin(ULONG startPin, BOOL forward, PaWinWdmFilter* filte ...@@ -1114,6 +1127,7 @@ static ULONG GetConnectedPin(ULONG startPin, BOOL forward, PaWinWdmFilter* filte
} }
} }
} }
PA_LOGL_;
return KSFILTER_NODE; return KSFILTER_NODE;
} }
...@@ -1123,6 +1137,7 @@ static void DumpConnectionsAndNodes(PaWinWdmFilter* filter) ...@@ -1123,6 +1137,7 @@ static void DumpConnectionsAndNodes(PaWinWdmFilter* filter)
const KSTOPOLOGY_CONNECTION* connections = (const KSTOPOLOGY_CONNECTION*)(filter->connections + 1); const KSTOPOLOGY_CONNECTION* connections = (const KSTOPOLOGY_CONNECTION*)(filter->connections + 1);
const GUID* nodes = (const GUID*)(filter->nodes + 1); const GUID* nodes = (const GUID*)(filter->nodes + 1);
PA_LOGE_;
PA_DEBUG(("DumpConnectionsAndNodes: connections=%d, nodes=%d\n", filter->connections->Count, filter->nodes->Count)); PA_DEBUG(("DumpConnectionsAndNodes: connections=%d, nodes=%d\n", filter->connections->Count, filter->nodes->Count));
for (i=0; i < filter->connections->Count; ++i) for (i=0; i < filter->connections->Count; ++i)
...@@ -1147,6 +1162,7 @@ static void DumpConnectionsAndNodes(PaWinWdmFilter* filter) ...@@ -1147,6 +1162,7 @@ static void DumpConnectionsAndNodes(PaWinWdmFilter* filter)
pConn->Data4[6], pConn->Data4[7] pConn->Data4[6], pConn->Data4[7]
)); ));
} }
PA_LOGL_;
} }
...@@ -1196,6 +1212,7 @@ static PaError GetNameFromCategory(const GUID* pGUID, BOOL input, wchar_t* name, ...@@ -1196,6 +1212,7 @@ static PaError GetNameFromCategory(const GUID* pGUID, BOOL input, wchar_t* name,
PaError result = paUnanticipatedHostError; PaError result = paUnanticipatedHostError;
USHORT usbTerminalGUID = (USHORT)(pGUID->Data1 - 0xDFF219E0); USHORT usbTerminalGUID = (USHORT)(pGUID->Data1 - 0xDFF219E0);
PA_LOGE_;
if (input && usbTerminalGUID >= 0x301 && usbTerminalGUID < 0x400) if (input && usbTerminalGUID >= 0x301 && usbTerminalGUID < 0x400)
{ {
/* Output terminal name for an input !? Set it to Line! */ /* Output terminal name for an input !? Set it to Line! */
...@@ -1235,6 +1252,7 @@ static PaError GetNameFromCategory(const GUID* pGUID, BOOL input, wchar_t* name, ...@@ -1235,6 +1252,7 @@ static PaError GetNameFromCategory(const GUID* pGUID, BOOL input, wchar_t* name,
{ {
PaWinWDM_SetLastErrorInfo(result, "GetNameFromCategory: usbTerminalGUID = %04X ", usbTerminalGUID); PaWinWDM_SetLastErrorInfo(result, "GetNameFromCategory: usbTerminalGUID = %04X ", usbTerminalGUID);
} }
PA_LOGL_;
return result; return result;
} }
...@@ -1633,6 +1651,8 @@ static PaWinWdmPin* PinNew(PaWinWdmFilter* parentFilter, unsigned long pinId, Pa ...@@ -1633,6 +1651,8 @@ static PaWinWdmPin* PinNew(PaWinWdmFilter* parentFilter, unsigned long pinId, Pa
else else
{ {
KSPIN_PHYSICALCONNECTION* pc = (KSPIN_PHYSICALCONNECTION*)PaUtil_AllocateMemory(cbBytes + 2); KSPIN_PHYSICALCONNECTION* pc = (KSPIN_PHYSICALCONNECTION*)PaUtil_AllocateMemory(cbBytes + 2);
ULONG pcPin;
wchar_t symbLinkName[MAX_PATH];
PA_DEBUG(("PinNew: Physical connection found!\n")); PA_DEBUG(("PinNew: Physical connection found!\n"));
if (pc == NULL) if (pc == NULL)
{ {
...@@ -1647,10 +1667,18 @@ static PaWinWdmPin* PinNew(PaWinWdmFilter* parentFilter, unsigned long pinId, Pa ...@@ -1647,10 +1667,18 @@ static PaWinWdmPin* PinNew(PaWinWdmFilter* parentFilter, unsigned long pinId, Pa
cbBytes, cbBytes,
NULL NULL
); );
if (result == paNoError)
{ pcPin = pc->Pin;
wchar_t symbLinkName[MAX_PATH];
wcsncpy(symbLinkName, pc->SymbolicLinkName, MAX_PATH); wcsncpy(symbLinkName, pc->SymbolicLinkName, MAX_PATH);
PaUtil_FreeMemory( pc );
if (result != paNoError)
{
/* Shouldn't happen, but fail if it does */
PA_DEBUG(("PinNew: failed to retrieve physical connection!\n"));
goto error;
}
if (symbLinkName[1] == TEXT('?')) if (symbLinkName[1] == TEXT('?'))
{ {
symbLinkName[1] = TEXT('\\'); symbLinkName[1] = TEXT('\\');
...@@ -1692,7 +1720,7 @@ static PaWinWdmPin* PinNew(PaWinWdmFilter* parentFilter, unsigned long pinId, Pa ...@@ -1692,7 +1720,7 @@ static PaWinWdmPin* PinNew(PaWinWdmFilter* parentFilter, unsigned long pinId, Pa
PA_DEBUG(("PinNew: Checking for output endpoint pin id...\n")); PA_DEBUG(("PinNew: Checking for output endpoint pin id...\n"));
endpointPinId = GetConnectedPin(pc->Pin, TRUE, pin->parentFilter->topologyFilter, -1, NULL, NULL); endpointPinId = GetConnectedPin(pcPin, TRUE, pin->parentFilter->topologyFilter, -1, NULL, NULL);
if (endpointPinId == KSFILTER_NODE) if (endpointPinId == KSFILTER_NODE)
{ {
...@@ -1737,23 +1765,24 @@ static PaWinWdmPin* PinNew(PaWinWdmFilter* parentFilter, unsigned long pinId, Pa ...@@ -1737,23 +1765,24 @@ static PaWinWdmPin* PinNew(PaWinWdmFilter* parentFilter, unsigned long pinId, Pa
{ {
result = GetNameFromCategory(&category, (pin->dataFlow == KSPIN_DATAFLOW_OUT), pin->friendlyName, MAX_PATH); result = GetNameFromCategory(&category, (pin->dataFlow == KSPIN_DATAFLOW_OUT), pin->friendlyName, MAX_PATH);
} }
}
/* Make sure we get a name for the pin */
if (wcslen(pin->friendlyName) == 0) if (wcslen(pin->friendlyName) == 0)
{ {
wcscpy(pin->friendlyName, L"Output"); wcscpy(pin->friendlyName, kOutputName);
} }
#ifdef UNICODE #ifdef UNICODE
PA_DEBUG(("PinNew: Pin name '%s'\n", pin->friendlyName)); PA_DEBUG(("PinNew: Pin name '%s'\n", pin->friendlyName));
#else #else
PA_DEBUG(("PinNew: Pin name '%S'\n", pin->friendlyName)); PA_DEBUG(("PinNew: Pin name '%S'\n", pin->friendlyName));
#endif #endif
}
/* Set endpoint pin ID (this is the topology INPUT pin, since portmixer will always traverse the /* Set endpoint pin ID (this is the topology INPUT pin, since portmixer will always traverse the
filter in audio streaming direction, see http://msdn.microsoft.com/en-us/library/windows/hardware/ff536331(v=vs.85).aspx filter in audio streaming direction, see http://msdn.microsoft.com/en-us/library/windows/hardware/ff536331(v=vs.85).aspx
for more information) for more information)
*/ */
pin->endpointPinId = pc->Pin; pin->endpointPinId = pcPin;
} }
else else
{ {
...@@ -1765,14 +1794,13 @@ static PaWinWdmPin* PinNew(PaWinWdmFilter* parentFilter, unsigned long pinId, Pa ...@@ -1765,14 +1794,13 @@ static PaWinWdmPin* PinNew(PaWinWdmFilter* parentFilter, unsigned long pinId, Pa
ULONG muxNodeIdTest = (unsigned)-1; ULONG muxNodeIdTest = (unsigned)-1;
PA_DEBUG(("PinNew: Checking for input endpoint pin id (%d)...\n", i)); PA_DEBUG(("PinNew: Checking for input endpoint pin id (%d)...\n", i));
endpointPinId = GetConnectedPin(pc->Pin, endpointPinId = GetConnectedPin(pcPin,
FALSE, FALSE,
pin->parentFilter->topologyFilter, pin->parentFilter->topologyFilter,
(int)i, (int)i,
NULL, NULL,
&muxNodeIdTest); &muxNodeIdTest);
if (endpointPinId == KSFILTER_NODE) if (endpointPinId == KSFILTER_NODE)
{ {
/* We're done */ /* We're done */
...@@ -1874,7 +1902,7 @@ static PaWinWdmPin* PinNew(PaWinWdmFilter* parentFilter, unsigned long pinId, Pa ...@@ -1874,7 +1902,7 @@ static PaWinWdmPin* PinNew(PaWinWdmFilter* parentFilter, unsigned long pinId, Pa
} }
} }
endpointPinId = GetConnectedPin(pc->Pin, endpointPinId = GetConnectedPin(pcPin,
FALSE, FALSE,
pin->parentFilter->topologyFilter, pin->parentFilter->topologyFilter,
muxPos, muxPos,
...@@ -1936,8 +1964,6 @@ static PaWinWdmPin* PinNew(PaWinWdmFilter* parentFilter, unsigned long pinId, Pa ...@@ -1936,8 +1964,6 @@ static PaWinWdmPin* PinNew(PaWinWdmFilter* parentFilter, unsigned long pinId, Pa
} }
} }
} }
PaUtil_FreeMemory(pc);
}
} }
else else
{ {
...@@ -1966,18 +1992,14 @@ error: ...@@ -1966,18 +1992,14 @@ error:
Error cleanup Error cleanup
*/ */
PaUtil_FreeMemory( item );
if( pin )
{
if (pin->parentFilter->topologyFilter && pin->parentFilter->topologyFilter->handle != NULL) if (pin->parentFilter->topologyFilter && pin->parentFilter->topologyFilter->handle != NULL)
{ {
FilterRelease(pin->parentFilter->topologyFilter); FilterRelease(pin->parentFilter->topologyFilter);
} }
PaUtil_FreeMemory( pin->pinConnect ); PaUtil_FreeMemory( item );
PaUtil_FreeMemory( pin->dataRangesItem ); PinFree(pin);
PaUtil_FreeMemory( pin );
}
*error = result; *error = result;
PA_LOGL_; PA_LOGL_;
return NULL; return NULL;
...@@ -2264,6 +2286,8 @@ static PaError PinQueryNotificationSupport(PaWinWdmPin* pPin, BOOL* pbResult) ...@@ -2264,6 +2286,8 @@ static PaError PinQueryNotificationSupport(PaWinWdmPin* pPin, BOOL* pbResult)
PaError result = paNoError; PaError result = paNoError;
KSPROPERTY propIn; KSPROPERTY propIn;
PA_LOGE_;
propIn.Set = KSPROPSETID_RtAudio; propIn.Set = KSPROPSETID_RtAudio;
propIn.Id = 8; /* = KSPROPERTY_RTAUDIO_QUERY_NOTIFICATION_SUPPORT */ propIn.Id = 8; /* = KSPROPERTY_RTAUDIO_QUERY_NOTIFICATION_SUPPORT */
propIn.Flags = KSPROPERTY_TYPE_GET; propIn.Flags = KSPROPERTY_TYPE_GET;
...@@ -2280,8 +2304,8 @@ static PaError PinQueryNotificationSupport(PaWinWdmPin* pPin, BOOL* pbResult) ...@@ -2280,8 +2304,8 @@ static PaError PinQueryNotificationSupport(PaWinWdmPin* pPin, BOOL* pbResult)
PA_DEBUG(("Failed PinQueryNotificationSupport\n")); PA_DEBUG(("Failed PinQueryNotificationSupport\n"));
} }
PA_LOGL_;
return result; return result;
} }
static PaError PinGetBufferWithNotification(PaWinWdmPin* pPin, void** pBuffer, DWORD* pRequestedBufSize, BOOL* pbCallMemBarrier) static PaError PinGetBufferWithNotification(PaWinWdmPin* pPin, void** pBuffer, DWORD* pRequestedBufSize, BOOL* pbCallMemBarrier)
...@@ -2290,6 +2314,8 @@ static PaError PinGetBufferWithNotification(PaWinWdmPin* pPin, void** pBuffer, D ...@@ -2290,6 +2314,8 @@ static PaError PinGetBufferWithNotification(PaWinWdmPin* pPin, void** pBuffer, D
KSRTAUDIO_BUFFER_PROPERTY_WITH_NOTIFICATION propIn; KSRTAUDIO_BUFFER_PROPERTY_WITH_NOTIFICATION propIn;
KSRTAUDIO_BUFFER propOut; KSRTAUDIO_BUFFER propOut;
PA_LOGE_;
propIn.BaseAddress = 0; propIn.BaseAddress = 0;
propIn.NotificationCount = 2; propIn.NotificationCount = 2;
propIn.RequestedBufferSize = *pRequestedBufSize; propIn.RequestedBufferSize = *pRequestedBufSize;
...@@ -2315,6 +2341,7 @@ static PaError PinGetBufferWithNotification(PaWinWdmPin* pPin, void** pBuffer, D ...@@ -2315,6 +2341,7 @@ static PaError PinGetBufferWithNotification(PaWinWdmPin* pPin, void** pBuffer, D
PA_DEBUG(("Failed to get buffer with notification\n")); PA_DEBUG(("Failed to get buffer with notification\n"));
} }
PA_LOGL_;
return result; return result;
} }
...@@ -2324,6 +2351,8 @@ static PaError PinGetBufferWithoutNotification(PaWinWdmPin* pPin, void** pBuffer ...@@ -2324,6 +2351,8 @@ static PaError PinGetBufferWithoutNotification(PaWinWdmPin* pPin, void** pBuffer
KSRTAUDIO_BUFFER_PROPERTY propIn; KSRTAUDIO_BUFFER_PROPERTY propIn;
KSRTAUDIO_BUFFER propOut; KSRTAUDIO_BUFFER propOut;
PA_LOGE_;
propIn.BaseAddress = NULL; propIn.BaseAddress = NULL;
propIn.RequestedBufferSize = *pRequestedBufSize; propIn.RequestedBufferSize = *pRequestedBufSize;
propIn.Property.Set = KSPROPSETID_RtAudio; propIn.Property.Set = KSPROPSETID_RtAudio;
...@@ -2348,6 +2377,7 @@ static PaError PinGetBufferWithoutNotification(PaWinWdmPin* pPin, void** pBuffer ...@@ -2348,6 +2377,7 @@ static PaError PinGetBufferWithoutNotification(PaWinWdmPin* pPin, void** pBuffer
PA_DEBUG(("Failed to get buffer without notification\n")); PA_DEBUG(("Failed to get buffer without notification\n"));
} }
PA_LOGL_;
return result; return result;
} }
...@@ -2365,9 +2395,17 @@ requested buffer size on multiples of 128 bytes: ...@@ -2365,9 +2395,17 @@ requested buffer size on multiples of 128 bytes:
static PaError PinGetBuffer(PaWinWdmPin* pPin, void** pBuffer, DWORD* pRequestedBufSize, BOOL* pbCallMemBarrier) static PaError PinGetBuffer(PaWinWdmPin* pPin, void** pBuffer, DWORD* pRequestedBufSize, BOOL* pbCallMemBarrier)
{ {
PaError result = paNoError; PaError result = paNoError;
int limit = 1000;
PA_LOGE_;
while (1) while (1)
{ {
limit--;
if (limit == 0) {
PA_DEBUG(("PinGetBuffer: LOOP LIMIT REACHED\n"));
break;
}
if (pPin->pinKsSubType != SubType_kPolled) if (pPin->pinKsSubType != SubType_kPolled)
{ {
/* In case of unknown (or notification), we try both modes */ /* In case of unknown (or notification), we try both modes */
...@@ -2410,6 +2448,8 @@ static PaError PinGetBuffer(PaWinWdmPin* pPin, void** pBuffer, DWORD* pRequested ...@@ -2410,6 +2448,8 @@ static PaError PinGetBuffer(PaWinWdmPin* pPin, void** pBuffer, DWORD* pRequested
} }
} }
PA_LOGL_;
return result; return result;
} }
...@@ -2424,7 +2464,7 @@ static PaError PinRegisterPositionRegister(PaWinWdmPin* pPin) ...@@ -2424,7 +2464,7 @@ static PaError PinRegisterPositionRegister(PaWinWdmPin* pPin)
propIn.BaseAddress = NULL; propIn.BaseAddress = NULL;
propIn.Property.Set = KSPROPSETID_RtAudio; propIn.Property.Set = KSPROPSETID_RtAudio;
propIn.Property.Id = KSPROPERTY_RTAUDIO_POSITIONREGISTER; propIn.Property.Id = KSPROPERTY_RTAUDIO_POSITIONREGISTER;
propIn.Property.Flags = KSPROPERTY_TYPE_GET; propIn.Property.Flags = KSPROPERTY_TYPE_SET;
result = WdmSyncIoctl(pPin->handle, IOCTL_KS_PROPERTY, result = WdmSyncIoctl(pPin->handle, IOCTL_KS_PROPERTY,
&propIn, &propIn,
...@@ -2808,7 +2848,7 @@ error: ...@@ -2808,7 +2848,7 @@ error:
{ {
if (filter->pins[pinId]) if (filter->pins[pinId])
{ {
PaUtil_FreeMemory(filter->pins[pinId]); PinFree(filter->pins[pinId]);
filter->pins[pinId] = 0; filter->pins[pinId] = 0;
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment