ReactOS  0.4.13-dev-482-ge57f103
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 520 of file misc.c.

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

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 119 of file misc.c.

128 {
129  DWORD nChannels, nBitsPerSample;
130  KSDATAFORMAT_WAVEFORMATEX WaveFormat;
131  PKSP_PIN Pin;
132  PKSMULTIPLE_ITEM Item;
134  DWORD dwResult;
135 
136  /* allocate request */
138  if (!Pin)
139  {
140  /* no memory */
141  return FALSE;
142  }
143 
144  Item = (PKSMULTIPLE_ITEM)(Pin + 1);
146 
147  /* setup request */
148  Pin->PinId = PinId;
149  Pin->Property.Flags = KSPROPERTY_TYPE_GET;
150  Pin->Property.Set = KSPROPSETID_Pin;
151  Pin->Property.Id = KSPROPERTY_PIN_DATAINTERSECTION;
152  Item->Count = 1;
153  Item->Size = sizeof(KSDATAFORMAT_WAVEFORMATEX);
154 
155 
156  DataFormat->WaveFormatEx.wFormatTag = WaveFormatEx->wFormatTag;
157  DataFormat->WaveFormatEx.nSamplesPerSec = SampleFrequency;
158  DataFormat->WaveFormatEx.nBlockAlign = WaveFormatEx->nBlockAlign;
159  DataFormat->WaveFormatEx.cbSize = 0;
160  DataFormat->DataFormat.FormatSize = sizeof(KSDATAFORMAT) + sizeof(WAVEFORMATEX);
161  DataFormat->DataFormat.Flags = 0;
162  DataFormat->DataFormat.Reserved = 0;
163  DataFormat->DataFormat.MajorFormat = KSDATAFORMAT_TYPE_AUDIO;
164  DataFormat->DataFormat.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
165  DataFormat->DataFormat.Specifier = KSDATAFORMAT_SPECIFIER_WAVEFORMATEX;
166  DataFormat->DataFormat.SampleSize = 4;
167 
168  for(nChannels = 1; nChannels <= 2; nChannels++)
169  {
170  for(nBitsPerSample = MinimumBitsPerSample; nBitsPerSample <= MaximumBitsPerSample; nBitsPerSample += 8)
171  {
172  DataFormat->WaveFormatEx.nChannels = nChannels;
173  DataFormat->WaveFormatEx.nAvgBytesPerSec = (nBitsPerSample / 8) * nChannels * SampleFrequency;
174  DataFormat->WaveFormatEx.wBitsPerSample = nBitsPerSample;
175 
176  DPRINT("CurrentFormat: InFormat nChannels %u wBitsPerSample %u nSamplesPerSec %u\n",
177  nChannels, nBitsPerSample, SampleFrequency);
178 
180  (LPVOID)&WaveFormat, sizeof(KSDATAFORMAT_WAVEFORMATEX), NULL);
181 
182  DPRINT("dwResult %x\n", dwResult);
183 
184 
185  if (dwResult == ERROR_SUCCESS)
186  {
187  /* found a compatible audio range */
188  WaveFormatOut->cbSize = 0;
189  WaveFormatOut->nBlockAlign = WaveFormatEx->nBlockAlign;
190  WaveFormatOut->wFormatTag = WaveFormatEx->wFormatTag;
191  WaveFormatOut->nAvgBytesPerSec = (nBitsPerSample / 8) * nChannels * SampleFrequency;
192  WaveFormatOut->wBitsPerSample = nBitsPerSample;
193  WaveFormatOut->nSamplesPerSec = SampleFrequency;
194  WaveFormatOut->nChannels = nChannels;
195 
196  /* free buffer */
197  HeapFree(GetProcessHeap(), 0, Pin);
198 
199  DPRINT("InFormat nChannels %u wBitsPerSample %u nSamplesPerSec %u\nOutFormat nChannels %u nBitsPerSample %u nSamplesPerSec %u\n",
200  WaveFormatEx->nChannels, WaveFormatEx->wBitsPerSample, WaveFormatEx->nSamplesPerSec,
201  WaveFormatOut->nChannels, WaveFormatOut->wBitsPerSample, WaveFormatOut->nSamplesPerSec);
202 
203  return TRUE;
204  }
205  }
206  }
207 
208  /* free buffer */
209  HeapFree(GetProcessHeap(), 0, Pin);
210  ASSERT(0);
211  return FALSE;
212 }
ULONG Count
Definition: ks.h:2010
#define IOCTL_KS_PROPERTY
Definition: ks.h:150
#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:2009
DWORD nAvgBytesPerSec
Definition: mmreg.h:81
WORD nChannels
Definition: mmreg.h:79
int nChannels
Definition: pcmconverter.c:96
#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:395
Definition: ks.h:672
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:520
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:301
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:394

