ReactOS 0.4.15-dev-8339-g4028de8
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}
#define NULL
Definition: types.h:112
#define NonPagedPool
Definition: env_spec_w32.h:307
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFCOLLECTION _In_ ULONG Index

◆ 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}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
LONG NTSTATUS
Definition: precomp.h:26
_In_ PIRP Irp
Definition: csq.h:116
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
static KSDISPATCH_TABLE PinTable
Definition: pin.c:684
Status
Definition: gdiplustypes.h:25
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
void * PVOID
Definition: typedefs.h:50
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

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}
Definition: bufpool.h:45
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_SUCCESS
Definition: shellext.h:65
uint32_t * PULONG
Definition: typedefs.h:59
uint16_t * PUSHORT
Definition: typedefs.h:56
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_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:409
unsigned char UCHAR
Definition: xmlstorage.h:181

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);
415 }
416
417 return STATUS_SUCCESS;
418}
#define DPRINT1
Definition: precomp.h:8
_Check_return_ unsigned long __cdecl _byteswap_ulong(_In_ unsigned long)
_Check_return_ unsigned short __cdecl _byteswap_ushort(_In_ unsigned short)
#define ASSERT(a)
Definition: mode.c:44
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239

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;
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 {
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);
70 }
71
72 ResultOut = ExAllocatePool(NonPagedPool, NewSamples * NumChannels * BytesPerSample);
73 if (!ResultOut)
74 {
75 ExFreePool(FloatIn);
76 ExFreePool(FloatOut);
79 }
80
81 State = src_new(SRC_SINC_FASTEST, NumChannels, &error);
82 if (!State)
83 {
84 DPRINT1("src_new failed with %x\n", error);
86 ExFreePool(FloatIn);
87 ExFreePool(FloatOut);
88 ExFreePool(ResultOut);
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);
150 KeRestoreFloatingPointState(&FloatSave);
151 return STATUS_SUCCESS;
152}
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
_Check_return_ __CRT_INLINE long lrintf(_In_ float x)
Definition: math.h:293
#define KeSaveFloatingPointState(x)
Definition: kmixer.h:32
#define KeRestoreFloatingPointState(x)
Definition: kmixer.h:33
#define error(str)
Definition: mkdosfs.c:1605
unsigned __int64 ULONG64
Definition: imports.h:198
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
Definition: string.c:80
void src_int_to_float_array(const int *in, float *out, int len)
Definition: samplerate.c:482
void src_float_to_short_array(const float *in, short *out, int len)
Definition: samplerate.c:460
void src_short_to_float_array(const short *in, float *out, int len)
Definition: samplerate.c:449
void src_float_to_int_array(const float *in, int *out, int len)
Definition: samplerate.c:493
int src_process(SRC_STATE *state, SRC_DATA *data)
Definition: samplerate.c:89
SRC_STATE * src_delete(SRC_STATE *state)
Definition: samplerate.c:74
SRC_STATE * src_new(int converter_type, int channels, int *error)
Definition: samplerate.c:15
struct SRC_STATE_tag SRC_STATE
Definition: samplerate.h:23
@ SRC_SINC_FASTEST
Definition: samplerate.h:161
#define DPRINT
Definition: sndvol32.h:73
float FLOAT
Definition: typedefs.h:69
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
FLOAT * PFLOAT
Definition: windef.h:174

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}
#define UNIMPLEMENTED
Definition: debug.h:118
#define IoCompleteRequest
Definition: irp.c:1240
#define IO_NO_INCREMENT
Definition: iotypes.h:598

◆ 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 {
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}
const GUID KSPROPSETID_Connection
Definition: pin.c:113
#define KSPROPERTY_TYPE_SET
Definition: dmksctrl.h:43
@ KSPROPERTY_CONNECTION_DATAFORMAT
Definition: ks.h:351
struct KSP_PIN * PKSP_PIN
struct KSDATAFORMAT_WAVEFORMATEX * PKSDATAFORMAT_WAVEFORMATEX
if(dx< 0)
Definition: linetemp.h:194
WAVEFORMATEX WaveFormatEx
Definition: ksmedia.h:632
Definition: ks.h:642
Property(long _type, long _tag, INREAL _value)
Definition: reader.h:125
WORD wBitsPerSample
Definition: audioclient.idl:45
DWORD nSamplesPerSec
Definition: audioclient.idl:42
struct _IO_STACK_LOCATION::@1574::@1575 DeviceIoControl
union _IO_STACK_LOCATION::@1574 Parameters
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:235

◆ 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 FALSE
Definition: types.h:117

◆ 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}

◆ 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 {
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}
enum OutputFormat_ OutputFormat
#define TRUE
Definition: types.h:120
NTSTATUS PerformQualityConversion(PUCHAR Buffer, ULONG BufferLength, ULONG OldWidth, ULONG NewWidth, PVOID *Result, PULONG ResultLength)
Definition: pin.c:276
NTSTATUS PerformChannelConversion(PUCHAR Buffer, ULONG BufferLength, ULONG OldChannels, ULONG NewChannels, ULONG BitsPerSample, PVOID *Result, PULONG ResultLength)
Definition: pin.c:155
NTSTATUS PerformSampleRateConversion(PUCHAR Buffer, ULONG BufferLength, ULONG OldRate, ULONG NewRate, ULONG BytesPerSample, ULONG NumChannels, PVOID *Result, PULONG ResultLength)
Definition: pin.c:19
struct KSSTREAM_HEADER * PKSSTREAM_HEADER
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
PVOID Data
Definition: ks.h:2742
ULONG DataUsed
Definition: ks.h:2741
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550

◆ 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}

◆ 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}

◆ 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}

◆ 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}

◆ 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}

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:
=
{
}
NTSTATUS NTAPI Pin_fnDeviceIoControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pin.c:423
NTSTATUS NTAPI Pin_fnRead(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pin.c:471
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_fnQuerySecurity(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pin.c:527
NTSTATUS NTAPI Pin_fnWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pin.c:485
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
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(), and DispatchCreateSysAudioPin().