ReactOS 0.4.15-dev-7842-g558ab78
deviceinstance.c File Reference
#include "precomp.h"
Include dependency graph for deviceinstance.c:

Go to the source code of this file.

Macros

#define SOUND_KERNEL_BUFFER_COUNT   10
 
#define SOUND_KERNEL_BUFFER_SIZE   16384
 

Functions

MMRESULT AllocateSoundDeviceInstance (OUT PSOUND_DEVICE_INSTANCE *SoundDeviceInstance)
 
VOID FreeSoundDeviceInstance (IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
 
BOOLEAN IsValidSoundDeviceInstance (IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
 
MMRESULT ListSoundDeviceInstance (IN PSOUND_DEVICE SoundDevice, IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
 
MMRESULT UnlistSoundDeviceInstance (IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
 
MMRESULT CreateSoundDeviceInstance (IN PSOUND_DEVICE SoundDevice, OUT PSOUND_DEVICE_INSTANCE *SoundDeviceInstance)
 
MMRESULT DestroySoundDeviceInstance (IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
 
MMRESULT DestroyAllSoundDeviceInstances (IN PSOUND_DEVICE SoundDevice)
 
MMRESULT GetSoundDeviceFromInstance (IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, OUT PSOUND_DEVICE *SoundDevice)
 
MMRESULT GetSoundDeviceInstanceHandle (IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, OUT PVOID *Handle)
 
MMRESULT SetSoundDeviceInstanceMmeData (IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN HDRVR MmeHandle, IN DWORD_PTR ClientCallback, IN DWORD_PTR ClientCallbackData, IN DWORD Flags)
 

Macro Definition Documentation

◆ SOUND_KERNEL_BUFFER_COUNT

#define SOUND_KERNEL_BUFFER_COUNT   10

Definition at line 17 of file deviceinstance.c.

◆ SOUND_KERNEL_BUFFER_SIZE

#define SOUND_KERNEL_BUFFER_SIZE   16384

Definition at line 18 of file deviceinstance.c.

Function Documentation

◆ AllocateSoundDeviceInstance()

MMRESULT AllocateSoundDeviceInstance ( OUT PSOUND_DEVICE_INSTANCE SoundDeviceInstance)

Definition at line 21 of file deviceinstance.c.

23{
24 PSOUND_DEVICE_INSTANCE NewInstance;
25
26 VALIDATE_MMSYS_PARAMETER( SoundDeviceInstance );
27
28 /* Allocate memory for the new instance */
30
31 if ( ! NewInstance )
32 return MMSYSERR_NOMEM;
33
34 /* Use default frame size */
36 /* Use default buffer count */
38
39 /* Provide the caller with the new instance pointer */
40 *SoundDeviceInstance = NewInstance;
41
42 return MMSYSERR_NOERROR;
43}
#define SOUND_KERNEL_BUFFER_COUNT
#define SOUND_KERNEL_BUFFER_SIZE
#define VALIDATE_MMSYS_PARAMETER(parameter_condition)
Definition: mmebuddy.h:71
#define AllocateStruct(thing)
Definition: mmebuddy.h:27
#define MMSYSERR_NOMEM
Definition: mmsystem.h:103
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96

Referenced by CreateSoundDeviceInstance().

◆ CreateSoundDeviceInstance()

MMRESULT CreateSoundDeviceInstance ( IN PSOUND_DEVICE  SoundDevice,
OUT PSOUND_DEVICE_INSTANCE SoundDeviceInstance 
)

Definition at line 162 of file deviceinstance.c.

165{
168
169 SND_TRACE(L"Creating a sound device instance\n");
170
172 VALIDATE_MMSYS_PARAMETER( SoundDeviceInstance != NULL );
173
174 Result = AllocateSoundDeviceInstance(SoundDeviceInstance);
175
176 if ( ! MMSUCCESS(Result) )
178
179 /* Get the "open" routine from the function table, and validate it */
181 if ( ! MMSUCCESS(Result) )
182 {
183 FreeSoundDeviceInstance(*SoundDeviceInstance);
185 }
186
187 if ( FunctionTable->Open == NULL )
188 {
189 FreeSoundDeviceInstance(*SoundDeviceInstance);
191 }
192
193 /* Set up the members of the structure */
194 (*SoundDeviceInstance)->Next = NULL;
195 (*SoundDeviceInstance)->Device = SoundDevice;
196 (*SoundDeviceInstance)->Handle = NULL;
197 (*SoundDeviceInstance)->Thread = NULL;
198
199 (*SoundDeviceInstance)->WinMM.Handle = INVALID_HANDLE_VALUE;
200 (*SoundDeviceInstance)->WinMM.ClientCallback = 0;
201 (*SoundDeviceInstance)->WinMM.ClientCallbackInstanceData = 0;
202 (*SoundDeviceInstance)->WinMM.Flags = 0;
203
204 /* Initialise the members of the struct used by the sound thread */
205 (*SoundDeviceInstance)->HeadWaveHeader = NULL;
206 (*SoundDeviceInstance)->TailWaveHeader = NULL;
207
208 (*SoundDeviceInstance)->OutstandingBuffers = 0;
209
210 (*SoundDeviceInstance)->LoopsRemaining = 0;
211
212 /* Create the streaming thread (TODO - is this for wave only?) */
213 Result = CreateSoundThread(&(*SoundDeviceInstance)->Thread);
214 if ( ! MMSUCCESS(Result) )
215 {
216 FreeSoundDeviceInstance(*SoundDeviceInstance);
218 }
219
220 /* Add the instance to the list */
221 Result = ListSoundDeviceInstance(SoundDevice, *SoundDeviceInstance);
222 if ( ! MMSUCCESS(Result) )
223 {
224 FreeSoundDeviceInstance(*SoundDeviceInstance);
226 }
227
228 /* Try and open the device */
229 Result = FunctionTable->Open(SoundDevice, (&(*SoundDeviceInstance)->Handle));
230 if ( ! MMSUCCESS(Result) )
231 {
232 UnlistSoundDeviceInstance(*SoundDeviceInstance);
233 FreeSoundDeviceInstance(*SoundDeviceInstance);
235 }
236
237 return MMSYSERR_NOERROR;
238}
VOID FreeSoundDeviceInstance(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
MMRESULT AllocateSoundDeviceInstance(OUT PSOUND_DEVICE_INSTANCE *SoundDeviceInstance)
MMRESULT UnlistSoundDeviceInstance(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
MMRESULT ListSoundDeviceInstance(IN PSOUND_DEVICE SoundDevice, IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
#define NULL
Definition: types.h:112
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOLEAN IsValidSoundDevice(IN PSOUND_DEVICE SoundDevice)
Definition: devicelist.c:87
MMRESULT CreateSoundThread(OUT PSOUND_THREAD *Thread)
Definition: thread.c:209
MMRESULT GetSoundDeviceFunctionTable(IN PSOUND_DEVICE SoundDevice, OUT PMMFUNCTION_TABLE *FunctionTable)
Definition: functiontable.c:47
MMRESULT TranslateInternalMmResult(IN MMRESULT Result)
Definition: utility.c:132
#define MMSUCCESS(result)
Definition: mmebuddy.h:80
#define SND_TRACE(...)
UINT MMRESULT
Definition: mmsystem.h:962
#define MMSYSERR_NOTSUPPORTED
Definition: mmsystem.h:104
#define L(x)
Definition: ntvdm.h:50
static WLX_DISPATCH_VERSION_1_4 FunctionTable
Definition: wlx.c:722
_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 MmeOpenDevice().

◆ DestroyAllSoundDeviceInstances()

MMRESULT DestroyAllSoundDeviceInstances ( IN PSOUND_DEVICE  SoundDevice)

Definition at line 305 of file deviceinstance.c.

307{
309 PSOUND_DEVICE_INSTANCE SoundDeviceInstance, NextDeviceInstance;
310
311 SoundDeviceInstance = SoundDevice->HeadInstance;
312
313 while ( SoundDeviceInstance )
314 {
315 NextDeviceInstance = SoundDeviceInstance->Next;
316 Result = DestroySoundDeviceInstance(SoundDeviceInstance);
318 SoundDeviceInstance = NextDeviceInstance;
319 }
320
321 return MMSYSERR_NOERROR;
322}
MMRESULT DestroySoundDeviceInstance(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
#define SND_ASSERT(condition)
struct _SOUND_DEVICE_INSTANCE * Next
Definition: mmebuddy.h:269

◆ DestroySoundDeviceInstance()

MMRESULT DestroySoundDeviceInstance ( IN PSOUND_DEVICE_INSTANCE  SoundDeviceInstance)

Definition at line 241 of file deviceinstance.c.

243{
246 PSOUND_DEVICE SoundDevice;
248
249 SND_TRACE(L"Destroying a sound device instance\n");
250
252
253 Result = GetSoundDeviceFromInstance(SoundDeviceInstance, &SoundDevice);
254 if ( ! MMSUCCESS(Result) )
256
257 Result = GetSoundDeviceInstanceHandle(SoundDeviceInstance, &Handle);
258 if ( ! MMSUCCESS(Result) )
260
261 /* Get the "close" routine from the function table, and validate it */
263 if ( ! MMSUCCESS(Result) )
265
266 SND_ASSERT( FunctionTable->Close );
267 if ( FunctionTable->Close == NULL )
268 {
269 /* This indicates bad practice, really! If you can open, why not close?! */
271 }
272
273 /* Stop the streaming thread */
274 if ( SoundDeviceInstance->Thread )
275 {
276 Result = DestroySoundThread(SoundDeviceInstance->Thread);
277 SND_ASSERT( MMSUCCESS(Result) ); /* It should succeed! */
278 if ( ! MMSUCCESS(Result ) )
279 {
281 }
282 }
283
284 /* Blank this out here */
285 SoundDeviceInstance->Thread = NULL;
286
287 /* Try and close the device */
288 Result = FunctionTable->Close(SoundDeviceInstance, Handle);
289 SND_ASSERT( MMSUCCESS(Result) ); /* It should succeed! */
290 if ( ! MMSUCCESS(Result) )
292
293 /* Drop it from the list */
294 Result = UnlistSoundDeviceInstance(SoundDeviceInstance);
295 SND_ASSERT( MMSUCCESS(Result) ); /* It should succeed! */
296 if ( ! MMSUCCESS(Result) )
298
299 FreeSoundDeviceInstance(SoundDeviceInstance);
300
301 return MMSYSERR_NOERROR;
302}
MMRESULT GetSoundDeviceFromInstance(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, OUT PSOUND_DEVICE *SoundDevice)
MMRESULT GetSoundDeviceInstanceHandle(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, OUT PVOID *Handle)
BOOLEAN IsValidSoundDeviceInstance(IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
ULONG Handle
Definition: gdb_input.c:15
MMRESULT DestroySoundThread(IN PSOUND_THREAD Thread)
Definition: thread.c:272

Referenced by DestroyAllSoundDeviceInstances(), and MmeCloseDevice().

◆ FreeSoundDeviceInstance()

VOID FreeSoundDeviceInstance ( IN PSOUND_DEVICE_INSTANCE  SoundDeviceInstance)

Definition at line 46 of file deviceinstance.c.

48{
49 /*
50 Device is marked as invalid by now, but we can still do some sanity
51 checking.
52 */
53 SND_ASSERT( SoundDeviceInstance->Thread == NULL );
54
55 ZeroMemory(SoundDeviceInstance, sizeof(SOUND_DEVICE_INSTANCE));
56 FreeMemory(SoundDeviceInstance);
57}
static VOID FreeMemory(PCREATE_DATA Data)
Definition: create.c:134
#define ZeroMemory
Definition: winbase.h:1712

Referenced by CreateSoundDeviceInstance(), and DestroySoundDeviceInstance().

◆ GetSoundDeviceFromInstance()

◆ GetSoundDeviceInstanceHandle()

◆ IsValidSoundDeviceInstance()

BOOLEAN IsValidSoundDeviceInstance ( IN PSOUND_DEVICE_INSTANCE  SoundDeviceInstance)

Definition at line 60 of file deviceinstance.c.

62{
63 PSOUND_DEVICE SoundDevice;
64 PSOUND_DEVICE_INSTANCE CurrentInstance;
65
66 if ( ! SoundDeviceInstance )
67 return FALSE;
68
69 /* GetSoundDeviceFromInstance would send us into a recursive loop... */
70 SoundDevice = SoundDeviceInstance->Device;
71 SND_ASSERT(SoundDevice);
72
73 CurrentInstance = SoundDevice->HeadInstance;
74
75 while ( CurrentInstance )
76 {
77 if ( CurrentInstance == SoundDeviceInstance )
78 return TRUE;
79
80 CurrentInstance = CurrentInstance->Next;
81 }
82
83 return FALSE;
84}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
struct _SOUND_DEVICE_INSTANCE * HeadInstance
Definition: mmebuddy.h:259

Referenced by CallSoundThread(), CloseNt4SoundDevice(), DestroySoundDeviceInstance(), GetSoundDeviceFromInstance(), GetSoundDeviceInstanceHandle(), MmeCloseDevice(), MmeGetPosition(), MmeSetState(), PrepareWaveHeader(), SetNt4WaveDeviceFormat(), SetSoundDeviceInstanceMmeData(), SetWaveDeviceFormat(), StopStreaming(), UnlistSoundDeviceInstance(), UnprepareWaveHeader(), and WriteWaveHeader().

◆ ListSoundDeviceInstance()

MMRESULT ListSoundDeviceInstance ( IN PSOUND_DEVICE  SoundDevice,
IN PSOUND_DEVICE_INSTANCE  SoundDeviceInstance 
)

Definition at line 87 of file deviceinstance.c.

90{
92 VALIDATE_MMSYS_PARAMETER( SoundDeviceInstance );
93
94 SND_TRACE(L"Listing sound device instance\n");
95
96 if ( ! SoundDevice->HeadInstance )
97 {
98 /* First entry - assign to head and tail */
99 SoundDevice->HeadInstance = SoundDeviceInstance;
100 SoundDevice->TailInstance = SoundDeviceInstance;
101 }
102 else
103 {
104 /* Attach to the end */
105 SoundDevice->TailInstance->Next = SoundDeviceInstance;
106 SoundDevice->TailInstance = SoundDeviceInstance;
107 }
108
109 return MMSYSERR_NOERROR;
110}

Referenced by CreateSoundDeviceInstance().

◆ SetSoundDeviceInstanceMmeData()

MMRESULT SetSoundDeviceInstanceMmeData ( IN PSOUND_DEVICE_INSTANCE  SoundDeviceInstance,
IN HDRVR  MmeHandle,
IN DWORD_PTR  ClientCallback,
IN DWORD_PTR  ClientCallbackData,
IN DWORD  Flags 
)

Definition at line 351 of file deviceinstance.c.

357{
359
360 SND_TRACE(L"Setting MME data - handle %x, callback %x, instance data %x, flags %x\n",
361 MmeHandle, ClientCallback, ClientCallbackData, Flags);
362
363 SoundDeviceInstance->WinMM.Handle = MmeHandle;
364 SoundDeviceInstance->WinMM.ClientCallback = ClientCallback;
365 SoundDeviceInstance->WinMM.ClientCallbackInstanceData = ClientCallbackData;
366 SoundDeviceInstance->WinMM.Flags = Flags;
367
368 return MMSYSERR_NOERROR;
369}
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by MmeOpenDevice().

◆ UnlistSoundDeviceInstance()

MMRESULT UnlistSoundDeviceInstance ( IN PSOUND_DEVICE_INSTANCE  SoundDeviceInstance)

Definition at line 113 of file deviceinstance.c.

115{
117 PSOUND_DEVICE SoundDevice;
118 PSOUND_DEVICE_INSTANCE CurrentInstance, PreviousInstance;
119
121
122 SND_TRACE(L"Unlisting sound device instance\n");
123
124 Result = GetSoundDeviceFromInstance(SoundDeviceInstance, &SoundDevice);
126 if ( ! MMSUCCESS(Result) )
128
129 PreviousInstance = NULL;
130 CurrentInstance = SoundDevice->HeadInstance;
131
132 while ( CurrentInstance )
133 {
134 if ( CurrentInstance == SoundDeviceInstance )
135 {
136 if ( ! PreviousInstance )
137 {
138 /* This is the head node */
139 SoundDevice->HeadInstance = SoundDevice->HeadInstance->Next;
140 }
141 else
142 {
143 /* There are nodes before this one - cut ours out */
144 PreviousInstance->Next = CurrentInstance->Next;
145 }
146
147 if ( ! CurrentInstance->Next )
148 {
149 /* This is the tail node */
150 SoundDevice->TailInstance = PreviousInstance;
151 }
152 }
153
154 PreviousInstance = CurrentInstance;
155 CurrentInstance = CurrentInstance->Next;
156 }
157
158 return MMSYSERR_NOERROR;
159}
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] STATPROPSETSTG *rgelt, [out] ULONG *pceltFetched)
struct _SOUND_DEVICE_INSTANCE * TailInstance
Definition: mmebuddy.h:260

Referenced by CreateSoundDeviceInstance(), and DestroySoundDeviceInstance().