ReactOS  0.4.14-dev-552-g2fad488
misc.c File Reference
#include "precomp.h"
Include dependency graph for misc.c:

Go to the source code of this file.

Functions

VOID PerformChannelConversion (PUCHAR Buffer, ULONG BufferLength, PULONG BytesRead, ULONG OldChannels, ULONG NewChannels, ULONG BitsPerSample, PUCHAR Result, ULONG ResultLength, PULONG BytesWritten)
 
BOOL SetPinFormat (IN HANDLE hPin, IN LPWAVEFORMATEX WaveFormatEx)
 
BOOL DoDataIntersection (HANDLE hFilter, DWORD PinId, DWORD SampleFrequency, LPWAVEFORMATEX WaveFormatEx, DWORD MinimumBitsPerSample, DWORD MaximumBitsPerSample, DWORD MaximumChannels, LPWAVEFORMATEX WaveFormatOut)
 
DWORD OpenPin (HANDLE hFilter, ULONG PinId, LPWAVEFORMATEX WaveFormatEx, PHANDLE hPin, BOOL bLoop)
 
DWORD OpenFilter (IN LPCWSTR lpFileName, IN PHANDLE OutHandle)
 
DWORD SyncOverlappedDeviceIoControl (IN HANDLE Handle, IN DWORD IoControlCode, IN LPVOID InBuffer, IN DWORD InBufferSize, OUT LPVOID OutBuffer, IN DWORD OutBufferSize, OUT LPDWORD BytesTransferred OPTIONAL)
 
DWORD GetFilterPinCount (IN HANDLE hFilter, OUT PULONG NumPins)
 
DWORD GetFilterNodeProperty (IN HANDLE hFilter, IN ULONG PropertyId, OUT PKSMULTIPLE_ITEM *OutMultipleItem)
 
DWORD GetFilterPinCommunication (IN HANDLE hFilter, IN ULONG PinId, OUT PKSPIN_COMMUNICATION Communication)
 
DWORD GetFilterPinDataFlow (IN HANDLE hFilter, IN ULONG PinId, OUT PKSPIN_DATAFLOW DataFlow)
 
DWORD GetFilterPinDataRanges (IN HANDLE hFilter, IN ULONG PinId, IN OUT PKSMULTIPLE_ITEM *OutMultipleItem)
 
BOOL CreateCompatiblePin (IN HANDLE hFilter, IN DWORD PinId, IN BOOL bLoop, IN LPWAVEFORMATEX WaveFormatEx, OUT LPWAVEFORMATEX WaveFormatOut, OUT PHANDLE hPin)
 

Variables

const GUID KSPROPSETID_Pin = {0x8C134960L, 0x51AD, 0x11CF, {0x87, 0x8A, 0x94, 0xF8, 0x01, 0xC1, 0x00, 0x00}}
 
const GUID KSPROPSETID_Topology = {0x720D4AC0L, 0x7533, 0x11D0, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}}
 
