- fix broadcast address for name lookups after iphlpapi change
[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 IDirectSoundBufferImpl IDirectSoundBufferImpl;
49 typedef struct IDirectSoundCaptureImpl IDirectSoundCaptureImpl;
50 typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl;
51 typedef struct IDirectSoundFullDuplexImpl IDirectSoundFullDuplexImpl;
52 typedef struct IDirectSoundNotifyImpl IDirectSoundNotifyImpl;
53 typedef struct IDirectSoundCaptureNotifyImpl IDirectSoundCaptureNotifyImpl;
54 typedef struct IDirectSound3DListenerImpl IDirectSound3DListenerImpl;
55 typedef struct IDirectSound3DBufferImpl IDirectSound3DBufferImpl;
56 typedef struct IKsBufferPropertySetImpl IKsBufferPropertySetImpl;
57 typedef struct IKsPrivatePropertySetImpl IKsPrivatePropertySetImpl;
58 typedef struct PrimaryBufferImpl PrimaryBufferImpl;
59 typedef struct SecondaryBufferImpl SecondaryBufferImpl;
60 typedef struct IClassFactoryImpl IClassFactoryImpl;
61
62 /*****************************************************************************
63  * IDirectSound implementation structure
64  */
65 struct IDirectSoundImpl
66 {
67     /* IUnknown fields */
68     ICOM_VFIELD(IDirectSound8);
69     DWORD                       ref;
70     /* IDirectSoundImpl fields */
71     GUID                        guid;
72     PIDSDRIVER                  driver;
73     DSDRIVERDESC                drvdesc;
74     DSDRIVERCAPS                drvcaps;
75     DWORD                       priolevel;
76     WAVEFORMATEX                wfx; /* current main waveformat */
77     HWAVEOUT                    hwo;
78     LPWAVEHDR                   pwave[DS_HEL_FRAGS];
79     UINT                        timerID, pwplay, pwwrite, pwqueue, prebuf, precount;
80     DWORD                       fraglen;
81     PIDSDRIVERBUFFER            hwbuf;
82     LPBYTE                      buffer;
83     DWORD                       writelead, buflen, state, playpos, mixpos;
84     BOOL                        need_remix;
85     int                         nrofbuffers;
86     IDirectSoundBufferImpl**    buffers;
87     RTL_RWLOCK                  lock;
88     CRITICAL_SECTION            mixlock;
89     DSVOLUMEPAN                 volpan;
90     PrimaryBufferImpl*          primary;
91     DSBUFFERDESC                dsbd;
92     DWORD                       speaker_config;
93
94     /* DirectSound3DListener fields */
95     IDirectSound3DListenerImpl* listener;
96     DS3DLISTENER                ds3dl;
97     CRITICAL_SECTION            ds3dl_lock;
98     BOOL                        ds3dl_need_recalc;
99 };
100
101 /* reference counted buffer memory for duplicated buffer memory */
102 typedef struct BufferMemory
103 {
104     DWORD                       ref;
105     LPBYTE                      memory;
106 } BufferMemory;
107
108 /*****************************************************************************
109  * IDirectSoundBuffer implementation structure
110  */
111 struct IDirectSoundBufferImpl
112 {
113     /* FIXME: document */
114     /* IUnknown fields */
115     ICOM_VFIELD(IDirectSoundBuffer8);
116     DWORD                       ref;
117     /* IDirectSoundBufferImpl fields */
118     SecondaryBufferImpl*        dsb;
119     IDirectSoundImpl*           dsound;
120     CRITICAL_SECTION            lock;
121     PIDSDRIVERBUFFER            hwbuf;
122     WAVEFORMATEX                wfx;
123     BufferMemory*               buffer;
124     DWORD                       playflags,state,leadin;
125     DWORD                       playpos,startpos,writelead,buflen;
126     DWORD                       nAvgBytesPerSec;
127     DWORD                       freq;
128     DSVOLUMEPAN                 volpan, cvolpan;
129     DSBUFFERDESC                dsbd;
130     /* used for frequency conversion (PerfectPitch) */
131     ULONG                       freqAdjust, freqAcc;
132     /* used for intelligent (well, sort of) prebuffering */
133     DWORD                       probably_valid_to, last_playpos;
134     DWORD                       primary_mixpos, buf_mixpos;
135     BOOL                        need_remix;
136
137     /* IDirectSoundNotifyImpl fields */
138     IDirectSoundNotifyImpl*     notify;
139     LPDSBPOSITIONNOTIFY         notifies;
140     int                         nrofnotifies;
141     PIDSDRIVERNOTIFY            hwnotify;
142
143     /* DirectSound3DBuffer fields */
144     IDirectSound3DBufferImpl*   ds3db;
145     DS3DBUFFER                  ds3db_ds3db;
146     LONG                        ds3db_lVolume;
147     BOOL                        ds3db_need_recalc;
148
149     /* IKsPropertySet fields */
150     IKsBufferPropertySetImpl*   iks;
151 };
152
153 HRESULT WINAPI IDirectSoundBufferImpl_Create(
154     IDirectSoundImpl *ds,
155     IDirectSoundBufferImpl **pdsb,
156     LPCDSBUFFERDESC dsbd);
157
158 /*****************************************************************************
159  * SecondaryBuffer implementation structure
160  */
161 struct SecondaryBufferImpl
162 {
163     ICOM_VFIELD(IDirectSoundBuffer8);
164     DWORD                       ref;
165     IDirectSoundBufferImpl*     dsb;
166 };
167
168 HRESULT WINAPI SecondaryBufferImpl_Create(
169     IDirectSoundBufferImpl *dsb,
170     SecondaryBufferImpl **pdsb);
171
172 /*****************************************************************************
173  * PrimaryBuffer implementation structure
174  */
175 struct PrimaryBufferImpl
176 {
177     ICOM_VFIELD(IDirectSoundBuffer8);
178     DWORD                       ref;
179     IDirectSoundImpl*           dsound;
180 };
181
182 HRESULT WINAPI PrimaryBufferImpl_Create(
183     IDirectSoundImpl *ds,
184     PrimaryBufferImpl **pdsb,
185     LPCDSBUFFERDESC dsbd);
186
187 /*****************************************************************************
188  * IDirectSoundCapture implementation structure
189  */
190 struct IDirectSoundCaptureImpl
191 {
192     /* IUnknown fields */
193     ICOM_VFIELD(IDirectSoundCapture);
194     DWORD                              ref;
195
196     /* IDirectSoundCaptureImpl fields */
197     GUID                               guid;
198     BOOL                               initialized;
199
200     /* DirectSound driver stuff */
201     PIDSCDRIVER                        driver;
202     DSDRIVERDESC                       drvdesc;
203     DSCDRIVERCAPS                      drvcaps;
204     PIDSCDRIVERBUFFER                  hwbuf;
205
206     /* wave driver info */
207     HWAVEIN                            hwi;
208
209     /* more stuff */
210     LPBYTE                             buffer;
211     DWORD                              buflen;
212     DWORD                              read_position;
213
214     PWAVEFORMATEX                      pwfx;
215
216     IDirectSoundCaptureBufferImpl*     capture_buffer;
217     DWORD                              state;
218     LPWAVEHDR                          pwave;
219     int                                nrofpwaves;
220     int                                index;
221     CRITICAL_SECTION                   lock;
222 };
223
224 /*****************************************************************************
225  * IDirectSoundCaptureBuffer implementation structure
226  */
227 struct IDirectSoundCaptureBufferImpl
228 {
229     /* IUnknown fields */
230     ICOM_VFIELD(IDirectSoundCaptureBuffer8);
231     DWORD                               ref;
232
233     /* IDirectSoundCaptureBufferImpl fields */
234     IDirectSoundCaptureImpl*            dsound;
235     /* FIXME: don't need this */
236     LPDSCBUFFERDESC                     pdscbd;
237     DWORD                               flags;
238
239     /* IDirectSoundCaptureNotifyImpl fields */
240     IDirectSoundCaptureNotifyImpl*      notify;
241     LPDSBPOSITIONNOTIFY                 notifies;
242     int                                 nrofnotifies;
243     PIDSDRIVERNOTIFY                    hwnotify;
244 };
245
246 /*****************************************************************************
247  * IDirectSoundFullDuplex implementation structure
248  */
249 struct IDirectSoundFullDuplexImpl
250 {
251     /* IUnknown fields */
252     ICOM_VFIELD(IDirectSoundFullDuplex);
253     DWORD                       ref;
254
255     /* IDirectSoundFullDuplexImpl fields */
256     CRITICAL_SECTION            lock;
257 };
258
259 /*****************************************************************************
260  * IDirectSoundNotify implementation structure
261  */
262 struct IDirectSoundNotifyImpl
263 {
264     /* IUnknown fields */
265     ICOM_VFIELD(IDirectSoundNotify);
266     DWORD                       ref;
267     IDirectSoundBufferImpl*     dsb;
268 };
269
270 HRESULT WINAPI IDirectSoundNotifyImpl_Create(
271     IDirectSoundBufferImpl *dsb,
272     IDirectSoundNotifyImpl **pdsn);
273
274 /*****************************************************************************
275  * IDirectSoundCaptureNotify implementation structure
276  */
277 struct IDirectSoundCaptureNotifyImpl
278 {
279     /* IUnknown fields */
280     ICOM_VFIELD(IDirectSoundNotify);
281     DWORD                               ref;
282     IDirectSoundCaptureBufferImpl*      dscb;
283 };
284
285 HRESULT WINAPI IDirectSoundCaptureNotifyImpl_Create(
286     IDirectSoundCaptureBufferImpl *dscb,
287     IDirectSoundCaptureNotifyImpl ** pdscn);
288
289 /*****************************************************************************
290  *  IDirectSound3DListener implementation structure
291  */
292 struct IDirectSound3DListenerImpl
293 {
294     /* IUnknown fields */
295     ICOM_VFIELD(IDirectSound3DListener);
296     DWORD                       ref;
297     /* IDirectSound3DListenerImpl fields */
298     IDirectSoundImpl*           dsound;
299 };
300
301 HRESULT WINAPI IDirectSound3DListenerImpl_Create(
302     PrimaryBufferImpl *pb,
303     IDirectSound3DListenerImpl **pdsl);
304
305 /*****************************************************************************
306  *  IKsBufferPropertySet implementation structure
307  */
308 struct IKsBufferPropertySetImpl
309 {
310     /* IUnknown fields */
311     ICOM_VFIELD(IKsPropertySet);
312     DWORD                       ref;
313     /* IKsPropertySetImpl fields */
314     IDirectSoundBufferImpl*     dsb;
315 };
316
317 HRESULT WINAPI IKsBufferPropertySetImpl_Create(
318     IDirectSoundBufferImpl *dsb,
319     IKsBufferPropertySetImpl **piks);
320
321 /*****************************************************************************
322  *  IKsPrivatePropertySet implementation structure
323  */
324 struct IKsPrivatePropertySetImpl
325 {
326     /* IUnknown fields */
327     ICOM_VFIELD(IKsPropertySet);
328     DWORD                       ref;
329 };
330
331 HRESULT WINAPI IKsPrivatePropertySetImpl_Create(
332     IKsPrivatePropertySetImpl **piks);
333
334 /*****************************************************************************
335  * IDirectSound3DBuffer implementation structure
336  */
337 struct IDirectSound3DBufferImpl
338 {
339     /* IUnknown fields */
340     ICOM_VFIELD(IDirectSound3DBuffer);
341     DWORD                       ref;
342     /* IDirectSound3DBufferImpl fields */
343     IDirectSoundBufferImpl*     dsb;
344 };
345
346 HRESULT WINAPI IDirectSound3DBufferImpl_Create(
347     IDirectSoundBufferImpl *dsb,
348     IDirectSound3DBufferImpl **pds3db);
349
350 /*******************************************************************************
351  * DirectSound ClassFactory implementation structure
352  */
353 struct IClassFactoryImpl
354 {
355     /* IUnknown fields */
356     ICOM_VFIELD(IClassFactory);
357     DWORD                       ref;
358 };
359
360 extern IClassFactoryImpl DSOUND_CAPTURE_CF;
361 extern IClassFactoryImpl DSOUND_FULLDUPLEX_CF;
362
363 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
364 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
365
366 /* primary.c */
367
368 HRESULT DSOUND_PrimaryCreate(IDirectSoundImpl *This);
369 HRESULT DSOUND_PrimaryDestroy(IDirectSoundImpl *This);
370 HRESULT DSOUND_PrimaryPlay(IDirectSoundImpl *This);
371 HRESULT DSOUND_PrimaryStop(IDirectSoundImpl *This);
372 HRESULT DSOUND_PrimaryGetPosition(IDirectSoundImpl *This, LPDWORD playpos, LPDWORD writepos);
373
374 /* buffer.c */
375
376 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
377                               DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix);
378
379 /* mixer.c */
380
381 void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
382 void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb);
383 void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos);
384 void DSOUND_WaveQueue(IDirectSoundImpl *dsound, DWORD mixq);
385 void DSOUND_PerformMix(IDirectSoundImpl *dsound);
386 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
387 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
388
389 /* sound3d.c */
390
391 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb);
392
393 #define STATE_STOPPED   0
394 #define STATE_STARTING  1
395 #define STATE_PLAYING   2
396 #define STATE_CAPTURING 2
397 #define STATE_STOPPING  3
398
399 #define DSOUND_FREQSHIFT (14)
400
401 extern IDirectSoundImpl* dsound;
402
403 extern HRESULT mmErr(UINT err);
404 extern void setup_dsound_options(void);