From 1ac7d54efd5afa907946e51324c40682c7fc6114 Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Wed, 26 Oct 2016 18:09:19 +0000 Subject: [PATCH] [USBAUDIO] - implement audio volume property handler svn path=/trunk/; revision=73042 --- reactos/drivers/usb/usbaudio/filter.c | 86 +++++++++++++++++++++++-- reactos/drivers/usb/usbaudio/pin.c | 58 ----------------- reactos/drivers/usb/usbaudio/usbaudio.h | 2 - 3 files changed, 81 insertions(+), 65 deletions(-) diff --git a/reactos/drivers/usb/usbaudio/filter.c b/reactos/drivers/usb/usbaudio/filter.c index d066af07507..2b074c152d0 100644 --- a/reactos/drivers/usb/usbaudio/filter.c +++ b/reactos/drivers/usb/usbaudio/filter.c @@ -157,7 +157,6 @@ UsbAudioGetSetProperty( /* submit urb */ Status = SubmitUrbSync(DeviceObject, Urb); - DPRINT1("UsbAudioGetSetProperty Status %x\n", Status); FreeFunction(Urb); return Status; } @@ -215,12 +214,12 @@ FilterAudioMuteHandler( FeatureUnitDescriptor = (PUSB_AUDIO_CONTROL_FEATURE_UNIT_DESCRIPTOR)NodeContext->Descriptor; if (Property->NodeProperty.Property.Flags & KSPROPERTY_TYPE_GET) { - Status = UsbAudioGetSetProperty(FilterContext->DeviceExtension->LowerDevice, 0x81, 0x100, FeatureUnitDescriptor->bUnitID << 8, Data, 1, USBD_TRANSFER_DIRECTION_IN); + Status = UsbAudioGetSetProperty(FilterContext->DeviceExtension->LowerDevice, 0x81, 0x1 << 8, FeatureUnitDescriptor->bUnitID << 8, Data, 1, USBD_TRANSFER_DIRECTION_IN); Irp->IoStatus.Information = sizeof(BOOL); } else { - Status = UsbAudioGetSetProperty(FilterContext->DeviceExtension->LowerDevice, 0x01, 0x100, FeatureUnitDescriptor->bUnitID << 8, Data, 1, USBD_TRANSFER_DIRECTION_OUT); + Status = UsbAudioGetSetProperty(FilterContext->DeviceExtension->LowerDevice, 0x01, 0x1 << 8, FeatureUnitDescriptor->bUnitID << 8, Data, 1, USBD_TRANSFER_DIRECTION_OUT); } } } @@ -234,8 +233,85 @@ FilterAudioVolumeHandler( IN PKSIDENTIFIER Request, IN OUT PVOID Data) { - UNIMPLEMENTED - return STATUS_SUCCESS; + PKSNODEPROPERTY_AUDIO_CHANNEL Property; + PKSFILTER Filter; + PFILTER_CONTEXT FilterContext; + PNODE_CONTEXT NodeContext; + PUSB_AUDIO_CONTROL_FEATURE_UNIT_DESCRIPTOR FeatureUnitDescriptor; + PSHORT TransferBuffer; + LONG Value; + NTSTATUS Status = STATUS_INVALID_PARAMETER; + + + /* get filter from irp */ + Filter = KsGetFilterFromIrp(Irp); + + if (Filter) + { + /* get property */ + Property = (PKSNODEPROPERTY_AUDIO_CHANNEL)Request; + + /* get filter context */ + FilterContext = (PFILTER_CONTEXT)Filter->Context; + + TransferBuffer = AllocFunction(sizeof(USHORT) * 3); + ASSERT(TransferBuffer); + + Value = *(PLONG)Data; + + /* search for node context */ + NodeContext = FindNodeContextWithNode(FilterContext->DeviceExtension->NodeContext, FilterContext->DeviceExtension->NodeContextCount, Property->NodeProperty.NodeId); + if (NodeContext) + { + FeatureUnitDescriptor = (PUSB_AUDIO_CONTROL_FEATURE_UNIT_DESCRIPTOR)NodeContext->Descriptor; + if (Property->NodeProperty.Property.Flags & KSPROPERTY_TYPE_GET) + { + Status = UsbAudioGetSetProperty(FilterContext->DeviceExtension->LowerDevice, 0x81, 0x2 << 8, FeatureUnitDescriptor->bUnitID << 8, &TransferBuffer[0], sizeof(USHORT), USBD_TRANSFER_DIRECTION_IN); + Value = (LONG)TransferBuffer[0] * 256; + + *(PLONG)Data = Value; + Irp->IoStatus.Information = sizeof(BOOL); + } + else + { + /* downscale value */ + Value /= 256; + + /* get minimum value */ + UsbAudioGetSetProperty(FilterContext->DeviceExtension->LowerDevice, 0x82, 0x2 << 8, FeatureUnitDescriptor->bUnitID << 8, &TransferBuffer[0], sizeof(USHORT), USBD_TRANSFER_DIRECTION_IN); + + /* get maximum value */ + UsbAudioGetSetProperty(FilterContext->DeviceExtension->LowerDevice, 0x83, 0x2 << 8, FeatureUnitDescriptor->bUnitID << 8, &TransferBuffer[1], sizeof(USHORT), USBD_TRANSFER_DIRECTION_IN); + + if (TransferBuffer[0] > Value) + { + /* use minimum value */ + Value = TransferBuffer[0]; + } + + if (TransferBuffer[1] < Value) + { + /* use maximum value */ + Value = TransferBuffer[1]; + } + + /* store value */ + TransferBuffer[2] = Value; + + /* set volume request */ + Status = UsbAudioGetSetProperty(FilterContext->DeviceExtension->LowerDevice, 0x01, 0x2 << 8, FeatureUnitDescriptor->bUnitID << 8, &TransferBuffer[2], sizeof(USHORT), USBD_TRANSFER_DIRECTION_OUT); + if (NT_SUCCESS(Status)) + { + /* store number of bytes transferred*/ + Irp->IoStatus.Information = sizeof(LONG); + } + } + } + + /* free transfer buffer */ + FreeFunction(TransferBuffer); + } + return Status; } diff --git a/reactos/drivers/usb/usbaudio/pin.c b/reactos/drivers/usb/usbaudio/pin.c index daba4c477db..207a9c66024 100644 --- a/reactos/drivers/usb/usbaudio/pin.c +++ b/reactos/drivers/usb/usbaudio/pin.c @@ -90,61 +90,6 @@ UsbAudioAllocCaptureUrbIso( } -NTSTATUS -UsbAudioSetVolume( - IN PKSPIN Pin) -{ - PURB Urb; - PUCHAR SampleRateBuffer; - PPIN_CONTEXT PinContext; - NTSTATUS Status; - - /* allocate sample rate buffer */ - SampleRateBuffer = AllocFunction(sizeof(ULONG)); - if (!SampleRateBuffer) - { - /* no memory */ - return STATUS_INSUFFICIENT_RESOURCES; - } - - /* allocate urb */ - Urb = AllocFunction(sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST)); - if (!Urb) - { - /* no memory */ - FreeFunction(SampleRateBuffer); - return STATUS_INSUFFICIENT_RESOURCES; - } - - /* FIXME: determine controls and format urb */ - UsbBuildVendorRequest(Urb, - URB_FUNCTION_CLASS_INTERFACE, - sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST), - USBD_TRANSFER_DIRECTION_OUT, - 0, - 0x01, - 0x200, - 0x300, - SampleRateBuffer, - NULL, - 2, - NULL); - - /* get pin context */ - PinContext = Pin->Context; - - SampleRateBuffer[0] = 0xC2; - SampleRateBuffer[1] = 0xFE; - - /* submit urb */ - Status = SubmitUrbSync(PinContext->LowerDevice, Urb); - - DPRINT1("UsbAudioSetVolume Pin %p Status %x\n", Pin, Status); - FreeFunction(Urb); - FreeFunction(SampleRateBuffer); - return Status; -} - NTSTATUS UsbAudioSetFormat( IN PKSPIN Pin) @@ -643,9 +588,6 @@ USBAudioPinCreate( ASSERT(Status == STATUS_SUCCESS); } - /* FIXME move to build filter topology*/ - UsbAudioSetVolume(Pin); - /* select streaming interface */ Status = USBAudioSelectAudioStreamingInterface(PinContext, PinContext->DeviceExtension, PinContext->DeviceExtension->ConfigurationDescriptor); if (!NT_SUCCESS(Status)) diff --git a/reactos/drivers/usb/usbaudio/usbaudio.h b/reactos/drivers/usb/usbaudio/usbaudio.h index 6050806c58c..864dd80f060 100644 --- a/reactos/drivers/usb/usbaudio/usbaudio.h +++ b/reactos/drivers/usb/usbaudio/usbaudio.h @@ -62,8 +62,6 @@ DEFINE_KSPROPERTY_TABLE(TopologySet) {\ DEFINE_KSPROPERTY_ITEM_AUDIO_MUTE(Handler)\ } - - #include typedef struct