const GUID KSPROPSETID_Audio = {0x45FFAAA0L, 0x6E1B, 0x11D0, {0xBC, 0xF2, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}
 

Function Documentation

◆ CreateCompatiblePin()

BOOL CreateCompatiblePin ( IN HANDLE  hFilter,
IN DWORD  PinId,
IN BOOL  bLoop,
IN LPWAVEFORMATEX  WaveFormatEx,
OUT LPWAVEFORMATEX  WaveFormatOut,
OUT PHANDLE  hPin 
)

Definition at line 517 of file misc.c.

524 {
525  PKSMULTIPLE_ITEM Item = NULL;
526  PKSDATARANGE_AUDIO AudioRange;
527  DWORD dwResult;
528  DWORD dwIndex, nChannels;
529 
530  dwResult = GetFilterPinDataRanges(hFilter, PinId, &Item);
531 
532  if (dwResult != ERROR_SUCCESS)
533  {
534  /* failed to get data ranges */
535  return FALSE;
536  }
537 
538  CopyMemory(WaveFormatOut, WaveFormatEx, sizeof(WAVEFORMATEX));
539 
540  /* iterate through all dataranges */
541  AudioRange = (PKSDATARANGE_AUDIO)(Item + 1);
542  for(dwIndex = 0; dwIndex < Item->Count; dwIndex++)
543  {
544  if (AudioRange->DataRange.FormatSize != sizeof(KSDATARANGE_AUDIO))
545  {
547  AudioRange = (PKSDATARANGE_AUDIO)((PUCHAR)AudioRange + AudioRange->DataRange.FormatSize);
548  continue;
549  }
550 
551  if (WaveFormatOut->nSamplesPerSec < AudioRange->MinimumSampleFrequency)
552  WaveFormatOut->nSamplesPerSec = AudioRange->MinimumSampleFrequency;
553  else if (WaveFormatOut->nSamplesPerSec > AudioRange->MaximumSampleFrequency)
554  WaveFormatOut->nSamplesPerSec = AudioRange->MaximumSampleFrequency;
555 
556  if (WaveFormatOut->wBitsPerSample < AudioRange->MinimumBitsPerSample)
557  WaveFormatOut->wBitsPerSample = AudioRange->MinimumBitsPerSample;
558  else if (WaveFormatOut->wBitsPerSample > AudioRange->MaximumBitsPerSample)
559  WaveFormatOut->wBitsPerSample = AudioRange->MaximumBitsPerSample;
560 
561  DPRINT("MinimumBitsPerSample %u MaximumBitsPerSample %u MinimumSampleFrequency %u MaximumSampleFrequency %u\n",
562  AudioRange->MinimumBitsPerSample, AudioRange->MaximumBitsPerSample, AudioRange->MinimumSampleFrequency, AudioRange->MaximumSampleFrequency);
563 
564  for(nChannels = 1; nChannels <= AudioRange->MaximumChannels; nChannels++)
565  {
566  WaveFormatOut->nChannels = nChannels;
567 
568  dwResult = OpenPin(hFilter, PinId, WaveFormatOut, hPin, TRUE);
569  if (dwResult == ERROR_SUCCESS)
570  {
571  DPRINT("InFormat nChannels %u wBitsPerSample %u nSamplesPerSec %u\nOutFormat nChannels %u nBitsPerSample %u nSamplesPerSec %u\n",
572  WaveFormatEx->nChannels, WaveFormatEx->wBitsPerSample, WaveFormatEx->nSamplesPerSec,
573  WaveFormatOut->nChannels, WaveFormatOut->wBitsPerSample, WaveFormatOut->nSamplesPerSec);
574 
575 
576  /* free buffer */
577  HeapFree(GetProcessHeap(), 0, Item);
578  return TRUE;
579  }
580  }
581  AudioRange = (PKSDATARANGE_AUDIO)((PUCHAR)AudioRange + AudioRange->DataRange.FormatSize);
582  }
583 
584  /* free buffer */
585  HeapFree(GetProcessHeap(), 0, Item);
586  return FALSE;
587 }
ULONG Count
Definition: ks.h:1980
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
ULONG MaximumBitsPerSample
Definition: ksmedia.h:582
unsigned char * PUCHAR
Definition: retypes.h:3
int nChannels
Definition: pcmconverter.c:95
KSDATARANGE DataRange
Definition: ksmedia.h:579
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
DWORD OpenPin(HANDLE hFilter, ULONG PinId, LPWAVEFORMATEX WaveFormatEx, PHANDLE hPin, BOOL bLoop)
Definition: misc.c:212
#define GetProcessHeap()
Definition: compat.h:403
ULONG MinimumSampleFrequency
Definition: ksmedia.h:583
#define CopyMemory
Definition: winbase.h:1640
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG MaximumChannels
Definition: ksmedia.h:580
struct KSDATARANGE_AUDIO * PKSDATARANGE_AUDIO
ULONG MaximumSampleFrequency
Definition: ksmedia.h:584
ULONG MinimumBitsPerSample
Definition: ksmedia.h:581
#define UNIMPLEMENTED
Definition: debug.h:114
DWORD GetFilterPinDataRanges(IN HANDLE hFilter, IN ULONG PinId, IN OUT PKSMULTIPLE_ITEM *OutMultipleItem)
Definition: misc.c:461
#define HeapFree(x, y, z)
Definition: compat.h:402

Referenced by NewDirectSoundCaptureBuffer().

◆ DoDataIntersection()

BOOL DoDataIntersection ( HANDLE  hFilter,
DWORD  PinId,
DWORD  SampleFrequency,
LPWAVEFORMATEX  WaveFormatEx,
DWORD  MinimumBitsPerSample,
DWORD  MaximumBitsPerSample,
DWORD  MaximumChannels,
LPWAVEFORMATEX  WaveFormatOut 
)

Definition at line 116 of file misc.c.

125 {
126  DWORD nChannels, nBitsPerSample;
127  KSDATAFORMAT_WAVEFORMATEX WaveFormat;
128  PKSP_PIN Pin;
129  PKSMULTIPLE_ITEM Item;
131  DWORD dwResult;
132 
133  /* allocate request */
135  if (!Pin)
136  {
137  /* no memory */
138  return FALSE;
139  }
140 
141  Item = (PKSMULTIPLE_ITEM)(Pin + 1);
143 
144  /* setup request */
145  Pin->PinId = PinId;
146  Pin->Property.Flags = KSPROPERTY_TYPE_GET;
147  Pin->Property.Set = KSPROPSETID_Pin;
148  Pin->Property.Id = KSPROPERTY_PIN_DATAINTERSECTION;
149  Item->Count = 1;
150  Item->Size = sizeof(KSDATAFORMAT_WAVEFORMATEX);
151 
152 
153  DataFormat->WaveFormatEx.wFormatTag = WaveFormatEx->wFormatTag;
154  DataFormat->WaveFormatEx.nSamplesPerSec = SampleFrequency;
155  DataFormat->WaveFormatEx.nBlockAlign = WaveFormatEx->nBlockAlign;
156  DataFormat->WaveFormatEx.cbSize = 0;
157  DataFormat->DataFormat.FormatSize = sizeof(KSDATAFORMAT) + sizeof(WAVEFORMATEX);
158  DataFormat->DataFormat.Flags = 0;
159  DataFormat->DataFormat.Reserved = 0;
160  DataFormat->DataFormat.MajorFormat = KSDATAFORMAT_TYPE_AUDIO;
161  DataFormat->DataFormat.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
162  DataFormat->DataFormat.Specifier = KSDATAFORMAT_SPECIFIER_WAVEFORMATEX;
163  DataFormat->DataFormat.SampleSize = 4;
164 
165  for(nChannels = 1; nChannels <= 2; nChannels++)
166  {
167  for(nBitsPerSample = MinimumBitsPerSample; nBitsPerSample <= MaximumBitsPerSample; nBitsPerSample += 8)
168  {
169  DataFormat->WaveFormatEx.nChannels = nChannels;
170  DataFormat->WaveFormatEx.nAvgBytesPerSec = (nBitsPerSample / 8) * nChannels * SampleFrequency;
171  DataFormat->WaveFormatEx.wBitsPerSample = nBitsPerSample;
172 
173  DPRINT("CurrentFormat: InFormat nChannels %u wBitsPerSample %u nSamplesPerSec %u\n",
174  nChannels, nBitsPerSample, SampleFrequency);
175 
177  (LPVOID)&WaveFormat, sizeof(KSDATAFORMAT_WAVEFORMATEX), NULL);
178 
179  DPRINT("dwResult %x\n", dwResult);
180 
181 
182  if (dwResult == ERROR_SUCCESS)
183  {
184  /* found a compatible audio range */
185  WaveFormatOut->cbSize = 0;
186  WaveFormatOut->nBlockAlign = WaveFormatEx->nBlockAlign;
187  WaveFormatOut->wFormatTag = WaveFormatEx->wFormatTag;
188  WaveFormatOut->nAvgBytesPerSec = (nBitsPerSample / 8) * nChannels * SampleFrequency;
189  WaveFormatOut->wBitsPerSample = nBitsPerSample;
190  WaveFormatOut->nSamplesPerSec = SampleFrequency;
191  WaveFormatOut->nChannels = nChannels;
192 
193  /* free buffer */
194  HeapFree(GetProcessHeap(), 0, Pin);
195 
196  DPRINT("InFormat nChannels %u wBitsPerSample %u nSamplesPerSec %u\nOutFormat nChannels %u nBitsPerSample %u nSamplesPerSec %u\n",
197  WaveFormatEx->nChannels, WaveFormatEx->wBitsPerSample, WaveFormatEx->nSamplesPerSec,
198  WaveFormatOut->nChannels, WaveFormatOut->wBitsPerSample, WaveFormatOut->nSamplesPerSec);
199 
200  return TRUE;
201  }
202  }
203  }
204 
205  /* free buffer */
206  HeapFree(GetProcessHeap(), 0, Pin);
207  ASSERT(0);
208  return FALSE;
209 }
ULONG Count
Definition: ks.h:1980
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
#define TRUE
Definition: types.h:120
#define KSDATAFORMAT_SUBTYPE_PCM
Definition: ksmedia.h:921
#define ERROR_SUCCESS
Definition: deptool.c:10
ULONG Size
Definition: ks.h:1979
DWORD nAvgBytesPerSec
Definition: mmreg.h:81
WORD nChannels
Definition: mmreg.h:79
int nChannels
Definition: pcmconverter.c:95
#define KSPROPERTY_TYPE_GET
Definition: dmksctrl.h:42
#define KSDATAFORMAT_SPECIFIER_WAVEFORMATEX
Definition: ksmedia.h:931
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define GetProcessHeap()
Definition: compat.h:403
Definition: ks.h:642
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
IN PDCB IN VBO IN ULONG IN BOOLEAN Pin
Definition: fatprocs.h:415
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONG Flags
Definition: ntfs.h:532
WORD wFormatTag
Definition: mmreg.h:78
DWORD SyncOverlappedDeviceIoControl(IN HANDLE Handle, IN DWORD IoControlCode, IN LPVOID InBuffer, IN DWORD InBufferSize, OUT LPVOID OutBuffer, IN DWORD OutBufferSize, OUT LPDWORD BytesTransferred OPTIONAL)
Definition: misc.c:298
struct KSMULTIPLE_ITEM * PKSMULTIPLE_ITEM
#define KSDATAFORMAT_TYPE_AUDIO
Definition: ksmedia.h:883
struct KSDATAFORMAT_WAVEFORMATEX * PKSDATAFORMAT_WAVEFORMATEX
WORD cbSize
Definition: mmreg.h:84
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
const GUID KSPROPSETID_Pin
Definition: misc.c:12
DWORD nSamplesPerSec
Definition: mmreg.h:80
WORD nBlockAlign
Definition: mmreg.h:82
WORD wBitsPerSample
Definition: mmreg.h:83
#define HeapFree(x, y, z)
Definition: compat.h:402

