ReactOS  0.4.14-dev-583-g2a1ba2c
sysaudio.h File Reference
#include <portcls.h>
Include dependency graph for sysaudio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  PIN_INFO
 
struct  KSAUDIO_DEVICE_ENTRY
 
struct  SYSAUDIODEVEXT
 
struct  DISPATCH_CONTEXT
 

Typedefs

typedef struct KSAUDIO_DEVICE_ENTRYPKSAUDIO_DEVICE_ENTRY
 
typedef struct SYSAUDIODEVEXTPSYSAUDIODEVEXT
 
typedef struct DISPATCH_CONTEXTPDISPATCH_CONTEXT
 

Functions

NTSTATUS SysAudioAllocateDeviceHeader (IN SYSAUDIODEVEXT *DeviceExtension)
 
NTSTATUS SysAudioRegisterDeviceInterfaces (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS SysAudioRegisterNotifications (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS SysAudioHandleProperty (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS SysAudioOpenKMixer (IN SYSAUDIODEVEXT *DeviceExtension)
 
NTSTATUS OpenDevice (IN PUNICODE_STRING DeviceName, IN PHANDLE HandleOut, IN PFILE_OBJECT *FileObjectOut)
 
PKSAUDIO_DEVICE_ENTRY GetListEntry (IN PLIST_ENTRY Head, IN ULONG Index)
 
NTSTATUS NTAPI DispatchCreateSysAudioPin (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
ULONG GetDeviceCount (PSYSAUDIODEVEXT DeviceExtension, BOOL WaveIn)
 
NTSTATUS GetPinInstanceCount (PKSAUDIO_DEVICE_ENTRY Entry, PKSPIN_CINSTANCES PinInstances, PKSPIN_CONNECT PinConnect)
 
NTSTATUS ComputeCompatibleFormat (IN PKSAUDIO_DEVICE_ENTRY Entry, IN ULONG PinId, IN PKSDATAFORMAT_WAVEFORMATEX ClientFormat, OUT PKSDATAFORMAT_WAVEFORMATEX MixerFormat)
 
PVOID AllocateItem (IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
 
VOID FreeItem (IN PVOID Item)
 

Typedef Documentation

◆ PDISPATCH_CONTEXT

◆ PKSAUDIO_DEVICE_ENTRY

◆ PSYSAUDIODEVEXT

Function Documentation

◆ AllocateItem()

PVOID AllocateItem ( IN POOL_TYPE  PoolType,
IN SIZE_T  NumberOfBytes 
)

Definition at line 30 of file misc.c.

33 {
35  if (!Item)
36  return Item;
37 
39  return Item;
40 }
#define TAG_KS
Definition: misc.c:14
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:998
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
_Must_inspect_result_ _In_ FLT_CONTEXT_TYPE _In_ SIZE_T _In_ POOL_TYPE PoolType
Definition: fltkernel.h:1444

Referenced by BdaCreateFilterFactoryEx(), BdaCreatePin(), FindProductName(), GetSysAudioDevicePnpName(), InsertPinHandle(), KspCopyCreateRequest(), ReadKeyValue(), USBSTOR_ClassRequest(), and USBSTOR_GetMaxLUN().

◆ ComputeCompatibleFormat()

NTSTATUS ComputeCompatibleFormat ( IN PKSAUDIO_DEVICE_ENTRY  Entry,
IN ULONG  PinId,
IN PKSDATAFORMAT_WAVEFORMATEX  ClientFormat,
OUT PKSDATAFORMAT_WAVEFORMATEX  MixerFormat 
)

Definition at line 135 of file control.c.

140 {
141  BOOL bFound;
143  PKSP_PIN PinRequest;
145  PKSMULTIPLE_ITEM MultipleItem;
146  ULONG Length;
147  PKSDATARANGE_AUDIO AudioRange;
148  ULONG Index;
149 
150  Length = sizeof(KSP_PIN) + sizeof(KSMULTIPLE_ITEM) + ClientFormat->DataFormat.FormatSize;
151  PinRequest = AllocateItem(NonPagedPool, Length);
152  if (!PinRequest)
153  return STATUS_UNSUCCESSFUL;
154 
155  PinRequest->PinId = PinId;
156  PinRequest->Property.Set = KSPROPSETID_Pin;
157  PinRequest->Property.Flags = KSPROPERTY_TYPE_GET;
159 
160  MultipleItem = (PKSMULTIPLE_ITEM)(PinRequest + 1);
161  MultipleItem->Count = 1;
162  MultipleItem->Size = ClientFormat->DataFormat.FormatSize;
163 
164  RtlMoveMemory(MultipleItem + 1, ClientFormat, ClientFormat->DataFormat.FormatSize);
165  /* Query the miniport data intersection handler */
167 
168  DPRINT("Status %x\n", Status);
169 
170  if (NT_SUCCESS(Status))
171  {
172  FreeItem(PinRequest);
173  return Status;
174  }
175 
176  /* Setup request block */
177  PinRequest->Property.Id = KSPROPERTY_PIN_DATARANGES;
178  /* Query pin data ranges */
180 
182  {
183  /* Failed to get data ranges */
184  return Status;
185  }
186 
187  MultipleItem = AllocateItem(NonPagedPool, BytesReturned);
188  if (!MultipleItem)
189  {
190  FreeItem(PinRequest);
191  return STATUS_NO_MEMORY;
192  }
193 
194  Status = KsSynchronousIoControlDevice(Entry->FileObject, KernelMode, IOCTL_KS_PROPERTY, (PVOID)PinRequest, sizeof(KSP_PIN), (PVOID)MultipleItem, BytesReturned, &BytesReturned);
195  if (!NT_SUCCESS(Status))
196  {
197  DPRINT("Property Request KSPROPERTY_PIN_DATARANGES failed with %x\n", Status);
198  FreeItem(MultipleItem);
199  FreeItem(PinRequest);
200  return STATUS_UNSUCCESSFUL;
201  }
202 
203  AudioRange = (PKSDATARANGE_AUDIO)(MultipleItem + 1);
204  bFound = FALSE;
205  for(Index = 0; Index < MultipleItem->Count; Index++)
206  {
207  if (AudioRange->DataRange.FormatSize != sizeof(KSDATARANGE_AUDIO))
208  {
210  AudioRange = (PKSDATARANGE_AUDIO)((PUCHAR)AudioRange + AudioRange->DataRange.FormatSize);
211  continue;
212  }
213  /* Select best quality available */
214 
215  MixerFormat->DataFormat.FormatSize = sizeof(KSDATAFORMAT) + sizeof(WAVEFORMATEX);
216  MixerFormat->DataFormat.Flags = 0;
217  MixerFormat->DataFormat.Reserved = 0;
218  MixerFormat->DataFormat.MajorFormat = KSDATAFORMAT_TYPE_AUDIO;
219  MixerFormat->DataFormat.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
220  MixerFormat->DataFormat.Specifier = KSDATAFORMAT_SPECIFIER_WAVEFORMATEX;
221  MixerFormat->DataFormat.SampleSize = 4;
222  MixerFormat->WaveFormatEx.wFormatTag = ClientFormat->WaveFormatEx.wFormatTag;
223 #ifndef NO_AC97_HACK
224  /* HACK: AC97 does not support mono render / record */
225  MixerFormat->WaveFormatEx.nChannels = 2;
226  /*HACK: AC97 only supports 16-Bit Bits */
227  MixerFormat->WaveFormatEx.wBitsPerSample = 16;
228 
229 #else
230  MixerFormat->WaveFormatEx.nChannels = min(ClientFormat->WaveFormatEx.nChannels, AudioRange->MaximumChannels);
231  MixerFormat->WaveFormatEx.wBitsPerSample = AudioRange->MaximumBitsPerSample;
232 #endif
233 
234 #ifdef KMIXER_RESAMPLING_IMPLEMENTED
235  MixerFormat->WaveFormatEx.nSamplesPerSec = AudioRange->MaximumSampleFrequency;
236 #else
237  MixerFormat->WaveFormatEx.nSamplesPerSec = max(AudioRange->MinimumSampleFrequency, min(ClientFormat->WaveFormatEx.nSamplesPerSec, AudioRange->MaximumSampleFrequency));
238 #endif
239 
240  MixerFormat->WaveFormatEx.cbSize = 0;
241  MixerFormat->WaveFormatEx.nBlockAlign = (MixerFormat->WaveFormatEx.nChannels * MixerFormat->WaveFormatEx.wBitsPerSample) / 8;
242  MixerFormat->WaveFormatEx.nAvgBytesPerSec = MixerFormat->WaveFormatEx.nChannels * MixerFormat->WaveFormatEx.nSamplesPerSec * (MixerFormat->WaveFormatEx.wBitsPerSample / 8);
243 
244  bFound = TRUE;
245  break;
246 
247  AudioRange = (PKSDATARANGE_AUDIO)((PUCHAR)AudioRange + AudioRange->DataRange.FormatSize);
248  }
249 
250 #if 0
251  DPRINT1("\nNum Max Channels %u Channels %u Old Channels %u\n Max SampleRate %u SampleRate %u Old SampleRate %u\n Max BitsPerSample %u BitsPerSample %u Old BitsPerSample %u\n",
252  AudioRange->MaximumChannels, MixerFormat->WaveFormatEx.nChannels, ClientFormat->WaveFormatEx.nChannels,
253  AudioRange->MaximumSampleFrequency, MixerFormat->WaveFormatEx.nSamplesPerSec, ClientFormat->WaveFormatEx.nSamplesPerSec,
254  AudioRange->MaximumBitsPerSample, MixerFormat->WaveFormatEx.wBitsPerSample, ClientFormat->WaveFormatEx.wBitsPerSample);
255 
256 
257 #endif
258 
259  FreeItem(MultipleItem);
260  FreeItem(PinRequest);
261 
262  if (bFound)
263  return STATUS_SUCCESS;
264  else
265  return STATUS_NOT_IMPLEMENTED;
266 }
ULONG Count
Definition: ks.h:1980
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
#define max(a, b)
Definition: svc.c:63
#define TRUE
Definition: types.h:120
ULONG Size
Definition: ks.h:1979
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
ULONG MaximumBitsPerSample
Definition: ksmedia.h:582
unsigned char * PUCHAR
Definition: retypes.h:3
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
LONG NTSTATUS
Definition: precomp.h:26
#define KSPROPERTY_TYPE_GET
Definition: dmksctrl.h:42
GUID Set
Definition: dmksctrl.h:76
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
KSDDKAPI NTSTATUS NTAPI KsSynchronousIoControlDevice(IN PFILE_OBJECT FileObject, IN KPROCESSOR_MODE RequestorMode, IN ULONG IoControl, IN PVOID InBuffer, IN ULONG InSize, OUT PVOID OutBuffer, IN ULONG OutSize, OUT PULONG BytesReturned)
Definition: api.c:1099
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
unsigned int BOOL
Definition: ntddk_ex.h:94
KSPROPERTY Property
Definition: ks.h:643
KSDATARANGE DataRange
Definition: ksmedia.h:579
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
ULONG PinId
Definition: ks.h:644
Definition: ks.h:642
ULONG Id
Definition: dmksctrl.h:77
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG MinimumSampleFrequency
Definition: ksmedia.h:583
static const UCHAR Index[8]
Definition: usbohci.c:18
ULONG MaximumChannels
Definition: ksmedia.h:580
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
struct KSDATARANGE_AUDIO * PKSDATARANGE_AUDIO
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
ULONG Flags
Definition: dmksctrl.h:78
struct KSMULTIPLE_ITEM * PKSMULTIPLE_ITEM
#define STATUS_MORE_ENTRIES
Definition: udferr_usr.h:124
Status
Definition: gdiplustypes.h:24
const GUID KSPROPSETID_Pin
Definition: control.c:17
const GUID KSDATAFORMAT_SPECIFIER_WAVEFORMATEX
Definition: control.c:22
ULONG MaximumSampleFrequency
Definition: ksmedia.h:584
const GUID KSDATAFORMAT_TYPE_AUDIO
Definition: control.c:20
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
_In_ FILTER_INFORMATION_CLASS _In_ ULONG _Out_ PULONG BytesReturned
Definition: fltkernel.h:1716
#define min(a, b)
Definition: monoChain.cc:55
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define UNIMPLEMENTED
Definition: debug.h:114
const GUID KSDATAFORMAT_SUBTYPE_PCM
Definition: control.c:21
return STATUS_SUCCESS
Definition: btrfs.c:2938
base of all file and directory entries
Definition: entries.h:82

Referenced by InstantiatePins().

◆ DispatchCreateSysAudioPin()

NTSTATUS NTAPI DispatchCreateSysAudioPin ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 431 of file pin.c.

434 {
436  PIO_STACK_LOCATION IoStack;
437  PKSAUDIO_DEVICE_ENTRY DeviceEntry;
439  PDISPATCH_CONTEXT DispatchContext;
440 
441  DPRINT("DispatchCreateSysAudioPin entered\n");
442 
443  /* get current stack location */
445 
446  /* sanity checks */
447  ASSERT(IoStack->FileObject);
448  ASSERT(IoStack->FileObject->RelatedFileObject);
449  ASSERT(IoStack->FileObject->RelatedFileObject->FsContext);
450 
451  /* get current attached virtual device */
452  DeviceEntry = (PKSAUDIO_DEVICE_ENTRY)IoStack->FileObject->RelatedFileObject->FsContext;
453 
454  /* check for success */
455  if (!NT_SUCCESS(Status))
456  {
457  /* failed */
458  Irp->IoStatus.Status = Status;
460  return Status;
461  }
462 
463  /* get connect details */
465 
466  /* check for success */
467  if (!NT_SUCCESS(Status))
468  {
469  /* failed to obtain connect details */
470  Irp->IoStatus.Status = Status;
472  return Status;
473  }
474 
475 
476  /* allocate dispatch context */
477  DispatchContext = AllocateItem(NonPagedPool, sizeof(DISPATCH_CONTEXT));
478  if (!DispatchContext)
479  {
480  /* failed */
481  Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
484  }
485 
486  /* zero dispatch context */
487  RtlZeroMemory(DispatchContext, sizeof(DISPATCH_CONTEXT));
488 
489  /* allocate object header */
490  Status = KsAllocateObjectHeader(&DispatchContext->ObjectHeader, 0, NULL, Irp, &PinTable);
491  if (!NT_SUCCESS(Status))
492  {
493  /* failed */
494  FreeItem(DispatchContext);
495  Irp->IoStatus.Status = Status;
497  return Status;
498  }
499 
500  /* now instantiate the pins */
501  Status = InstantiatePins(DeviceEntry, Connect, DispatchContext, (PSYSAUDIODEVEXT)DeviceObject->DeviceExtension);
502  if (!NT_SUCCESS(Status))
503  {
504  /* failed */
505  KsFreeObjectHeader(DispatchContext->ObjectHeader);
506  FreeItem(DispatchContext);
507  }
508  else
509  {
510  /* store dispatch context */
511  IoStack->FileObject->FsContext = (PVOID)DispatchContext;
512  }
513 
514 
515  /* FIXME create items for clocks / allocators */
516  Irp->IoStatus.Status = Status;
518  return Status;
519 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PKSPIN_CONNECT Connect
Definition: ks.h:4536
_In_ PIRP Irp
Definition: csq.h:116
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
LONG NTSTATUS
Definition: precomp.h:26
struct KSAUDIO_DEVICE_ENTRY * PKSAUDIO_DEVICE_ENTRY
KSDDKAPI VOID NTAPI KsFreeObjectHeader(IN PVOID Header)
Definition: api.c:720
NTSTATUS GetConnectRequest(IN PIRP Irp, OUT PKSPIN_CONNECT *Result)
Definition: pin.c:392
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
void * PVOID
Definition: retypes.h:9
NTSTATUS NTAPI InstantiatePins(IN PKSAUDIO_DEVICE_ENTRY DeviceEntry, IN PKSPIN_CONNECT Connect, IN PDISPATCH_CONTEXT DispatchContext, IN PSYSAUDIODEVEXT DeviceExtension)
Definition: pin.c:264
if(!(yy_init))
Definition: macro.lex.yy.c:714
static KSDISPATCH_TABLE PinTable
Definition: pin.c:163
Definition: sysaudio.h:12
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
KSDDKAPI NTSTATUS NTAPI KsAllocateObjectHeader(OUT KSOBJECT_HEADER *Header, IN ULONG ItemsCount, IN PKSOBJECT_CREATE_ITEM ItemsList OPTIONAL, IN PIRP Irp, IN KSDISPATCH_TABLE *Table)
Definition: api.c:610
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
KSOBJECT_HEADER ObjectHeader
Definition: private.hpp:437
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by DispatchCreateSysAudio().

◆ FreeItem()

◆ GetDeviceCount()

ULONG GetDeviceCount ( PSYSAUDIODEVEXT  DeviceExtension,
BOOL  WaveIn 
)

◆ GetListEntry()

PKSAUDIO_DEVICE_ENTRY GetListEntry ( IN PLIST_ENTRY  Head,
IN ULONG  Index 
)

Definition at line 45 of file control.c.

48 {
49  PLIST_ENTRY Entry = Head->Flink;
50 
51  while(Index-- && Entry != Head)
52  Entry = Entry->Flink;
53 
54  if (Entry == Head)
55  return NULL;
56 
58 }
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
Definition: sysaudio.h:12
static const UCHAR Index[8]
Definition: usbohci.c:18
Definition: typedefs.h:117
base of all file and directory entries
Definition: entries.h:82

Referenced by HandleSysAudioFilterPinProperties(), CIconWatcher::RemoveIconFromWatcher(), SysAudioHandleProperty(), and SysAudioOpenVirtualDevice().

◆ GetPinInstanceCount()

NTSTATUS GetPinInstanceCount ( PKSAUDIO_DEVICE_ENTRY  Entry,
PKSPIN_CINSTANCES  PinInstances,
PKSPIN_CONNECT  PinConnect 
)

Definition at line 269 of file control.c.

273 {
274  KSP_PIN PinRequest;
276 
277  /* query the instance count */
278  PinRequest.PinId = PinConnect->PinId;
279  PinRequest.Property.Set = KSPROPSETID_Pin;
280  PinRequest.Property.Flags = KSPROPERTY_TYPE_GET;
282  ASSERT(Entry->FileObject);
283  return KsSynchronousIoControlDevice(Entry->FileObject, KernelMode, IOCTL_KS_PROPERTY, (PVOID)&PinRequest, sizeof(KSP_PIN), (PVOID)PinInstances, sizeof(KSPIN_CINSTANCES), &BytesReturned);
284 
285 }
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
#define KSPROPERTY_TYPE_GET
Definition: dmksctrl.h:42
GUID Set
Definition: dmksctrl.h:76
KSDDKAPI NTSTATUS NTAPI KsSynchronousIoControlDevice(IN PFILE_OBJECT FileObject, IN KPROCESSOR_MODE RequestorMode, IN ULONG IoControl, IN PVOID InBuffer, IN ULONG InSize, OUT PVOID OutBuffer, IN ULONG OutSize, OUT PULONG BytesReturned)
Definition: api.c:1099
ULONG PinId
Definition: ks.h:2603
KSPROPERTY Property
Definition: ks.h:643
ULONG PinId
Definition: ks.h:644
Definition: ks.h:642
ULONG Id
Definition: dmksctrl.h:77
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONG Flags
Definition: dmksctrl.h:78
const GUID KSPROPSETID_Pin
Definition: control.c:17
_In_ FILTER_INFORMATION_CLASS _In_ ULONG _Out_ PULONG BytesReturned
Definition: fltkernel.h:1716
unsigned int ULONG
Definition: retypes.h:1
base of all file and directory entries
Definition: entries.h:82

Referenced by InstantiatePins().

◆ OpenDevice()

NTSTATUS OpenDevice ( IN PUNICODE_STRING  DeviceName,
IN PHANDLE  HandleOut,
IN PFILE_OBJECT FileObjectOut 
)

Definition at line 21 of file deviface.c.

25 {
31 
33 
34  Status = ZwCreateFile(&NodeHandle,
38  NULL,
39  0,
40  0,
41  FILE_OPEN,
43  NULL,
44  0);
45 
46 
47  if (!NT_SUCCESS(Status))
48  {
49  DPRINT("ZwCreateFile failed with %x %S\n", Status, DeviceName->Buffer);
50  return Status;
51  }
52 
54  if (!NT_SUCCESS(Status))
55  {
57  DPRINT("ObReferenceObjectByHandle failed with %x\n", Status);
58  return Status;
59  }
60 
61  *HandleOut = NodeHandle;
62  *FileObjectOut = FileObject;
63  return Status;
64 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
_In_ PKSNODE_CREATE _In_ ACCESS_MASK _Out_ PHANDLE NodeHandle
Definition: ks.h:4546
WCHAR DeviceName[]
Definition: adapter.cpp:21
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
* PFILE_OBJECT
Definition: iotypes.h:1955
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define GENERIC_READ
Definition: compat.h:124
#define SYNCHRONIZE
Definition: nt_native.h:61
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231

Referenced by InsertAudioDevice().

◆ SysAudioAllocateDeviceHeader()

NTSTATUS SysAudioAllocateDeviceHeader ( IN SYSAUDIODEVEXT DeviceExtension)

Definition at line 104 of file dispatcher.c.

106 {
108  PKSOBJECT_CREATE_ITEM CreateItem;
109 
110  /* allocate create item */
111  CreateItem = AllocateItem(NonPagedPool, sizeof(KSOBJECT_CREATE_ITEM));
112  if (!CreateItem)
114 
115  /* initialize create item struct */
116  RtlZeroMemory(CreateItem, sizeof(KSOBJECT_CREATE_ITEM));
117  CreateItem->Create = DispatchCreateSysAudio;
118 
119  /* FIXME Sysaudio doesnt need a named create item because it installs itself
120  * via the device interface
121  */
122  RtlInitUnicodeString(&CreateItem->ObjectClass, L"GLOBAL");
123  CreateItem->Flags = KSCREATE_ITEM_WILDCARD;
124 
125  Status = KsAllocateDeviceHeader(&DeviceExtension->KsDeviceHeader,
126  1,
127  CreateItem);
128  return Status;
129 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
KSDDKAPI NTSTATUS NTAPI KsAllocateDeviceHeader(OUT KSDEVICE_HEADER *OutHeader, IN ULONG ItemsCount, IN PKSOBJECT_CREATE_ITEM ItemsList OPTIONAL)
Definition: api.c:522
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
LONG NTSTATUS
Definition: precomp.h:26
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI DispatchCreateSysAudio(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: dispatcher.c:65
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

Referenced by SysAudio_AddDevice().

◆ SysAudioHandleProperty()

NTSTATUS SysAudioHandleProperty ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 288 of file control.c.

291 {
292  PIO_STACK_LOCATION IoStack;
294  KSPROPERTY PropertyRequest;
296  PULONG Index;
298  PSYSAUDIODEVEXT DeviceExtension;
300  PSYSAUDIO_INSTANCE_INFO InstanceInfo;
303  PKSP_PIN Pin;
305 
307 
308  if (IoStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(KSPROPERTY))
309  {
310  /* buffer must be at least of sizeof KSPROPERTY */
312  }
313 
314  Property = (PKSPROPERTY)IoStack->Parameters.DeviceIoControl.Type3InputBuffer;
315  DeviceExtension = (PSYSAUDIODEVEXT)DeviceObject->DeviceExtension;
316 
318  {
319  return HandleSysAudioFilterPinProperties(Irp, Property, DeviceExtension);
320  }
322  {
323  if (IoStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(KSP_PIN))
324  {
325  /* too small buffer */
327  }
328  Pin = (PKSP_PIN)IoStack->Parameters.DeviceIoControl.Type3InputBuffer;
329  Entry = GetListEntry(&DeviceExtension->KsAudioDeviceList, Pin->Reserved);
330  ASSERT(Entry != NULL);
331 
332  /* forward request to the filter implementing the property */
334  (PVOID)IoStack->Parameters.DeviceIoControl.Type3InputBuffer,
335  IoStack->Parameters.DeviceIoControl.InputBufferLength,
336  Irp->UserBuffer,
337  IoStack->Parameters.DeviceIoControl.OutputBufferLength,
338  &BytesReturned);
339 
341  }
343  {
345  {
346  if (IoStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(KSPROPERTY) + sizeof(ULONG))
347  {
348  /* invalid request */
349  return SetIrpIoStatus(Irp, STATUS_UNSUCCESSFUL, sizeof(KSPROPERTY) + sizeof(ULONG));
350  }
351  Index = (PULONG)(Property + 1);
352 
353  if (DeviceExtension->NumberOfKsAudioDevices <= *Index)
354  {
355  /* invalid index */
357  }
358 
359  Entry = GetListEntry(&DeviceExtension->KsAudioDeviceList, *Index);
360  ASSERT(Entry != NULL);
361 
362  BytesReturned = Entry->DeviceName.Length + sizeof(WCHAR);
363  if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < BytesReturned)
364  {
365  /* too small buffer */
367  }
368 
369  /* copy device name */
370  DeviceName = (LPWSTR)Irp->UserBuffer;
371 
372  RtlMoveMemory(DeviceName, Entry->DeviceName.Buffer, Entry->DeviceName.Length);
373  DeviceName[Entry->DeviceName.Length / sizeof(WCHAR)] = L'\0';
375  }
376 
378  {
379  if (IoStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(KSPROPERTY) + sizeof(ULONG))
380  {
381  /* too small buffer */
382  return SetIrpIoStatus(Irp, STATUS_BUFFER_TOO_SMALL, sizeof(KSPROPERTY) + sizeof(ULONG));
383  }
384 
385  if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(KSCOMPONENTID))
386  {
387  /* too small buffer */
389  }
390 
391  Index = (PULONG)(Property + 1);
392 
393  if (DeviceExtension->NumberOfKsAudioDevices <= *Index)
394  {
395  /* invalid index */
397  }
398  Entry = GetListEntry(&DeviceExtension->KsAudioDeviceList, *Index);
399  ASSERT(Entry != NULL);
400 
401  PropertyRequest.Set = KSPROPSETID_General;
402  PropertyRequest.Id = KSPROPERTY_GENERAL_COMPONENTID;
403  PropertyRequest.Flags = KSPROPERTY_TYPE_GET;
404 
405  /* call the filter */
407  if (!NT_SUCCESS(Status))
408  {
409  DPRINT("KsSynchronousIoControlDevice failed with %x for KSPROPERTY_GENERAL_COMPONENTID\n", Status);
410  return SetIrpIoStatus(Irp, Status, 0);
411  }
412  RtlMoveMemory(Irp->UserBuffer, &ComponentId, sizeof(KSCOMPONENTID));
414  }
416  {
417  if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(ULONG))
418  {
419  /* too small buffer */
421  }
422 
423  *((PULONG)Irp->UserBuffer) = DeviceExtension->NumberOfKsAudioDevices;
424  return SetIrpIoStatus(Irp, STATUS_SUCCESS, sizeof(ULONG));
425  }
427  {
428  if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(ULONG))
429  {
430  /* too small buffer */
432  }
433 
434  if (Property->Flags & KSPROPERTY_TYPE_SET)
435  {
436  Index = (PULONG)Irp->UserBuffer;
437  return SysAudioOpenVirtualDevice(Irp, *Index, DeviceExtension);
438  }
439  }
441  {
442  if (IoStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(SYSAUDIO_INSTANCE_INFO))
443  {
444  /* too small buffer */
446  }
447 
448  /* get input parameter */
449  InstanceInfo = (PSYSAUDIO_INSTANCE_INFO)Property;
450 
451  if (Property->Flags & KSPROPERTY_TYPE_SET)
452  {
453  return SysAudioOpenVirtualDevice(Irp, InstanceInfo->DeviceNumber, DeviceExtension);
454  }
455  }
456  }
457 
459  DPRINT1("Unhandled property Set |%S| Id %u Flags %x\n", GuidString.Buffer, Property->Id, Property->Flags);
462 }
static PWSTR GuidString
Definition: apphelp.c:91
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
NTSTATUS SetIrpIoStatus(IN PIRP Irp, IN NTSTATUS Status, IN ULONG Length)
Definition: control.c:25
struct _Entry Entry
Definition: kefuncs.h:640
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
LIST_ENTRY KsAudioDeviceList
Definition: sysaudio.h:30
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char UINT32 ComponentId
Definition: acpixf.h:1270
ULONG NumberOfKsAudioDevices
Definition: sysaudio.h:28
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define KSPROPERTY_TYPE_GET
Definition: dmksctrl.h:42
const GUID KSPROPSETID_General
Definition: control.c:16
GUID Set
Definition: dmksctrl.h:76
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:233
KSDDKAPI NTSTATUS NTAPI KsSynchronousIoControlDevice(IN PFILE_OBJECT FileObject, IN KPROCESSOR_MODE RequestorMode, IN ULONG IoControl, IN PVOID InBuffer, IN ULONG InSize, OUT PVOID OutBuffer, IN ULONG OutSize, OUT PULONG BytesReturned)
Definition: api.c:1099
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
Definition: ks.h:642
struct SYSAUDIO_INSTANCE_INFO * PSYSAUDIO_INSTANCE_INFO
NTSTATUS HandleSysAudioFilterPinProperties(PIRP Irp, PKSPROPERTY Property, PSYSAUDIODEVEXT DeviceExtension)
Definition: control.c:94
ULONG Id
Definition: dmksctrl.h:77
IN PDCB IN VBO IN ULONG IN BOOLEAN Pin
Definition: fatprocs.h:415
__wchar_t WCHAR
Definition: xmlstorage.h:180
Definition: sysaudio.h:12
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const UCHAR Index[8]
Definition: usbohci.c:18
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
ULONG Flags
Definition: dmksctrl.h:78
static const WCHAR L[]
Definition: oid.c:1250
NTSYSAPI NTSTATUS WINAPI RtlStringFromGUID(REFGUID, PUNICODE_STRING)
Status
Definition: gdiplustypes.h:24
_In_ DWORD Property
Definition: setupapi.h:1545
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
const GUID KSPROPSETID_Pin
Definition: control.c:17
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
NTSTATUS SysAudioOpenVirtualDevice(IN PIRP Irp, IN ULONG DeviceNumber, PSYSAUDIODEVEXT DeviceExtension)
Definition: control.c:61
const GUID KSPROPSETID_Sysaudio
Definition: control.c:15
_In_ FILTER_INFORMATION_CLASS _In_ ULONG _Out_ PULONG BytesReturned
Definition: fltkernel.h:1716
unsigned int * PULONG
Definition: retypes.h:1
struct KSP_PIN * PKSP_PIN
#define DPRINT1
Definition: precomp.h:8
const GUID KSPROPSETID_Topology
Definition: control.c:19
unsigned int ULONG
Definition: retypes.h:1
struct KSIDENTIFIER * PKSPROPERTY
PKSAUDIO_DEVICE_ENTRY GetListEntry(IN PLIST_ENTRY Head, IN ULONG Index)
Definition: control.c:45
WCHAR * LPWSTR
Definition: xmlstorage.h:184
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define KSPROPERTY_TYPE_SET
Definition: dmksctrl.h:43
base of all file and directory entries
Definition: entries.h:82

Referenced by Dispatch_fnDeviceIoControl().

◆ SysAudioOpenKMixer()

NTSTATUS SysAudioOpenKMixer ( IN SYSAUDIODEVEXT DeviceExtension)

Definition at line 132 of file dispatcher.c.

134 {
136  UNICODE_STRING DeviceInstanceName = RTL_CONSTANT_STRING(L"\\Device\\kmixer\\GLOBAL");
137  UNICODE_STRING DevicePath = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\kmixer");
138 
139  Status = ZwLoadDriver(&DevicePath);
140 
141  if (NT_SUCCESS(Status))
142  {
143  Status = OpenDevice(&DeviceInstanceName, &DeviceExtension->KMixerHandle, &DeviceExtension->KMixerFileObject);
144  if (!NT_SUCCESS(Status))
145  {
146  DeviceExtension->KMixerHandle = NULL;
147  DeviceExtension->KMixerFileObject = NULL;
148  }
149  }
150 
151  DPRINT("Status %lx KMixerHandle %p KMixerFileObject %p\n", Status, DeviceExtension->KMixerHandle, DeviceExtension->KMixerFileObject);
152  return STATUS_SUCCESS;
153 }
LONG NTSTATUS
Definition: precomp.h:26
MMRESULT OpenDevice(DeviceInfo **private_data, MIDIOPENDESC *open_desc, DWORD flags)
Definition: beepmidi.c:264
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by SysAudio_AddDevice().

◆ SysAudioRegisterDeviceInterfaces()

NTSTATUS SysAudioRegisterDeviceInterfaces ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 214 of file deviface.c.

216 {
219 
221  if (NT_SUCCESS(Status))
222  {
225  }
226  else
227  {
228  DPRINT("Failed to register KSCATEGORY_PREFERRED_MIDIOUT_DEVICE interface Status %x\n", Status);
229  return Status;
230  }
231 
233  if (NT_SUCCESS(Status))
234  {
237  }
238  else
239  {
240  DPRINT("Failed to register KSCATEGORY_PREFERRED_WAVEIN_DEVICE interface Status %x\n", Status);
241  return Status;
242  }
243 
245  if (NT_SUCCESS(Status))
246  {
249  }
250  else
251  {
252  DPRINT("Failed to register KSCATEGORY_PREFERRED_WAVEOUT_DEVICE interface Status %x\n", Status);
253  }
254 
256  if (NT_SUCCESS(Status))
257  {
260  }
261  else
262  {
263  DPRINT("Failed to register KSCATEGORY_SYSAUDIO interface Status %x\n", Status);
264  }
265 
266  return Status;
267 }
const GUID KSCATEGORY_PREFERRED_WAVEIN_DEVICE
Definition: main.c:20
#define TRUE
Definition: types.h:120
const GUID KSCATEGORY_PREFERRED_MIDIOUT_DEVICE
Definition: main.c:21
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
#define KSCATEGORY_SYSAUDIO
Definition: ksmedia.h:217
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
const GUID KSCATEGORY_PREFERRED_WAVEOUT_DEVICE
Definition: main.c:19
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
static const WCHAR SymbolicLink[]
Definition: interface.c:31

Referenced by SysAudio_AddDevice().

◆ SysAudioRegisterNotifications()

NTSTATUS SysAudioRegisterNotifications ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  DeviceObject 
)

Definition at line 172 of file deviface.c.

175 {
177  PSYSAUDIODEVEXT DeviceExtension;
178 
179  DeviceExtension = (PSYSAUDIODEVEXT)DeviceObject->DeviceExtension;
180 
184  DriverObject,
187  (PVOID*)&DeviceExtension->KsAudioNotificationEntry);
188 
189  if (!NT_SUCCESS(Status))
190  {
191  DPRINT("IoRegisterPlugPlayNotification failed with %x\n", Status);
192  }
193 
197  DriverObject,
200  (PVOID*)&DeviceExtension->EchoCancelNotificationEntry);
201 
202  if (!NT_SUCCESS(Status))
203  {
204  /* ignore failure for now */
205  DPRINT("IoRegisterPlugPlayNotification failed for DMOCATEGORY_ACOUSTIC_ECHO_CANCEL\n", Status);
206  }
207 
208  return STATUS_SUCCESS;
209 }
const GUID DMOCATEGORY_ACOUSTIC_ECHO_CANCEL
Definition: deviface.c:18
LONG NTSTATUS
Definition: precomp.h:26
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1196
PVOID DeviceExtension
Definition: env_spec_w32.h:418
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
void * PVOID
Definition: retypes.h:9
NTSTATUS NTAPI DeviceInterfaceChangeCallback(IN PVOID NotificationStructure, IN PVOID Context)
Definition: deviface.c:48
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PVOID EchoCancelNotificationEntry
Definition: sysaudio.h:32
PVOID KsAudioNotificationEntry
Definition: sysaudio.h:31
NTSTATUS NTAPI IoRegisterPlugPlayNotification(IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory, IN ULONG EventCategoryFlags, IN PVOID EventCategoryData OPTIONAL, IN PDRIVER_OBJECT DriverObject, IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, IN PVOID Context, OUT PVOID *NotificationEntry)
Definition: pnpnotify.c:249
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
struct SYSAUDIODEVEXT * PSYSAUDIODEVEXT
const GUID KS_CATEGORY_AUDIO
Definition: deviface.c:16
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by SysAudio_AddDevice().