Fixes for -Wmissing-declaration and -Wwrite-string warnings.
[wine] / dlls / dsound / dsound_private.h
1 /*                      DirectSound
2  *
3  * Copyright 1998 Marcus Meissner
4  * Copyright 1998 Rob Riggs
5  * Copyright 2000-2001 TransGaming Technologies, Inc.
6  *
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.
11  *
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.
16  *
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
20  */
21
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 */
25
26 #define DS_HEL_FRAGS 48 /* HEL only: number of waveOut fragments in primary buffer
27                          * (changing this won't help you) */
28
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
34
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;
43
44 /*****************************************************************************
45  * Predeclare the interface implementation structures
46  */
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;
66 typedef struct DirectSoundDevice             DirectSoundDevice;
67 typedef struct DirectSoundCaptureDevice      DirectSoundCaptureDevice;
68
69 /*****************************************************************************
70  * IDirectSound implementation structure
71  */
72 struct IDirectSoundImpl
73 {
74     /* IUnknown fields */
75     const IDirectSound8Vtbl    *lpVtbl;
76     DWORD                       ref;
77
78     DirectSoundDevice          *device;
79     LPUNKNOWN                   pUnknown;
80     LPDIRECTSOUND               pDS;
81     LPDIRECTSOUND8              pDS8;
82 };
83
84 struct DirectSoundDevice
85 {
86     DWORD                       ref;
87
88     GUID                        guid;
89     PIDSDRIVER                  driver;
90     DSDRIVERDESC                drvdesc;
91     DSDRIVERCAPS                drvcaps;
92     DWORD                       priolevel;
93     PWAVEFORMATEX               pwfx;
94     HWAVEOUT                    hwo;
95     LPWAVEHDR                   pwave[DS_HEL_FRAGS];
96     UINT                        timerID, pwplay, pwwrite, pwqueue, prebuf, precount;
97     DWORD                       fraglen;
98     PIDSDRIVERBUFFER            hwbuf;
99     LPBYTE                      buffer;
100     DWORD                       writelead, buflen, state, playpos, mixpos;
101     BOOL                        need_remix;
102     int                         nrofbuffers;
103     IDirectSoundBufferImpl**    buffers;
104     RTL_RWLOCK                  buffer_list_lock;
105     CRITICAL_SECTION            mixlock;
106     PrimaryBufferImpl*          primary;
107     DSBUFFERDESC                dsbd;
108     DWORD                       speaker_config;
109     LPBYTE                      tmp_buffer;
110     DWORD                       tmp_buffer_len;
111
112     /* DirectSound3DListener fields */
113     IDirectSound3DListenerImpl* listener;
114     DS3DLISTENER                ds3dl;
115     BOOL                        ds3dl_need_recalc;
116 };
117
118 /* reference counted buffer memory for duplicated buffer memory */
119 typedef struct BufferMemory
120 {
121     DWORD                       ref;
122     LPBYTE                      memory;
123 } BufferMemory;
124
125 HRESULT WINAPI IDirectSoundImpl_Create(
126     LPDIRECTSOUND8 * ppds);
127
128 HRESULT WINAPI DSOUND_Create(
129     LPDIRECTSOUND *ppDS,
130     IUnknown *pUnkOuter);
131
132 HRESULT WINAPI DSOUND_Create8(
133     LPDIRECTSOUND8 *ppDS,
134     IUnknown *pUnkOuter);
135
136 /*****************************************************************************
137  * IDirectSound COM components
138  */
139 struct IDirectSound_IUnknown {
140     const IUnknownVtbl         *lpVtbl;
141     DWORD                       ref;
142     LPDIRECTSOUND8              pds;
143 };
144
145 HRESULT WINAPI IDirectSound_IUnknown_Create(
146     LPDIRECTSOUND8 pds,
147     LPUNKNOWN * ppunk);
148
149 struct IDirectSound_IDirectSound {
150     const IDirectSoundVtbl     *lpVtbl;
151     DWORD                       ref;
152     LPDIRECTSOUND8              pds;
153 };
154
155 HRESULT WINAPI IDirectSound_IDirectSound_Create(
156     LPDIRECTSOUND8 pds,
157     LPDIRECTSOUND * ppds);
158
159 /*****************************************************************************
160  * IDirectSound8 COM components
161  */
162 struct IDirectSound8_IUnknown {
163     const IUnknownVtbl         *lpVtbl;
164     DWORD                       ref;
165     LPDIRECTSOUND8              pds;
166 };
167
168 HRESULT WINAPI IDirectSound8_IUnknown_Create(
169     LPDIRECTSOUND8 pds,
170     LPUNKNOWN * ppunk);
171
172 struct IDirectSound8_IDirectSound {
173     const IDirectSoundVtbl     *lpVtbl;
174     DWORD                       ref;
175     LPDIRECTSOUND8              pds;
176 };
177
178 HRESULT WINAPI IDirectSound8_IDirectSound_Create(
179     LPDIRECTSOUND8 pds,
180     LPDIRECTSOUND * ppds);
181
182 struct IDirectSound8_IDirectSound8 {
183     const IDirectSound8Vtbl    *lpVtbl;
184     DWORD                       ref;
185     LPDIRECTSOUND8              pds;
186 };
187
188 HRESULT WINAPI IDirectSound8_IDirectSound8_Create(
189     LPDIRECTSOUND8 pds,
190     LPDIRECTSOUND8 * ppds);
191
192 /*****************************************************************************
193  * IDirectSoundBuffer implementation structure
194  */
195 struct IDirectSoundBufferImpl
196 {
197     /* FIXME: document */
198     /* IUnknown fields */
199     const IDirectSoundBuffer8Vtbl *lpVtbl;
200     DWORD                       ref;
201     /* IDirectSoundBufferImpl fields */
202     SecondaryBufferImpl*        dsb;
203     IDirectSoundImpl*           dsound;
204     CRITICAL_SECTION            lock;
205     PIDSDRIVERBUFFER            hwbuf;
206     PWAVEFORMATEX               pwfx;
207     BufferMemory*               buffer;
208     DWORD                       playflags,state,leadin;
209     DWORD                       playpos,startpos,writelead,buflen;
210     DWORD                       nAvgBytesPerSec;
211     DWORD                       freq;
212     DSVOLUMEPAN                 volpan, cvolpan;
213     DSBUFFERDESC                dsbd;
214     /* used for frequency conversion (PerfectPitch) */
215     ULONG                       freqAdjust, freqAcc;
216     /* used for intelligent (well, sort of) prebuffering */
217     DWORD                       probably_valid_to, last_playpos;
218     DWORD                       primary_mixpos, buf_mixpos;
219     BOOL                        need_remix;
220
221     /* IDirectSoundNotifyImpl fields */
222     IDirectSoundNotifyImpl*     notify;
223     LPDSBPOSITIONNOTIFY         notifies;
224     int                         nrofnotifies;
225     PIDSDRIVERNOTIFY            hwnotify;
226
227     /* DirectSound3DBuffer fields */
228     IDirectSound3DBufferImpl*   ds3db;
229     DS3DBUFFER                  ds3db_ds3db;
230     LONG                        ds3db_lVolume;
231     BOOL                        ds3db_need_recalc;
232
233     /* IKsPropertySet fields */
234     IKsBufferPropertySetImpl*   iks;
235 };
236
237 HRESULT WINAPI IDirectSoundBufferImpl_Create(
238     IDirectSoundImpl *ds,
239     IDirectSoundBufferImpl **pdsb,
240     LPCDSBUFFERDESC dsbd);
241 HRESULT WINAPI IDirectSoundBufferImpl_Destroy(
242     IDirectSoundBufferImpl *pdsb);
243
244 /*****************************************************************************
245  * SecondaryBuffer implementation structure
246  */
247 struct SecondaryBufferImpl
248 {
249     const IDirectSoundBuffer8Vtbl *lpVtbl;
250     DWORD                       ref;
251     IDirectSoundBufferImpl*     dsb;
252 };
253
254 HRESULT WINAPI SecondaryBufferImpl_Create(
255     IDirectSoundBufferImpl *dsb,
256     SecondaryBufferImpl **pdsb);
257 HRESULT WINAPI SecondaryBufferImpl_Destroy(
258     SecondaryBufferImpl *pdsb);
259
260 /*****************************************************************************
261  * PrimaryBuffer implementation structure
262  */
263 struct PrimaryBufferImpl
264 {
265     const IDirectSoundBuffer8Vtbl *lpVtbl;
266     DWORD                       ref;
267     IDirectSoundImpl*           dsound;
268 };
269
270 HRESULT WINAPI PrimaryBufferImpl_Create(
271     IDirectSoundImpl *ds,
272     PrimaryBufferImpl **pdsb,
273     LPCDSBUFFERDESC dsbd);
274
275 /*****************************************************************************
276  * IDirectSoundCapture implementation structure
277  */
278 struct IDirectSoundCaptureImpl
279 {
280     /* IUnknown fields */
281     const IDirectSoundCaptureVtbl     *lpVtbl;
282     DWORD                              ref;
283
284     DirectSoundCaptureDevice          *device;
285 };
286
287 struct DirectSoundCaptureDevice
288 {
289     /* IDirectSoundCaptureImpl fields */
290     GUID                               guid;
291     DWORD                              ref;
292
293     /* DirectSound driver stuff */
294     PIDSCDRIVER                        driver;
295     DSDRIVERDESC                       drvdesc;
296     DSCDRIVERCAPS                      drvcaps;
297     PIDSCDRIVERBUFFER                  hwbuf;
298
299     /* wave driver info */
300     HWAVEIN                            hwi;
301
302     /* more stuff */
303     LPBYTE                             buffer;
304     DWORD                              buflen;
305     DWORD                              read_position;
306
307     PWAVEFORMATEX                      pwfx;
308
309     IDirectSoundCaptureBufferImpl*     capture_buffer;
310     DWORD                              state;
311     LPWAVEHDR                          pwave;
312     int                                nrofpwaves;
313     int                                index;
314     CRITICAL_SECTION                   lock;
315 };
316
317 HRESULT WINAPI IDirectSoundCaptureImpl_Create(
318     LPDIRECTSOUNDCAPTURE8 * ppds);
319
320 HRESULT WINAPI DSOUND_CaptureCreate(
321     LPDIRECTSOUNDCAPTURE *ppDSC,
322     IUnknown *pUnkOuter);
323
324 HRESULT WINAPI DSOUND_CaptureCreate8(
325     LPDIRECTSOUNDCAPTURE8 *ppDSC8,
326     IUnknown *pUnkOuter);
327
328 /*****************************************************************************
329  * IDirectSoundCaptureBuffer implementation structure
330  */
331 struct IDirectSoundCaptureBufferImpl
332 {
333     /* IUnknown fields */
334     const IDirectSoundCaptureBuffer8Vtbl *lpVtbl;
335     DWORD                               ref;
336
337     /* IDirectSoundCaptureBufferImpl fields */
338     IDirectSoundCaptureImpl*            dsound;
339     /* FIXME: don't need this */
340     LPDSCBUFFERDESC                     pdscbd;
341     DWORD                               flags;
342
343     /* IDirectSoundCaptureNotifyImpl fields */
344     IDirectSoundCaptureNotifyImpl*      notify;
345     LPDSBPOSITIONNOTIFY                 notifies;
346     int                                 nrofnotifies;
347     PIDSDRIVERNOTIFY                    hwnotify;
348 };
349
350 /*****************************************************************************
351  * IDirectSoundFullDuplex implementation structure
352  */
353 struct IDirectSoundFullDuplexImpl
354 {
355     /* IUnknown fields */
356     const IDirectSoundFullDuplexVtbl *lpVtbl;
357     DWORD                       ref;
358
359     /* IDirectSoundFullDuplexImpl fields */
360     CRITICAL_SECTION            lock;
361 };
362
363 /*****************************************************************************
364  * IDirectSoundNotify implementation structure
365  */
366 struct IDirectSoundNotifyImpl
367 {
368     /* IUnknown fields */
369     const IDirectSoundNotifyVtbl *lpVtbl;
370     DWORD                       ref;
371     IDirectSoundBufferImpl*     dsb;
372 };
373
374 HRESULT WINAPI IDirectSoundNotifyImpl_Create(
375     IDirectSoundBufferImpl *dsb,
376     IDirectSoundNotifyImpl **pdsn);
377 HRESULT WINAPI IDirectSoundNotifyImpl_Destroy(
378     IDirectSoundNotifyImpl *pdsn);
379
380 /*****************************************************************************
381  * IDirectSoundCaptureNotify implementation structure
382  */
383 struct IDirectSoundCaptureNotifyImpl
384 {
385     /* IUnknown fields */
386     const IDirectSoundNotifyVtbl       *lpVtbl;
387     DWORD                               ref;
388     IDirectSoundCaptureBufferImpl*      dscb;
389 };
390
391 HRESULT WINAPI IDirectSoundCaptureNotifyImpl_Create(
392     IDirectSoundCaptureBufferImpl *dscb,
393     IDirectSoundCaptureNotifyImpl ** pdscn);
394
395 /*****************************************************************************
396  *  IDirectSound3DListener implementation structure
397  */
398 struct IDirectSound3DListenerImpl
399 {
400     /* IUnknown fields */
401     const IDirectSound3DListenerVtbl *lpVtbl;
402     DWORD                       ref;
403     /* IDirectSound3DListenerImpl fields */
404     IDirectSoundImpl*           dsound;
405 };
406
407 HRESULT WINAPI IDirectSound3DListenerImpl_Create(
408     PrimaryBufferImpl *pb,
409     IDirectSound3DListenerImpl **pdsl);
410
411 /*****************************************************************************
412  *  IKsBufferPropertySet implementation structure
413  */
414 struct IKsBufferPropertySetImpl
415 {
416     /* IUnknown fields */
417     const IKsPropertySetVtbl   *lpVtbl;
418     DWORD                       ref;
419     /* IKsPropertySetImpl fields */
420     IDirectSoundBufferImpl*     dsb;
421 };
422
423 HRESULT WINAPI IKsBufferPropertySetImpl_Create(
424     IDirectSoundBufferImpl *dsb,
425     IKsBufferPropertySetImpl **piks);
426 HRESULT WINAPI IKsBufferPropertySetImpl_Destroy(
427     IKsBufferPropertySetImpl *piks);
428
429 /*****************************************************************************
430  *  IKsPrivatePropertySet implementation structure
431  */
432 struct IKsPrivatePropertySetImpl
433 {
434     /* IUnknown fields */
435     const IKsPropertySetVtbl   *lpVtbl;
436     DWORD                       ref;
437 };
438
439 HRESULT WINAPI IKsPrivatePropertySetImpl_Create(
440     IKsPrivatePropertySetImpl **piks);
441
442 /*****************************************************************************
443  * IDirectSound3DBuffer implementation structure
444  */
445 struct IDirectSound3DBufferImpl
446 {
447     /* IUnknown fields */
448     const IDirectSound3DBufferVtbl *lpVtbl;
449     DWORD                       ref;
450     /* IDirectSound3DBufferImpl fields */
451     IDirectSoundBufferImpl*     dsb;
452 };
453
454 HRESULT WINAPI IDirectSound3DBufferImpl_Create(
455     IDirectSoundBufferImpl *dsb,
456     IDirectSound3DBufferImpl **pds3db);
457 HRESULT WINAPI IDirectSound3DBufferImpl_Destroy(
458     IDirectSound3DBufferImpl *pds3db);
459
460 /*******************************************************************************
461  * DirectSound ClassFactory implementation structure
462  */
463 struct IClassFactoryImpl
464 {
465     /* IUnknown fields */
466     const IClassFactoryVtbl    *lpVtbl;
467     DWORD                       ref;
468 };
469
470 extern IClassFactoryImpl DSOUND_CAPTURE_CF;
471 extern IClassFactoryImpl DSOUND_FULLDUPLEX_CF;
472
473 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
474 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan);
475 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
476
477 /* dsound.c */
478
479 HRESULT DSOUND_AddBuffer(IDirectSoundImpl * pDS, IDirectSoundBufferImpl * pDSB);
480 HRESULT DSOUND_RemoveBuffer(IDirectSoundImpl * pDS, IDirectSoundBufferImpl * pDSB);
481
482 /* primary.c */
483
484 HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device);
485 HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device);
486 HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device);
487 HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device);
488 HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos);
489
490 /* buffer.c */
491
492 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This, DWORD pplay, DWORD pwrite);
493
494 /* mixer.c */
495
496 void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
497 void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb);
498 void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos);
499 void DSOUND_WaveQueue(DirectSoundDevice *device, DWORD mixq);
500 void DSOUND_PerformMix(DirectSoundDevice *device);
501 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
502 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
503
504 /* sound3d.c */
505
506 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb);
507
508 #define STATE_STOPPED   0
509 #define STATE_STARTING  1
510 #define STATE_PLAYING   2
511 #define STATE_CAPTURING 2
512 #define STATE_STOPPING  3
513
514 #define DSOUND_FREQSHIFT (14)
515
516 extern DirectSoundDevice* DSOUND_renderer[MAXWAVEDRIVERS];
517 extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS];
518
519 extern DirectSoundCaptureDevice * DSOUND_capture[MAXWAVEDRIVERS];
520 extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS];
521
522 extern HRESULT mmErr(UINT err);
523 extern void setup_dsound_options(void);
524 extern const char * get_device_id(LPCGUID pGuid);