◆ GetFilterNodeProperty()

DWORD GetFilterNodeProperty ( IN HANDLE  hFilter,
IN ULONG  PropertyId,
OUT PKSMULTIPLE_ITEM OutMultipleItem 
)

Definition at line 375 of file misc.c.

379 {
381  PKSMULTIPLE_ITEM MultipleItem;
383 
384  /* setup query request */
385  Property.Id = PropertyId;
388 
389  /* query the size */
391 
392  if (Status != ERROR_MORE_DATA)
393  {
394  /* failed */
395  DPRINT("Failed to query PropertyId %lu ErrorCode %lx\n", PropertyId, Status);
396  return Status;
397  }
398 
399  MultipleItem = HeapAlloc(GetProcessHeap(), 0, BytesReturned);
400  if (!MultipleItem)
401  {
402  /* not enough memory */
403  DPRINT("Failed to allocate %u Bytes\n", BytesReturned);
404  return ERROR_OUTOFMEMORY;
405  }
406 
407  /* retrieve data ranges */
409 
410 
411  if (Status != ERROR_SUCCESS)
412  {
413  /* failed to get data ranges */
414  DPRINT("SyncOverlappedDeviceIoControl failed with %lx\n", Status);
415 
416  HeapFree(GetProcessHeap(), 0, MultipleItem);
417  return Status;
418  }
419 
420  /* save result */
421  *OutMultipleItem = MultipleItem;
422  return Status;
423 
424 }
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
#define ERROR_SUCCESS
Definition: deptool.c:10
_In_ PSTORAGE_PROPERTY_ID PropertyId
Definition: classpnp.h:966
const GUID KSPROPSETID_Topology
Definition: misc.c:13
#define KSPROPERTY_TYPE_GET
Definition: dmksctrl.h:42
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define GetProcessHeap()
Definition: compat.h:403
Definition: ks.h:642
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD SyncOverlappedDeviceIoControl(IN HANDLE Handle, IN DWORD IoControlCode, IN LPVOID InBuffer, IN DWORD InBufferSize, OUT LPVOID OutBuffer, IN DWORD OutBufferSize, OUT LPDWORD BytesTransferred OPTIONAL)
Definition: misc.c:298
#define ERROR_MORE_DATA
Definition: dderror.h:13
Status
Definition: gdiplustypes.h:24
_In_ DWORD Property
Definition: setupapi.h:1545
_In_ FILTER_INFORMATION_CLASS _In_ ULONG _Out_ PULONG BytesReturned
Definition: fltkernel.h:1716
#define HeapFree(x, y, z)
Definition: compat.h:402
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

