ReactOS  0.4.14-dev-999-g61c8d34
header.c File Reference
#include "precomp.h"
Include dependency graph for header.c:

Go to the source code of this file.

Classes

struct  THREADED_WAVEHEADER_PARAMETERS
 

Functions

MMRESULT WaveHeaderOperationInSoundThread (PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN PVOID Parameter)
 
MMRESULT WaveHeaderOperation (MMWAVEHEADER_FUNC Function, PSOUND_DEVICE_INSTANCE SoundDeviceInstance, PWAVEHDR Header)
 
VOID SanitizeWaveHeader (PWAVEHDR Header)
 
MMRESULT PrepareWaveHeader (IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN PWAVEHDR Header)
 
MMRESULT UnprepareWaveHeader (IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN PWAVEHDR Header)
 
MMRESULT WriteWaveHeader (IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN PWAVEHDR Header)
 
MMRESULT EnqueueWaveHeader (PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN PVOID Parameter)
 
VOID CompleteWaveHeader (IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN PWAVEHDR Header)
 

Function Documentation

◆ CompleteWaveHeader()

VOID CompleteWaveHeader ( IN PSOUND_DEVICE_INSTANCE  SoundDeviceInstance,
IN PWAVEHDR  Header 
)

Definition at line 274 of file header.c.

277 {
278  PWAVEHDR PrevHdr = NULL, CurrHdr = NULL;
280  PSOUND_DEVICE SoundDevice;
283 
284  SND_TRACE(L"BUFFER COMPLETE :)\n");
285 
286  // TODO: Set header flags?
287  // TODO: Call client
288  // TODO: Streaming
289 
290  //DoWaveStreaming(SoundDeviceInstance);
291 
292  Result = GetSoundDeviceFromInstance(SoundDeviceInstance, &SoundDevice);
294  Result = GetSoundDeviceType(SoundDevice, &DeviceType);
296 
297  Extension = (PWAVEHDR_EXTENSION)Header->reserved;
299 
300  /* Remove the header from the queue, like so */
301  if ( SoundDeviceInstance->HeadWaveHeader == Header )
302  {
303  SoundDeviceInstance->HeadWaveHeader = Header->lpNext;
304 
305  SND_TRACE(L"Dropping head node\n");
306 
307  /* If nothing after the head, then there is no tail */
308  if ( Header->lpNext == NULL )
309  {
310  SND_TRACE(L"Dropping tail node\n");
311  SoundDeviceInstance->TailWaveHeader = NULL;
312  }
313  }
314  else
315  {
316  PrevHdr = NULL;
317  CurrHdr = SoundDeviceInstance->HeadWaveHeader;
318 
319  SND_TRACE(L"Relinking nodes\n");
320 
321  while ( CurrHdr != Header )
322  {
323  PrevHdr = CurrHdr;
324  CurrHdr = CurrHdr->lpNext;
325  SND_ASSERT( CurrHdr );
326  }
327 
328  SND_ASSERT( PrevHdr );
329 
330  PrevHdr->lpNext = CurrHdr->lpNext;
331 
332  /* If this is the tail node, update the tail */
333  if ( Header->lpNext == NULL )
334  {
335  SND_TRACE(L"Updating tail node\n");
336  SoundDeviceInstance->TailWaveHeader = PrevHdr;
337  }
338  }
339 
340  /* Make sure we're not using this as the current buffer any more, either! */
341 /*
342  if ( SoundDeviceInstance->CurrentWaveHeader == Header )
343  {
344  SoundDeviceInstance->CurrentWaveHeader = Header->lpNext;
345  }
346 */
347 
348  DUMP_WAVEHDR_QUEUE(SoundDeviceInstance);
349 
350  SND_TRACE(L"Returning buffer to client...\n");
351 
352  /* Update the header */
353  Header->dwFlags &= ~WHDR_INQUEUE;
354  Header->dwFlags |= WHDR_DONE;
355 
357  {
358  // FIXME: We won't be called on incomplete buffer!
359  Header->dwBytesRecorded = Extension->BytesCompleted;
360  }
361 
362  /* Safe to do this without thread protection, as we're done with the header */
363  NotifyMmeClient(SoundDeviceInstance,
365  (DWORD_PTR)Header);
366 }
#define WOM_DONE
Definition: mmsystem.h:183
#define MMSUCCESS(result)
Definition: mmebuddy.h:80
DeviceType
Definition: mmdrv.h:41
UINT MMRESULT
Definition: mmsystem.h:962
#define DUMP_WAVEHDR_QUEUE(sound_device_instance)
VOID NotifyMmeClient(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN UINT Message, IN DWORD_PTR Parameter)
Definition: mmewrap.c:75
UCHAR MMDEVICE_TYPE
Definition: mmebuddy.h:88
Definition: Header.h:8
smooth NULL
Definition: ftsmooth.c:416
#define SND_ASSERT(condition)
_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
struct _WAVEHDR_EXTENSION * PWAVEHDR_EXTENSION
static const WCHAR L[]
Definition: oid.c:1250
uint32_t DWORD_PTR
Definition: typedefs.h:64
struct wavehdr_tag * lpNext
Definition: mmsystem.h:1020
MMRESULT GetSoundDeviceType(IN PSOUND_DEVICE SoundDevice, OUT PMMDEVICE_TYPE DeviceType)
Definition: devicelist.c:346
#define WHDR_INQUEUE
Definition: mmsystem.h:197
#define WHDR_DONE
Definition: mmsystem.h:193
#define WIM_DATA
Definition: mmsystem.h:186
MMRESULT GetSoundDeviceFromInstance(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, OUT PSOUND_DEVICE *SoundDevice)
_Inout_opt_ PUNICODE_STRING Extension
Definition: fltkernel.h:1092
#define SND_TRACE(...)

Referenced by CompleteIO(), and StopStreamingInSoundThread().

◆ EnqueueWaveHeader()

MMRESULT EnqueueWaveHeader ( PSOUND_DEVICE_INSTANCE  SoundDeviceInstance,
IN PVOID  Parameter 
)

Definition at line 218 of file header.c.

221 {
222  PWAVEHDR WaveHeader = (PWAVEHDR) Parameter;
223 
224  VALIDATE_MMSYS_PARAMETER( SoundDeviceInstance );
226 
227  /* Initialise */
228  WaveHeader->lpNext = NULL;
229 
230  /* Set the "in queue" flag */
231  WaveHeader->dwFlags |= WHDR_INQUEUE;
232 
233  if ( ! SoundDeviceInstance->HeadWaveHeader )
234  {
235  /* This is the first header in the queue */
236  SND_TRACE(L"Enqueued first wave header\n");
237  SoundDeviceInstance->HeadWaveHeader = WaveHeader;
238  SoundDeviceInstance->TailWaveHeader = WaveHeader;
239 
240  /* Only do wave streaming when the stream has not been paused */
241  if (SoundDeviceInstance->bPaused == FALSE)
242  {
243  DoWaveStreaming(SoundDeviceInstance);
244  }
245  }
246  else
247  {
248  /* There are already queued headers - make this one the tail */
249  SND_TRACE(L"Enqueued next wave header\n");
250 
251  /* FIXME - Make sure that the buffer has not already been added to the list */
252  if ( SoundDeviceInstance->TailWaveHeader != WaveHeader )
253  {
254  SND_ASSERT(SoundDeviceInstance->TailWaveHeader != WaveHeader);
255 
256  SoundDeviceInstance->TailWaveHeader->lpNext = WaveHeader;
257  SoundDeviceInstance->TailWaveHeader = WaveHeader;
258  DUMP_WAVEHDR_QUEUE(SoundDeviceInstance);
259 
260  /* Only do wave streaming when the stream has not been paused */
261  if ( SoundDeviceInstance->bPaused == FALSE )
262  {
263  DoWaveStreaming(SoundDeviceInstance);
264  }
265  }
266  }
267 
268  DUMP_WAVEHDR_QUEUE(SoundDeviceInstance);
269 
270  return MMSYSERR_NOERROR;
271 }
struct wavehdr_tag * PWAVEHDR
PWAVEHDR HeadWaveHeader
Definition: mmebuddy.h:287
_In_ PVOID Parameter
Definition: ldrtypes.h:241
#define DUMP_WAVEHDR_QUEUE(sound_device_instance)
#define VALIDATE_MMSYS_PARAMETER(parameter_condition)
Definition: mmebuddy.h:71
DWORD dwFlags
Definition: mmsystem.h:1018
VOID DoWaveStreaming(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
Definition: streaming.c:20
smooth NULL
Definition: ftsmooth.c:416
#define SND_ASSERT(condition)
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
static const WCHAR L[]
Definition: oid.c:1250
PWAVEHDR TailWaveHeader
Definition: mmebuddy.h:292
struct wavehdr_tag * lpNext
Definition: mmsystem.h:1020
#define WHDR_INQUEUE
Definition: mmsystem.h:197
#define SND_TRACE(...)

Referenced by WriteWaveHeader().

◆ PrepareWaveHeader()

MMRESULT PrepareWaveHeader ( IN PSOUND_DEVICE_INSTANCE  SoundDeviceInstance,
IN PWAVEHDR  Header 
)

Definition at line 89 of file header.c.

92 {
94  PSOUND_DEVICE SoundDevice;
97 
100 
101  SND_TRACE(L"Preparing wave header\n");
102 
103  Result = GetSoundDeviceFromInstance(SoundDeviceInstance, &SoundDevice);
104  if ( ! MMSUCCESS(Result) )
106 
108  if ( ! MMSUCCESS(Result) )
110 
112  if ( ! Extension )
113  return MMSYSERR_NOMEM;
114 
115  Header->reserved = (DWORD_PTR) Extension;
116  Extension->BytesCommitted = 0;
117  Extension->BytesCompleted = 0;
118 
119  /* Configure the flags */
120  Header->dwFlags |= WHDR_PREPARED;
121 
122  return MMSYSERR_NOERROR;
123 }
#define DWORD_PTR
Definition: treelist.c:76
#define MMSUCCESS(result)
Definition: mmebuddy.h:80
MMRESULT TranslateInternalMmResult(IN MMRESULT Result)
Definition: utility.c:132
UINT MMRESULT
Definition: mmsystem.h:962
#define VALIDATE_MMSYS_PARAMETER(parameter_condition)
Definition: mmebuddy.h:71
MMRESULT GetSoundDeviceFunctionTable(IN PSOUND_DEVICE SoundDevice, OUT PMMFUNCTION_TABLE *FunctionTable)
Definition: functiontable.c:47
#define MMSYSERR_NOMEM
Definition: mmsystem.h:103
Definition: Header.h:8
_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
BOOLEAN IsValidSoundDeviceInstance(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
#define AllocateStruct(thing)
Definition: mmebuddy.h:27
static const WCHAR L[]
Definition: oid.c:1250
#define WHDR_PREPARED
Definition: mmsystem.h:194
static WLX_DISPATCH_VERSION_1_4 FunctionTable
Definition: wlx.c:736
MMRESULT GetSoundDeviceFromInstance(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, OUT PSOUND_DEVICE *SoundDevice)
_Inout_opt_ PUNICODE_STRING Extension
Definition: fltkernel.h:1092
#define SND_TRACE(...)

◆ SanitizeWaveHeader()

VOID SanitizeWaveHeader ( PWAVEHDR  Header)

Definition at line 64 of file header.c.

66 {
69 
70  Header->dwBytesRecorded = 0;
71 
72  Extension->BytesCommitted = 0;
73  Extension->BytesCompleted = 0;
74 }
Definition: Header.h:8
#define SND_ASSERT(condition)
struct _WAVEHDR_EXTENSION * PWAVEHDR_EXTENSION
_Inout_opt_ PUNICODE_STRING Extension
Definition: fltkernel.h:1092

Referenced by WriteWaveHeader().

◆ UnprepareWaveHeader()

MMRESULT UnprepareWaveHeader ( IN PSOUND_DEVICE_INSTANCE  SoundDeviceInstance,
IN PWAVEHDR  Header 
)

Definition at line 126 of file header.c.

129 {
131  PSOUND_DEVICE SoundDevice;
134 
137 
138  SND_TRACE(L"Un-preparing wave header\n");
139 
140  Result = GetSoundDeviceFromInstance(SoundDeviceInstance, &SoundDevice);
141  if ( ! MMSUCCESS(Result) )
143 
145  if ( ! MMSUCCESS(Result) )
147 
148  SND_ASSERT( Header->reserved );
149  Extension = (PWAVEHDR_EXTENSION) Header->reserved;
151 
152  /* Configure the flags */
153  Header->dwFlags &= ~WHDR_PREPARED;
154 
155  return MMSYSERR_NOERROR;
156 }
static VOID FreeMemory(PCREATE_DATA Data)
Definition: create.c:134
#define MMSUCCESS(result)
Definition: mmebuddy.h:80
MMRESULT TranslateInternalMmResult(IN MMRESULT Result)
Definition: utility.c:132
UINT MMRESULT
Definition: mmsystem.h:962
#define VALIDATE_MMSYS_PARAMETER(parameter_condition)
Definition: mmebuddy.h:71
MMRESULT GetSoundDeviceFunctionTable(IN PSOUND_DEVICE SoundDevice, OUT PMMFUNCTION_TABLE *FunctionTable)
Definition: functiontable.c:47
Definition: Header.h:8
#define SND_ASSERT(condition)
_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
BOOLEAN IsValidSoundDeviceInstance(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
struct _WAVEHDR_EXTENSION * PWAVEHDR_EXTENSION
static const WCHAR L[]
Definition: oid.c:1250
#define WHDR_PREPARED
Definition: mmsystem.h:194
static WLX_DISPATCH_VERSION_1_4 FunctionTable
Definition: wlx.c:736
MMRESULT GetSoundDeviceFromInstance(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, OUT PSOUND_DEVICE *SoundDevice)
_Inout_opt_ PUNICODE_STRING Extension
Definition: fltkernel.h:1092
#define SND_TRACE(...)

◆ WaveHeaderOperation()

MMRESULT WaveHeaderOperation ( MMWAVEHEADER_FUNC  Function,
PSOUND_DEVICE_INSTANCE  SoundDeviceInstance,
PWAVEHDR  Header 
)

Definition at line 42 of file header.c.

46 {
48 
49  Parameters.Function = Function;
50  Parameters.Header = Header;
51 
52  return CallSoundThread(SoundDeviceInstance,
54  &Parameters);
55 }
MMRESULT CallSoundThread(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN SOUND_THREAD_REQUEST_HANDLER RequestHandler, IN PVOID Parameter OPTIONAL)
Definition: thread.c:71
static LPOVERLAPPED_COMPLETION_ROUTINE Function
Definition: sync.c:684
Definition: Header.h:8
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:872
MMRESULT WaveHeaderOperationInSoundThread(PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN PVOID Parameter)
Definition: header.c:33

◆ WaveHeaderOperationInSoundThread()

MMRESULT WaveHeaderOperationInSoundThread ( PSOUND_DEVICE_INSTANCE  SoundDeviceInstance,
IN PVOID  Parameter 
)

Definition at line 33 of file header.c.

36 {
38  return Parameters->Function(SoundDeviceInstance, Parameters->Header);
39 }
_In_ PVOID Parameter
Definition: ldrtypes.h:241
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:872

Referenced by WaveHeaderOperation().

◆ WriteWaveHeader()

MMRESULT WriteWaveHeader ( IN PSOUND_DEVICE_INSTANCE  SoundDeviceInstance,
IN PWAVEHDR  Header 
)

Definition at line 159 of file header.c.

162 {
164  PSOUND_DEVICE SoundDevice;
166 
169 
170  SND_TRACE(L"Submitting wave header\n");
171 
172  Result = GetSoundDeviceFromInstance(SoundDeviceInstance, &SoundDevice);
173  if ( ! MMSUCCESS(Result) )
175 
177  if ( ! MMSUCCESS(Result) )
179 
180  if ( ! FunctionTable->CommitWaveBuffer )
181  return MMSYSERR_NOTSUPPORTED;
182 
183  /*
184  A few minor sanity checks - any custom checks should've been carried
185  out during wave header preparation etc.
186  */
187  VALIDATE_MMSYS_PARAMETER( Header->lpData != NULL );
188  VALIDATE_MMSYS_PARAMETER( Header->dwBufferLength > 0 );
190  VALIDATE_MMSYS_PARAMETER( ! (Header->dwFlags & WHDR_INQUEUE) );
191 
193 
194  /* Clear the "done" flag for the buffer */
195  Header->dwFlags &= ~WHDR_DONE;
196 
197  Result = CallSoundThread(SoundDeviceInstance,
199  Header);
200 
201  return Result;
202 }
VOID SanitizeWaveHeader(PWAVEHDR Header)
Definition: header.c:64
MMRESULT CallSoundThread(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN SOUND_THREAD_REQUEST_HANDLER RequestHandler, IN PVOID Parameter OPTIONAL)
Definition: thread.c:71
#define MMSUCCESS(result)
Definition: mmebuddy.h:80
MMRESULT TranslateInternalMmResult(IN MMRESULT Result)
Definition: utility.c:132
UINT MMRESULT
Definition: mmsystem.h:962
#define VALIDATE_MMSYS_PARAMETER(parameter_condition)
Definition: mmebuddy.h:71
MMRESULT EnqueueWaveHeader(PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN PVOID Parameter)
Definition: header.c:218
MMRESULT GetSoundDeviceFunctionTable(IN PSOUND_DEVICE SoundDevice, OUT PMMFUNCTION_TABLE *FunctionTable)
Definition: functiontable.c:47
Definition: Header.h:8
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
BOOLEAN IsValidSoundDeviceInstance(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
#define MMSYSERR_NOTSUPPORTED
Definition: mmsystem.h:104
static const WCHAR L[]
Definition: oid.c:1250
#define WHDR_INQUEUE
Definition: mmsystem.h:197
#define WHDR_PREPARED
Definition: mmsystem.h:194
#define WHDR_DONE
Definition: mmsystem.h:193
static WLX_DISPATCH_VERSION_1_4 FunctionTable
Definition: wlx.c:736
MMRESULT GetSoundDeviceFromInstance(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, OUT PSOUND_DEVICE *SoundDevice)
#define SND_TRACE(...)