ReactOS  0.4.13-dev-257-gfabbd7c
pin.c File Reference
#include "kmixer.h"
#include <samplerate.h>
#include <debug.h>
Include dependency graph for pin.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS PerformSampleRateConversion (PUCHAR Buffer, ULONG BufferLength, ULONG OldRate, ULONG NewRate, ULONG BytesPerSample, ULONG NumChannels, PVOID *Result, PULONG ResultLength)
 
NTSTATUS PerformChannelConversion (PUCHAR Buffer, ULONG BufferLength, ULONG OldChannels, ULONG NewChannels, ULONG BitsPerSample, PVOID *Result, PULONG ResultLength)
 
NTSTATUS PerformQualityConversion (PUCHAR Buffer, ULONG BufferLength, ULONG OldWidth, ULONG NewWidth, PVOID *Result, PULONG ResultLength)
 
NTSTATUS NTAPI Pin_fnDeviceIoControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI Pin_fnRead (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI Pin_fnWrite (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI Pin_fnFlush (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI Pin_fnClose (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI Pin_fnQuerySecurity (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS NTAPI Pin_fnSetSecurity (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
BOOLEAN NTAPI Pin_fnFastDeviceIoControl (PFILE_OBJECT FileObject, BOOLEAN Wait, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength, ULONG IoControlCode, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject)
 
BOOLEAN NTAPI Pin_fnFastRead (PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, ULONG LockKey, PVOID Buffer, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject)
 
BOOLEAN NTAPI Pin_fnFastWrite (PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, ULONG LockKey, PVOID Buffer, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject)
 
NTSTATUS CreatePin (IN PIRP Irp)
 
voidcalloc (size_t Elements, size_t ElementSize)
 
void free (PVOID Block)
 

Variables

const GUID KSPROPSETID_Connection = {0x1D58C920L, 0xAC9B, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}}
 
static KSDISPATCH_TABLE PinTable
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file pin.c.

Function Documentation

◆ calloc()

void* calloc ( size_t  Elements,
size_t  ElementSize 
)

Definition at line 722 of file pin.c.

723 {
724  ULONG Index;
725  PUCHAR Block = ExAllocatePool(NonPagedPool, Elements * ElementSize);
726  if (!Block)
727  return NULL;
728 
729  for(Index = 0; Index < Elements * ElementSize; Index++)
730  Block[Index] = 0;
731 
732  return Block;
733 }
unsigned char * PUCHAR
Definition: retypes.h:3
smooth NULL
Definition: ftsmooth.c:416
static const UCHAR Index[8]
Definition: usbohci.c:18
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
unsigned int ULONG
Definition: retypes.h:1

◆ CreatePin()

NTSTATUS CreatePin ( IN PIRP  Irp)

Definition at line 699 of file pin.c.

701 {
703  KSOBJECT_HEADER ObjectHeader;
705  PIO_STACK_LOCATION IoStack;
706 
707 
709  if (!DataFormat)
711 
713 
715  IoStack->FileObject->FsContext2 = (PVOID)DataFormat;
716 
717  /* allocate object header */
718  Status = KsAllocateObjectHeader(&ObjectHeader, 0, NULL, Irp, &PinTable);
719  return Status;
720 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
Status
Definition: gdiplustypes.h:24
static KSDISPATCH_TABLE PinTable
Definition: pin.c:684
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
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 RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

Referenced by DispatchCreateKMixPin().

◆ free()

void free ( PVOID  Block)

Definition at line 735 of file pin.c.

736 {
737  ExFreePool(Block);
738 }
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

◆ PerformChannelConversion()

NTSTATUS PerformChannelConversion ( PUCHAR  Buffer,
ULONG  BufferLength,
ULONG  OldChannels,
ULONG  NewChannels,
ULONG  BitsPerSample,
PVOID Result,
PULONG  ResultLength 
)

Definition at line 155 of file pin.c.

163 {
164  ULONG Samples;
165  ULONG NewIndex, OldIndex;
166 
167  Samples = BufferLength / (BitsPerSample / 8) / OldChannels;
168 
169  if (NewChannels > OldChannels)
170  {
171  if (BitsPerSample == 8)
172  {
173  PUCHAR BufferOut = ExAllocatePool(NonPagedPool, Samples * NewChannels);
174  if (!BufferOut)
176 
177  for(NewIndex = 0, OldIndex = 0; OldIndex < Samples * OldChannels; NewIndex += NewChannels, OldIndex += OldChannels)
178  {
179  ULONG SubIndex = 0;
180 
181  RtlMoveMemory(&BufferOut[NewIndex], &Buffer[OldIndex], OldChannels * sizeof(UCHAR));
182 
183  do
184  {
185  /* 2 channel stretched to 4 looks like LRLR */
186  BufferOut[NewIndex+OldChannels + SubIndex] = Buffer[OldIndex + (SubIndex % OldChannels)];
187  }while(SubIndex++ < NewChannels - OldChannels);
188  }
189  *Result = BufferOut;
190  *ResultLength = Samples * NewChannels;
191  }
192  else if (BitsPerSample == 16)
193  {
194  PUSHORT BufferOut = ExAllocatePool(NonPagedPool, Samples * NewChannels);
195  if (!BufferOut)
197 
198  for(NewIndex = 0, OldIndex = 0; OldIndex < Samples * OldChannels; NewIndex += NewChannels, OldIndex += OldChannels)
199  {
200  ULONG SubIndex = 0;
201 
202  RtlMoveMemory(&BufferOut[NewIndex], &Buffer[OldIndex], OldChannels * sizeof(USHORT));
203 
204  do
205  {
206  BufferOut[NewIndex+OldChannels + SubIndex] = Buffer[OldIndex + (SubIndex % OldChannels)];
207  }while(SubIndex++ < NewChannels - OldChannels);
208  }
209  *Result = BufferOut;
210  *ResultLength = Samples * NewChannels;
211  }
212  else if (BitsPerSample == 24)
213  {
214  PUCHAR BufferOut = ExAllocatePool(NonPagedPool, Samples * NewChannels);
215  if (!BufferOut)
217 
218  for(NewIndex = 0, OldIndex = 0; OldIndex < Samples * OldChannels; NewIndex += NewChannels, OldIndex += OldChannels)
219  {
220  ULONG SubIndex = 0;
221 
222  RtlMoveMemory(&BufferOut[NewIndex], &Buffer[OldIndex], OldChannels * 3);
223 
224  do
225  {
226  RtlMoveMemory(&BufferOut[(NewIndex+OldChannels + SubIndex) * 3], &Buffer[(OldIndex + (SubIndex % OldChannels)) * 3], 3);
227  }while(SubIndex++ < NewChannels - OldChannels);
228  }
229  *Result = BufferOut;
230  *ResultLength = Samples * NewChannels;
231  }
232  else if (BitsPerSample == 32)
233  {
234  PULONG BufferOut = ExAllocatePool(NonPagedPool, Samples * NewChannels);
235  if (!BufferOut)
237 
238  for(NewIndex = 0, OldIndex = 0; OldIndex < Samples * OldChannels; NewIndex += NewChannels, OldIndex += OldChannels)
239  {
240  ULONG SubIndex = 0;
241 
242  RtlMoveMemory(&BufferOut[NewIndex], &Buffer[OldIndex], OldChannels * sizeof(ULONG));
243 
244  do
245  {
246  BufferOut[NewIndex+OldChannels + SubIndex] = Buffer[OldIndex + (SubIndex % OldChannels)];
247  }while(SubIndex++ < NewChannels - OldChannels);
248  }
249  *Result = BufferOut;
250  *ResultLength = Samples * NewChannels;
251  }
252 
253  }
254  else
255  {
256  PUSHORT BufferOut = ExAllocatePool(NonPagedPool, Samples * NewChannels);
257  if (!BufferOut)
259 
260  for(NewIndex = 0, OldIndex = 0; OldIndex < Samples * OldChannels; NewIndex += NewChannels, OldIndex += OldChannels)
261  {
262  /* TODO
263  * mix stream instead of just dumping part of it ;)
264  */
265  RtlMoveMemory(&BufferOut[NewIndex], &Buffer[OldIndex], NewChannels * (BitsPerSample/8));
266  }
267 
268  *Result = BufferOut;
269  *ResultLength = Samples * NewChannels;
270  }
271  return STATUS_SUCCESS;
272 }
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
unsigned char * PUCHAR
Definition: retypes.h:3
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
_In_ ULONG BufferLength
Definition: usbdlib.h:225
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
Definition: bufpool.h:45
unsigned char UCHAR
Definition: xmlstorage.h:181
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
unsigned short USHORT
Definition: pedump.c:61
unsigned int * PULONG
Definition: retypes.h:1
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2745
unsigned short * PUSHORT
Definition: retypes.h:2

Referenced by Pin_fnFastWrite().

◆ PerformQualityConversion()

NTSTATUS PerformQualityConversion ( PUCHAR  Buffer,
ULONG  BufferLength,
ULONG  OldWidth,
ULONG  NewWidth,
PVOID Result,
PULONG  ResultLength 
)

Definition at line 276 of file pin.c.

283 {
284  ULONG Samples;
285  ULONG Index;
286 
287  ASSERT(OldWidth != NewWidth);
288 
289  Samples = BufferLength / (OldWidth / 8);
290  //DPRINT("Samples %u BufferLength %u\n", Samples, BufferLength);
291 
292  if (OldWidth == 8 && NewWidth == 16)
293  {
294  USHORT Sample;
295  PUSHORT BufferOut = ExAllocatePool(NonPagedPool, Samples * sizeof(USHORT));
296  if (!BufferOut)
298 
299  for(Index = 0; Index < Samples; Index++)
300  {
301  Sample = Buffer[Index];
302  Sample *= 2;
303 #ifdef _X86_
304  Sample = _byteswap_ushort(Sample);
305 #endif
306  BufferOut[Index] = Sample;
307  }
308  *Result = BufferOut;
309  *ResultLength = Samples * sizeof(USHORT);
310  }
311  else if (OldWidth == 8 && NewWidth == 32)
312  {
313  ULONG Sample;
314  PULONG BufferOut = ExAllocatePool(NonPagedPool, Samples * sizeof(ULONG));
315  if (!BufferOut)
317 
318  for(Index = 0; Index < Samples; Index++)
319  {
320  Sample = Buffer[Index];
321  Sample *= 16777216;
322 #ifdef _X86_
323  Sample = _byteswap_ulong(Sample);
324 #endif
325  BufferOut[Index] = Sample;
326  }
327  *Result = BufferOut;
328  *ResultLength = Samples * sizeof(ULONG);
329  }
330  else if (OldWidth == 16 && NewWidth == 32)
331  {
332  ULONG Sample;
333  PUSHORT BufferIn = (PUSHORT)Buffer;
334  PULONG BufferOut = ExAllocatePool(NonPagedPool, Samples * sizeof(ULONG));
335  if (!BufferOut)
337 
338  for(Index = 0; Index < Samples; Index++)
339  {
340  Sample = BufferIn[Index];
341  Sample *= 65536;
342 #ifdef _X86_
343  Sample = _byteswap_ulong(Sample);
344 #endif
345  BufferOut[Index] = Sample;
346  }
347  *Result = BufferOut;
348  *ResultLength = Samples * sizeof(ULONG);
349  }
350 
351  else if (OldWidth == 16 && NewWidth == 8)
352  {
353  USHORT Sample;
354  PUSHORT BufferIn = (PUSHORT)Buffer;
355  PUCHAR BufferOut = ExAllocatePool(NonPagedPool, Samples * sizeof(UCHAR));
356  if (!BufferOut)
358 
359  for(Index = 0; Index < Samples; Index++)
360  {
361  Sample = BufferIn[Index];
362 #ifdef _X86_
363  Sample = _byteswap_ushort(Sample);
364 #endif
365  Sample /= 256;
366  BufferOut[Index] = (Sample & 0xFF);
367  }
368  *Result = BufferOut;
369  *ResultLength = Samples * sizeof(UCHAR);
370  }
371  else if (OldWidth == 32 && NewWidth == 8)
372  {
373  ULONG Sample;
374  PULONG BufferIn = (PULONG)Buffer;
375  PUCHAR BufferOut = ExAllocatePool(NonPagedPool, Samples * sizeof(UCHAR));
376  if (!BufferOut)
378 
379  for(Index = 0; Index < Samples; Index++)
380  {
381  Sample = BufferIn[Index];
382 #ifdef _X86_
383  Sample = _byteswap_ulong(Sample);
384 #endif
385  Sample /= 16777216;
386  BufferOut[Index] = (Sample & 0xFF);
387  }
388  *Result = BufferOut;
389  *ResultLength = Samples * sizeof(UCHAR);
390  }
391  else if (OldWidth == 32 && NewWidth == 16)
392  {
393  USHORT Sample;
394  PULONG BufferIn = (PULONG)Buffer;
395  PUSHORT BufferOut = ExAllocatePool(NonPagedPool, Samples * sizeof(USHORT));
396  if (!BufferOut)
398 
399  for(Index = 0; Index < Samples; Index++)
400  {
401  Sample = BufferIn[Index];
402 #ifdef _X86_
403  Sample = _byteswap_ulong(Sample);
404 #endif
405  Sample /= 65536;
406  BufferOut[Index] = (Sample & 0xFFFF);
407  }
408  *Result = BufferOut;
409  *ResultLength = Samples * sizeof(USHORT);
410  }
411  else
412  {
413  DPRINT1("Not implemented conversion OldWidth %u NewWidth %u\n", OldWidth, NewWidth);
414  return STATUS_NOT_IMPLEMENTED;
415  }
416 
417  return STATUS_SUCCESS;
418 }
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
unsigned char * PUCHAR
Definition: retypes.h:3
_Check_return_ unsigned short __cdecl _byteswap_ushort(_In_ unsigned short)
_In_ ULONG BufferLength
Definition: usbdlib.h:225
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
Definition: bufpool.h:45
_Check_return_ unsigned long __cdecl _byteswap_ulong(_In_ unsigned long)
static const UCHAR Index[8]
Definition: usbohci.c:18
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
unsigned short USHORT
Definition: pedump.c:61
unsigned int * PULONG
Definition: retypes.h:1
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2745
unsigned short * PUSHORT
Definition: retypes.h:2

Referenced by Pin_fnFastWrite().

◆ PerformSampleRateConversion()

NTSTATUS PerformSampleRateConversion ( PUCHAR  Buffer,
ULONG  BufferLength,
ULONG  OldRate,
ULONG  NewRate,
ULONG  BytesPerSample,
ULONG  NumChannels,
PVOID Result,
PULONG  ResultLength 
)

Definition at line 19 of file pin.c.

28 {
29  KFLOATING_SAVE FloatSave;
31  ULONG Index;
32  SRC_STATE * State;
33  SRC_DATA Data;
34  PUCHAR ResultOut;
35  int error;
36  PFLOAT FloatIn, FloatOut;
37  ULONG NumSamples;
38  ULONG NewSamples;
39 
40  DPRINT("PerformSampleRateConversion OldRate %u NewRate %u BytesPerSample %u NumChannels %u Irql %u\n", OldRate, NewRate, BytesPerSample, NumChannels, KeGetCurrentIrql());
41 
42  ASSERT(BytesPerSample == 1 || BytesPerSample == 2 || BytesPerSample == 4);
43 
44  /* first acquire float save context */
45  Status = KeSaveFloatingPointState(&FloatSave);
46 
47  if (!NT_SUCCESS(Status))
48  {
49  DPRINT1("KeSaveFloatingPointState failed with %x\n", Status);
50  return Status;
51  }
52 
53  NumSamples = BufferLength / (BytesPerSample * NumChannels);
54 
55  FloatIn = ExAllocatePool(NonPagedPool, NumSamples * NumChannels * sizeof(FLOAT));
56  if (!FloatIn)
57  {
58  KeRestoreFloatingPointState(&FloatSave);
60  }
61 
62  NewSamples = ((((ULONG64)NumSamples * NewRate) + (OldRate / 2)) / OldRate) + 2;
63 
64  FloatOut = ExAllocatePool(NonPagedPool, NewSamples * NumChannels * sizeof(FLOAT));
65  if (!FloatOut)
66  {
67  ExFreePool(FloatIn);
68  KeRestoreFloatingPointState(&FloatSave);
70  }
71 
72  ResultOut = ExAllocatePool(NonPagedPool, NewSamples * NumChannels * BytesPerSample);
73  if (!ResultOut)
74  {
75  ExFreePool(FloatIn);
76  ExFreePool(FloatOut);
77  KeRestoreFloatingPointState(&FloatSave);
79  }
80 
81  State = src_new(SRC_SINC_FASTEST, NumChannels, &error);
82  if (!State)
83  {
84  DPRINT1("src_new failed with %x\n", error);
85  KeRestoreFloatingPointState(&FloatSave);
86  ExFreePool(FloatIn);
87  ExFreePool(FloatOut);
88  ExFreePool(ResultOut);
89  return STATUS_UNSUCCESSFUL;
90  }
91 
92  /* fixme use asm */
93  if (BytesPerSample == 1)
94  {
95  for(Index = 0; Index < NumSamples * NumChannels; Index++)
96  FloatIn[Index] = (float)(Buffer[Index] / (1.0 * 0x80));
97  }
98  else if (BytesPerSample == 2)
99  {
100  src_short_to_float_array((short*)Buffer, FloatIn, NumSamples * NumChannels);
101  }
102  else if (BytesPerSample == 4)
103  {
104  src_int_to_float_array((int*)Buffer, FloatIn, NumSamples * NumChannels);
105  }
106 
107  Data.data_in = FloatIn;
108  Data.data_out = FloatOut;
109  Data.input_frames = NumSamples;
110  Data.output_frames = NewSamples;
111  Data.src_ratio = (double)NewRate / (double)OldRate;
112 
114  if (error)
115  {
116  DPRINT1("src_process failed with %x\n", error);
117  KeRestoreFloatingPointState(&FloatSave);
118  ExFreePool(FloatIn);
119  ExFreePool(FloatOut);
120  ExFreePool(ResultOut);
121  return STATUS_UNSUCCESSFUL;
122  }
123 
124  if (BytesPerSample == 1)
125  {
126  /* FIXME perform over/under clipping */
127 
128  for(Index = 0; Index < Data.output_frames_gen * NumChannels; Index++)
129  ResultOut[Index] = (lrintf(FloatOut[Index]) >> 24);
130  }
131  else if (BytesPerSample == 2)
132  {
133  PUSHORT Res = (PUSHORT)ResultOut;
134 
135  src_float_to_short_array(FloatOut, (short*)Res, Data.output_frames_gen * NumChannels);
136  }
137  else if (BytesPerSample == 4)
138  {
139  PULONG Res = (PULONG)ResultOut;
140 
141  src_float_to_int_array(FloatOut, (int*)Res, Data.output_frames_gen * NumChannels);
142  }
143 
144 
145  *Result = ResultOut;
146  *ResultLength = Data.output_frames_gen * BytesPerSample * NumChannels;
147  ExFreePool(FloatIn);
148  ExFreePool(FloatOut);
149  src_delete(State);
150  KeRestoreFloatingPointState(&FloatSave);
151  return STATUS_SUCCESS;
152 }
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
SRC_STATE * src_new(int converter_type, int channels, int *error)
Definition: samplerate.c:15
void src_float_to_int_array(const float *in, int *out, int len)
Definition: samplerate.c:493
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define error(str)
Definition: mkdosfs.c:1605
unsigned char * PUCHAR
Definition: retypes.h:3
void src_int_to_float_array(const int *in, float *out, int len)
Definition: samplerate.c:482
LONG NTSTATUS
Definition: precomp.h:26
FLOAT * PFLOAT
Definition: windef.h:174
struct SRC_STATE_tag SRC_STATE
Definition: samplerate.h:23
_In_ ULONG BufferLength
Definition: usbdlib.h:225
void src_float_to_short_array(const float *in, short *out, int len)
Definition: samplerate.c:460
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
Definition: string.c:80
SRC_STATE * src_delete(SRC_STATE *state)
Definition: samplerate.c:74
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
_Check_return_ __CRT_INLINE long lrintf(_In_ float x)
Definition: math.h:268
#define KeRestoreFloatingPointState(x)
Definition: kmixer.h:33
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const UCHAR Index[8]
Definition: usbohci.c:18
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
unsigned __int64 ULONG64
Definition: imports.h:198
#define KeSaveFloatingPointState(x)
Definition: kmixer.h:32
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
Status
Definition: gdiplustypes.h:24
enum State_ State
Definition: pofuncs.h:54
unsigned int * PULONG
Definition: retypes.h:1
#define DPRINT1
Definition: precomp.h:8
float FLOAT
Definition: typedefs.h:67
void src_short_to_float_array(const short *in, float *out, int len)
Definition: samplerate.c:449
int src_process(SRC_STATE *state, SRC_DATA *data)
Definition: samplerate.c:89
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2745
unsigned short * PUSHORT
Definition: retypes.h:2
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by Pin_fnFastWrite().

◆ Pin_fnClose()

NTSTATUS NTAPI Pin_fnClose ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 513 of file pin.c.

516 {
518 
519  Irp->IoStatus.Status = STATUS_SUCCESS;
520  Irp->IoStatus.Information = 0;
522  return STATUS_SUCCESS;
523 }
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define UNIMPLEMENTED
Definition: debug.h:114
return STATUS_SUCCESS
Definition: btrfs.c:2745

◆ Pin_fnDeviceIoControl()

NTSTATUS NTAPI Pin_fnDeviceIoControl ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 423 of file pin.c.

426 {
427  PIO_STACK_LOCATION IoStack;
429  //DPRINT1("Pin_fnDeviceIoControl called DeviceObject %p Irp %p\n", DeviceObject);
430 
432 
433  if (IoStack->Parameters.DeviceIoControl.InputBufferLength == sizeof(KSP_PIN) && IoStack->Parameters.DeviceIoControl.OutputBufferLength == sizeof(KSDATAFORMAT_WAVEFORMATEX))
434  {
435  Property = (PKSP_PIN)IoStack->Parameters.DeviceIoControl.Type3InputBuffer;
436 
438  {
440  {
442  PKSDATAFORMAT_WAVEFORMATEX WaveFormat;
443 
444  Formats = (PKSDATAFORMAT_WAVEFORMATEX)IoStack->FileObject->FsContext2;
445  WaveFormat = (PKSDATAFORMAT_WAVEFORMATEX)Irp->UserBuffer;
446 
447  ASSERT(Property->PinId == 0 || Property->PinId == 1);
448  ASSERT(Formats);
449  ASSERT(WaveFormat);
450 
451  Formats[Property->PinId].WaveFormatEx.nChannels = WaveFormat->WaveFormatEx.nChannels;
452  Formats[Property->PinId].WaveFormatEx.wBitsPerSample = WaveFormat->WaveFormatEx.wBitsPerSample;
453  Formats[Property->PinId].WaveFormatEx.nSamplesPerSec = WaveFormat->WaveFormatEx.nSamplesPerSec;
454 
455  Irp->IoStatus.Information = 0;
456  Irp->IoStatus.Status = STATUS_SUCCESS;
458  return STATUS_SUCCESS;
459  }
460  }
461  }
462  DPRINT1("Size %u Expected %u\n",IoStack->Parameters.DeviceIoControl.OutputBufferLength, sizeof(KSDATAFORMAT_WAVEFORMATEX));
463  Irp->IoStatus.Information = 0;
464  Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
466  return STATUS_UNSUCCESSFUL;
467 }
_In_ PIRP Irp
Definition: csq.h:116
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:233
WORD wBitsPerSample
Definition: audioclient.idl:45
const GUID KSPROPSETID_Connection
Definition: pin.c:113
#define IoCompleteRequest
Definition: irp.c:1240
DWORD nSamplesPerSec
Definition: audioclient.idl:42
Definition: ks.h:672
if(!(yy_init))
Definition: macro.lex.yy.c:714
WAVEFORMATEX WaveFormatEx
Definition: ksmedia.h:532
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ DWORD Property
Definition: setupapi.h:1545
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
struct KSDATAFORMAT_WAVEFORMATEX * PKSDATAFORMAT_WAVEFORMATEX
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
struct KSP_PIN * PKSP_PIN
#define DPRINT1
Definition: precomp.h:8
#define IO_NO_INCREMENT
Definition: iotypes.h:565
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
return STATUS_SUCCESS
Definition: btrfs.c:2745
#define KSPROPERTY_TYPE_SET
Definition: dmksctrl.h:43
Property(long _type, long _tag, INREAL _value)
Definition: reader.h:125

◆ Pin_fnFastDeviceIoControl()

BOOLEAN NTAPI Pin_fnFastDeviceIoControl ( PFILE_OBJECT  FileObject,
BOOLEAN  Wait,
PVOID  InputBuffer,
ULONG  InputBufferLength,
PVOID  OutputBuffer,
ULONG  OutputBufferLength,
ULONG  IoControlCode,
PIO_STATUS_BLOCK  IoStatus,
PDEVICE_OBJECT  DeviceObject 
)

Definition at line 556 of file pin.c.

566 {
568 
569 
570  return FALSE;
571 }
#define UNIMPLEMENTED
Definition: debug.h:114

◆ Pin_fnFastRead()

BOOLEAN NTAPI Pin_fnFastRead ( PFILE_OBJECT  FileObject,
PLARGE_INTEGER  FileOffset,
ULONG  Length,
BOOLEAN  Wait,
ULONG  LockKey,
PVOID  Buffer,
PIO_STATUS_BLOCK  IoStatus,
PDEVICE_OBJECT  DeviceObject 
)

Definition at line 576 of file pin.c.

585 {
587  return FALSE;
588 
589 }
#define UNIMPLEMENTED
Definition: debug.h:114

◆ Pin_fnFastWrite()

BOOLEAN NTAPI Pin_fnFastWrite ( PFILE_OBJECT  FileObject,
PLARGE_INTEGER  FileOffset,
ULONG  Length,
BOOLEAN  Wait,
ULONG  LockKey,
PVOID  Buffer,
PIO_STATUS_BLOCK  IoStatus,
PDEVICE_OBJECT  DeviceObject 
)

Definition at line 593 of file pin.c.

602 {
603  PKSSTREAM_HEADER StreamHeader;
604  PVOID BufferOut;
609 
610  DPRINT("Pin_fnFastWrite called DeviceObject %p Irp %p\n", DeviceObject);
611 
612  Formats = (PKSDATAFORMAT_WAVEFORMATEX)FileObject->FsContext2;
613 
614  InputFormat = Formats;
615  OutputFormat = (Formats + 1);
616  StreamHeader = (PKSSTREAM_HEADER)Buffer;
617 
618 
619  DPRINT("Num Channels %u Old Channels %u\n SampleRate %u Old SampleRate %u\n BitsPerSample %u Old BitsPerSample %u\n",
620  InputFormat->WaveFormatEx.nChannels, OutputFormat->WaveFormatEx.nChannels,
621  InputFormat->WaveFormatEx.nSamplesPerSec, OutputFormat->WaveFormatEx.nSamplesPerSec,
622  InputFormat->WaveFormatEx.wBitsPerSample, OutputFormat->WaveFormatEx.wBitsPerSample);
623 
624  if (InputFormat->WaveFormatEx.wBitsPerSample != OutputFormat->WaveFormatEx.wBitsPerSample)
625  {
626  Status = PerformQualityConversion(StreamHeader->Data,
627  StreamHeader->DataUsed,
628  InputFormat->WaveFormatEx.wBitsPerSample,
629  OutputFormat->WaveFormatEx.wBitsPerSample,
630  &BufferOut,
631  &BufferLength);
632  if (NT_SUCCESS(Status))
633  {
634  ExFreePool(StreamHeader->Data);
635  StreamHeader->Data = BufferOut;
636  StreamHeader->DataUsed = BufferLength;
637  }
638  }
639 
640  if (InputFormat->WaveFormatEx.nChannels != OutputFormat->WaveFormatEx.nChannels)
641  {
642  Status = PerformChannelConversion(StreamHeader->Data,
643  StreamHeader->DataUsed,
644  InputFormat->WaveFormatEx.nChannels,
645  OutputFormat->WaveFormatEx.nChannels,
646  OutputFormat->WaveFormatEx.wBitsPerSample,
647  &BufferOut,
648  &BufferLength);
649 
650  if (NT_SUCCESS(Status))
651  {
652  ExFreePool(StreamHeader->Data);
653  StreamHeader->Data = BufferOut;
654  StreamHeader->DataUsed = BufferLength;
655  }
656  }
657 
658  if (InputFormat->WaveFormatEx.nSamplesPerSec != OutputFormat->WaveFormatEx.nSamplesPerSec)
659  {
660  Status = PerformSampleRateConversion(StreamHeader->Data,
661  StreamHeader->DataUsed,
662  InputFormat->WaveFormatEx.nSamplesPerSec,
663  OutputFormat->WaveFormatEx.nSamplesPerSec,
664  OutputFormat->WaveFormatEx.wBitsPerSample / 8,
665  OutputFormat->WaveFormatEx.nChannels,
666  &BufferOut,
667  &BufferLength);
668  if (NT_SUCCESS(Status))
669  {
670  ExFreePool(StreamHeader->Data);
671  StreamHeader->Data = BufferOut;
672  StreamHeader->DataUsed = BufferLength;
673  }
674  }
675 
676  IoStatus->Status = Status;
677 
678  if (NT_SUCCESS(Status))
679  return TRUE;
680  else
681  return FALSE;
682 }
#define TRUE
Definition: types.h:120
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
LONG NTSTATUS
Definition: precomp.h:26
enum OutputFormat_ OutputFormat
struct KSSTREAM_HEADER * PKSSTREAM_HEADER
_In_ ULONG BufferLength
Definition: usbdlib.h:225
WORD wBitsPerSample
Definition: audioclient.idl:45
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
DWORD nSamplesPerSec
Definition: audioclient.idl:42
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PVOID Data
Definition: ks.h:2771
NTSTATUS PerformQualityConversion(PUCHAR Buffer, ULONG BufferLength, ULONG OldWidth, ULONG NewWidth, PVOID *Result, PULONG ResultLength)
Definition: pin.c:276
WAVEFORMATEX WaveFormatEx
Definition: ksmedia.h:532
ULONG DataUsed
Definition: ks.h:2770
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
struct KSDATAFORMAT_WAVEFORMATEX * PKSDATAFORMAT_WAVEFORMATEX
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS PerformSampleRateConversion(PUCHAR Buffer, ULONG BufferLength, ULONG OldRate, ULONG NewRate, ULONG BytesPerSample, ULONG NumChannels, PVOID *Result, PULONG ResultLength)
Definition: pin.c:19
return STATUS_SUCCESS
Definition: btrfs.c:2745
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
NTSTATUS PerformChannelConversion(PUCHAR Buffer, ULONG BufferLength, ULONG OldChannels, ULONG NewChannels, ULONG BitsPerSample, PVOID *Result, PULONG ResultLength)
Definition: pin.c:155

◆ Pin_fnFlush()

NTSTATUS NTAPI Pin_fnFlush ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 499 of file pin.c.

502 {
504 
505  Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
506  Irp->IoStatus.Information = 0;
508  return STATUS_UNSUCCESSFUL;
509 }
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define UNIMPLEMENTED
Definition: debug.h:114

◆ Pin_fnQuerySecurity()

NTSTATUS NTAPI Pin_fnQuerySecurity ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 527 of file pin.c.

530 {
532 
533  Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
534  Irp->IoStatus.Information = 0;
536  return STATUS_UNSUCCESSFUL;
537 }
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define UNIMPLEMENTED
Definition: debug.h:114

◆ Pin_fnRead()

NTSTATUS NTAPI Pin_fnRead ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 471 of file pin.c.

474 {
476 
477  Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
478  Irp->IoStatus.Information = 0;
480  return STATUS_UNSUCCESSFUL;
481 }
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define UNIMPLEMENTED
Definition: debug.h:114

◆ Pin_fnSetSecurity()

NTSTATUS NTAPI Pin_fnSetSecurity ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 541 of file pin.c.

544 {
545 
547 
548  Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
549  Irp->IoStatus.Information = 0;
551  return STATUS_UNSUCCESSFUL;
552 }
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define UNIMPLEMENTED
Definition: debug.h:114

◆ Pin_fnWrite()

NTSTATUS NTAPI Pin_fnWrite ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp 
)

Definition at line 485 of file pin.c.

488 {
490 
491  Irp->IoStatus.Information = 0;
492  Irp->IoStatus.Status = STATUS_SUCCESS;
494  return STATUS_SUCCESS;
495 }
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define UNIMPLEMENTED
Definition: debug.h:114
return STATUS_SUCCESS
Definition: btrfs.c:2745

Variable Documentation

◆ KSPROPSETID_Connection

const GUID KSPROPSETID_Connection = {0x1D58C920L, 0xAC9B, 0x11CF, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}}

Definition at line 16 of file pin.c.

◆ PinTable

KSDISPATCH_TABLE PinTable
static
Initial value:
=
{
}
BOOLEAN NTAPI Pin_fnFastWrite(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, ULONG LockKey, PVOID Buffer, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject)
Definition: pin.c:593
NTSTATUS NTAPI Pin_fnClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pin.c:513
BOOLEAN NTAPI Pin_fnFastRead(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, ULONG LockKey, PVOID Buffer, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject)
Definition: pin.c:576
NTSTATUS NTAPI Pin_fnSetSecurity(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pin.c:541
NTSTATUS NTAPI Pin_fnFlush(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pin.c:499
NTSTATUS NTAPI Pin_fnRead(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pin.c:471
NTSTATUS NTAPI Pin_fnWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pin.c:485
NTSTATUS NTAPI Pin_fnDeviceIoControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pin.c:423
NTSTATUS NTAPI Pin_fnQuerySecurity(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pin.c:527
BOOLEAN NTAPI Pin_fnFastDeviceIoControl(PFILE_OBJECT FileObject, BOOLEAN Wait, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength, ULONG IoControlCode, PIO_STATUS_BLOCK IoStatus, PDEVICE_OBJECT DeviceObject)
Definition: pin.c:556

Definition at line 684 of file pin.c.

Referenced by CreatePin().