I am so sorry for not mentioning the environment. I am tesing it with a typical Windows XP sp2 and using iMic USB audio device.
The basic code frame is that
NTSTATUS DriverEntry ( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath )
{
…
DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = USBMonInternalIOCTL;
…
}
NTSTATUS USBMonInternalIOCTL ( IN PDEVICE_OBJECT fdo, IN PIRP Irp )
{
…
stack = IoGetCurrentIrpStackLocation(Irp);
pdx = (PDEVICE_EXTENSION) fdo->DeviceExtension;
dwControlCode = stack->Parameters.DeviceIoControl.IoControlCode;
if( IOCTL_INTERNAL_USB_SUBMIT_URB == dwControlCode)
{
IoCopyCurrentIrpStackLocationToNext(Irp);
IoSetCompletionRoutine(Irp, InternalIOCTLCompletion, …);
ntStatus = IoCallDriver(pdx->LowerDeviceObject, Irp);
}
}
NTSTATUS InternalIOCTLCompletion
(IN PDEVICE_OBJECT fdo, IN PIRP Irp, IN PVOID Context )
{
if ( IOCTL_INTERNAL_USB_SUBMIT_URB == dwControlCode )
{
pUrb = (PURB)stack->Parameters.Others.Argument1;
if(pIsochTransfer->Hdr.Length < sizeof(struct _URB_ISOCH_TRANSFER ))
{
return;
}
bReadFromDevice = (BOOLEAN)(pIsochTransfer->TransferFlags & USBD_TRANSFER_DIRECTION_IN);
<<< do some work for massaging Data. >>>.
}
}
A pretty simple code structure.
First, I want to see if I can put all 0’s in the buffer. So I put all 0’s in the buffer at the length of 480, then some of garbage data come out at the end of 462 samples with the size of 18. But If I clean it with 500 or at least 498(480+18) Everything is cleaned.
Look like below
------------------------------a;skjfeijfiewj------------------------------a;skjfeijfiewj
|<--------1’st frame------------------->|<-------------2’nd frame--------------->|
|<---------------------------------------->| 480 samples
|<------------->| 18 samples
So that’s why I wonder if the USB dvier is skipping data in upper level.