Consolidate secondary buffer list processing and locking.
[wine/dcerpc.git] / dlls / dsound / dsound_private.h
blob6f003e7a4ba086deb3b3b0b108e2ad46edadbcbc
1 /* DirectSound
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998 Rob Riggs
5 * Copyright 2000-2001 TransGaming Technologies, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 /* Linux does not support better timing than 10ms */
23 #define DS_TIME_RES 10 /* Resolution of multimedia timer */
24 #define DS_TIME_DEL 10 /* Delay of multimedia timer callback, and duration of HEL fragment */
26 #define DS_HEL_FRAGS 48 /* HEL only: number of waveOut fragments in primary buffer
27 * (changing this won't help you) */
29 /* direct sound hardware acceleration levels */
30 #define DS_HW_ACCEL_FULL 0 /* default on Windows 98 */
31 #define DS_HW_ACCEL_STANDARD 1 /* default on Windows 2000 */
32 #define DS_HW_ACCEL_BASIC 2
33 #define DS_HW_ACCEL_EMULATION 3
35 extern int ds_emuldriver;
36 extern int ds_hel_margin;
37 extern int ds_hel_queue;
38 extern int ds_snd_queue_max;
39 extern int ds_snd_queue_min;
40 extern int ds_hw_accel;
41 extern int ds_default_playback;
42 extern int ds_default_capture;
44 /*****************************************************************************
45 * Predeclare the interface implementation structures
47 typedef struct IDirectSoundImpl IDirectSoundImpl;
48 typedef struct IDirectSound_IUnknown IDirectSound_IUnknown;
49 typedef struct IDirectSound_IDirectSound IDirectSound_IDirectSound;
50 typedef struct IDirectSound8_IUnknown IDirectSound8_IUnknown;
51 typedef struct IDirectSound8_IDirectSound IDirectSound8_IDirectSound;
52 typedef struct IDirectSound8_IDirectSound8 IDirectSound8_IDirectSound8;
53 typedef struct IDirectSoundBufferImpl IDirectSoundBufferImpl;
54 typedef struct IDirectSoundCaptureImpl IDirectSoundCaptureImpl;
55 typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl;
56 typedef struct IDirectSoundFullDuplexImpl IDirectSoundFullDuplexImpl;
57 typedef struct IDirectSoundNotifyImpl IDirectSoundNotifyImpl;
58 typedef struct IDirectSoundCaptureNotifyImpl IDirectSoundCaptureNotifyImpl;
59 typedef struct IDirectSound3DListenerImpl IDirectSound3DListenerImpl;
60 typedef struct IDirectSound3DBufferImpl IDirectSound3DBufferImpl;
61 typedef struct IKsBufferPropertySetImpl IKsBufferPropertySetImpl;
62 typedef struct IKsPrivatePropertySetImpl IKsPrivatePropertySetImpl;
63 typedef struct PrimaryBufferImpl PrimaryBufferImpl;
64 typedef struct SecondaryBufferImpl SecondaryBufferImpl;
65 typedef struct IClassFactoryImpl IClassFactoryImpl;
67 /*****************************************************************************
68 * IDirectSound implementation structure
70 struct IDirectSoundImpl
72 /* IUnknown fields */
73 IDirectSound8Vtbl *lpVtbl;
74 DWORD ref;
75 /* IDirectSoundImpl fields */
76 GUID guid;
77 PIDSDRIVER driver;
78 DSDRIVERDESC drvdesc;
79 DSDRIVERCAPS drvcaps;
80 DWORD priolevel;
81 PWAVEFORMATEX pwfx;
82 HWAVEOUT hwo;
83 LPWAVEHDR pwave[DS_HEL_FRAGS];
84 UINT timerID, pwplay, pwwrite, pwqueue, prebuf, precount;
85 DWORD fraglen;
86 PIDSDRIVERBUFFER hwbuf;
87 LPBYTE buffer;
88 DWORD writelead, buflen, state, playpos, mixpos;
89 BOOL need_remix;
90 int nrofbuffers;
91 IDirectSoundBufferImpl** buffers;
92 RTL_RWLOCK buffer_list_lock;
93 CRITICAL_SECTION mixlock;
94 PrimaryBufferImpl* primary;
95 DSBUFFERDESC dsbd;
96 DWORD speaker_config;
97 BOOL initialized;
99 /* DirectSound3DListener fields */
100 IDirectSound3DListenerImpl* listener;
101 DS3DLISTENER ds3dl;
102 BOOL ds3dl_need_recalc;
104 LPUNKNOWN pUnknown;
105 LPDIRECTSOUND pDS;
106 LPDIRECTSOUND8 pDS8;
109 /* reference counted buffer memory for duplicated buffer memory */
110 typedef struct BufferMemory
112 DWORD ref;
113 LPBYTE memory;
114 } BufferMemory;
116 HRESULT WINAPI IDirectSoundImpl_Create(
117 LPCGUID lpcGUID,
118 LPDIRECTSOUND8 * ppds);
120 HRESULT WINAPI DSOUND_Create(
121 LPCGUID lpcGUID,
122 LPDIRECTSOUND *ppDS,
123 IUnknown *pUnkOuter);
125 HRESULT WINAPI DSOUND_Create8(
126 LPCGUID lpcGUID,
127 LPDIRECTSOUND8 *ppDS,
128 IUnknown *pUnkOuter);
130 /*****************************************************************************
131 * IDirectSound COM components
133 struct IDirectSound_IUnknown {
134 IUnknownVtbl *lpVtbl;
135 DWORD ref;
136 LPDIRECTSOUND8 pds;
139 HRESULT WINAPI IDirectSound_IUnknown_Create(
140 LPDIRECTSOUND8 pds,
141 LPUNKNOWN * ppunk);
143 struct IDirectSound_IDirectSound {
144 IDirectSoundVtbl *lpVtbl;
145 DWORD ref;
146 LPDIRECTSOUND8 pds;
149 HRESULT WINAPI IDirectSound_IDirectSound_Create(
150 LPDIRECTSOUND8 pds,
151 LPDIRECTSOUND * ppds);
153 /*****************************************************************************
154 * IDirectSound8 COM components
156 struct IDirectSound8_IUnknown {
157 IUnknownVtbl *lpVtbl;
158 DWORD ref;
159 LPDIRECTSOUND8 pds;
162 HRESULT WINAPI IDirectSound8_IUnknown_Create(
163 LPDIRECTSOUND8 pds,
164 LPUNKNOWN * ppunk);
166 struct IDirectSound8_IDirectSound {
167 IDirectSoundVtbl *lpVtbl;
168 DWORD ref;
169 LPDIRECTSOUND8 pds;
172 HRESULT WINAPI IDirectSound8_IDirectSound_Create(
173 LPDIRECTSOUND8 pds,
174 LPDIRECTSOUND * ppds);
176 struct IDirectSound8_IDirectSound8 {
177 IDirectSound8Vtbl *lpVtbl;
178 DWORD ref;
179 LPDIRECTSOUND8 pds;
182 HRESULT WINAPI IDirectSound8_IDirectSound8_Create(
183 LPDIRECTSOUND8 pds,
184 LPDIRECTSOUND8 * ppds);
186 /*****************************************************************************
187 * IDirectSoundBuffer implementation structure
189 struct IDirectSoundBufferImpl
191 /* FIXME: document */
192 /* IUnknown fields */
193 IDirectSoundBuffer8Vtbl *lpVtbl;
194 DWORD ref;
195 /* IDirectSoundBufferImpl fields */
196 SecondaryBufferImpl* dsb;
197 IDirectSoundImpl* dsound;
198 CRITICAL_SECTION lock;
199 PIDSDRIVERBUFFER hwbuf;
200 PWAVEFORMATEX pwfx;
201 BufferMemory* buffer;
202 DWORD playflags,state,leadin;
203 DWORD playpos,startpos,writelead,buflen;
204 DWORD nAvgBytesPerSec;
205 DWORD freq;
206 DSVOLUMEPAN volpan, cvolpan;
207 DSBUFFERDESC dsbd;
208 /* used for frequency conversion (PerfectPitch) */
209 ULONG freqAdjust, freqAcc;
210 /* used for intelligent (well, sort of) prebuffering */
211 DWORD probably_valid_to, last_playpos;
212 DWORD primary_mixpos, buf_mixpos;
213 BOOL need_remix;
215 /* IDirectSoundNotifyImpl fields */
216 IDirectSoundNotifyImpl* notify;
217 LPDSBPOSITIONNOTIFY notifies;
218 int nrofnotifies;
219 PIDSDRIVERNOTIFY hwnotify;
221 /* DirectSound3DBuffer fields */
222 IDirectSound3DBufferImpl* ds3db;
223 DS3DBUFFER ds3db_ds3db;
224 LONG ds3db_lVolume;
225 BOOL ds3db_need_recalc;
227 /* IKsPropertySet fields */
228 IKsBufferPropertySetImpl* iks;
231 HRESULT WINAPI IDirectSoundBufferImpl_Create(
232 IDirectSoundImpl *ds,
233 IDirectSoundBufferImpl **pdsb,
234 LPCDSBUFFERDESC dsbd);
235 HRESULT WINAPI IDirectSoundBufferImpl_Destroy(
236 IDirectSoundBufferImpl *pdsb);
238 /*****************************************************************************
239 * SecondaryBuffer implementation structure
241 struct SecondaryBufferImpl
243 IDirectSoundBuffer8Vtbl *lpVtbl;
244 DWORD ref;
245 IDirectSoundBufferImpl* dsb;
248 HRESULT WINAPI SecondaryBufferImpl_Create(
249 IDirectSoundBufferImpl *dsb,
250 SecondaryBufferImpl **pdsb);
251 HRESULT WINAPI SecondaryBufferImpl_Destroy(
252 SecondaryBufferImpl *pdsb);
254 /*****************************************************************************
255 * PrimaryBuffer implementation structure
257 struct PrimaryBufferImpl
259 IDirectSoundBuffer8Vtbl *lpVtbl;
260 DWORD ref;
261 IDirectSoundImpl* dsound;
264 HRESULT WINAPI PrimaryBufferImpl_Create(
265 IDirectSoundImpl *ds,
266 PrimaryBufferImpl **pdsb,
267 LPCDSBUFFERDESC dsbd);
269 /*****************************************************************************
270 * IDirectSoundCapture implementation structure
272 struct IDirectSoundCaptureImpl
274 /* IUnknown fields */
275 IDirectSoundCaptureVtbl *lpVtbl;
276 DWORD ref;
278 /* IDirectSoundCaptureImpl fields */
279 GUID guid;
280 BOOL initialized;
282 /* DirectSound driver stuff */
283 PIDSCDRIVER driver;
284 DSDRIVERDESC drvdesc;
285 DSCDRIVERCAPS drvcaps;
286 PIDSCDRIVERBUFFER hwbuf;
288 /* wave driver info */
289 HWAVEIN hwi;
291 /* more stuff */
292 LPBYTE buffer;
293 DWORD buflen;
294 DWORD read_position;
296 PWAVEFORMATEX pwfx;
298 IDirectSoundCaptureBufferImpl* capture_buffer;
299 DWORD state;
300 LPWAVEHDR pwave;
301 int nrofpwaves;
302 int index;
303 CRITICAL_SECTION lock;
306 /*****************************************************************************
307 * IDirectSoundCaptureBuffer implementation structure
309 struct IDirectSoundCaptureBufferImpl
311 /* IUnknown fields */
312 IDirectSoundCaptureBuffer8Vtbl *lpVtbl;
313 DWORD ref;
315 /* IDirectSoundCaptureBufferImpl fields */
316 IDirectSoundCaptureImpl* dsound;
317 /* FIXME: don't need this */
318 LPDSCBUFFERDESC pdscbd;
319 DWORD flags;
321 /* IDirectSoundCaptureNotifyImpl fields */
322 IDirectSoundCaptureNotifyImpl* notify;
323 LPDSBPOSITIONNOTIFY notifies;
324 int nrofnotifies;
325 PIDSDRIVERNOTIFY hwnotify;
328 /*****************************************************************************
329 * IDirectSoundFullDuplex implementation structure
331 struct IDirectSoundFullDuplexImpl
333 /* IUnknown fields */
334 IDirectSoundFullDuplexVtbl *lpVtbl;
335 DWORD ref;
337 /* IDirectSoundFullDuplexImpl fields */
338 CRITICAL_SECTION lock;
341 /*****************************************************************************
342 * IDirectSoundNotify implementation structure
344 struct IDirectSoundNotifyImpl
346 /* IUnknown fields */
347 IDirectSoundNotifyVtbl *lpVtbl;
348 DWORD ref;
349 IDirectSoundBufferImpl* dsb;
352 HRESULT WINAPI IDirectSoundNotifyImpl_Create(
353 IDirectSoundBufferImpl *dsb,
354 IDirectSoundNotifyImpl **pdsn);
355 HRESULT WINAPI IDirectSoundNotifyImpl_Destroy(
356 IDirectSoundNotifyImpl *pdsn);
358 /*****************************************************************************
359 * IDirectSoundCaptureNotify implementation structure
361 struct IDirectSoundCaptureNotifyImpl
363 /* IUnknown fields */
364 IDirectSoundNotifyVtbl *lpVtbl;
365 DWORD ref;
366 IDirectSoundCaptureBufferImpl* dscb;
369 HRESULT WINAPI IDirectSoundCaptureNotifyImpl_Create(
370 IDirectSoundCaptureBufferImpl *dscb,
371 IDirectSoundCaptureNotifyImpl ** pdscn);
373 /*****************************************************************************
374 * IDirectSound3DListener implementation structure
376 struct IDirectSound3DListenerImpl
378 /* IUnknown fields */
379 IDirectSound3DListenerVtbl *lpVtbl;
380 DWORD ref;
381 /* IDirectSound3DListenerImpl fields */
382 IDirectSoundImpl* dsound;
385 HRESULT WINAPI IDirectSound3DListenerImpl_Create(
386 PrimaryBufferImpl *pb,
387 IDirectSound3DListenerImpl **pdsl);
389 /*****************************************************************************
390 * IKsBufferPropertySet implementation structure
392 struct IKsBufferPropertySetImpl
394 /* IUnknown fields */
395 IKsPropertySetVtbl *lpVtbl;
396 DWORD ref;
397 /* IKsPropertySetImpl fields */
398 IDirectSoundBufferImpl* dsb;
401 HRESULT WINAPI IKsBufferPropertySetImpl_Create(
402 IDirectSoundBufferImpl *dsb,
403 IKsBufferPropertySetImpl **piks);
404 HRESULT WINAPI IKsBufferPropertySetImpl_Destroy(
405 IKsBufferPropertySetImpl *piks);
407 /*****************************************************************************
408 * IKsPrivatePropertySet implementation structure
410 struct IKsPrivatePropertySetImpl
412 /* IUnknown fields */
413 IKsPropertySetVtbl *lpVtbl;
414 DWORD ref;
417 HRESULT WINAPI IKsPrivatePropertySetImpl_Create(
418 IKsPrivatePropertySetImpl **piks);
420 /*****************************************************************************
421 * IDirectSound3DBuffer implementation structure
423 struct IDirectSound3DBufferImpl
425 /* IUnknown fields */
426 IDirectSound3DBufferVtbl *lpVtbl;
427 DWORD ref;
428 /* IDirectSound3DBufferImpl fields */
429 IDirectSoundBufferImpl* dsb;
432 HRESULT WINAPI IDirectSound3DBufferImpl_Create(
433 IDirectSoundBufferImpl *dsb,
434 IDirectSound3DBufferImpl **pds3db);
435 HRESULT WINAPI IDirectSound3DBufferImpl_Destroy(
436 IDirectSound3DBufferImpl *pds3db);
438 /*******************************************************************************
439 * DirectSound ClassFactory implementation structure
441 struct IClassFactoryImpl
443 /* IUnknown fields */
444 IClassFactoryVtbl *lpVtbl;
445 DWORD ref;
448 extern IClassFactoryImpl DSOUND_CAPTURE_CF;
449 extern IClassFactoryImpl DSOUND_FULLDUPLEX_CF;
451 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
452 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan);
453 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
455 /* dsound.c */
457 HRESULT DSOUND_AddBuffer(IDirectSoundImpl * pDS, IDirectSoundBufferImpl * pDSB);
458 HRESULT DSOUND_RemoveBuffer(IDirectSoundImpl * pDS, IDirectSoundBufferImpl * pDSB);
460 /* primary.c */
462 HRESULT DSOUND_PrimaryCreate(IDirectSoundImpl *This);
463 HRESULT DSOUND_PrimaryDestroy(IDirectSoundImpl *This);
464 HRESULT DSOUND_PrimaryPlay(IDirectSoundImpl *This);
465 HRESULT DSOUND_PrimaryStop(IDirectSoundImpl *This);
466 HRESULT DSOUND_PrimaryGetPosition(IDirectSoundImpl *This, LPDWORD playpos, LPDWORD writepos);
468 /* buffer.c */
470 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
471 DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix);
473 /* mixer.c */
475 void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
476 void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb);
477 void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos);
478 void DSOUND_WaveQueue(IDirectSoundImpl *dsound, DWORD mixq);
479 void DSOUND_PerformMix(IDirectSoundImpl *dsound);
480 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
481 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
483 /* sound3d.c */
485 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb);
487 #define STATE_STOPPED 0
488 #define STATE_STARTING 1
489 #define STATE_PLAYING 2
490 #define STATE_CAPTURING 2
491 #define STATE_STOPPING 3
493 #define DSOUND_FREQSHIFT (14)
495 extern IDirectSoundImpl* dsound;
497 extern GUID renderer_guids[MAXWAVEDRIVERS];
498 extern GUID capture_guids[MAXWAVEDRIVERS];
500 extern HRESULT mmErr(UINT err);
501 extern void setup_dsound_options(void);
502 extern const char * get_device_id(LPCGUID pGuid);