◆ GetFilterPinCommunication()

DWORD GetFilterPinCommunication ( IN HANDLE  hFilter,
IN ULONG  PinId,
OUT PKSPIN_COMMUNICATION  Communication 
)

Definition at line 427 of file misc.c.

431 {
433 
437  Property.PinId = PinId;
438  Property.Reserved = 0;
439 
440  return SyncOverlappedDeviceIoControl(hFilter, IOCTL_KS_PROPERTY, (LPVOID)&Property, sizeof(KSP_PIN), (LPVOID)Communication, sizeof(KSPIN_COMMUNICATION), NULL);
441 }
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
#define KSPROPERTY_TYPE_GET
Definition: dmksctrl.h:42
smooth NULL
Definition: ftsmooth.c:416
Definition: ks.h:642
DWORD SyncOverlappedDeviceIoControl(IN HANDLE Handle, IN DWORD IoControlCode, IN LPVOID InBuffer, IN DWORD InBufferSize, OUT LPVOID OutBuffer, IN DWORD OutBufferSize, OUT LPDWORD BytesTransferred OPTIONAL)
Definition: misc.c:298
_In_ DWORD Property
Definition: setupapi.h:1545
KSPIN_COMMUNICATION
Definition: ks.h:1253
const GUID KSPROPSETID_Pin
Definition: misc.c:12
Property(long _type, long _tag, INREAL _value)
Definition: reader.h:125

Referenced by FindAudioFilterPins().

◆ GetFilterPinCount()

DWORD GetFilterPinCount ( IN HANDLE  hFilter,
OUT PULONG  NumPins 
)

Definition at line 357 of file misc.c.

360 {
361  KSPROPERTY Pin;
362 
363  *NumPins = 0;
364 
365  /* setup the pin request */
367  Pin.Set = KSPROPSETID_Pin;
369 
370  /* query the device */
371  return SyncOverlappedDeviceIoControl(hFilter, IOCTL_KS_PROPERTY, (LPVOID)&Pin, sizeof(KSPROPERTY), (PVOID)NumPins, sizeof(ULONG), NULL);
372 }
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
#define KSPROPERTY_TYPE_GET
Definition: dmksctrl.h:42
smooth NULL
Definition: ftsmooth.c:416
IN PDCB IN VBO IN ULONG IN BOOLEAN Pin
Definition: fatprocs.h:415
ULONG Flags
Definition: ntfs.h:532
DWORD SyncOverlappedDeviceIoControl(IN HANDLE Handle, IN DWORD IoControlCode, IN LPVOID InBuffer, IN DWORD InBufferSize, OUT LPVOID OutBuffer, IN DWORD OutBufferSize, OUT LPDWORD BytesTransferred OPTIONAL)
Definition: misc.c:298
const GUID KSPROPSETID_Pin
Definition: misc.c:12
unsigned int ULONG
Definition: retypes.h:1

Referenced by EnumerateAudioFilter().

◆ GetFilterPinDataFlow()

DWORD GetFilterPinDataFlow ( IN HANDLE  hFilter,
IN ULONG  PinId,
OUT PKSPIN_DATAFLOW  DataFlow 
)

Definition at line 444 of file misc.c.

448 {
450 
454  Property.PinId = PinId;
455  Property.Reserved = 0;
456 
458 }
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
#define KSPROPERTY_TYPE_GET
Definition: dmksctrl.h:42
smooth NULL
Definition: ftsmooth.c:416
KSPIN_DATAFLOW
Definition: ks.h:1248
Definition: ks.h:642
DWORD SyncOverlappedDeviceIoControl(IN HANDLE Handle, IN DWORD IoControlCode, IN LPVOID InBuffer, IN DWORD InBufferSize, OUT LPVOID OutBuffer, IN DWORD OutBufferSize, OUT LPDWORD BytesTransferred OPTIONAL)
Definition: misc.c:298
_In_ DWORD Property
Definition: setupapi.h:1545
const GUID KSPROPSETID_Pin
Definition: misc.c:12
DataFlow
Property(long _type, long _tag, INREAL _value)
Definition: reader.h:125

Referenced by FindAudioFilterPins().

◆ GetFilterPinDataRanges()

DWORD GetFilterPinDataRanges ( IN HANDLE  hFilter,
IN ULONG  PinId,
IN OUT PKSMULTIPLE_ITEM OutMultipleItem 
)

Definition at line 461 of file misc.c.

465 {
467  ULONG BytesReturned = 0;
468  DWORD Status;
469  PKSMULTIPLE_ITEM MultipleItem;
470 
471  /* prepare request */
472  Property.Reserved = 0;
473  Property.PinId = PinId;
477 
478  /* retrieve size of data ranges buffer */
480 
481 #if 0
482  if (Status != ERROR_MORE_DATA)
483  {
484  DPRINT("SyncOverlappedDeviceIoControl failed with %lx\n", Status);
485  return Status;
486  }
487 #endif
488 
490  MultipleItem = HeapAlloc(GetProcessHeap(), 0, BytesReturned);
491  if (!MultipleItem)
492  {
493  /* not enough memory */
494  DPRINT("Failed to allocate %u Bytes\n", BytesReturned);
495  return ERROR_OUTOFMEMORY;
496  }
497 
498  /* retrieve data ranges */
500 
501 
502  if (Status != ERROR_SUCCESS)
503  {
504  /* failed to get data ranges */
505  DPRINT("SyncOverlappedDeviceIoControl failed with %lx\n", Status);
506 
507  HeapFree(GetProcessHeap(), 0, MultipleItem);
508  return Status;
509  }
510 
511  /* save result */
512  *OutMultipleItem = MultipleItem;
513  return Status;
514 }
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KSPROPERTY_TYPE_GET
Definition: dmksctrl.h:42
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define GetProcessHeap()
Definition: compat.h:403
Definition: ks.h:642
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
DWORD SyncOverlappedDeviceIoControl(IN HANDLE Handle, IN DWORD IoControlCode, IN LPVOID InBuffer, IN DWORD InBufferSize, OUT LPVOID OutBuffer, IN DWORD OutBufferSize, OUT LPDWORD BytesTransferred OPTIONAL)
Definition: misc.c:298
#define ERROR_MORE_DATA
Definition: dderror.h:13
Status
Definition: gdiplustypes.h:24
_In_ DWORD Property
Definition: setupapi.h:1545
_In_ FILTER_INFORMATION_CLASS _In_ ULONG _Out_ PULONG BytesReturned
Definition: fltkernel.h:1716
const GUID KSPROPSETID_Pin
Definition: misc.c:12
unsigned int ULONG
Definition: retypes.h:1
Property(long _type, long _tag, INREAL _value)
Definition: reader.h:125
#define HeapFree(x, y, z)
Definition: compat.h:402
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

Referenced by CreateCompatiblePin().

◆ OpenFilter()

DWORD OpenFilter ( IN LPCWSTR  lpFileName,
IN PHANDLE  OutHandle 
)

Definition at line 277 of file misc.c.

