Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Create request
- if (context->request == NULL)
- {
- ntStatus = WdfRequestCreate(&objectAttributes, NULL, &context->request);
- if (!NT_SUCCESS(ntStatus))
- {
- DbgPrint("WdfRequestCreate failed: %x\n", ntStatus);
- return;
- }
- }
- else
- {
- //Reuse request
- WDF_REQUEST_REUSE_PARAMS paramsR;
- WDF_REQUEST_REUSE_PARAMS_INIT(¶msR, WDF_REQUEST_REUSE_NO_FLAGS, STATUS_SUCCESS);
- ntStatus = WdfRequestReuse(context->request, ¶msR);
- if (!NT_SUCCESS(ntStatus))
- DbgPrint("sendAudioData: WdfRequestReuse failed: %x\n", ntStatus);
- ASSERT(NT_SUCCESS(ntStatus));
- }
- //Create URB structure
- if (context->urbMemory == NULL)
- {
- WDF_OBJECT_ATTRIBUTES_INIT(&objectAttributes);
- objectAttributes.ParentObject = usbDevice;
- ntStatus = WdfUsbTargetDeviceCreateIsochUrb(usbDevice, &objectAttributes, MAX_PAKETS, &context->urbMemory, NULL);
- if (!NT_SUCCESS(ntStatus))
- {
- DbgPrint("sendAudioData: WdfTargetDeviceCreateIsochUrb failed: %x\n", ntStatus);
- return;
- }
- }
- //Create outputBuffer
- ULONG bufferLen = numPackets * numOfSamplesPerPacket * getAudioBufferForChannel(channel)->getSampleSize();
- if (context->dataBuffer == NULL)
- {
- AudioBuffer* buffer = getAudioBufferForChannel(channel);
- PHYSICAL_ADDRESS low;
- RtlZeroMemory(&low, sizeof(PHYSICAL_ADDRESS));
- PHYSICAL_ADDRESS high;
- high.QuadPart = _UI64_MAX;
- PHYSICAL_ADDRESS skip;
- skip.QuadPart = PAGE_SIZE;
- context->dataBuffer = MmAllocatePagesForMdlEx(low, high, skip, buffer->getSampleSize()*buffer->getSize(), MmCached, MM_ALLOCATE_PREFER_CONTIGUOUS);
- }
- PURB urb = (PURB)WdfMemoryGetBuffer(context->urbMemory, NULL);
- urb->UrbIsochronousTransfer.Hdr.Length = GET_ISO_URB_SIZE(numPackets);
- urb->UrbIsochronousTransfer.Hdr.Function = URB_FUNCTION_ISOCH_TRANSFER;
- urb->UrbIsochronousTransfer.PipeHandle = WdfUsbTargetPipeWdmGetPipeHandle(channelEndpoints[channel].dataPipe);
- urb->UrbIsochronousTransfer.TransferFlags = USBD_TRANSFER_DIRECTION_OUT | USBD_START_ISO_TRANSFER_ASAP;
- urb->UrbIsochronousTransfer.TransferBufferLength = bufferLen;
- urb->UrbIsochronousTransfer.NumberOfPackets = numPackets;
- urb->UrbIsochronousTransfer.TransferBufferMDL = context->dataBuffer;
- for (ULONG i = 0; i != numPackets; i++)
- urb->UrbIsochronousTransfer.IsoPacket[i].Offset = i * numOfSamplesPerPacket * getAudioBufferForChannel(channel)->getSampleSize();
- //Copy audio data into buffer
- AudioBuffer* buffer = getAudioBufferForChannel(channel);
- //ToDo: Temporary - in final release shoud be removed - add dummy samples
- buffer->fillBufferWithSine(currentFrequency);
- //I've tried both possibilities - both with the same result
- //BYTE* ioBuff = (BYTE*)MmGetMdlVirtualAddress(context->dataBuffer);
- BYTE* ioBuff = (BYTE*)MmGetSystemAddressForMdlSafe(context->dataBuffer, HighPagePriority);
- //Following 2 lines couses probelm
- memset(ioBuff, 0, bufferLen);
- buffer->popSamples(ioBuff, numOfSamplesPerPacket * numPackets);
- ntStatus = WdfUsbTargetPipeFormatRequestForUrb(channelEndpoints[channel].dataPipe, context->request, context->urbMemory, 0);
- if (!NT_SUCCESS(ntStatus))
- {
- DbgPrint("WdfUsbTargetDeviceFormatRequestForUrb failed: %x\n", ntStatus);
- return;
- }
- SendContext* sContext = &channelEndpoints[channel].sendSpecificContext;
- sContext->device = this;
- sContext->channel = channel;
- WdfRequestSetCompletionRoutine(context->request, sendRequestComplete, sContext);
- if (WdfRequestSend(context->request, WdfUsbTargetPipeGetIoTarget(channelEndpoints[channel].dataPipe), WDF_NO_SEND_OPTIONS) == FALSE)
- {
- ntStatus = WdfRequestGetStatus(context->request);
- DbgPrint("WdfRequestSend failed with status code 0x%x\n", ntStatus);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement