2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel Streaming
4 * FILE: drivers/wdm/audio/legacy/wdmaud/deviface.c
5 * PURPOSE: System Audio graph builder
6 * PROGRAMMER: Andrew Greenwood
11 const GUID KSPROPSETID_Pin
= {0x8C134960L
, 0x51AD, 0x11CF, {0x87, 0x8A, 0x94, 0xF8, 0x01, 0xC1, 0x00, 0x00}};
12 const GUID KSPROPSETID_Connection
= {0x1D58C920L
, 0xAC9B, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}};
13 const GUID KSPROPSETID_Sysaudio
= {0xCBE3FAA0L
, 0xCC75, 0x11D0, {0xB4, 0x65, 0x00, 0x00, 0x1A, 0x18, 0x18, 0xE6}};
14 const GUID KSPROPSETID_General
= {0x1464EDA5L
, 0x6A8F, 0x11D1, {0x9A, 0xA7, 0x00, 0xA0, 0xC9, 0x22, 0x31, 0x96}};
15 const GUID KSINTERFACESETID_Standard
= {0x1A8766A0L
, 0x62CE, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}};
16 const GUID KSMEDIUMSETID_Standard
= {0x4747B320L
, 0x62CE, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}};
17 const GUID KSDATAFORMAT_TYPE_AUDIO
= {0x73647561L
, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
18 const GUID KSDATAFORMAT_SUBTYPE_PCM
= {0x00000001L
, 0x0000, 0x0010, {0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}};
19 const GUID KSDATAFORMAT_SPECIFIER_WAVEFORMATEX
= {0x05589f81L
, 0xc356, 0x11ce, {0xbf, 0x01, 0x00, 0xaa, 0x00, 0x55, 0x59, 0x5a}};
20 const GUID KSPROPSETID_Topology
= {0x720D4AC0L
, 0x7533, 0x11D0, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}};
25 IN PDEVICE_OBJECT DeviceObject
,
27 IN PWDMAUD_DEVICE_INFO DeviceInfo
,
28 IN PWDMAUD_CLIENT ClientInfo
)
30 if (DeviceInfo
->DeviceType
== MIXER_DEVICE_TYPE
)
32 return WdmAudControlOpenMixer(DeviceObject
, Irp
, DeviceInfo
, ClientInfo
);
35 if (DeviceInfo
->DeviceType
== WAVE_OUT_DEVICE_TYPE
|| DeviceInfo
->DeviceType
== WAVE_IN_DEVICE_TYPE
)
37 return WdmAudControlOpenWave(DeviceObject
, Irp
, DeviceInfo
, ClientInfo
);
40 return SetIrpIoStatus(Irp
, STATUS_NOT_SUPPORTED
, sizeof(WDMAUD_DEVICE_INFO
));
44 WdmAudControlDeviceType(
45 IN PDEVICE_OBJECT DeviceObject
,
47 IN PWDMAUD_DEVICE_INFO DeviceInfo
,
48 IN PWDMAUD_CLIENT ClientInfo
)
52 PWDMAUD_DEVICE_EXTENSION DeviceExtension
;
54 DeviceExtension
= (PWDMAUD_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
56 if (DeviceInfo
->DeviceType
== MIXER_DEVICE_TYPE
)
58 Result
= DeviceExtension
->MixerInfoCount
;
60 else if (DeviceInfo
->DeviceType
== WAVE_OUT_DEVICE_TYPE
)
62 Result
= DeviceExtension
->WaveOutDeviceCount
;
64 else if (DeviceInfo
->DeviceType
== WAVE_IN_DEVICE_TYPE
)
66 Result
= DeviceExtension
->WaveInDeviceCount
;
69 /* store result count */
70 DeviceInfo
->DeviceCount
= Result
;
72 DPRINT("WdmAudControlDeviceType Status %x Devices %u\n", Status
, DeviceInfo
->DeviceCount
);
73 return SetIrpIoStatus(Irp
, STATUS_SUCCESS
, sizeof(WDMAUD_DEVICE_INFO
));
77 WdmAudControlDeviceState(
78 IN PDEVICE_OBJECT DeviceObject
,
80 IN PWDMAUD_DEVICE_INFO DeviceInfo
,
81 IN PWDMAUD_CLIENT ClientInfo
)
87 PFILE_OBJECT FileObject
;
89 //DPRINT1("WdmAudControlDeviceState\n");
91 Status
= ObReferenceObjectByHandle(DeviceInfo
->hDevice
, GENERIC_READ
| GENERIC_WRITE
, IoFileObjectType
, KernelMode
, (PVOID
*)&FileObject
, NULL
);
92 if (!NT_SUCCESS(Status
))
94 DPRINT1("Error: invalid device handle provided %p Type %x\n", DeviceInfo
->hDevice
, DeviceInfo
->DeviceType
);
95 return SetIrpIoStatus(Irp
, STATUS_UNSUCCESSFUL
, 0);
98 Property
.Set
= KSPROPSETID_Connection
;
99 Property
.Id
= KSPROPERTY_CONNECTION_STATE
;
100 Property
.Flags
= KSPROPERTY_TYPE_SET
;
102 State
= DeviceInfo
->u
.State
;
104 Status
= KsSynchronousIoControlDevice(FileObject
, KernelMode
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)&State
, sizeof(KSSTATE
), &BytesReturned
);
106 ObDereferenceObject(FileObject
);
108 //DPRINT1("WdmAudControlDeviceState Status %x\n", Status);
109 return SetIrpIoStatus(Irp
, Status
, sizeof(WDMAUD_DEVICE_INFO
));
114 IN PDEVICE_OBJECT DeviceObject
,
116 IN PWDMAUD_DEVICE_INFO DeviceInfo
,
117 IN PWDMAUD_CLIENT ClientInfo
)
119 PWDMAUD_DEVICE_EXTENSION DeviceExtension
;
120 NTSTATUS Status
= STATUS_UNSUCCESSFUL
;
122 DPRINT("WdmAudCapabilities entered\n");
124 DeviceExtension
= (PWDMAUD_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
126 if (DeviceInfo
->DeviceType
== MIXER_DEVICE_TYPE
)
128 Status
= WdmAudMixerCapabilities(DeviceObject
, DeviceInfo
, ClientInfo
, DeviceExtension
);
130 else if (DeviceInfo
->DeviceType
== WAVE_IN_DEVICE_TYPE
|| DeviceInfo
->DeviceType
== WAVE_OUT_DEVICE_TYPE
)
132 Status
= WdmAudWaveCapabilities(DeviceObject
, DeviceInfo
, ClientInfo
, DeviceExtension
);
135 return SetIrpIoStatus(Irp
, Status
, sizeof(WDMAUD_DEVICE_INFO
));
141 IN PDEVICE_OBJECT DeviceObject
,
143 IN PWDMAUD_DEVICE_INFO DeviceInfo
,
144 IN PWDMAUD_CLIENT ClientInfo
)
148 for(Index
= 0; Index
< ClientInfo
->NumPins
; Index
++)
150 if (ClientInfo
->hPins
[Index
].Handle
== DeviceInfo
->hDevice
&& ClientInfo
->hPins
[Index
].Type
!= MIXER_DEVICE_TYPE
)
152 DPRINT1("Closing device %p\n", DeviceInfo
->hDevice
);
153 ZwClose(DeviceInfo
->hDevice
);
154 ClientInfo
->hPins
[Index
].Handle
= NULL
;
155 SetIrpIoStatus(Irp
, STATUS_SUCCESS
, sizeof(WDMAUD_DEVICE_INFO
));
156 return STATUS_SUCCESS
;
160 SetIrpIoStatus(Irp
, STATUS_INVALID_PARAMETER
, sizeof(WDMAUD_DEVICE_INFO
));
161 return STATUS_INVALID_PARAMETER
;
167 IN PDEVICE_OBJECT DeviceObject
,
169 IN PWDMAUD_DEVICE_INFO DeviceInfo
,
170 IN PWDMAUD_CLIENT ClientInfo
)
172 PFILE_OBJECT FileObject
;
175 KSALLOCATOR_FRAMING Framing
;
178 /* Get sysaudio pin file object */
179 Status
= ObReferenceObjectByHandle(DeviceInfo
->hDevice
, GENERIC_WRITE
, IoFileObjectType
, KernelMode
, (PVOID
*)&FileObject
, NULL
);
180 if (!NT_SUCCESS(Status
))
182 DPRINT1("Invalid buffer handle %x\n", DeviceInfo
->hDevice
);
183 return SetIrpIoStatus(Irp
, Status
, 0);
186 /* Setup get framing request */
187 Property
.Id
= KSPROPERTY_CONNECTION_ALLOCATORFRAMING
;
188 Property
.Flags
= KSPROPERTY_TYPE_GET
;
189 Property
.Set
= KSPROPSETID_Connection
;
191 Status
= KsSynchronousIoControlDevice(FileObject
, KernelMode
, IOCTL_KS_PROPERTY
, (PVOID
)&Property
, sizeof(KSPROPERTY
), (PVOID
)&Framing
, sizeof(KSALLOCATOR_FRAMING
), &BytesReturned
);
193 if (NT_SUCCESS(Status
))
195 /* Store framesize */
196 DeviceInfo
->u
.FrameSize
= Framing
.FrameSize
;
199 /* Release file object */
200 ObDereferenceObject(FileObject
);
202 return SetIrpIoStatus(Irp
, Status
, sizeof(WDMAUD_DEVICE_INFO
));
210 IN PDEVICE_OBJECT DeviceObject
,
213 PIO_STACK_LOCATION IoStack
;
214 PWDMAUD_DEVICE_INFO DeviceInfo
;
215 PWDMAUD_CLIENT ClientInfo
;
217 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
219 DPRINT("WdmAudDeviceControl entered\n");
221 if (IoStack
->Parameters
.DeviceIoControl
.InputBufferLength
< sizeof(WDMAUD_DEVICE_INFO
))
223 /* invalid parameter */
224 DPRINT1("Input buffer too small size %u expected %u\n", IoStack
->Parameters
.DeviceIoControl
.InputBufferLength
, sizeof(WDMAUD_DEVICE_INFO
));
225 return SetIrpIoStatus(Irp
, STATUS_INVALID_PARAMETER
, 0);
228 DeviceInfo
= (PWDMAUD_DEVICE_INFO
)Irp
->AssociatedIrp
.SystemBuffer
;
230 if (DeviceInfo
->DeviceType
< MIN_SOUND_DEVICE_TYPE
|| DeviceInfo
->DeviceType
> MAX_SOUND_DEVICE_TYPE
)
232 /* invalid parameter */
233 DPRINT1("Error: device type not set\n");
234 return SetIrpIoStatus(Irp
, STATUS_INVALID_PARAMETER
, 0);
237 if (!IoStack
->FileObject
)
239 /* file object parameter */
240 DPRINT1("Error: file object is not attached\n");
241 return SetIrpIoStatus(Irp
, STATUS_UNSUCCESSFUL
, 0);
243 ClientInfo
= (PWDMAUD_CLIENT
)IoStack
->FileObject
->FsContext
;
245 DPRINT("WdmAudDeviceControl entered\n");
247 switch(IoStack
->Parameters
.DeviceIoControl
.IoControlCode
)
249 case IOCTL_OPEN_WDMAUD
:
250 return WdmAudControlOpen(DeviceObject
, Irp
, DeviceInfo
, ClientInfo
);
251 case IOCTL_GETNUMDEVS_TYPE
:
252 return WdmAudControlDeviceType(DeviceObject
, Irp
, DeviceInfo
, ClientInfo
);
253 case IOCTL_SETDEVICE_STATE
:
254 return WdmAudControlDeviceState(DeviceObject
, Irp
, DeviceInfo
, ClientInfo
);
255 case IOCTL_GETCAPABILITIES
:
256 return WdmAudCapabilities(DeviceObject
, Irp
, DeviceInfo
, ClientInfo
);
257 case IOCTL_CLOSE_WDMAUD
:
258 return WdmAudIoctlClose(DeviceObject
, Irp
, DeviceInfo
, ClientInfo
);
259 case IOCTL_GETFRAMESIZE
:
260 return WdmAudFrameSize(DeviceObject
, Irp
, DeviceInfo
, ClientInfo
);
261 case IOCTL_GETLINEINFO
:
262 return WdmAudGetLineInfo(DeviceObject
, Irp
, DeviceInfo
, ClientInfo
);
263 case IOCTL_GETLINECONTROLS
:
264 return WdmAudGetLineControls(DeviceObject
, Irp
, DeviceInfo
, ClientInfo
);
265 case IOCTL_SETCONTROLDETAILS
:
266 return WdmAudSetControlDetails(DeviceObject
, Irp
, DeviceInfo
, ClientInfo
);
267 case IOCTL_GETCONTROLDETAILS
:
268 return WdmAudGetControlDetails(DeviceObject
, Irp
, DeviceInfo
, ClientInfo
);
271 case IOCTL_GETVOLUME
:
272 case IOCTL_SETVOLUME
:
274 DPRINT1("Unhandeled %x\n", IoStack
->Parameters
.DeviceIoControl
.IoControlCode
);
278 return SetIrpIoStatus(Irp
, STATUS_NOT_IMPLEMENTED
, 0);
285 IN PDEVICE_OBJECT DeviceObject
,
289 PWDMAUD_DEVICE_INFO DeviceInfo
;
290 PFILE_OBJECT FileObject
;
291 PIO_STACK_LOCATION IoStack
;
295 /* get current irp stack location */
296 IoStack
= IoGetCurrentIrpStackLocation(Irp
);
298 /* store the input buffer in UserBuffer - as KsProbeStreamIrp operates on IRP_MJ_DEVICE_CONTROL */
299 Irp
->UserBuffer
= MmGetMdlVirtualAddress(Irp
->MdlAddress
);
302 ASSERT(Irp
->UserBuffer
);
304 /* get the length of the request length */
305 Length
= IoStack
->Parameters
.Write
.Length
;
307 /* store outputbuffer length */
308 IoStack
->Parameters
.DeviceIoControl
.OutputBufferLength
= Length
;
310 /* store mdl address */
311 Mdl
= Irp
->MdlAddress
;
313 /* remove mdladdress as KsProbeStreamIrp will interprete it as an already probed audio buffer */
314 Irp
->MdlAddress
= NULL
;
316 /* check for success */
318 if (IoStack
->MajorFunction
== IRP_MJ_WRITE
)
320 /* probe the write stream irp */
321 Status
= KsProbeStreamIrp(Irp
, KSPROBE_STREAMWRITE
| KSPROBE_ALLOCATEMDL
| KSPROBE_PROBEANDLOCK
, Length
);
325 /* probe the read stream irp */
326 Status
= KsProbeStreamIrp(Irp
, KSPROBE_STREAMREAD
| KSPROBE_ALLOCATEMDL
| KSPROBE_PROBEANDLOCK
, Length
);
329 /* now free the mdl */
332 if (!NT_SUCCESS(Status
))
334 DPRINT1("KsProbeStreamIrp failed with Status %x\n", Status
);
335 return SetIrpIoStatus(Irp
, Status
, 0);
338 /* get device info */
339 DeviceInfo
= (PWDMAUD_DEVICE_INFO
)Irp
->AssociatedIrp
.SystemBuffer
;
342 /* now get sysaudio file object */
343 Status
= ObReferenceObjectByHandle(DeviceInfo
->hDevice
, GENERIC_WRITE
, IoFileObjectType
, KernelMode
, (PVOID
*)&FileObject
, NULL
);
344 if (!NT_SUCCESS(Status
))
346 DPRINT1("Invalid pin handle %x\n", DeviceInfo
->hDevice
);
347 return SetIrpIoStatus(Irp
, Status
, 0);
350 /* skip current irp stack location */
351 IoSkipCurrentIrpStackLocation(Irp
);
353 /* get next stack location */
354 IoStack
= IoGetNextIrpStackLocation(Irp
);
356 /* attach file object */
357 IoStack
->FileObject
= FileObject
;
358 IoStack
->Parameters
.Write
.Length
= sizeof(KSSTREAM_HEADER
);
359 IoStack
->MajorFunction
= IRP_MJ_WRITE
;
361 /* mark irp as pending */
362 IoMarkIrpPending(Irp
);
363 /* call the driver */
364 Status
= IoCallDriver(IoGetRelatedDeviceObject(FileObject
), Irp
);
366 /* dereference file object */
367 ObDereferenceObject(FileObject
);