280 {
281  HANDLE Handle;
282 
283  /* open the filter */
285 
286  /* check for success */
288  {
289  DPRINT("Failed to open Filter %ws\n", lpFileName);
290  return GetLastError();
291  }
292 
293  *OutHandle = Handle;
294  return ERROR_SUCCESS;
295 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define OPEN_EXISTING
Definition: compat.h:434
_In_ HANDLE Handle
Definition: extypes.h:390
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define GENERIC_READ
Definition: compat.h:124
#define CreateFileW
Definition: compat.h:408
#define FILE_FLAG_OVERLAPPED
Definition: disk.h:46
_In_ LPCSTR lpFileName
Definition: winbase.h:3028

Referenced by EnumerateAudioFilter().

◆ OpenPin()

DWORD OpenPin ( HANDLE  hFilter,
ULONG  PinId,
LPWAVEFORMATEX  WaveFormatEx,
PHANDLE  hPin,
BOOL  bLoop 
)

Definition at line 212 of file misc.c.

218 {
219  DWORD Size, Result;
220  PKSPIN_CONNECT PinConnect;
222 
223  /* calculate request size */
224  Size = sizeof(KSPIN_CONNECT) + sizeof(KSDATAFORMAT_WAVEFORMATEX);
225 
226  PinConnect = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Size);
227  if (!PinConnect)
228  {
229  /* not enough memory */
230  return DSERR_OUTOFMEMORY;
231  }
232  /* build pin request */
234 
235  if (bLoop)
237  else
239 
240  PinConnect->Interface.Flags = 0;
241  PinConnect->Medium.Set = KSMEDIUMSETID_Standard;
242  PinConnect->Medium.Id = KSMEDIUM_TYPE_ANYINSTANCE;
243  PinConnect->Medium.Flags = 0;
244  PinConnect->PinToHandle = NULL;
245  PinConnect->PinId = PinId;
247  PinConnect->Priority.PrioritySubClass = 1;
248 
249  DataFormat = (PKSDATAFORMAT_WAVEFORMATEX) (PinConnect + 1);
250 
251  /* initialize data format */
252  DataFormat->WaveFormatEx.wFormatTag = WaveFormatEx->wFormatTag;
253  DataFormat->WaveFormatEx.nChannels = WaveFormatEx->nChannels;
254  DataFormat->WaveFormatEx.nSamplesPerSec = WaveFormatEx->nSamplesPerSec;
255  DataFormat->WaveFormatEx.nBlockAlign = WaveFormatEx->nBlockAlign;
256  DataFormat->WaveFormatEx.nAvgBytesPerSec = WaveFormatEx->nAvgBytesPerSec;
257  DataFormat->WaveFormatEx.wBitsPerSample = WaveFormatEx->wBitsPerSample;
258  DataFormat->WaveFormatEx.cbSize = 0;
259  DataFormat->DataFormat.FormatSize = sizeof(KSDATAFORMAT) + sizeof(WAVEFORMATEX);
260  DataFormat->DataFormat.Flags = 0;
261  DataFormat->DataFormat.Reserved = 0;
262  DataFormat->DataFormat.MajorFormat = KSDATAFORMAT_TYPE_AUDIO;
263 
264  DataFormat->DataFormat.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
265  DataFormat->DataFormat.Specifier = KSDATAFORMAT_SPECIFIER_WAVEFORMATEX;
266  DataFormat->DataFormat.SampleSize = 4;
267 
268  Result = KsCreatePin(hFilter, PinConnect, GENERIC_READ | GENERIC_WRITE, hPin);
269 
270  HeapFree(GetProcessHeap(), 0, PinConnect);
271 
272  return Result;
273 }
KSPIN_INTERFACE Interface
Definition: ks.h:2601
#define KSDATAFORMAT_SUBTYPE_PCM
Definition: ksmedia.h:921
KSPIN_MEDIUM Medium
Definition: ks.h:2602
KSDDKAPI DWORD NTAPI KsCreatePin(HANDLE FilterHandle, PKSPIN_CONNECT Connect, ACCESS_MASK DesiredAccess, PHANDLE ConnectionHandle)
Definition: ksuser.c:192
#define KSPRIORITY_NORMAL
Definition: ks.h:1386
DWORD nAvgBytesPerSec
Definition: mmreg.h:81
WORD nChannels
Definition: mmreg.h:79
#define KSINTERFACESETID_Standard
Definition: ks.h:280
ULONG PriorityClass
Definition: ks.h:1391
#define KSMEDIUMSETID_Standard
Definition: ks.h:306
GUID Set
Definition: dmksctrl.h:76
#define KSDATAFORMAT_SPECIFIER_WAVEFORMATEX
Definition: ksmedia.h:931
#define DSERR_OUTOFMEMORY
Definition: dsound.h:125
ULONG PinId
Definition: ks.h:2603
HANDLE PinToHandle
Definition: ks.h:2604
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
_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
ULONG PrioritySubClass
Definition: ks.h:1392
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
ULONG Id
Definition: dmksctrl.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
WORD wFormatTag
Definition: mmreg.h:78
ULONG Flags
Definition: dmksctrl.h:78
#define GENERIC_READ
Definition: compat.h:124
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define KSDATAFORMAT_TYPE_AUDIO
Definition: ksmedia.h:883
struct KSDATAFORMAT_WAVEFORMATEX * PKSDATAFORMAT_WAVEFORMATEX
#define KSMEDIUM_TYPE_ANYINSTANCE
Definition: ks.h:301
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
DWORD nSamplesPerSec
Definition: mmreg.h:80
WORD nBlockAlign
Definition: mmreg.h:82
WORD wBitsPerSample
Definition: mmreg.h:83
KSPRIORITY Priority
Definition: ks.h:2605
#define HeapFree(x, y, z)
Definition: compat.h:402

