Author: janderwald
Date: Wed Sep 28 20:31:32 2016
New Revision: 72843
URL:
http://svn.reactos.org/svn/reactos?rev=72843&view=rev
Log:
[USBAUDIO]
- implement USBAudioSelectAudioStreamingInterface
Modified:
trunk/reactos/drivers/usb/usbaudio/filter.c
trunk/reactos/drivers/usb/usbaudio/pin.c
trunk/reactos/drivers/usb/usbaudio/usbaudio.c
Modified: trunk/reactos/drivers/usb/usbaudio/filter.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbaudio/filte…
==============================================================================
--- trunk/reactos/drivers/usb/usbaudio/filter.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/usb/usbaudio/filter.c [iso-8859-1] Wed Sep 28 20:31:32 2016
@@ -136,6 +136,7 @@
FilterContext->LowerDevice = Device->NextDeviceObject;
Filter->Context = FilterContext;
+ DPRINT("USBAudioFilterCreate FilterContext %p LowerDevice %p DeviceExtension
%p\n", FilterContext, FilterContext->LowerDevice,
FilterContext->DeviceExtension);
KsAddItemToObjectBag(Filter->Bag, FilterContext, ExFreePool);
return STATUS_SUCCESS;
}
Modified: trunk/reactos/drivers/usb/usbaudio/pin.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbaudio/pin.c…
==============================================================================
--- trunk/reactos/drivers/usb/usbaudio/pin.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/usb/usbaudio/pin.c [iso-8859-1] Wed Sep 28 20:31:32 2016
@@ -10,80 +10,8 @@
#include "usbaudio.h"
NTSTATUS
-NTAPI
-USBAudioPinCreate(
- _In_ PKSPIN Pin,
- _In_ PIRP Irp)
-{
- PKSFILTER Filter;
- PFILTER_CONTEXT FilterContext;
- PPIN_CONTEXT PinContext;
-
- Filter = KsPinGetParentFilter(Pin);
- if (Filter == NULL)
- {
- /* invalid parameter */
- return STATUS_INVALID_PARAMETER;
- }
-
- /* get filter context */
- FilterContext = Filter->Context;
-
- /* allocate pin context */
- PinContext = AllocFunction(sizeof(PIN_CONTEXT));
- if (!PinContext)
- {
- /* no memory*/
- return STATUS_INSUFFICIENT_RESOURCES;
- }
-
- /* init pin context */
- PinContext->DeviceExtension = FilterContext->DeviceExtension;
- PinContext->LowerDevice = FilterContext->LowerDevice;
-
- /* store pin context*/
- Pin->Context = PinContext;
-
- return STATUS_SUCCESS;
-}
-
-NTSTATUS
-NTAPI
-USBAudioPinClose(
- _In_ PKSPIN Pin,
- _In_ PIRP Irp)
-{
- UNIMPLEMENTED
- return STATUS_NOT_IMPLEMENTED;
-}
-
-
-NTSTATUS
-NTAPI
-USBAudioPinProcess(
- _In_ PKSPIN Pin)
-{
- UNIMPLEMENTED
- return STATUS_SUCCESS;
-}
-
-
-VOID
-NTAPI
-USBAudioPinReset(
- _In_ PKSPIN Pin)
-{
- UNIMPLEMENTED
-}
-
-NTSTATUS
-NTAPI
-USBAudioPinSetDataFormat(
- _In_ PKSPIN Pin,
- _In_opt_ PKSDATAFORMAT OldFormat,
- _In_opt_ PKSMULTIPLE_ITEM OldAttributeList,
- _In_ const KSDATARANGE* DataRange,
- _In_opt_ const KSATTRIBUTE_LIST* AttributeRange)
+UsbAudioSetFormat(
+ IN PKSPIN Pin)
{
PURB Urb;
PUCHAR SampleRateBuffer;
@@ -99,14 +27,16 @@
return STATUS_INSUFFICIENT_RESOURCES;
}
- if (IsEqualGUIDAligned(&Pin->ConnectionFormat->MajorFormat,
&KSDATAFORMAT_TYPE_AUDIO) &&
- IsEqualGUIDAligned(&Pin->ConnectionFormat->SubFormat,
&KSDATAFORMAT_SUBTYPE_PCM) &&
+ if (IsEqualGUIDAligned(&Pin->ConnectionFormat->MajorFormat,
&KSDATAFORMAT_TYPE_AUDIO) &&
+ IsEqualGUIDAligned(&Pin->ConnectionFormat->SubFormat,
&KSDATAFORMAT_SUBTYPE_PCM) &&
IsEqualGUIDAligned(&Pin->ConnectionFormat->Specifier,
&KSDATAFORMAT_SPECIFIER_WAVEFORMATEX))
{
WaveFormatEx = (PKSDATAFORMAT_WAVEFORMATEX)Pin->ConnectionFormat;
SampleRateBuffer[0] = (WaveFormatEx->WaveFormatEx.nSamplesPerSec >> 16)
& 0xFF;
SampleRateBuffer[1] = (WaveFormatEx->WaveFormatEx.nSamplesPerSec >> 8)
& 0xFF;
SampleRateBuffer[2] = (WaveFormatEx->WaveFormatEx.nSamplesPerSec >> 0)
& 0xFF;
+
+ /* TODO: verify connection format */
}
else
{
@@ -127,17 +57,17 @@
/* format urb */
UsbBuildVendorRequest(Urb,
- URB_FUNCTION_CLASS_ENDPOINT,
- sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST),
- USBD_TRANSFER_DIRECTION_OUT,
- 0,
- 0x01,
- 0x100,
- 0x81, //bEndpointAddress
- SampleRateBuffer,
- NULL,
- 3,
- NULL);
+ URB_FUNCTION_CLASS_ENDPOINT,
+ sizeof(URB),
+ USBD_TRANSFER_DIRECTION_OUT,
+ 0,
+ 0x01,
+ 0x100,
+ 0x81, //FIXME bEndpointAddress
+ SampleRateBuffer,
+ NULL,
+ 3,
+ NULL);
/* get pin context */
PinContext = Pin->Context;
@@ -152,6 +82,200 @@
}
NTSTATUS
+USBAudioSelectAudioStreamingInterface(
+ IN PDEVICE_EXTENSION DeviceExtension,
+ IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor)
+{
+ PURB Urb;
+ PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
+ NTSTATUS Status;
+
+ /* grab interface descriptor */
+ InterfaceDescriptor = USBD_ParseConfigurationDescriptorEx(ConfigurationDescriptor,
ConfigurationDescriptor, -1, -1, USB_DEVICE_CLASS_AUDIO, -1, -1);
+ if (!InterfaceDescriptor)
+ {
+ /* no such interface */
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ /* select the first interface with audio streaming and non zero num of endpoints */
+ while (InterfaceDescriptor != NULL)
+ {
+ if (InterfaceDescriptor->bInterfaceSubClass == 0x02 /* AUDIO_STREAMING */
&& InterfaceDescriptor->bNumEndpoints > 0)
+ {
+ break;
+ }
+ InterfaceDescriptor =
USBD_ParseConfigurationDescriptorEx(ConfigurationDescriptor,
(PVOID)((ULONG_PTR)InterfaceDescriptor + InterfaceDescriptor->bLength), -1, -1,
USB_DEVICE_CLASS_AUDIO, -1, -1);
+ }
+
+ if (!InterfaceDescriptor)
+ {
+ /* no such interface */
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ Urb =
AllocFunction(GET_SELECT_INTERFACE_REQUEST_SIZE(InterfaceDescriptor->bNumEndpoints));
+ if (!Urb)
+ {
+ /* no memory */
+ return USBD_STATUS_INSUFFICIENT_RESOURCES;
+ }
+
+ /* now prepare interface urb */
+ UsbBuildSelectInterfaceRequest(Urb,
GET_SELECT_INTERFACE_REQUEST_SIZE(InterfaceDescriptor->bNumEndpoints),
DeviceExtension->ConfigurationHandle, InterfaceDescriptor->bInterfaceNumber,
InterfaceDescriptor->bAlternateSetting);
+
+ /* copy interface information */
+ RtlCopyMemory(&Urb->UrbSelectInterface.Interface,
DeviceExtension->InterfaceInfo, DeviceExtension->InterfaceInfo->Length);
+
+ /* set configuration handle */
+ Urb->UrbSelectInterface.ConfigurationHandle =
DeviceExtension->ConfigurationHandle;
+
+ /* now select the interface */
+ Status = SubmitUrbSync(DeviceExtension->LowerDevice, Urb);
+
+ DPRINT1("USBAudioSelectAudioStreamingInterface Status %x UrbStatus %x\n",
Status, Urb->UrbSelectInterface.Hdr.Status);
+
+ /* did it succeeed */
+ if (NT_SUCCESS(Status))
+ {
+ /* update configuration info */
+ ASSERT(Urb->UrbSelectInterface.Interface.Length ==
DeviceExtension->InterfaceInfo->Length);
+ RtlCopyMemory(DeviceExtension->InterfaceInfo,
&Urb->UrbSelectInterface.Interface, Urb->UrbSelectInterface.Interface.Length);
+ }
+
+ /* free urb */
+ FreeFunction(Urb);
+ return Status;
+}
+
+NTSTATUS
+InitCapturePin(
+ IN PKSPIN Pin)
+{
+ NTSTATUS Status;
+
+ /* set sample rate */
+ Status = UsbAudioSetFormat(Pin);
+
+ /* TODO: init pin */
+ return Status;
+}
+
+NTSTATUS
+InitStreamPin(
+ IN PKSPIN Pin)
+{
+ UNIMPLEMENTED
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+
+NTSTATUS
+NTAPI
+USBAudioPinCreate(
+ _In_ PKSPIN Pin,
+ _In_ PIRP Irp)
+{
+ PKSFILTER Filter;
+ PFILTER_CONTEXT FilterContext;
+ PPIN_CONTEXT PinContext;
+ NTSTATUS Status;
+
+ Filter = KsPinGetParentFilter(Pin);
+ if (Filter == NULL)
+ {
+ /* invalid parameter */
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ /* get filter context */
+ FilterContext = Filter->Context;
+
+ /* allocate pin context */
+ PinContext = AllocFunction(sizeof(PIN_CONTEXT));
+ if (!PinContext)
+ {
+ /* no memory*/
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+
+ /* init pin context */
+ PinContext->DeviceExtension = FilterContext->DeviceExtension;
+ PinContext->LowerDevice = FilterContext->LowerDevice;
+
+ /* store pin context*/
+ Pin->Context = PinContext;
+
+ /* select streaming interface */
+ Status = USBAudioSelectAudioStreamingInterface(PinContext->DeviceExtension,
PinContext->DeviceExtension->ConfigurationDescriptor);
+ if (!NT_SUCCESS(Status))
+ {
+ /* failed */
+ return Status;
+ }
+
+ if (Pin->DataFlow == KSPIN_DATAFLOW_OUT)
+ {
+ /* init capture pin */
+ Status = InitCapturePin(Pin);
+ }
+ else
+ {
+ /* audio streaming pin*/
+ Status = InitStreamPin(Pin);
+ }
+
+ return STATUS_SUCCESS;
+}
+
+NTSTATUS
+NTAPI
+USBAudioPinClose(
+ _In_ PKSPIN Pin,
+ _In_ PIRP Irp)
+{
+ UNIMPLEMENTED
+ return STATUS_NOT_IMPLEMENTED;
+}
+
+
+NTSTATUS
+NTAPI
+USBAudioPinProcess(
+ _In_ PKSPIN Pin)
+{
+ return STATUS_SUCCESS;
+}
+
+
+VOID
+NTAPI
+USBAudioPinReset(
+ _In_ PKSPIN Pin)
+{
+ UNIMPLEMENTED
+}
+
+NTSTATUS
+NTAPI
+USBAudioPinSetDataFormat(
+ _In_ PKSPIN Pin,
+ _In_opt_ PKSDATAFORMAT OldFormat,
+ _In_opt_ PKSMULTIPLE_ITEM OldAttributeList,
+ _In_ const KSDATARANGE* DataRange,
+ _In_opt_ const KSATTRIBUTE_LIST* AttributeRange)
+{
+ if (OldFormat == NULL)
+ {
+ /* TODO: verify connection format */
+ UNIMPLEMENTED
+ return STATUS_SUCCESS;
+ }
+
+ return UsbAudioSetFormat(Pin);
+}
+
+NTSTATUS
NTAPI
USBAudioPinSetDeviceState(
_In_ PKSPIN Pin,
Modified: trunk/reactos/drivers/usb/usbaudio/usbaudio.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbaudio/usbau…
==============================================================================
--- trunk/reactos/drivers/usb/usbaudio/usbaudio.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/usb/usbaudio/usbaudio.c [iso-8859-1] Wed Sep 28 20:31:32 2016
@@ -79,14 +79,6 @@
if (Status == STATUS_PENDING)
{
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
- }
-
- // complete request
- IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
- if (Status == STATUS_PENDING)
- {
- // get final status
Status = IoStatus.Status;
}