◆ GetFilterNodeProperty()

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

Definition at line 378 of file misc.c.

382 {
384  PKSMULTIPLE_ITEM MultipleItem;
386 
387  /* setup query request */
388  Property.Id = PropertyId;
391 
392  /* query the size */
394 
395  if (Status != ERROR_MORE_DATA)
396  {
397  /* failed */
398  DPRINT("Failed to query PropertyId %lu ErrorCode %lx\n", PropertyId, Status);
399  return Status;
400  }
401 
402  MultipleItem = HeapAlloc(GetProcessHeap(), 0, BytesReturned);
403  if (!MultipleItem)
404  {
405  /* not enough memory */
406  DPRINT("Failed to allocate %u Bytes\n", BytesReturned);
407  return ERROR_OUTOFMEMORY;
408  }
409 
410  /* retrieve data ranges */
412 
413 
414  if (Status != ERROR_SUCCESS)
415  {
416  /* failed to get data ranges */
417  DPRINT("SyncOverlappedDeviceIoControl failed with %lx\n", Status);
418 
419  HeapFree(GetProcessHeap(), 0, MultipleItem);
420  return Status;
421  }
422 
423  /* save result */
424  *OutMultipleItem = MultipleItem;
425  return Status;
426 
427 }
#define IOCTL_KS_PROPERTY
Definition: ks.h:150
#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:395
Definition: ks.h:672
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:301
#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:394
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

◆ GetFilterPinCommunication()

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

Definition at line 430 of file misc.c.

434 {
436 
440  Property.PinId = PinId;
441  Property.Reserved = 0;
442 
443  return SyncOverlappedDeviceIoControl(hFilter, IOCTL_KS_PROPERTY, (LPVOID)&Property, sizeof(KSP_PIN), (LPVOID)Communication, sizeof(KSPIN_COMMUNICATION), NULL);
444 }
#define IOCTL_KS_PROPERTY
Definition: ks.h:150
#define KSPROPERTY_TYPE_GET
Definition: dmksctrl.h:42
smooth NULL
Definition: ftsmooth.c:416
Definition: ks.h:672
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:301
_In_ DWORD Property
Definition: setupapi.h:1545
KSPIN_COMMUNICATION
Definition: ks.h:1283
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 360 of file misc.c.

363 {
364  KSPROPERTY Pin;
365 
366  *NumPins = 0;
367 
368  /* setup the pin request */
370  Pin.Set = KSPROPSETID_Pin;
372 
373  /* query the device */
374  return SyncOverlappedDeviceIoControl(hFilter, IOCTL_KS_PROPERTY, (LPVOID)&Pin, sizeof(KSPROPERTY), (PVOID)NumPins, sizeof(ULONG), NULL);
375 }
#define IOCTL_KS_PROPERTY
Definition: ks.h:150
#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:520
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:301
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 447 of file misc.c.

451 {
453 
457  Property.PinId = PinId;
458  Property.Reserved = 0;
459 
461 }
#define IOCTL_KS_PROPERTY
Definition: ks.h:150
#define KSPROPERTY_TYPE_GET
Definition: dmksctrl.h:42
smooth NULL
Definition: ftsmooth.c:416
KSPIN_DATAFLOW
Definition: ks.h:1278
Definition: ks.h:672
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:301
_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 464 of file misc.c.

468 {
470  ULONG BytesReturned = 0;
471  DWORD Status;
472  PKSMULTIPLE_ITEM MultipleItem;
473 
474  /* prepare request */
475  Property.Reserved = 0;
476  Property.PinId = PinId;
480 
481  /* retrieve size of data ranges buffer */
483 
484 #if 0
485  if (Status != ERROR_MORE_DATA)
486  {
487  DPRINT("SyncOverlappedDeviceIoControl failed with %lx\n", Status);
488  return Status;
489  }
490 #endif
491 
493  MultipleItem = HeapAlloc(GetProcessHeap(), 0, BytesReturned);
494  if (!MultipleItem)
495  {
496  /* not enough memory */
497  DPRINT("Failed to allocate %u Bytes\n", BytesReturned);
498  return ERROR_OUTOFMEMORY;
499  }
500 
501  /* retrieve data ranges */
503 
504 
505  if (Status != ERROR_SUCCESS)
506  {
507  /* failed to get data ranges */
508  DPRINT("SyncOverlappedDeviceIoControl failed with %lx\n", Status);
509 
510  HeapFree(GetProcessHeap(), 0, MultipleItem);
511  return Status;
512  }
513 
514  /* save result */
515  *OutMultipleItem = MultipleItem;
516  return Status;
517 }
#define IOCTL_KS_PROPERTY
Definition: ks.h:150
#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:395
Definition: ks.h:672
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:301
#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:394
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

