📄 isochapi.c
字号:
// free up resources
CloseHandle(hDevice);
}
else {
dwRet = GetLastError();
TRACE(TL_ERROR, (hWnd, "Error = 0x%x\r\n", dwRet));
}
TRACE(TL_TRACE, (hWnd, "Exit IsochQueryCurrentCycleTime = %d\r\n", dwRet));
return(dwRet);
} // IsochQueryCurrentCycleTime
ULONG
WINAPI
IsochQueryResources(
HWND hWnd,
PSTR szDeviceName,
PISOCH_QUERY_RESOURCES isochQueryResources
)
{
HANDLE hDevice;
DWORD dwRet, dwBytesRet;
TRACE(TL_TRACE, (hWnd, "Enter IsochQueryResources\r\n"));
TRACE(TL_TRACE, (hWnd, "fulSpeed = 0x%x\r\n", isochQueryResources->fulSpeed));
hDevice = OpenDevice(hWnd, szDeviceName, FALSE);
if (hDevice != INVALID_HANDLE_VALUE) {
dwRet = DeviceIoControl( hDevice,
IOCTL_ISOCH_QUERY_RESOURCES,
isochQueryResources,
sizeof(ISOCH_QUERY_RESOURCES),
isochQueryResources,
sizeof(ISOCH_QUERY_RESOURCES),
&dwBytesRet,
NULL
);
if (dwRet) {
dwRet = ERROR_SUCCESS;
TRACE(TL_TRACE, (hWnd, "BytesPerFrameAvailable = 0x%x\r\n", isochQueryResources->BytesPerFrameAvailable));
TRACE(TL_TRACE, (hWnd, "ChannelsAvailable.LowPart = 0x%x\r\n", isochQueryResources->ChannelsAvailable.LowPart));
TRACE(TL_TRACE, (hWnd, "ChannelsAvailable.HighPart = 0x%x\r\n", isochQueryResources->ChannelsAvailable.HighPart));
}
else {
dwRet = GetLastError();
TRACE(TL_ERROR, (hWnd, "Error = 0x%x\r\n", dwRet));
}
// free up resources
CloseHandle(hDevice);
}
else {
dwRet = GetLastError();
TRACE(TL_ERROR, (hWnd, "Error = 0x%x\r\n", dwRet));
}
TRACE(TL_TRACE, (hWnd, "Exit IsochQueryResources = %d\r\n", dwRet));
return(dwRet);
} // IsochQueryResources
ULONG
WINAPI
IsochSetChannelBandwidth(
HWND hWnd,
PSTR szDeviceName,
PISOCH_SET_CHANNEL_BANDWIDTH isochSetChannelBandwidth
)
{
HANDLE hDevice;
DWORD dwRet, dwBytesRet;
TRACE(TL_TRACE, (hWnd, "Enter IsochSetChannelBandwidth\r\n"));
TRACE(TL_TRACE, (hWnd, "hBandwidth = 0x%x\r\n", isochSetChannelBandwidth->hBandwidth));
TRACE(TL_TRACE, (hWnd, "nMaxBytesPerFrame = 0x%x\r\n", isochSetChannelBandwidth->nMaxBytesPerFrame));
hDevice = OpenDevice(hWnd, szDeviceName, FALSE);
if (hDevice != INVALID_HANDLE_VALUE) {
dwRet = DeviceIoControl( hDevice,
IOCTL_ISOCH_SET_CHANNEL_BANDWIDTH,
isochSetChannelBandwidth,
sizeof(ISOCH_SET_CHANNEL_BANDWIDTH),
NULL,
0,
&dwBytesRet,
NULL
);
if (!dwRet) {
dwRet = GetLastError();
TRACE(TL_ERROR, (hWnd, "Error = 0x%x\r\n", dwRet));
}
else {
dwRet = ERROR_SUCCESS;
}
// free up resources
CloseHandle(hDevice);
}
else {
dwRet = GetLastError();
TRACE(TL_ERROR, (hWnd, "Error = 0x%x\r\n", dwRet));
}
TRACE(TL_TRACE, (hWnd, "Exit IsochSetChannelBandwidth = %d\r\n", dwRet));
return(dwRet);
} // IsochSetChannelBandwidth
ULONG
WINAPI
IsochStop(
HWND hWnd,
PSTR szDeviceName,
PISOCH_STOP isochStop
)
{
HANDLE hDevice;
DWORD dwRet, dwBytesRet;
TRACE(TL_TRACE, (hWnd, "Enter IsochStop\r\n"));
TRACE(TL_TRACE, (hWnd, "hResource = %p\r\n", isochStop->hResource));
TRACE(TL_TRACE, (hWnd, "fulFlags = 0x%x\r\n", isochStop->fulFlags));
hDevice = OpenDevice(hWnd, szDeviceName, FALSE);
if (hDevice != INVALID_HANDLE_VALUE) {
dwRet = DeviceIoControl( hDevice,
IOCTL_ISOCH_STOP,
isochStop,
sizeof(ISOCH_STOP),
NULL,
0,
&dwBytesRet,
NULL
);
if (!dwRet) {
dwRet = GetLastError();
TRACE(TL_ERROR, (hWnd, "Error = 0x%x\r\n", dwRet));
}
else {
dwRet = ERROR_SUCCESS;
}
// free up resources
CloseHandle(hDevice);
}
else {
dwRet = GetLastError();
TRACE(TL_ERROR, (hWnd, "Error = 0x%x\r\n", dwRet));
}
TRACE(TL_TRACE, (hWnd, "Exit IsochStop = %d\r\n", dwRet));
return(dwRet);
} // IsochStop
ULONG
WINAPI
IsochTalk(
HWND hWnd,
PSTR szDeviceName,
PISOCH_TALK isochTalk
)
{
HANDLE hDevice;
DWORD dwRet, dwBytesRet;
TRACE(TL_TRACE, (hWnd, "Enter IsochTalk\r\n"));
TRACE(TL_TRACE, (hWnd, "hResource = %p\r\n", isochTalk->hResource));
TRACE(TL_TRACE, (hWnd, "fulFlags = 0x%x\r\n", isochTalk->fulFlags));
TRACE(TL_TRACE, (hWnd, "StartTime.CL_CycleOffset = 0x%x\r\n", isochTalk->StartTime.CL_CycleOffset));
TRACE(TL_TRACE, (hWnd, "StartTime.CL_CycleCount = 0x%x\r\n", isochTalk->StartTime.CL_CycleCount));
TRACE(TL_TRACE, (hWnd, "StartTime.CL_SecondCount = 0x%x\r\n", isochTalk->StartTime.CL_SecondCount));
hDevice = OpenDevice(hWnd, szDeviceName, FALSE);
if (hDevice != INVALID_HANDLE_VALUE) {
dwRet = DeviceIoControl( hDevice,
IOCTL_ISOCH_TALK,
isochTalk,
sizeof(ISOCH_TALK),
NULL,
0,
&dwBytesRet,
NULL
);
if (!dwRet) {
dwRet = GetLastError();
TRACE(TL_ERROR, (hWnd, "Error = 0x%x\r\n", dwRet));
}
else {
dwRet = ERROR_SUCCESS;
}
// free up resources
CloseHandle(hDevice);
}
else {
dwRet = GetLastError();
TRACE(TL_ERROR, (hWnd, "Error = 0x%x\r\n", dwRet));
}
TRACE(TL_TRACE, (hWnd, "Exit IsochTalk = %d\r\n", dwRet));
return(dwRet);
} // IsochTalk
void
WINAPI
IsochStartLoopback(
HWND hWnd,
PSTR szDeviceName,
PISOCH_LOOPBACK_PARAMS isochLoopbackParams
)
{
isochLoopbackParams->szDeviceName = szDeviceName;
isochLoopbackParams->hWnd = hWnd;
isochLoopbackParams->bKill = FALSE;
isochLoopbackParams->bLoopback = TRUE;
isochLoopbackParams->hThread = CreateThread( NULL,
0,
IsochAttachThread,
(LPVOID) isochLoopbackParams,
0,
&isochLoopbackParams->ThreadId
);
} // IsochStartLoopback
void
WINAPI
IsochStopLoopback(
PISOCH_LOOPBACK_PARAMS isochLoopbackParams
)
{
// kill the thread
isochLoopbackParams->bKill = TRUE;
// wait for the running thread to exit before returning
WaitForSingleObjectEx(isochLoopbackParams->hThread,
INFINITE,
FALSE);
// close the handle
CloseHandle(isochLoopbackParams->hThread);
return;
} // IsochStopLoopback
DWORD
WINAPI
IsochAttachThread(
LPVOID lpParameter
)
{
PISOCH_LOOPBACK_PARAMS pIsochLoopbackParams;
PISOCH_ATTACH_BUFFERS pIsochAttachBuffers;
ISOCH_ATTACH_BUFFERS isochAttachBuffers;
RING3_ISOCH_DESCRIPTOR R3_IsochDescriptor;
PRING3_ISOCH_DESCRIPTOR pR3TempDescriptor;
HANDLE hDevice;
DWORD dwRet, dwBytesRet;
ULONG ulBufferSize;
OVERLAPPED overLapped;
BOOLEAN bIsochTalk = FALSE;
BOOLEAN bIsochListen = FALSE;
ULONG i, n;
TRACE(TL_TRACE, (NULL, "Enter IsochAttachThread\r\n"));
// get pointer to our thread parameters
pIsochLoopbackParams = (PISOCH_LOOPBACK_PARAMS)lpParameter;
// reset our pass / fail parameteres
pIsochLoopbackParams->ulFail = 0;
pIsochLoopbackParams->ulPass = 0;
pIsochLoopbackParams->ulIterations = 0;
isochAttachBuffers = pIsochLoopbackParams->isochAttachBuffers;
R3_IsochDescriptor = isochAttachBuffers.R3_IsochDescriptor[0];
// try to open the device
hDevice = OpenDevice(pIsochLoopbackParams->hWnd, pIsochLoopbackParams->szDeviceName, TRUE);
// device opened, so let's do loopback
if (hDevice != INVALID_HANDLE_VALUE) {
//
// if the bAutoAlloc flag is set, that means that we allocate according to
// the first descriptor. we assume there's only one configured descriptor
//
if (pIsochLoopbackParams->bAutoAlloc) {
// lets calculate the buffer size
ulBufferSize = sizeof(ISOCH_ATTACH_BUFFERS) +
(R3_IsochDescriptor.ulLength*isochAttachBuffers.nNumberOfDescriptors) +
(sizeof(RING3_ISOCH_DESCRIPTOR)*(isochAttachBuffers.nNumberOfDescriptors-1));
pIsochAttachBuffers = (PISOCH_ATTACH_BUFFERS)LocalAlloc(LPTR, ulBufferSize);
if (!pIsochAttachBuffers) {
pIsochLoopbackParams->bKill = TRUE;
goto Exit_IsochAttachThread;
}
ZeroMemory(pIsochAttachBuffers, ulBufferSize);
*pIsochAttachBuffers = isochAttachBuffers;
//
// now we need to setup each descriptor
//
pR3TempDescriptor = &pIsochAttachBuffers->R3_IsochDescriptor[0];
for (i=0; i < isochAttachBuffers.nNumberOfDescriptors; i++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -