ReactOS 0.4.15-dev-7887-g64a59a1
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
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,
366}
Definition: Header.h:9
#define NULL
Definition: types.h:112
_Inout_opt_ PUNICODE_STRING Extension
Definition: fltkernel.h:1092
DeviceType
Definition: mmdrv.h:42
struct _WAVEHDR_EXTENSION * PWAVEHDR_EXTENSION
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
MMRESULT GetSoundDeviceFromInstance(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, OUT PSOUND_DEVICE *SoundDevice)
MMRESULT GetSoundDeviceType(IN PSOUND_DEVICE SoundDevice, OUT PMMDEVICE_TYPE DeviceType)
Definition: devicelist.c:346
#define MMSUCCESS(result)
Definition: mmebuddy.h:80
#define DUMP_WAVEHDR_QUEUE(sound_device_instance)
#define SND_TRACE(...)
#define SND_ASSERT(condition)
#define WOM_DONE
Definition: mmsystem.h:183
UINT MMRESULT
Definition: mmsystem.h:962
#define WIM_DATA
Definition: mmsystem.h:186
#define WHDR_DONE
Definition: mmsystem.h:193
#define L(x)
Definition: ntvdm.h:50
@ WAVE_IN_DEVICE_TYPE
Definition: sndtypes.h:28
@ WAVE_OUT_DEVICE_TYPE
Definition: sndtypes.h:29
struct wavehdr_tag * lpNext
Definition: mmsystem.h:1020
uint32_t DWORD_PTR
Definition: typedefs.h:65
_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

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}
#define FALSE
Definition: types.h:117
VOID DoWaveStreaming(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
Definition: streaming.c:20
#define VALIDATE_MMSYS_PARAMETER(parameter_condition)
Definition: mmebuddy.h:71
struct wavehdr_tag * PWAVEHDR
#define WHDR_INQUEUE
Definition: mmsystem.h:197
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
PWAVEHDR TailWaveHeader
Definition: mmebuddy.h:292
PWAVEHDR HeadWaveHeader
Definition: mmebuddy.h:287
DWORD dwFlags
Definition: mmsystem.h:1018
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:323

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 AllocateStruct(thing)
Definition: mmebuddy.h:27
MMRESULT GetSoundDeviceFunctionTable(IN PSOUND_DEVICE SoundDevice, OUT PMMFUNCTION_TABLE *FunctionTable)
Definition: functiontable.c:47
MMRESULT TranslateInternalMmResult(IN MMRESULT Result)
Definition: utility.c:132
BOOLEAN IsValidSoundDeviceInstance(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
#define MMSYSERR_NOMEM
Definition: mmsystem.h:103
#define WHDR_PREPARED
Definition: mmsystem.h:194
#define DWORD_PTR
Definition: treelist.c:76
static WLX_DISPATCH_VERSION_1_4 FunctionTable
Definition: wlx.c:722

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

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

◆ 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}
_In_ CDROM_SCAN_FOR_SPECIAL_INFO _In_ PCDROM_SCAN_FOR_SPECIAL_HANDLER Function
Definition: cdrom.h:1156
MMRESULT CallSoundThread(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN SOUND_THREAD_REQUEST_HANDLER RequestHandler, IN PVOID Parameter OPTIONAL)
Definition: thread.c:71
MMRESULT WaveHeaderOperationInSoundThread(PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN PVOID Parameter)
Definition: header.c:33
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869

◆ 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}
MMWAVEHEADER_FUNC Function
Definition: header.c:22

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 )
182
183 /*
184 A few minor sanity checks - any custom checks should've been carried
185 out during wave header preparation etc.
186 */
188 VALIDATE_MMSYS_PARAMETER( Header->dwBufferLength > 0 );
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}
#define MMSYSERR_NOTSUPPORTED
Definition: mmsystem.h:104
MMRESULT EnqueueWaveHeader(PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN PVOID Parameter)
Definition: header.c:218
VOID SanitizeWaveHeader(PWAVEHDR Header)
Definition: header.c:64