Referenced by CreateCompatiblePin(), NewDirectSoundCaptureBuffer(), and PrimaryDirectSoundBuffer_SetFormat().

◆ PerformChannelConversion()

VOID PerformChannelConversion ( PUCHAR  Buffer,
ULONG  BufferLength,
PULONG  BytesRead,
ULONG  OldChannels,
ULONG  NewChannels,
ULONG  BitsPerSample,
PUCHAR  Result,
ULONG  ResultLength,
PULONG  BytesWritten 
)

Definition at line 18 of file misc.c.

28 {
29  DWORD NewIndex, OldIndex;
30  DWORD NewLength, Skip;
31 
32  if (NewChannels > OldChannels)
33  {
35  ASSERT(0);
36  }
37 
38  /* setup index */
39  NewIndex = 0;
40  OldIndex = 0;
41 
42  /* calculate offsets */
43  NewLength = NewChannels * (BitsPerSample/8);
44  Skip = OldChannels * (BitsPerSample/8);
45 
46  do
47  {
48  if (NewIndex + NewLength>= ResultLength)
49  {
50  NewIndex = ResultLength;
51  break;
52  }
53 
54  if (OldIndex + Skip >= BufferLength)
55  {
56  OldIndex = BufferLength;
57  break;
58  }
59 
60  /* copy first channel */
61  RtlMoveMemory(&Result[NewIndex], &Buffer[OldIndex], NewLength);
62 
63  /* skip other channels */
64  OldIndex += Skip;
65 
66  /* increment offset */
67  NewIndex += NewLength;
68 
69  }while(TRUE);
70 
71  *BytesRead = OldIndex;
72  *BytesWritten = NewIndex;
73 }
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
#define TRUE
Definition: types.h:120
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
static USHORT USHORT * NewLength
_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 long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define UNIMPLEMENTED
Definition: debug.h:114
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255

Referenced by MixerThreadRoutine().

◆ SetPinFormat()

BOOL SetPinFormat ( IN HANDLE  hPin,
IN LPWAVEFORMATEX  WaveFormatEx 
)

Definition at line 77 of file misc.c.

80 {
81  DWORD dwResult;
84 
85  /* setup connection request */
89 
90  /* setup data format */
91  DataFormat.WaveFormatEx.wFormatTag = WaveFormatEx->wFormatTag;
92  DataFormat.WaveFormatEx.nSamplesPerSec = WaveFormatEx->nSamplesPerSec;
93  DataFormat.WaveFormatEx.nBlockAlign = WaveFormatEx->nBlockAlign;
94  DataFormat.WaveFormatEx.cbSize = 0;
95  DataFormat.DataFormat.FormatSize = sizeof(KSDATAFORMAT) + sizeof(WAVEFORMATEX);
96  DataFormat.DataFormat.Flags = 0;
97  DataFormat.DataFormat.Reserved = 0;
98  DataFormat.DataFormat.MajorFormat = KSDATAFORMAT_TYPE_AUDIO;
99  DataFormat.DataFormat.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
100  DataFormat.DataFormat.Specifier = KSDATAFORMAT_SPECIFIER_WAVEFORMATEX;
101  DataFormat.DataFormat.SampleSize = 4;
102  DataFormat.WaveFormatEx.nChannels = WaveFormatEx->nChannels;
103  DataFormat.WaveFormatEx.nAvgBytesPerSec = WaveFormatEx->nAvgBytesPerSec;
104  DataFormat.WaveFormatEx.wBitsPerSample = WaveFormatEx->wBitsPerSample;
105 
107 
108  if (dwResult == ERROR_SUCCESS)
109  return TRUE;
110  else
111  return FALSE;
112 }
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
#define TRUE
Definition: types.h:120
#define KSDATAFORMAT_SUBTYPE_PCM
Definition: ksmedia.h:921
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KSPROPSETID_Connection
Definition: ks.h:346
#define KSDATAFORMAT_SPECIFIER_WAVEFORMATEX
Definition: ksmedia.h:931
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD SyncOverlappedDeviceIoControl(IN HANDLE Handle, IN DWORD IoControlCode, IN LPVOID InBuffer, IN DWORD InBufferSize, OUT LPVOID OutBuffer, IN DWORD OutBufferSize, OUT LPDWORD BytesTransferred OPTIONAL)
Definition: misc.c:298
#define KSDATAFORMAT_TYPE_AUDIO
Definition: ksmedia.h:883
_In_ DWORD Property
Definition: setupapi.h:1545
#define KSPROPERTY_TYPE_SET
Definition: dmksctrl.h:43