Referenced by CreateCompatiblePin().

◆ OpenFilter()

DWORD OpenFilter ( IN LPCWSTR  lpFileName,
IN PHANDLE  OutHandle 
)

Definition at line 280 of file misc.c.

283 {
284  HANDLE Handle;
285 
286  /* open the filter */
288 
289  /* check for success */
291  {
292  DPRINT("Failed to open Filter %ws\n", lpFileName);
293  return GetLastError();
294  }
295 
296  *OutHandle = Handle;
297  return ERROR_SUCCESS;
298 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
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:426
_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:400
#define FILE_FLAG_OVERLAPPED
Definition: disk.h:46
_In_ LPCSTR lpFileName
Definition: winbase.h:3011

Referenced by EnumerateAudioFilter().

◆ OpenPin()

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

Definition at line 215 of file misc.c.

221 {
222  DWORD Size, Result;
223  PKSPIN_CONNECT PinConnect;
225 
226  /* calculate request size */
227  Size = sizeof(KSPIN_CONNECT) + sizeof(KSDATAFORMAT_WAVEFORMATEX);
228 
229  PinConnect = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Size);
230  if (!PinConnect)
231  {
232  /* not enough memory */
233  return DSERR_OUTOFMEMORY;
234  }
235  /* build pin request */
237 
238  if (bLoop)
240  else
242 
243  PinConnect->Interface.Flags = 0;
244  PinConnect->Medium.Set = KSMEDIUMSETID_Standard;
245  PinConnect->Medium.Id = KSMEDIUM_TYPE_ANYINSTANCE;
246  PinConnect->Medium.Flags = 0;
247  PinConnect->PinToHandle = NULL;
248  PinConnect->PinId = PinId;
250  PinConnect->Priority.PrioritySubClass = 1;
251 
252  DataFormat = (PKSDATAFORMAT_WAVEFORMATEX) (PinConnect + 1);
253 
254  /* initialize data format */
255  DataFormat->WaveFormatEx.wFormatTag = WaveFormatEx->wFormatTag;
256  DataFormat->WaveFormatEx.nChannels = WaveFormatEx->nChannels;
257  DataFormat->WaveFormatEx.nSamplesPerSec = WaveFormatEx->nSamplesPerSec;
258  DataFormat->WaveFormatEx.nBlockAlign = WaveFormatEx->nBlockAlign;
259  DataFormat->WaveFormatEx.nAvgBytesPerSec = WaveFormatEx->nAvgBytesPerSec;
260  DataFormat->WaveFormatEx.wBitsPerSample = WaveFormatEx->wBitsPerSample;
261  DataFormat->WaveFormatEx.cbSize = 0;
262  DataFormat->DataFormat.FormatSize = sizeof(KSDATAFORMAT) + sizeof(WAVEFORMATEX);
263  DataFormat->DataFormat.Flags = 0;
264  DataFormat->DataFormat.Reserved = 0;
265  DataFormat->DataFormat.MajorFormat = KSDATAFORMAT_TYPE_AUDIO;
266 
267  DataFormat->DataFormat.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
268  DataFormat->DataFormat.Specifier = KSDATAFORMAT_SPECIFIER_WAVEFORMATEX;
269  DataFormat->DataFormat.SampleSize = 4;
270 
271  Result = KsCreatePin(hFilter, PinConnect, GENERIC_READ | GENERIC_WRITE, hPin);
272 
273  HeapFree(GetProcessHeap(), 0, PinConnect);
274 
275  return Result;
276 }
KSPIN_INTERFACE Interface
Definition: ks.h:2630
#define KSDATAFORMAT_SUBTYPE_PCM
Definition: ksmedia.h:921
KSPIN_MEDIUM Medium
Definition: ks.h:2631
KSDDKAPI DWORD NTAPI KsCreatePin(HANDLE FilterHandle, PKSPIN_CONNECT Connect, ACCESS_MASK DesiredAccess, PHANDLE ConnectionHandle)
Definition: ksuser.c:192
#define KSPRIORITY_NORMAL
Definition: ks.h:1416
DWORD nAvgBytesPerSec
Definition: mmreg.h:81
WORD nChannels
Definition: mmreg.h:79
#define KSINTERFACESETID_Standard
Definition: ks.h:310
ULONG PriorityClass
Definition: ks.h:1421
#define KSMEDIUMSETID_Standard
Definition: ks.h:336
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:2632
HANDLE PinToHandle
Definition: ks.h:2633
#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:1422
#define GetProcessHeap()
Definition: compat.h:395
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:331
#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:2634
#define HeapFree(x, y, z)
Definition: compat.h:394

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 Samples;
30  DWORD NewIndex, OldIndex;
31  DWORD NewLength, Skip;
32 
33  Samples = BufferLength / (BitsPerSample / 8) / OldChannels;
34 
35  if (NewChannels > OldChannels)
36  {
38  ASSERT(0);
39  }
40 
41  /* setup index */
42  NewIndex = 0;
43  OldIndex = 0;
44 
45  /* calculate offsets */
46  NewLength = NewChannels * (BitsPerSample/8);
47  Skip = OldChannels * (BitsPerSample/8);
48 
49  do
50  {
51  if (NewIndex + NewLength>= ResultLength)
52  {
53  NewIndex = ResultLength;
54  break;
55  }
56 
57  if (OldIndex + Skip >= BufferLength)
58  {
59  OldIndex = BufferLength;
60  break;
61  }
62 
63  /* copy first channel */
64  RtlMoveMemory(&Result[NewIndex], &Buffer[OldIndex], NewLength);
65 
66  /* skip other channels */
67  OldIndex += Skip;
68 
69  /* increment offset */
70  NewIndex += NewLength;
71 
72  }while(TRUE);
73 
74  *BytesRead = OldIndex;
75  *BytesWritten = NewIndex;
76 }
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 80 of file misc.c.

