kernel32/tests: Better check the NT path returned by QueryFullProcessImageName().
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 /* Linux does not support better timing than 10ms */
23 #define DS_TIME_RES 2  /* Resolution of multimedia timer */
24 #define DS_TIME_DEL 10  /* Delay of multimedia timer callback, and duration of HEL fragment */
25
26 #include "wingdi.h"
27 #include "mmdeviceapi.h"
28 #include "audioclient.h"
29 #include "mmsystem.h"
30
31 #include "wine/list.h"
32
33 extern int ds_emuldriver DECLSPEC_HIDDEN;
34 extern int ds_hel_buflen DECLSPEC_HIDDEN;
35 extern int ds_snd_queue_max DECLSPEC_HIDDEN;
36 extern int ds_snd_shadow_maxsize DECLSPEC_HIDDEN;
37 extern int ds_default_sample_rate DECLSPEC_HIDDEN;
38 extern int ds_default_bits_per_sample DECLSPEC_HIDDEN;
39
40 /*****************************************************************************
41  * Predeclare the interface implementation structures
42  */
43 typedef struct IDirectSoundImpl              IDirectSoundImpl;
44 typedef struct IDirectSound_IUnknown         IDirectSound_IUnknown;
45 typedef struct IDirectSound_IDirectSound     IDirectSound_IDirectSound;
46 typedef struct IDirectSound8_IUnknown        IDirectSound8_IUnknown;
47 typedef struct IDirectSound8_IDirectSound    IDirectSound8_IDirectSound;
48 typedef struct IDirectSound8_IDirectSound8   IDirectSound8_IDirectSound8;
49 typedef struct IDirectSoundBufferImpl        IDirectSoundBufferImpl;
50 typedef struct IDirectSoundCaptureImpl       IDirectSoundCaptureImpl;
51 typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl;
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 DirectSoundDevice             DirectSoundDevice;
58 typedef struct DirectSoundCaptureDevice      DirectSoundCaptureDevice;
59
60 /* dsound_convert.h */
61 typedef void (*bitsconvertfunc)(const void *, void *, UINT, UINT, INT, UINT, UINT);
62 extern const bitsconvertfunc convertbpp[5][4] DECLSPEC_HIDDEN;
63 typedef void (*mixfunc)(const void *, void *, unsigned);
64 extern const mixfunc mixfunctions[4] DECLSPEC_HIDDEN;
65 typedef void (*normfunc)(const void *, void *, unsigned);
66 extern const normfunc normfunctions[4] DECLSPEC_HIDDEN;
67
68 typedef struct _DSVOLUMEPAN
69 {
70     DWORD       dwTotalLeftAmpFactor;
71     DWORD       dwTotalRightAmpFactor;
72     LONG        lVolume;
73     DWORD       dwVolAmpFactor;
74     LONG        lPan;
75     DWORD       dwPanLeftAmpFactor;
76     DWORD       dwPanRightAmpFactor;
77 } DSVOLUMEPAN,*PDSVOLUMEPAN;
78
79 /*****************************************************************************
80  * IDirectSoundDevice implementation structure
81  */
82 struct DirectSoundDevice
83 {
84     LONG                        ref;
85
86     GUID                        guid;
87     DSCAPS                      drvcaps;
88     DWORD                       priolevel;
89     PWAVEFORMATEX               pwfx;
90     UINT                        timerID, pwplay, pwqueue, prebuf, helfrags;
91     UINT64                      last_pos_bytes;
92     DWORD                       fraglen;
93     LPBYTE                      buffer;
94     DWORD                       writelead, buflen, state, playpos, mixpos;
95     int                         nrofbuffers;
96     IDirectSoundBufferImpl**    buffers;
97     RTL_RWLOCK                  buffer_list_lock;
98     CRITICAL_SECTION            mixlock;
99     IDirectSoundBufferImpl     *primary;
100     DWORD                       speaker_config;
101     LPBYTE                      tmp_buffer, mix_buffer;
102     DWORD                       tmp_buffer_len, mix_buffer_len;
103
104     DSVOLUMEPAN                 volpan;
105
106     mixfunc mixfunction;
107     normfunc normfunction;
108
109     /* DirectSound3DListener fields */
110     IDirectSound3DListenerImpl* listener;
111     DS3DLISTENER                ds3dl;
112     BOOL                        ds3dl_need_recalc;
113
114     IMMDevice *mmdevice;
115     IAudioClient *client;
116     IAudioClock *clock;
117     IAudioStreamVolume *volume;
118     IAudioRenderClient *render;
119
120     struct list entry;
121 };
122
123 /* reference counted buffer memory for duplicated buffer memory */
124 typedef struct BufferMemory
125 {
126     LONG                        ref;
127     LPBYTE                      memory;
128     struct list buffers;
129 } BufferMemory;
130
131 ULONG DirectSoundDevice_Release(DirectSoundDevice * device) DECLSPEC_HIDDEN;
132 HRESULT DirectSoundDevice_Initialize(
133     DirectSoundDevice ** ppDevice,
134     LPCGUID lpcGUID) DECLSPEC_HIDDEN;
135 HRESULT DirectSoundDevice_AddBuffer(
136     DirectSoundDevice * device,
137     IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
138 HRESULT DirectSoundDevice_RemoveBuffer(
139     DirectSoundDevice * device,
140     IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
141 HRESULT DirectSoundDevice_GetCaps(DirectSoundDevice * device, LPDSCAPS lpDSCaps) DECLSPEC_HIDDEN;
142 HRESULT DirectSoundDevice_CreateSoundBuffer(
143     DirectSoundDevice * device,
144     LPCDSBUFFERDESC dsbd,
145     LPLPDIRECTSOUNDBUFFER ppdsb,
146     LPUNKNOWN lpunk,
147     BOOL from8) DECLSPEC_HIDDEN;
148 HRESULT DirectSoundDevice_DuplicateSoundBuffer(
149     DirectSoundDevice * device,
150     LPDIRECTSOUNDBUFFER psb,
151     LPLPDIRECTSOUNDBUFFER ppdsb) DECLSPEC_HIDDEN;
152 HRESULT DirectSoundDevice_SetCooperativeLevel(
153     DirectSoundDevice * devcie,
154     HWND hwnd,
155     DWORD level) DECLSPEC_HIDDEN;
156 HRESULT DirectSoundDevice_Compact(DirectSoundDevice * device) DECLSPEC_HIDDEN;
157 HRESULT DirectSoundDevice_GetSpeakerConfig(
158     DirectSoundDevice * device,
159     LPDWORD lpdwSpeakerConfig) DECLSPEC_HIDDEN;
160 HRESULT DirectSoundDevice_SetSpeakerConfig(
161     DirectSoundDevice * device,
162     DWORD config) DECLSPEC_HIDDEN;
163 HRESULT DirectSoundDevice_VerifyCertification(DirectSoundDevice * device,
164     LPDWORD pdwCertified) DECLSPEC_HIDDEN;
165
166 /*****************************************************************************
167  * IDirectSoundBuffer implementation structure
168  */
169 struct IDirectSoundBufferImpl
170 {
171     IDirectSoundBuffer8         IDirectSoundBuffer8_iface;
172     LONG                        numIfaces; /* "in use interfaces" refcount */
173     LONG                        ref;
174     /* IDirectSoundBufferImpl fields */
175     DirectSoundDevice*          device;
176     RTL_RWLOCK                  lock;
177     PWAVEFORMATEX               pwfx;
178     BufferMemory*               buffer;
179     LPBYTE                      tmp_buffer;
180     DWORD                       playflags,state,leadin;
181     DWORD                       writelead,buflen;
182     DWORD                       nAvgBytesPerSec;
183     DWORD                       freq, tmp_buffer_len, max_buffer_len;
184     DSVOLUMEPAN                 volpan;
185     DSBUFFERDESC                dsbd;
186     /* used for frequency conversion (PerfectPitch) */
187     ULONG                       freqneeded, freqAdjust, freqAcc, freqAccNext, resampleinmixer;
188     /* used for mixing */
189     DWORD                       primary_mixpos, buf_mixpos, sec_mixpos;
190
191     /* IDirectSoundNotifyImpl fields */
192     IDirectSoundNotifyImpl*     notify;
193     LPDSBPOSITIONNOTIFY         notifies;
194     int                         nrofnotifies;
195
196     /* DirectSound3DBuffer fields */
197     IDirectSound3DBufferImpl*   ds3db;
198     DS3DBUFFER                  ds3db_ds3db;
199     LONG                        ds3db_lVolume;
200     BOOL                        ds3db_need_recalc;
201
202     /* IKsPropertySet fields */
203     IKsBufferPropertySetImpl*   iks;
204     bitsconvertfunc convert;
205     struct list entry;
206 };
207
208 HRESULT IDirectSoundBufferImpl_Create(
209     DirectSoundDevice *device,
210     IDirectSoundBufferImpl **ppdsb,
211     LPCDSBUFFERDESC dsbd) DECLSPEC_HIDDEN;
212 HRESULT IDirectSoundBufferImpl_Destroy(
213     IDirectSoundBufferImpl *pdsb) DECLSPEC_HIDDEN;
214 HRESULT IDirectSoundBufferImpl_Duplicate(
215     DirectSoundDevice *device,
216     IDirectSoundBufferImpl **ppdsb,
217     IDirectSoundBufferImpl *pdsb) DECLSPEC_HIDDEN;
218 void secondarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
219
220 /*****************************************************************************
221  * DirectSoundCaptureDevice implementation structure
222  */
223 struct DirectSoundCaptureDevice
224 {
225     GUID                               guid;
226     LONG                               ref;
227
228     DSCCAPS                            drvcaps;
229
230     LPBYTE                             buffer;
231     DWORD                              buflen, write_pos_bytes;
232
233     PWAVEFORMATEX                      pwfx;
234
235     IDirectSoundCaptureBufferImpl*     capture_buffer;
236     DWORD                              state;
237     UINT timerID;
238     CRITICAL_SECTION                   lock;
239
240     IMMDevice *mmdevice;
241     IAudioClient *client;
242     IAudioCaptureClient *capture;
243
244     struct list entry;
245 };
246
247 /*****************************************************************************
248  * IDirectSoundCaptureBuffer implementation structure
249  */
250 struct IDirectSoundCaptureBufferImpl
251 {
252     /* IUnknown fields */
253     const IDirectSoundCaptureBuffer8Vtbl *lpVtbl;
254     LONG                                ref;
255
256     /* IDirectSoundCaptureBufferImpl fields */
257     DirectSoundCaptureDevice*           device;
258     /* FIXME: don't need this */
259     LPDSCBUFFERDESC                     pdscbd;
260     DWORD                               flags;
261
262     /* IDirectSoundCaptureNotifyImpl fields */
263     IDirectSoundCaptureNotifyImpl*      notify;
264     LPDSBPOSITIONNOTIFY                 notifies;
265     int                                 nrofnotifies;
266 };
267
268 /*****************************************************************************
269  *  IDirectSound3DListener implementation structure
270  */
271 struct IDirectSound3DListenerImpl
272 {
273     /* IUnknown fields */
274     const IDirectSound3DListenerVtbl *lpVtbl;
275     LONG                        ref;
276     /* IDirectSound3DListenerImpl fields */
277     DirectSoundDevice*          device;
278 };
279
280 HRESULT IDirectSound3DListenerImpl_Create(
281     DirectSoundDevice           *device,
282     IDirectSound3DListenerImpl **pdsl) DECLSPEC_HIDDEN;
283
284 /*****************************************************************************
285  *  IKsBufferPropertySet implementation structure
286  */
287 struct IKsBufferPropertySetImpl
288 {
289     /* IUnknown fields */
290     const IKsPropertySetVtbl   *lpVtbl;
291     LONG                        ref;
292     /* IKsPropertySetImpl fields */
293     IDirectSoundBufferImpl*     dsb;
294 };
295
296 HRESULT IKsBufferPropertySetImpl_Create(
297     IDirectSoundBufferImpl *dsb,
298     IKsBufferPropertySetImpl **piks) DECLSPEC_HIDDEN;
299 HRESULT IKsBufferPropertySetImpl_Destroy(
300     IKsBufferPropertySetImpl *piks) DECLSPEC_HIDDEN;
301
302 HRESULT IKsPrivatePropertySetImpl_Create(REFIID riid, IKsPropertySet **piks) DECLSPEC_HIDDEN;
303
304 /*****************************************************************************
305  * IDirectSound3DBuffer implementation structure
306  */
307 struct IDirectSound3DBufferImpl
308 {
309     /* IUnknown fields */
310     const IDirectSound3DBufferVtbl *lpVtbl;
311     LONG                        ref;
312     /* IDirectSound3DBufferImpl fields */
313     IDirectSoundBufferImpl*     dsb;
314 };
315
316 HRESULT IDirectSound3DBufferImpl_Create(
317     IDirectSoundBufferImpl *dsb,
318     IDirectSound3DBufferImpl **pds3db) DECLSPEC_HIDDEN;
319 HRESULT IDirectSound3DBufferImpl_Destroy(
320     IDirectSound3DBufferImpl *pds3db) DECLSPEC_HIDDEN;
321
322 /*******************************************************************************
323  */
324
325 /* dsound.c */
326
327 HRESULT DSOUND_Create(REFIID riid, LPDIRECTSOUND *ppDS) DECLSPEC_HIDDEN;
328 HRESULT DSOUND_Create8(REFIID riid, LPDIRECTSOUND8 *ppDS) DECLSPEC_HIDDEN;
329
330 /* primary.c */
331
332 DWORD DSOUND_fraglen(DWORD nSamplesPerSec, DWORD nBlockAlign) DECLSPEC_HIDDEN;
333 HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device) DECLSPEC_HIDDEN;
334 HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device) DECLSPEC_HIDDEN;
335 HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device) DECLSPEC_HIDDEN;
336 HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device) DECLSPEC_HIDDEN;
337 HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos) DECLSPEC_HIDDEN;
338 LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
339 HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) DECLSPEC_HIDDEN;
340 HRESULT primarybuffer_create(DirectSoundDevice *device, IDirectSoundBufferImpl **ppdsb,
341     const DSBUFFERDESC *dsbd) DECLSPEC_HIDDEN;
342 void primarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
343 HRESULT primarybuffer_SetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
344
345 /* duplex.c */
346  
347 HRESULT DSOUND_FullDuplexCreate(REFIID riid, LPDIRECTSOUNDFULLDUPLEX* ppDSFD) DECLSPEC_HIDDEN;
348
349 /* mixer.c */
350 DWORD DSOUND_bufpos_to_mixpos(const DirectSoundDevice* device, DWORD pos) DECLSPEC_HIDDEN;
351 void DSOUND_CheckEvent(const IDirectSoundBufferImpl *dsb, DWORD playpos, int len) DECLSPEC_HIDDEN;
352 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
353 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
354 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
355 void DSOUND_MixToTemporary(const IDirectSoundBufferImpl *dsb, DWORD writepos, DWORD mixlen, BOOL inmixer) DECLSPEC_HIDDEN;
356 DWORD DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl *dsb, DWORD secpos, DWORD secmixpos, DWORD* overshot) DECLSPEC_HIDDEN;
357
358 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) DECLSPEC_HIDDEN;
359
360 /* sound3d.c */
361
362 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
363
364 /* capture.c */
365  
366 HRESULT DSOUND_CaptureCreate(REFIID riid, LPDIRECTSOUNDCAPTURE *ppDSC) DECLSPEC_HIDDEN;
367 HRESULT DSOUND_CaptureCreate8(REFIID riid, LPDIRECTSOUNDCAPTURE8 *ppDSC8) DECLSPEC_HIDDEN;
368
369 #define STATE_STOPPED   0
370 #define STATE_STARTING  1
371 #define STATE_PLAYING   2
372 #define STATE_CAPTURING 2
373 #define STATE_STOPPING  3
374
375 #define DSOUND_FREQSHIFT (20)
376
377 extern CRITICAL_SECTION DSOUND_renderers_lock DECLSPEC_HIDDEN;
378 extern CRITICAL_SECTION DSOUND_capturers_lock DECLSPEC_HIDDEN;
379 extern struct list DSOUND_capturers DECLSPEC_HIDDEN;
380 extern struct list DSOUND_renderers DECLSPEC_HIDDEN;
381
382 extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
383 extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
384
385 extern WCHAR wine_vxd_drv[] DECLSPEC_HIDDEN;
386
387 HRESULT mmErr(UINT err) DECLSPEC_HIDDEN;
388 void setup_dsound_options(void) DECLSPEC_HIDDEN;
389 const char * dumpCooperativeLevel(DWORD level) DECLSPEC_HIDDEN;
390
391 HRESULT get_mmdevice(EDataFlow flow, const GUID *tgt, IMMDevice **device) DECLSPEC_HIDDEN;
392
393 BOOL DSOUND_check_supported(IAudioClient *client, DWORD rate,
394         DWORD depth, WORD channels) DECLSPEC_HIDDEN;
395 UINT DSOUND_create_timer(LPTIMECALLBACK cb, DWORD_PTR user) DECLSPEC_HIDDEN;
396 HRESULT enumerate_mmdevices(EDataFlow flow, GUID *guids,
397         LPDSENUMCALLBACKW cb, void *user) DECLSPEC_HIDDEN;