Referenced by PrimaryDirectSoundBuffer_SetFormat().

◆ SyncOverlappedDeviceIoControl()

DWORD SyncOverlappedDeviceIoControl ( IN HANDLE  Handle,
IN DWORD  IoControlCode,
IN LPVOID  InBuffer,
IN DWORD  InBufferSize,
OUT LPVOID  OutBuffer,
IN DWORD  OutBufferSize,
OUT LPDWORD BytesTransferred  OPTIONAL 
)

Definition at line 298 of file misc.c.

306 {
307  OVERLAPPED Overlapped;
308  BOOLEAN IoResult;
309  DWORD Transferred = 0;
310 
311  /* Overlapped I/O is done here - this is used for waiting for completion */
312  ZeroMemory(&Overlapped, sizeof(OVERLAPPED));
313  Overlapped.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
314 
315  if (!Overlapped.hEvent)
316  return GetLastError();
317 
318  /* Talk to the device */
319  IoResult = DeviceIoControl(Handle,
321  InBuffer,
322  InBufferSize,
323  OutBuffer,
325  BytesTransferred,
326  &Overlapped);
327 
328  /* If failure occurs, make sure it's not just due to the overlapped I/O */
329  if (!IoResult)
330  {
331  if ( GetLastError() != ERROR_IO_PENDING )
332  {
333  CloseHandle(Overlapped.hEvent);
334  return GetLastError();
335  }
336  }
337 
338  /* Wait for the I/O to complete */
339  IoResult = GetOverlappedResult(Handle,
340  &Overlapped,
341  &Transferred,
342  TRUE);
343 
344  /* Don't need this any more */
345  CloseHandle(Overlapped.hEvent);
346 
347  if (!IoResult)
348  return GetLastError();
349 
350  if ( BytesTransferred )
351  *BytesTransferred = Transferred;
352 
353  return ERROR_SUCCESS;
354 }
#define CreateEvent
Definition: winbase.h:3582
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL WINAPI GetOverlappedResult(IN HANDLE hFile, IN LPOVERLAPPED lpOverlapped, OUT LPDWORD lpNumberOfBytesTransferred, IN BOOL bWait)
Definition: iocompl.c:204
_In_ PIRP _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG OutBufferSize
Definition: classpnp.h:429
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1642
#define ERROR_IO_PENDING
Definition: dderror.h:15
HANDLE hEvent
Definition: winbase.h:792
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
_In_ PIRP _In_ ULONG _In_ ULONG _In_ ULONG InBufferSize
Definition: classpnp.h:429
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136

Referenced by DoDataIntersection(), GetFilterNodeProperty(), GetFilterPinCommunication(), GetFilterPinCount(), GetFilterPinDataFlow(), GetFilterPinDataRanges(), GetNt4SoundDeviceCapabilities(), IDirectSoundCaptureBufferImpl_GetCurrentPosition(), IDirectSoundCaptureBufferImpl_Start(), IDirectSoundCaptureBufferImpl_Stop(), IDirectSoundNotify_fnSetNotificationPositions(), IoStreamingThread(), MixerEventThreadRoutine(), MixerThreadRoutine(), PrimaryDirectSoundBuffer_GetPosition(), PrimaryDirectSoundBuffer_SetState(), QueryNt4WaveDeviceFormatSupport(), SetNt4WaveDeviceFormat(), SetPinFormat(), WdmAudCloseSoundDeviceByLegacy(), WdmAudGetCapabilitiesByLegacy(), WdmAudGetDeviceInterfaceStringByLegacy(), WdmAudGetNumWdmDevsByLegacy(), WdmAudGetWavePositionByLegacy(), WdmAudQueryMixerInfoByLegacy(), WdmAudResetStreamByLegacy(), WdmAudSetMixerDeviceFormatByLegacy(), WdmAudSetWaveDeviceFormatByLegacy(), and WdmAudSetWaveStateByLegacy().

Variable Documentation

◆ KSPROPSETID_Audio

const GUID KSPROPSETID_Audio = {0x45FFAAA0L, 0x6E1B, 0x11D0, {0xBC, 0xF2, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}

Definition at line 14 of file misc.c.

◆ KSPROPSETID_Pin

const GUID KSPROPSETID_Pin = {0x8C134960L, 0x51AD, 0x11CF, {0x87, 0x8A, 0x94, 0xF8, 0x01, 0xC1, 0x00, 0x00}}

◆ KSPROPSETID_Topology

const GUID KSPROPSETID_Topology = {0x720D4AC0L, 0x7533, 0x11D0, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}}

Definition at line 13 of file misc.c.

Referenced by GetFilterNodeProperty().