83 {
84  DWORD dwResult;
87 
88  /* setup connection request */
92 
93  /* setup data format */
94  DataFormat.WaveFormatEx.wFormatTag = WaveFormatEx->wFormatTag;
95  DataFormat.WaveFormatEx.nSamplesPerSec = WaveFormatEx->nSamplesPerSec;
96  DataFormat.WaveFormatEx.nBlockAlign = WaveFormatEx->nBlockAlign;
97  DataFormat.WaveFormatEx.cbSize = 0;
98  DataFormat.DataFormat.FormatSize = sizeof(KSDATAFORMAT) + sizeof(WAVEFORMATEX);
99  DataFormat.DataFormat.Flags = 0;
100  DataFormat.DataFormat.Reserved = 0;
101  DataFormat.DataFormat.MajorFormat = KSDATAFORMAT_TYPE_AUDIO;
102  DataFormat.DataFormat.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
103  DataFormat.DataFormat.Specifier = KSDATAFORMAT_SPECIFIER_WAVEFORMATEX;
104  DataFormat.DataFormat.SampleSize = 4;
105  DataFormat.WaveFormatEx.nChannels = WaveFormatEx->nChannels;
106  DataFormat.WaveFormatEx.nAvgBytesPerSec = WaveFormatEx->nAvgBytesPerSec;
107  DataFormat.WaveFormatEx.wBitsPerSample = WaveFormatEx->wBitsPerSample;
108 
110 
111  if (dwResult == ERROR_SUCCESS)
112  return TRUE;
113  else
114  return FALSE;
115 }
#define IOCTL_KS_PROPERTY
Definition: ks.h:150
#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:376
#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:301
#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 301 of file misc.c.

309 {
310  OVERLAPPED Overlapped;
311  BOOLEAN IoResult;
312  DWORD Transferred = 0;
313 
314  /* Overlapped I/O is done here - this is used for waiting for completion */
315  ZeroMemory(&Overlapped, sizeof(OVERLAPPED));
316  Overlapped.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
317 
318  if (!Overlapped.hEvent)
319  return GetLastError();
320 
321  /* Talk to the device */
322  IoResult = DeviceIoControl(Handle,
324  InBuffer,
325  InBufferSize,
326  OutBuffer,
328  BytesTransferred,
329  &Overlapped);
330 
331  /* If failure occurs, make sure it's not just due to the overlapped I/O */
332  if (!IoResult)
333  {
334  if ( GetLastError() != ERROR_IO_PENDING )
335  {
336  CloseHandle(Overlapped.hEvent);
337  return GetLastError();
338  }
339  }
340 
341  /* Wait for the I/O to complete */
342  IoResult = GetOverlappedResult(Handle,
343  &Overlapped,
344  &Transferred,
345  TRUE);
346 
347  /* Don't need this any more */
348  CloseHandle(Overlapped.hEvent);
349 
350  if (!IoResult)
351  return GetLastError();
352 
353  if ( BytesTransferred )
354  *BytesTransferred = Transferred;
355 
356  return ERROR_SUCCESS;
357 }
#define CreateEvent
Definition: winbase.h:3562
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
_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:1635
#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().